newList.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import 'react-quill/dist/quill.bubble.css';
  4. import moment from 'moment';
  5. import {Form,Icon,Button,Input,Select,Spin,Table,message,DatePicker,Modal,Upload,Popconfirm,Cascader,InputNumber,Radio,TimePicker,Tabs} from 'antd';
  6. import {areaSelect, getProvince} from '@/NewDicProvinceList';//省市区
  7. import { getGameState, splitUrl, getprovince,getBuyAuditType , getStatuslist, getLvl,beforeUploadFile,getSecretType} from '@/tools.js';
  8. import Editors from '@/richTextEditors';
  9. const PicturesWall = React.createClass({
  10. getInitialState() {
  11. return {
  12. previewVisible: false,
  13. previewImage: '',
  14. fileList: this.props.pictureUrl,
  15. }
  16. },
  17. getDefaultProps(){
  18. return{
  19. changeClick:this.modifyChange
  20. }
  21. },
  22. handleCancel() {
  23. this.setState({ previewVisible: false })
  24. },
  25. handlePreview(file) {
  26. this.setState({
  27. previewImage: file.url || file.thumbUrl,
  28. previewVisible: true,
  29. });
  30. },
  31. handleChange(info) {
  32. let fileList = info.fileList;
  33. this.setState({ fileList });
  34. this.props.fileList(fileList);
  35. },
  36. componentWillReceiveProps(nextProps) {
  37. this.state.fileList = nextProps.pictureUrl;
  38. },
  39. render() {
  40. const { previewVisible, previewImage, fileList } = this.state;
  41. const uploadButton = (
  42. <div>
  43. <Icon type="plus" />
  44. <div className="ant-upload-text">点击上传</div>
  45. </div>
  46. );
  47. return (
  48. <div style={{display:"inline-block"}}>
  49. <Upload
  50. beforeUpload={beforeUploadFile}
  51. action={globalConfig.context + "/api/admin/news/upload"}
  52. data={{ 'sign': 'news_title_picture' }}
  53. listType="picture-card"
  54. fileList={fileList}
  55. onPreview={this.handlePreview}
  56. onChange={this.handleChange} >
  57. {fileList.length >= 18 ? null : uploadButton}
  58. </Upload>
  59. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  60. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  61. </Modal>
  62. </div>
  63. );
  64. }
  65. });
  66. //主体
  67. const NewList = Form.create()(
  68. React.createClass({
  69. loadData(pageNo) {
  70. this.state.data = [];
  71. this.setState({
  72. loading: true,
  73. page: pageNo
  74. });
  75. $.ajax({
  76. method: 'get',
  77. dataType: 'json',
  78. crossDomain: false,
  79. url: globalConfig.context + '/api/admin/news/list',
  80. data: {
  81. pageNo: pageNo || 1,
  82. pageSize: this.state.pagination.pageSize,
  83. type: this.state.typeSearch,
  84. title: this.state.titleSearch,
  85. releaseStatus: this.state.releaseStatusSearch,
  86. startCreateTime: this.state.startCreateTimeSearch,
  87. endCreateTime: this.state.endCreateTimeSearch,
  88. },
  89. success: function(data) {
  90. let theArr = [];
  91. if (!data.data || !data.data.list) {
  92. if (data.error && data.error.length) {
  93. message.warning(data.error[0].message);
  94. }
  95. } else {
  96. for (let i = 0; i < data.data.list.length; i++) {
  97. let thisdata = data.data.list[i];
  98. theArr.push({
  99. key: i,
  100. id: thisdata.id,
  101. title: thisdata.title,
  102. type: thisdata.type,
  103. author: thisdata.author,
  104. releaseStatus: thisdata.releaseStatus,
  105. topNumber: thisdata.topNumber,
  106. sortNumber: thisdata.sortNumber,
  107. hotspot: thisdata.hotspot,
  108. releaseDate:thisdata.releaseDate,
  109. userName:thisdata.userName,
  110. });
  111. }
  112. this.state.pagination.current = data.data.pageNo;
  113. this.state.pagination.total = data.data.totalCount;
  114. }
  115. this.setState({
  116. dataSource: theArr,
  117. pagination: this.state.pagination
  118. });
  119. }.bind(this)
  120. }).always(
  121. function() {
  122. this.setState({
  123. loading: false
  124. });
  125. }.bind(this)
  126. );
  127. },
  128. getInitialState() {
  129. return {
  130. loading: false,
  131. flag: true,
  132. timesArr:[],
  133. totalData:{
  134. mark: false,
  135. content:"<p></p>",
  136. },
  137. classList: [],
  138. titleImg: [],
  139. pagination: {
  140. defaultCurrent: 1,
  141. defaultPageSize: 10,
  142. showQuickJumper: true,
  143. pageSize: 10,
  144. onChange: function(page) {
  145. this.loadData(page);
  146. this.setState({
  147. selectedRowKeys: []
  148. });
  149. }.bind(this),
  150. showTotal: function(total) {
  151. return '共' + total + '条数据';
  152. }
  153. },
  154. columns: [
  155. {
  156. title: '序号',
  157. dataIndex: 'key',
  158. key: 'key'
  159. },
  160. {
  161. title: '标题',
  162. dataIndex: 'title',
  163. key: 'title'
  164. },
  165. {
  166. title: '类型',
  167. dataIndex: 'type',
  168. key: 'type',
  169. render:(text,record)=>{
  170. if (text !== undefined) {
  171. let value = '';
  172. this.state.classList.map((obj)=>{
  173. if (obj.showNumber === text) {
  174. value = obj.typeName;
  175. }
  176. })
  177. return value;
  178. }
  179. }
  180. },
  181. {
  182. title: '发布状态',
  183. dataIndex: 'releaseStatus',
  184. key: 'releaseStatus',
  185. render:text=>{
  186. return text?'已发布':'未发布';
  187. }
  188. },
  189. {
  190. title: '发布时间',
  191. dataIndex: 'releaseDate',
  192. key: 'releaseDate'
  193. },
  194. {
  195. title: '排序',
  196. dataIndex: 'sortNumber',
  197. key: 'sortNumber'
  198. },
  199. {
  200. title: '置顶',
  201. dataIndex: 'topNumber',
  202. key: 'topNumber',
  203. render:text=>{
  204. return text?'否':'是';
  205. }
  206. },
  207. {
  208. title: '操作',
  209. dataIndex: 'a',
  210. key: 'a',
  211. render:(text,record,index)=>{
  212. return <div>
  213. {<Button type="primary" onClick={(event)=>{
  214. this.stopPropagation(event)
  215. this.tableRowClick(record)
  216. }}>修改</Button>}
  217. {<Popconfirm okText="确定" cancelText="取消" title="是否确认删除?" onConfirm={()=>{
  218. this.delete(record.id)
  219. }}>
  220. <Button type="primary" style={{marginLeft:"10px"}} onClick={(event)=>{
  221. this.stopPropagation(event)
  222. }}>删除</Button>
  223. </Popconfirm>}
  224. </div>
  225. }
  226. },
  227. ],
  228. dataSource: []
  229. };
  230. },
  231. classList(pageNo) {
  232. $.ajax({
  233. method: 'get',
  234. dataType: 'json',
  235. crossDomain: false,
  236. url: globalConfig.context + '/api/admin/news/ListNewsType',
  237. data: {
  238. pageNo: 1,
  239. pageSize: 99,
  240. },
  241. success: function(data) {
  242. let theArr = [];
  243. if (!data.data || !data.data.list) {
  244. if (data.error && data.error.length) {
  245. message.warning(data.error[0].message);
  246. }
  247. } else {
  248. for (let i = 0; i < data.data.list.length; i++) {
  249. let thisdata = data.data.list[i];
  250. theArr.push({
  251. key: i,
  252. id: thisdata.id,
  253. typeName: thisdata.typeName,
  254. showNumber: thisdata.showNumber,
  255. });
  256. }
  257. this.state.pagination.current = data.data.pageNo;
  258. this.state.pagination.total = data.data.totalCount;
  259. }
  260. this.setState({
  261. classList: theArr,
  262. });
  263. }.bind(this)
  264. }).always(
  265. function() {
  266. this.setState({
  267. loading: false
  268. });
  269. }.bind(this)
  270. );
  271. },
  272. componentWillMount() {
  273. this.loadData()
  274. this.classList()
  275. },
  276. detailes(record) {
  277. this.setState({
  278. loading:true
  279. });
  280. $.ajax({
  281. method: 'get',
  282. dataType: 'json',
  283. crossDomain: false,
  284. url: globalConfig.context + '/api/admin/news/detail',
  285. data: {
  286. id: record.id,
  287. },
  288. success: function(data) {
  289. let theArr = [];
  290. let thisdata = data.data;
  291. if (!data.data || !data.data.list) {
  292. if (data.error && data.error.length) {
  293. message.warning(data.error[0].message);
  294. }
  295. }
  296. this.setState({
  297. titleImg: thisdata.titleImg ? splitUrl(thisdata.titleImg, ',', globalConfig.avatarHost + '/upload') : [],
  298. })
  299. Object.assign(this.state.totalData,{
  300. content:thisdata.content,
  301. createTimes:thisdata.createTimes,
  302. editTimes:thisdata.editTimes,
  303. releaseDates:thisdata.releaseDates,
  304. },this.state.RowData)
  305. }.bind(this)
  306. }).always(
  307. function() {
  308. this.setState({
  309. loading: false
  310. });
  311. }.bind(this)
  312. );
  313. },
  314. stopPropagation(e){
  315. e.stopPropagation();
  316. e.nativeEvent.stopImmediatePropagation();
  317. },
  318. //项目列表整行点击
  319. tableRowClick(record, index) {
  320. this.state.RowData = record;
  321. this.setState({
  322. editvisible: true,
  323. });
  324. this.detailes(record);
  325. },
  326. edithandleCancel(e) {
  327. this.setState({
  328. editvisible: false
  329. },()=>{
  330. this.addReset()
  331. });
  332. this.loadData()
  333. },
  334. search() {
  335. this.loadData();
  336. },
  337. add(){
  338. this.setState({
  339. editvisible: true,
  340. flag: false,
  341. });
  342. },
  343. addNew(){
  344. let theorgCodeUrl = [];
  345. if (this.state.titleImg.length) {
  346. let picArr = [];
  347. this.state.titleImg.map(function (item) {
  348. if ( item.response && item.response.data && item.response.data.length ){
  349. picArr.push(item.response.data);
  350. }
  351. });
  352. theorgCodeUrl = picArr.join(",");
  353. };
  354. this.setState({
  355. loading:true
  356. });
  357. if (!this.state.flag) {
  358. this.change("auditStatus",2)
  359. }
  360. if(theorgCodeUrl.length){
  361. this.change("titleImg",theorgCodeUrl)
  362. }else{
  363. this.change("titleImg",[])
  364. }
  365. $.ajax({
  366. method: 'post',
  367. dataType: 'json',
  368. crossDomain: false,
  369. url: (this.state.flag?'/api/admin/news/update':'/api/admin/news/apply'),
  370. data: this.state.totalData,
  371. }).done(function(data) {
  372. this.setState({
  373. loading: false
  374. });
  375. if(!data.error.length) {
  376. message.success('保存成功!');
  377. this.cancelAdd()
  378. } else {
  379. message.warning(data.error[0].message);
  380. }
  381. }.bind(this));
  382. },
  383. saveNew(){
  384. this.change("releaseStatus",0,()=>{
  385. this.addNew()
  386. })
  387. },
  388. issueNew(){
  389. this.change("releaseStatus",1,()=>{
  390. this.addNew()
  391. })
  392. },
  393. delete(id){
  394. this.setState({
  395. loading:true
  396. });
  397. $.ajax({
  398. method: 'post',
  399. dataType: 'json',
  400. crossDomain: false,
  401. url: "/api/admin/news/deleteById",
  402. data: {
  403. id: id,
  404. },
  405. }).done(function(data) {
  406. this.setState({
  407. loading: false
  408. });
  409. if(!data.error.length) {
  410. message.success('删除成功!');
  411. this.loadData()
  412. } else {
  413. message.warning(data.error[0].message);
  414. }
  415. }.bind(this));
  416. },
  417. cancelAdd(){
  418. this.setState({
  419. editvisible: false,
  420. },()=>{
  421. this.setState({
  422. flag:true
  423. })
  424. this.addReset()
  425. });
  426. this.loadData()
  427. },
  428. //新增框的清零
  429. addReset(){
  430. this.setState({
  431. titleImg:[],
  432. totalData:{
  433. content:"<p></p>",
  434. },
  435. })
  436. },
  437. //搜索部分的清零
  438. reset() {
  439. this.setState({
  440. releaseStatusSearch: undefined,
  441. typeSearch: undefined,
  442. startCreateTimeSearch: undefined,
  443. endCreateTimeSearch: undefined,
  444. titleSearch: undefined,
  445. })
  446. this.loadData();
  447. },
  448. getOrgCodeUrl(e) {
  449. this.setState({ titleImg: e });
  450. },
  451. change(key, e, f){
  452. if(f === undefined ){
  453. this.state.totalData[key] = e
  454. this.setState({
  455. totalData:this.state.totalData
  456. })
  457. }else if(typeof(f) === "function"){
  458. this.state.totalData[key] = e
  459. this.setState({
  460. totalData:this.state.totalData
  461. },f)
  462. }
  463. },
  464. render() {
  465. const FormItem = Form.Item;
  466. const rowSelection = {
  467. selectedRowKeys: this.state.selectedRowKeys,
  468. onChange: (selectedRowKeys, selectedRows) => {
  469. this.setState({
  470. selectedRows: selectedRows.slice(-1),
  471. selectedRowKeys: selectedRowKeys.slice(-1)
  472. });
  473. }
  474. };
  475. let data = this.state.totalData;
  476. const { TextArea } = Input;//文本域
  477. const { TabPane } = Tabs;//标签页
  478. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;//日期输入框
  479. return (
  480. <div className="user-content">
  481. <div className="content-title">
  482. <span>新闻列表管理</span>
  483. <div className="user-search">
  484. <Input
  485. placeholder="企业名称"
  486. style={{ width: '150px', marginRight: '10px', marginBottom: '10px' }}
  487. value={this.state.nameSearch}
  488. onChange={(e) => {
  489. this.setState({ nameSearch: e.target.value });
  490. }}
  491. />
  492. <Button type="primary" onClick={this.search} style={{ marginRight: '10px' }}>
  493. 搜索
  494. </Button>
  495. <Button onClick={this.reset} style={{ marginRight: '10px' }}>
  496. 重置
  497. </Button>
  498. <Button type="primary" onClick={this.add} style={{ marginLeft: '100px'}}>
  499. 新增新闻
  500. </Button>
  501. </div>
  502. <div className="patent-table">
  503. <Spin spinning={this.state.loading}>
  504. <Table
  505. columns={this.state.columns}
  506. dataSource={this.state.dataSource}
  507. pagination={this.state.pagination}
  508. onRowClick={this.tableRowClick}
  509. />
  510. </Spin>
  511. </div>
  512. </div>
  513. <div className="patent-desc">
  514. <Modal
  515. className="customeDetails"
  516. title={this.state.flag?'新闻列表详情':'新增新闻列表'}
  517. width="1000px"
  518. visible={this.state.editvisible}
  519. onOk={this.edithandleCancel}
  520. onCancel={this.state.flag?this.edithandleCancel:this.cancelAdd}
  521. footer=""
  522. >
  523. <Form layout="horizontal" onSubmit={this.edithandleSubmit} id="demand-form">
  524. <Spin spinning={this.state.loading}>
  525. <div className="clearfix">
  526. <FormItem
  527. className="half-item"
  528. labelCol={{ span: 8 }}
  529. wrapperCol={{ span: 12 }}
  530. label="新闻标题"
  531. >
  532. <Input placeholder="请输入新闻标题" value={data.title}
  533. onChange={(e)=>{
  534. this.change('title',e.target.value)
  535. }} style={{width:'240px'}} />
  536. </FormItem>
  537. <FormItem
  538. className="half-item"
  539. labelCol={{ span: 8 }}
  540. wrapperCol={{ span: 12 }}
  541. label="新闻类别"
  542. >
  543. <Select value={data.type} style={{ width: 120 }}
  544. placeholder='请选择新闻类别' onChange={(e)=>{
  545. this.change('type',e)
  546. }}>
  547. {this.state.classList.map((obj)=>{
  548. return <Option value={obj.showNumber}>{obj.typeName}</Option>
  549. })}
  550. </Select>
  551. </FormItem>
  552. <FormItem
  553. className="half-item"
  554. labelCol={{ span: 8 }}
  555. wrapperCol={{ span: 12 }}
  556. label="排序"
  557. >
  558. <Input placeholder="请输入排序" value={data.sortNumber}
  559. onChange={(e)=>{
  560. this.change('sortNumber',e.target.value)
  561. }} style={{width:'240px'}} />
  562. </FormItem>
  563. <FormItem
  564. className="half-item"
  565. labelCol={{ span: 8 }}
  566. wrapperCol={{ span: 12 }}
  567. label="是否置顶"
  568. >
  569. <Radio.Group onChange={(e)=>{
  570. this.change('topNumber',e.target.value)
  571. }} value={data.topNumber}>
  572. <Radio value={0}>是</Radio>
  573. <Radio value={1}>否</Radio>
  574. </Radio.Group>
  575. </FormItem>
  576. </div>
  577. <div className="clearfix">
  578. <FormItem
  579. labelCol={{ span: 4 }}
  580. wrapperCol={{ span: 18 }}
  581. label='新闻大图'
  582. >
  583. <PicturesWall
  584. fileList={this.getOrgCodeUrl}
  585. pictureUrl={this.state.titleImg} />
  586. <p>图片建议:要清晰。</p>
  587. </FormItem>
  588. </div>
  589. <div className="clearfix">
  590. <FormItem
  591. labelCol={{ span: 4 }}
  592. wrapperCol={{ span: 18 }}
  593. label='新闻内容'
  594. >
  595. <Editors textContent={data.content}
  596. uploadUrl={'/api/admin/militaryEnterprises/uploadPicture'}
  597. uploadSign={'enterprises_pucture'}
  598. handleRichText={(value)=>{
  599. this.change('content',value)
  600. }}
  601. visible={data.visible} />
  602. </FormItem>
  603. </div>
  604. <div className="clearfix">
  605. {!data.releaseStatus?<Button type="primary" size="large" onClick={this.saveNew} style={{float:'right',marginRight:'80px',marginTop:'20px'}}>保存</Button>:
  606. <Button type="primary" size="large" onClick={this.saveNew} style={{float:'right',marginRight:'80px',marginTop:'20px',background:'coral',border:'none'}}>撤回</Button>}
  607. <Button type="primary" size="large" onClick={this.issueNew} style={{float:'right',marginRight:'20px',marginTop:'20px'}}>保存并发布</Button>
  608. </div>
  609. </Spin>
  610. </Form>
  611. </Modal>
  612. </div>
  613. </div>
  614. );
  615. }
  616. })
  617. );
  618. export default NewList;