caseList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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, getStatuslist, getLvl,beforeUploadFile} from '@/tools.js';
  8. import Editors from '@/richTextEditors';
  9. //主体
  10. const CaseList = Form.create()(
  11. React.createClass({
  12. loadData(pageNo) {
  13. this.state.data = [];
  14. this.setState({
  15. loading: true,
  16. page: pageNo
  17. });
  18. $.ajax({
  19. method: 'get',
  20. dataType: 'json',
  21. crossDomain: false,
  22. url: globalConfig.context + '/api/admin/listCases',
  23. data: {
  24. pageNo: pageNo || 1,
  25. pageSize: this.state.pagination.pageSize,
  26. title: this.state.titleSearch,
  27. },
  28. success: function(data) {
  29. let theArr = [];
  30. if (!data.data || !data.data.list) {
  31. if (data.error && data.error.length) {
  32. message.warning(data.error[0].message);
  33. }
  34. } else {
  35. for (let i = 0; i < data.data.list.length; i++) {
  36. let thisdata = data.data.list[i];
  37. theArr.push({
  38. key: i,
  39. id: thisdata.id,
  40. title: thisdata.title,
  41. releaseStatus: thisdata.releaseStatus,
  42. topNumber: thisdata.topNumber,
  43. sortNumber: thisdata.sortNumber,
  44. content: thisdata.content,
  45. createTimes: thisdata.createTimes,
  46. releaseDates:thisdata.releaseDates,
  47. editTimes:thisdata.editTimes,
  48. });
  49. }
  50. this.state.pagination.current = data.data.pageNo;
  51. this.state.pagination.total = data.data.totalCount;
  52. }
  53. this.setState({
  54. dataSource: theArr,
  55. pagination: this.state.pagination
  56. });
  57. }.bind(this)
  58. }).always(
  59. function() {
  60. this.setState({
  61. loading: false
  62. });
  63. }.bind(this)
  64. );
  65. },
  66. getInitialState() {
  67. return {
  68. loading: false,
  69. flag: true,
  70. totalData:{
  71. mark: false,
  72. },
  73. pagination: {
  74. defaultCurrent: 1,
  75. defaultPageSize: 10,
  76. showQuickJumper: true,
  77. pageSize: 10,
  78. onChange: function(page) {
  79. this.loadData(page);
  80. this.setState({
  81. selectedRowKeys: []
  82. });
  83. }.bind(this),
  84. showTotal: function(total) {
  85. return '共' + total + '条数据';
  86. }
  87. },
  88. columns: [
  89. {
  90. title: '序号',
  91. dataIndex: 'key',
  92. key: 'key'
  93. },
  94. {
  95. title: '公司',
  96. dataIndex: 'title',
  97. key: 'title'
  98. },
  99. {
  100. title: '排序',
  101. dataIndex: 'sortNumber',
  102. key: 'sortNumber'
  103. },
  104. {
  105. title: '发布状态',
  106. dataIndex: 'releaseStatus',
  107. key: 'releaseStatus',
  108. render:text=>{
  109. return text?'已发布':'未发布';
  110. }
  111. },
  112. {
  113. title: '置顶',
  114. dataIndex: 'topNumber',
  115. key: 'topNumber',
  116. render:text=>{
  117. return text?'否':'是';
  118. }
  119. },
  120. {
  121. title: '操作',
  122. dataIndex: 'a',
  123. key: 'a',
  124. render:(text,record,index)=>{
  125. return <Button type="primary" onClick={()=>{
  126. this.tableRowClick(record)
  127. }}>修改</Button>
  128. }
  129. },
  130. ],
  131. dataSource: []
  132. };
  133. },
  134. componentWillMount() {
  135. this.loadData()
  136. },
  137. detailes(record) {
  138. this.setState({
  139. loading:true
  140. });
  141. $.ajax({
  142. method: 'get',
  143. dataType: 'json',
  144. crossDomain: false,
  145. url: globalConfig.context + '/api/admin/detailsCases',
  146. data: {
  147. id: record.id,
  148. },
  149. success: function(data) {
  150. let theArr = [];
  151. let thisdata = data.data;
  152. if (!data.data || !data.data.list) {
  153. if (data.error && data.error.length) {
  154. message.warning(data.error[0].message);
  155. }
  156. }
  157. Object.assign(this.state.totalData,{},this.state.RowData)
  158. }.bind(this)
  159. }).always(
  160. function() {
  161. this.setState({
  162. loading: false
  163. });
  164. }.bind(this)
  165. );
  166. },
  167. stopPropagation(e){
  168. e.stopPropagation();
  169. e.nativeEvent.stopImmediatePropagation();
  170. },
  171. //项目列表整行点击
  172. tableRowClick(record, index) {
  173. this.state.RowData = record;
  174. this.setState({
  175. editvisible: true,
  176. });
  177. this.detailes(record);
  178. },
  179. edithandleCancel(e) {
  180. this.setState({
  181. editvisible: false
  182. },()=>{
  183. this.addReset()
  184. });
  185. this.loadData()
  186. },
  187. search() {
  188. this.loadData();
  189. },
  190. add(){
  191. this.setState({
  192. editvisible: true,
  193. flag: false,
  194. });
  195. },
  196. addNew(){
  197. this.setState({
  198. loading:true
  199. });
  200. $.ajax({
  201. method: 'post',
  202. dataType: 'json',
  203. crossDomain: false,
  204. url: globalConfig.context + (this.state.flag?'/api/admin/updateCases':'/api/admin/addCases'),
  205. data: this.state.totalData,
  206. }).done(function(data) {
  207. this.setState({
  208. loading: false
  209. });
  210. if(!data.error.length) {
  211. message.success('保存成功!');
  212. this.setState({
  213. editvisible:false,
  214. flag:true
  215. })
  216. this.addReset()
  217. this.loadData()
  218. } else {
  219. message.warning(data.error[0].message);
  220. }
  221. }.bind(this));
  222. },
  223. saveNew(){
  224. this.change("releaseStatus",0,()=>{
  225. this.addNew()
  226. })
  227. },
  228. issueNew(){
  229. this.change("releaseStatus",1,()=>{
  230. this.addNew()
  231. })
  232. },
  233. delete(id){
  234. this.setState({
  235. loading:true
  236. });
  237. $.ajax({
  238. method: 'post',
  239. dataType: 'json',
  240. crossDomain: false,
  241. url: "/api/admin/deleteCases",
  242. data: {
  243. id: id,
  244. },
  245. }).done(function(data) {
  246. this.setState({
  247. loading: false
  248. });
  249. if(!data.error.length) {
  250. message.success('删除成功!');
  251. this.loadData()
  252. } else {
  253. message.warning(data.error[0].message);
  254. }
  255. }.bind(this));
  256. },
  257. cancelAdd(){
  258. this.setState({
  259. editvisible: false,
  260. },()=>{
  261. this.setState({
  262. flag:true
  263. })
  264. this.addReset()
  265. });
  266. this.loadData()
  267. },
  268. //新增框的清零
  269. addReset(){
  270. this.setState({
  271. totalData:{
  272. content:"<p></p>",
  273. },
  274. })
  275. },
  276. //搜索部分的清零
  277. reset() {
  278. this.state.titleSearch = undefined;
  279. this.loadData();
  280. },
  281. change(key, e, f){
  282. if(f === undefined ){
  283. this.state.totalData[key] = e
  284. this.setState({
  285. totalData:this.state.totalData
  286. })
  287. }else if(typeof(f) === "function"){
  288. this.state.totalData[key] = e
  289. this.setState({
  290. totalData:this.state.totalData
  291. },f)
  292. }
  293. },
  294. render() {
  295. const FormItem = Form.Item;
  296. const rowSelection = {
  297. selectedRowKeys: this.state.selectedRowKeys,
  298. onChange: (selectedRowKeys, selectedRows) => {
  299. this.setState({
  300. selectedRows: selectedRows.slice(-1),
  301. selectedRowKeys: selectedRowKeys.slice(-1)
  302. });
  303. }
  304. };
  305. let data = this.state.totalData;
  306. const { TextArea } = Input;//文本域
  307. const { TabPane } = Tabs;//标签页
  308. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;//日期输入框
  309. return (
  310. <div className="user-content">
  311. <div className="content-title">
  312. <span>成功案例列表</span>
  313. <div className="user-search">
  314. <Input
  315. placeholder="企业名称"
  316. style={{ width: '150px', marginRight: '10px', marginBottom: '10px' }}
  317. value={this.state.nameSearch}
  318. onChange={(e) => {
  319. this.setState({ nameSearch: e.target.value });
  320. }}
  321. />
  322. <Button type="primary" onClick={this.search} style={{ marginRight: '10px' }}>
  323. 搜索
  324. </Button>
  325. <Button onClick={this.reset} style={{ marginRight: '10px' }}>
  326. 重置
  327. </Button>
  328. <Button type="primary" onClick={this.add} style={{ marginLeft: '100px'}}>
  329. 新增成功案例
  330. </Button>
  331. </div>
  332. <div className="patent-table">
  333. <Spin spinning={this.state.loading}>
  334. <Table
  335. columns={this.state.columns}
  336. dataSource={this.state.dataSource}
  337. pagination={this.state.pagination}
  338. onRowClick={this.tableRowClick}
  339. />
  340. </Spin>
  341. </div>
  342. </div>
  343. <div className="patent-desc">
  344. <Modal
  345. className="customeDetails"
  346. title={this.state.flag?'成功案例详情':'新增成功案例'}
  347. width="1000px"
  348. visible={this.state.editvisible}
  349. onOk={this.edithandleCancel}
  350. onCancel={this.state.flag?this.edithandleCancel:this.cancelAdd}
  351. footer=""
  352. >
  353. <Form layout="horizontal" onSubmit={this.edithandleSubmit} id="demand-form">
  354. <Spin spinning={this.state.loading}>
  355. <div className="clearfix">
  356. <FormItem
  357. className="half-item"
  358. labelCol={{ span: 8 }}
  359. wrapperCol={{ span: 12 }}
  360. label="公司"
  361. >
  362. <Input placeholder="请输入公司" value={data.title}
  363. onChange={(e)=>{
  364. this.change('title',e.target.value)
  365. }} style={{width:'240px'}} />
  366. </FormItem>
  367. <FormItem
  368. className="half-item"
  369. labelCol={{ span: 8 }}
  370. wrapperCol={{ span: 12 }}
  371. label="排序"
  372. >
  373. <Input placeholder="请输入排序" value={data.sortNumber}
  374. onChange={(e)=>{
  375. this.change('sortNumber',e.target.value)
  376. }} style={{width:'240px'}} />
  377. </FormItem>
  378. <FormItem
  379. className="half-item"
  380. labelCol={{ span: 8 }}
  381. wrapperCol={{ span: 12 }}
  382. label="是否置顶"
  383. >
  384. <Radio.Group onChange={(e)=>{
  385. this.change('topNumber',e.target.value)
  386. }} value={data.topNumber}>
  387. <Radio value={0}>是</Radio>
  388. <Radio value={1}>否</Radio>
  389. </Radio.Group>
  390. </FormItem>
  391. </div>
  392. <div className="clearfix">
  393. <FormItem
  394. labelCol={{ span: 4 }}
  395. wrapperCol={{ span: 18 }}
  396. label='案例服务项目'
  397. >
  398. <Editors textContent={data.content}
  399. uploadUrl={'/api/admin/militaryEnterprises/uploadPicture'}
  400. uploadSign={'enterprises_pucture'}
  401. handleRichText={(value)=>{
  402. this.change('content',value)
  403. }}
  404. visible={data.visible} />
  405. </FormItem>
  406. </div>
  407. <div className="clearfix">
  408. {!data.releaseStatus?<Button type="primary" size="large" onClick={this.saveNew} style={{float:'right',marginRight:'80px',marginTop:'20px'}}>保存</Button>:
  409. <Button type="primary" size="large" onClick={this.saveNew} style={{float:'right',marginRight:'80px',marginTop:'20px',background:'coral',border:'none'}}>撤回</Button>}
  410. <Button type="primary" size="large" onClick={this.issueNew} style={{float:'right',marginRight:'20px',marginTop:'20px'}}>保存并发布</Button>
  411. </div>
  412. </Spin>
  413. </Form>
  414. </Modal>
  415. </div>
  416. </div>
  417. );
  418. }
  419. })
  420. );
  421. export default CaseList;