inquiry.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. import React from 'react';
  2. import '../../leftTab.less';
  3. import ReactDom from 'react-dom';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. import Editors from '../../../richTextEditors'
  7. import '../content.less';
  8. import moment from 'moment';
  9. import { citySelect,provinceList,areaSelect,provinceSelect,addressList} from '../../../NewDicProvinceList';
  10. import { Form,Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload,Popconfirm,AutoComplete,Tabs,Checkbox,Tree,Cascader} from 'antd';
  11. import {patternOrganization,conditionOrganization,intentionalService,messageType,designatedObjects,socialAttributeS,industry,socialAttribute,industryS,designatedObjectse,auditStatusL} from '../../../dataDic.js';
  12. import {
  13. beforeUpload,
  14. getBase64,
  15. getprovince,
  16. getauditStatus,
  17. ShowModal
  18. } from "../../../tools.js";
  19. const TabPane = Tabs.TabPane;
  20. const TreeNodet = Tree.TreeNode;
  21. const CheckboxGroup = Checkbox.Group;
  22. import ShowModalDiv from "@/showModal.jsx";
  23. const Avatar = React.createClass({
  24. getInitialState() {
  25. return {
  26. imageUrl: ''
  27. }
  28. },
  29. handleChange(info) {
  30. if (info.file.status === 'done') {
  31. // Get this url from response in real world.
  32. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  33. this.props.urlData(info.file.response.data);
  34. }
  35. },
  36. componentWillReceiveProps(nextProps) {
  37. if (this.props.visible && !nextProps.visible) {
  38. this.state.imageUrl = null;
  39. };
  40. },
  41. render() {
  42. const imageUrl = this.state.imageUrl;
  43. return (
  44. <Upload
  45. className="avatar-uploader"
  46. name={this.props.name}
  47. showUploadList={false}
  48. action={globalConfig.context + "/api/admin/news/upload"}
  49. data={{ 'sign': 'news_title_picture' }}
  50. beforeUpload={beforeUpload}
  51. onChange={this.handleChange} >
  52. {
  53. (imageUrl || this.props.imageUrl) ?
  54. <img src={imageUrl || this.props.imageUrl} role="presentation" id={this.props.name} /> :
  55. <Icon type="plus" className="avatar-uploader-trigger" />
  56. }
  57. </Upload>
  58. );
  59. }
  60. });
  61. const Inquiry=React.createClass({
  62. loadData(pageNo, theType) {
  63. this.setState({
  64. loading: true,
  65. ispage:pageNo,
  66. });
  67. $.ajax({
  68. method: "get",
  69. dataType: "json",
  70. crossDomain: false,
  71. url: globalConfig.context + '/api/admin/news/list',
  72. data: {
  73. pageNo: pageNo || 1,
  74. pageSize: this.state.pagination.pageSize,
  75. type: theType || 1, //新闻类型
  76. title: this.state.searchTitle,
  77. author: this.state.searchAuthor,
  78. startCreateTime: this.state.startDate, //新闻开始时间 yyyy-MM-dd
  79. endCreateTime: this.state.endDate, //新闻结束时间 yyyy-MM-dd
  80. source: this.state.searchSource,
  81. hot: this.state.searchHot, //是否放在首页
  82. },
  83. success: function (data) {
  84. ShowModal(this);
  85. let theArr = [];
  86. if (!data.data || !data.data.list) {
  87. if (data.error && data.error.length) {
  88. message.warning(data.error[0].message);
  89. };
  90. } else {
  91. for (let i = 0; i < data.data.list.length; i++) {
  92. let thisdata = data.data.list[i];
  93. theArr.push({
  94. key: i,
  95. id: thisdata.id ? thisdata.id.toString() : null,
  96. createTime: thisdata.createTime,
  97. editTime: thisdata.editTime,
  98. title: thisdata.title,
  99. titleImg: thisdata.titleImg,
  100. author: thisdata.author,
  101. type: thisdata.type,
  102. hot: thisdata.hot,
  103. source: thisdata.source,
  104. sourceUrl: thisdata.sourceUrl,
  105. summary: thisdata.summary,
  106. content: thisdata.content,
  107. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  108. auditStatus:thisdata.auditStatus,
  109. });
  110. };
  111. this.state.pagination.current = data.data.pageNo;
  112. this.state.pagination.total = data.data.totalCount;
  113. };
  114. this.setState({
  115. tableData: theArr,
  116. pagination: this.state.pagination
  117. });
  118. }.bind(this),
  119. }).always(function () {
  120. this.setState({
  121. loading: false
  122. });
  123. }.bind(this));
  124. },
  125. loadDetailData() {
  126. this.setState({
  127. loading: true
  128. });
  129. $.ajax({
  130. method: "get",
  131. dataType: "json",
  132. crossDomain: false,
  133. url: globalConfig.context + '/api/admin/news/detail',
  134. data: {
  135. id: this.state.RowData.id //新闻主键ID(数字类型,非字符串)
  136. },
  137. success: function (data) {
  138. let theObj = {};
  139. if (!data.data) {
  140. if (data.error && data.error.length) {
  141. message.warning(data.error[0].message);
  142. }
  143. } else {
  144. theObj = data.data;
  145. if(theObj.provinceId==null||theObj.provinceId==''){
  146. theObj.provinceId=11
  147. }
  148. };
  149. this.setState({
  150. RowData: theObj,
  151. });
  152. }.bind(this),
  153. }).always(function () {
  154. this.setState({
  155. loading: false
  156. });
  157. }.bind(this));
  158. },
  159. getInitialState() {
  160. return {
  161. loading: false,
  162. visible: false,
  163. callnub:'1',
  164. selectedRowKeys: [],
  165. selectedRows: [],
  166. keysObj: {},
  167. RowData: {},
  168. pagination: {
  169. defaultCurrent: 1,
  170. defaultPageSize: 10,
  171. showQuickJumper: true,
  172. pageSize: 10,
  173. onChange: function (page) {
  174. this.loadData(page,this.state.callnub);
  175. }.bind(this),
  176. showTotal: function (total) {
  177. return '共' + total + '条数据';
  178. }
  179. },
  180. columns: [
  181. {
  182. title: '标题',
  183. dataIndex: 'title',
  184. key: 'title',
  185. width: '20%'
  186. }, {
  187. title: '发布时间',
  188. dataIndex: 'createTimeFormattedDate',
  189. key: 'createTimeFormattedDate',
  190. }, {
  191. title: '作者',
  192. dataIndex: 'author',
  193. key: 'author',
  194. }, {
  195. title: '审核状态',
  196. dataIndex: 'auditStatus',
  197. key: 'auditStatus',
  198. render: text => { return getauditStatus(text) }
  199. }, {
  200. title: '来源',
  201. dataIndex: 'source',
  202. key: 'source',
  203. }, {
  204. title: '简介',
  205. dataIndex: 'summary',
  206. key: 'summary',
  207. width: '50%'
  208. }
  209. ],
  210. list:provinceList,
  211. tableData: []
  212. };
  213. },
  214. tableRowClick(record, index) {
  215. this.state.RowData = record;
  216. this.loadDetailData();
  217. this.setState({
  218. visible: true
  219. });
  220. },
  221. componentWillMount() {
  222. this.loadData(1,1);
  223. },
  224. componentWillReceiveProps(nextProps) {
  225. if (this.props.newsType != nextProps.newsType) {
  226. this.state.searchTitle = undefined;
  227. this.state.searchAuthor = undefined;
  228. this.state.startDate = undefined;
  229. this.state.endDate = undefined;
  230. this.state.searchSource = undefined;
  231. this.state.searchHot = undefined;
  232. this.loadData(1, nextProps.newsType);
  233. };
  234. },
  235. callback(e) {
  236. this.setState({
  237. callnub: e,
  238. })
  239. if(e == 1) {
  240. this.setState({
  241. })
  242. this.reset();
  243. this.loadData(1,1);
  244. }
  245. if(e == 2) {
  246. this.setState({
  247. })
  248. this.reset();
  249. this.loadData(1,2);
  250. }
  251. if(e == 3) {
  252. this.setState({
  253. })
  254. this.reset();
  255. this.loadData(1,3);
  256. }
  257. if(e == 4) {
  258. this.setState({
  259. })
  260. this.reset();
  261. this.loadData(1,4);
  262. }
  263. if(e == 5) {
  264. this.setState({
  265. })
  266. this.reset();
  267. this.loadData(1,5);
  268. }
  269. },
  270. submit() {
  271. if (!this.state.RowData.title) {
  272. message.warning('必须填写一个标题!');
  273. return;
  274. };
  275. if (!this.state.RowData.createTimeFormattedDate) {
  276. message.warning('必须选择一个发布时间!');
  277. return;
  278. };
  279. if (!this.state.RowData.author) {
  280. message.warning('必须填写一个作者!');
  281. return;
  282. };
  283. this.setState({
  284. loading: true
  285. });
  286. $.ajax({
  287. method: "post",
  288. dataType: "json",
  289. crossDomain: false,
  290. url: globalConfig.context + (this.state.RowData.id ? '/api/admin/news/update' : '/api/admin/news/add'),
  291. data: {
  292. id: this.state.RowData.id || null, //主键,如果不填主键则为新增记录,填主键则为更新
  293. title: this.state.RowData.title,
  294. titleImg: this.state.RowData.titleImg,
  295. author: this.state.RowData.author,
  296. type: this.state.callnub,
  297. hot: this.state.RowData.hot || 0,
  298. source: this.state.RowData.source,
  299. sourceUrl: this.state.RowData.sourceUrl,
  300. summary: this.state.RowData.summary,
  301. content: this.state.RowData.content,
  302. createTimeFormattedDate: this.state.RowData.createTimeFormattedDate,
  303. provinceId: this.state.RowData.provinceId,
  304. },
  305. success: function (data) {
  306. if (data.error && data.error.length) {
  307. message.warning(data.error[0].message);
  308. } else {
  309. message.success('保存成功!');
  310. this.setState({ visible: false });
  311. this.loadData(this.state.ispage,this.state.callnub);
  312. };
  313. }.bind(this),
  314. }).always(function () {
  315. this.setState({
  316. loading: false
  317. });
  318. }.bind(this));
  319. },
  320. delectRow() {
  321. let deletedIds = [];
  322. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  323. let rowItem = this.state.selectedRows[idx];
  324. if (rowItem.id) {
  325. deletedIds.push(rowItem.id)
  326. };
  327. };
  328. this.setState({
  329. selectedRowKeys: [],
  330. loading: deletedIds.length > 0
  331. });
  332. $.ajax({
  333. method: "POST",
  334. dataType: "json",
  335. crossDomain: false,
  336. url: globalConfig.context + "/api/admin/news/delete",
  337. data: {
  338. ids: deletedIds
  339. }
  340. }).done(function (data) {
  341. if (data.error && data.error.length) {
  342. message.warning(data.error[0].message);
  343. } else {
  344. message.success('删除成功!');
  345. };
  346. this.setState({
  347. loading: false,
  348. });
  349. this.loadData(this.state.ispage,this.state.callnub);
  350. }.bind(this));
  351. },
  352. reset() {
  353. this.state.searchTitle = undefined;
  354. this.state.searchAuthor = undefined;
  355. this.state.startDate = undefined;
  356. this.state.endDate = undefined;
  357. this.state.searchSource = undefined;
  358. this.state.searchHot = undefined;
  359. },
  360. cleanCache(sign) {
  361. this.setState({
  362. loading: true
  363. });
  364. $.ajax({
  365. method: "post",
  366. dataType: "json",
  367. crossDomain: false,
  368. url: globalConfig.context + '/api/admin/news/cleanCache',
  369. data: {
  370. 'cacheKey': sign
  371. },
  372. success: function (data) {
  373. if (data.error && data.error.length) {
  374. message.warning(data.error[0].message);
  375. } else {
  376. message.success('清除缓存成功!');
  377. };
  378. }.bind(this),
  379. }).always(function () {
  380. this.setState({
  381. loading: false
  382. });
  383. }.bind(this));
  384. },
  385. clearCache() {
  386. if (!this.state.searchKey) {
  387. message.warning('必须选择一个位置!');
  388. return;
  389. };
  390. this.setState({
  391. loading: true
  392. });
  393. $.ajax({
  394. method: "get",
  395. dataType: "json",
  396. crossDomain: false,
  397. url: globalConfig.context + '/api/admin/banners/clearCache',
  398. data: {
  399. key: this.state.searchKey // 位置标示,必填
  400. },
  401. success: function (data) {
  402. if (data.error && data.error.length) {
  403. message.warning(data.error[0].message);
  404. } else {
  405. message.success('更新缓存成功!');
  406. };
  407. }.bind(this),
  408. }).always(function () {
  409. this.setState({
  410. loading: false
  411. });
  412. }.bind(this));
  413. },
  414. render(){
  415. const rowSelection = {
  416. selectedRowKeys: this.state.selectedRowKeys,
  417. onChange: (selectedRowKeys, selectedRows) => {
  418. this.setState({
  419. selectedRows: selectedRows.slice(-1),
  420. selectedRowKeys: selectedRowKeys.slice(-1)
  421. });
  422. }
  423. };
  424. const hasSelected = this.state.selectedRowKeys.length > 0;
  425. return (
  426. <div className="admin-content">
  427. <ShowModalDiv ShowModal={this.state.showModal} />
  428. <div className="admin-content-search">
  429. <Input
  430. placeholder="标题"
  431. style={{
  432. width: 200,
  433. marginBottom: "10px",
  434. marginRight: "10px"
  435. }}
  436. value={this.state.searchTitle}
  437. onChange={e => {
  438. this.setState({ searchTitle: e.target.value });
  439. }}
  440. />
  441. <Input
  442. placeholder="作者"
  443. style={{ width: 100, marginRight: "10px" }}
  444. value={this.state.searchAuthor}
  445. onChange={e => {
  446. this.setState({ searchAuthor: e.target.value });
  447. }}
  448. />
  449. <Input
  450. placeholder="来源"
  451. style={{ width: 100, marginRight: "10px" }}
  452. value={this.state.searchSource}
  453. onChange={e => {
  454. this.setState({ searchSource: e.target.value });
  455. }}
  456. />
  457. {this.props.newsType == 2 || this.props.newsType == 3 ? (
  458. <Select
  459. placeholder="显示在首页"
  460. style={{ width: 100, marginRight: "10px" }}
  461. value={this.state.searchHot}
  462. onChange={e => {
  463. this.setState({ searchHot: e });
  464. }}
  465. >
  466. <Select.Option value="0">不显示</Select.Option>
  467. <Select.Option value="1">显示</Select.Option>
  468. </Select>
  469. ) : (
  470. <span></span>
  471. )}
  472. <span style={{ marginRight: "10px" }}>发布时间</span>
  473. <DatePicker
  474. style={{ width: 110, marginRight: "10px" }}
  475. format="YYYY-MM-DD"
  476. placeholder="选择开始时间"
  477. value={
  478. this.state.startDate
  479. ? moment(this.state.startDate, "YYYY-MM-DD")
  480. : undefined
  481. }
  482. onChange={(t, str) => {
  483. this.setState({ startDate: str });
  484. }}
  485. />
  486. <span style={{ marginRight: "10px" }}>到</span>
  487. <DatePicker
  488. style={{ width: 110, marginRight: "10px" }}
  489. format="YYYY-MM-DD"
  490. placeholder="选择结束时间"
  491. value={
  492. this.state.endDate
  493. ? moment(this.state.endDate, "YYYY-MM-DD")
  494. : undefined
  495. }
  496. onChange={(t, str) => {
  497. this.setState({ endDate: str });
  498. }}
  499. />
  500. <Button
  501. type="primary"
  502. onClick={() => {
  503. this.loadData(1, this.state.callnub);
  504. }}
  505. style={{ marginRight: "10px" }}
  506. >
  507. 搜索
  508. </Button>
  509. <Button onClick={this.reset} style={{ marginRight: "10px" }}>
  510. 重置
  511. </Button>
  512. <Button type="ghost" onClick={this.clearCache}>
  513. 清除缓存
  514. </Button>
  515. </div>
  516. <div className="clearfix" style={{ marginLeft: "20px" }}>
  517. <Tabs
  518. onChange={this.callback}
  519. type="card"
  520. activeKey={this.state.callnub}
  521. style={{
  522. paddingLeft: "15px",
  523. paddingRight: "15px",
  524. marginRight: "20px"
  525. }}
  526. >
  527. <TabPane tab="科技快讯" key="1"></TabPane>
  528. <TabPane tab="交易问题" key="2"></TabPane>
  529. <TabPane tab="技淘动态" key="3"></TabPane>
  530. <TabPane tab="国家政策" key="4"></TabPane>
  531. <TabPane tab="地方政策" key="5"></TabPane>
  532. </Tabs>
  533. </div>
  534. <Spin spinning={this.state.loading}>
  535. <Table
  536. size="middle"
  537. className="no-all-select"
  538. columns={this.state.columns}
  539. dataSource={this.state.tableData}
  540. pagination={this.state.pagination}
  541. rowSelection={rowSelection}
  542. style={{
  543. cursor: 'pointer',
  544. }}
  545. onRowClick={this.tableRowClick}
  546. />
  547. </Spin>
  548. <Modal
  549. title="新闻详情"
  550. width={1000}
  551. className="news-modal"
  552. visible={this.state.visible}
  553. maskClosable={false}
  554. footer={null}
  555. afterClose={() => {
  556. this.state.RowData = {};
  557. }}
  558. onCancel={() => {
  559. this.setState({ visible: false });
  560. }}
  561. >
  562. <Spin spinning={this.state.loading}>
  563. <div className="clearfix">
  564. <div className="modal-box">
  565. <span className="modal-box-title">新闻标题 : </span>
  566. <div className="modal-box-detail">
  567. <span>{this.state.RowData.title}</span>
  568. </div>
  569. </div>
  570. <div className="modal-box">
  571. <span className="modal-box-title">简介 : </span>
  572. <div className="modal-box-detail">
  573. <span>{this.state.RowData.summary}</span>
  574. </div>
  575. </div>
  576. <div className="modal-box">
  577. <span className="modal-box-title">来源:</span>
  578. <div className="modal-box-detail">
  579. <span>{this.state.RowData.source}</span>
  580. </div>
  581. </div>
  582. <div className="modal-box">
  583. <span className="modal-box-title">来源链接 : </span>
  584. <div className="modal-box-detail">
  585. <span>{this.state.RowData.sourceUrl}</span>
  586. </div>
  587. </div>
  588. <div
  589. className="modal-box"
  590. style={{ position: "absolute", right: "0", width: "480px" }}
  591. >
  592. <span className="modal-box-title">标题图片</span>
  593. <div
  594. className="modal-box-detail clearfix"
  595. style={{ width: "360px" }}
  596. >
  597. <Avatar
  598. sign={"news_title_picture"}
  599. visible={this.state.visible}
  600. imageUrl={
  601. this.state.RowData.titleImg
  602. ? globalConfig.avatarHost +
  603. "/upload" +
  604. this.state.RowData.titleImg
  605. : null
  606. }
  607. urlData={url => {
  608. this.state.RowData.titleImg = url;
  609. }}
  610. />
  611. </div>
  612. </div>
  613. </div>
  614. <div className="clearfix">
  615. <div className="modal-box news-box">
  616. <span className="modal-box-title">作者 : </span>
  617. <div className="modal-box-detail">
  618. <span>{this.state.RowData.author}</span>
  619. </div>
  620. </div>
  621. <div className="modal-box news-box">
  622. <span className="modal-box-title">发布时间 : </span>
  623. <div className="modal-box-detail">
  624. <span>{this.state.RowData.createTimeFormattedDate}</span>
  625. </div>
  626. </div>
  627. {this.props.newsType == 2 || this.props.newsType == 3 ? (
  628. <div className="modal-box news-box">
  629. <span className="modal-box-title">发布在首页</span>
  630. <div className="modal-box-detail">
  631. <Radio.Group
  632. value={this.state.RowData.hot}
  633. onChange={e => {
  634. this.state.RowData.hot = e.target.value;
  635. this.setState({ RowData: this.state.RowData });
  636. }}
  637. >
  638. <Radio value={0}>否</Radio>
  639. <Radio value={1}>是</Radio>
  640. </Radio.Group>
  641. </div>
  642. </div>
  643. ) : (
  644. <div></div>
  645. )}
  646. </div>
  647. <div className="modal-box">
  648. <span className="modal-box-title">选择省份 : </span>
  649. <span>{getprovince(this.state.RowData.provinceId)}</span>
  650. </div>
  651. <Editors
  652. textContent={this.state.RowData.content}
  653. uploadUrl={"/api/admin/news/upload"}
  654. uploadSign={"news_content_picture"}
  655. handleRichText={value => {
  656. this.state.RowData.content = value;
  657. }}
  658. visible={this.state.visible}
  659. readonly
  660. />
  661. </Spin>
  662. </Modal>
  663. </div>
  664. );
  665. }
  666. })
  667. export default Inquiry;