techPolicyPublishs.jsx 25 KB

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