page.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import React from 'react';
  2. import { Button, Form, Modal, DatePicker, Input, Upload, Checkbox, Switch } from 'antd';
  3. import { Link } from 'react-router-dom';
  4. import moment from 'moment';
  5. import './index.less';
  6. import Page from '@src/containers/Page';
  7. import Block from '@src/components/Block';
  8. // import FilterLayout from '@src/layouts/FilterLayout';
  9. // import ActionLayout from '@src/layouts/ActionLayout';
  10. import TableLayout from '@src/layouts/TableLayout';
  11. // import { getMap, bindSearch, formatDate } from '@src/services/Tools';
  12. import { asyncDelConfirm, asyncSMessage } from '@src/services/AsyncTools';
  13. // import { TextbookType } from '../../../../Constant';
  14. import { Textbook } from '../../../stores/textbook';
  15. import { System } from '../../../stores/system';
  16. import { formatDate } from '../../../../../src/services/Tools';
  17. // import { Question } from '../../../stores/question';
  18. // import { Slient } from '../../../stores/slient';
  19. export default class extends Page {
  20. constructor(props) {
  21. super(props);
  22. this.actionList = [{
  23. key: 'add',
  24. name: '新建',
  25. render: (item) => {
  26. return <Button onClick={() => {
  27. linkTo('/subject/textbook/question');
  28. }}>{item.name}</Button>;
  29. },
  30. }];
  31. this.columns = [{
  32. title: '库头',
  33. dataIndex: 'startDate',
  34. render: (text) => {
  35. return formatDate(text, 'YYYY-MM-DD');
  36. },
  37. }, {
  38. title: '库尾',
  39. dataIndex: 'endDate',
  40. render: (text) => {
  41. return text ? formatDate(text, 'YYYY-MM-DD') : '-';
  42. },
  43. }, {
  44. title: '发布次数',
  45. dataIndex: 'historyNumber',
  46. render: (text, record) => {
  47. return text ? <a onClick={() => {
  48. this.loadHistory(record);
  49. }}>{text}</a> : 0;
  50. },
  51. }, {
  52. title: '开放问答',
  53. dataIndex: 'questionStatus',
  54. render: (text, record) => {
  55. return <Checkbox checked={text > 0} onChange={(e) => {
  56. this.changeLibrary(record.id, { questionStatus: e.target.checked ? 1 : 0 });
  57. }} />;
  58. },
  59. }, {
  60. title: '操作',
  61. dataIndex: 'handler',
  62. render: (text, record) => {
  63. return <div className="table-button">
  64. {(
  65. <a onClick={() => {
  66. this.setState({ post: record });
  67. this.props.form.getFieldDecorator('post.libraryId');
  68. this.props.form.setFieldsValue({ 'post.libraryId': record.id });
  69. }}>发布机经</a>
  70. )}
  71. {(
  72. <Link to={`/subject/textbook/question?libraryId=${record.id}`}>录入机经</Link>
  73. )}
  74. </div>;
  75. },
  76. }];
  77. }
  78. initData() {
  79. const { search } = this.state;
  80. const data = Object.assign({}, search);
  81. Textbook.listLibrary(data).then(result => {
  82. this.setTableData(result.list, result.total || 1);
  83. });
  84. }
  85. loadHistory(record) {
  86. Textbook.listHistory({ libraryId: record.id }).then(result => {
  87. this.setState({ history: result.list });
  88. });
  89. }
  90. submit() {
  91. this.props.form.validateFields(['add'], (err, fieldsValue) => {
  92. if (err) {
  93. return;
  94. }
  95. const data = fieldsValue.add;
  96. data.startDate.local();
  97. data.startDate = data.startDate.format('YYYY-MM-DDT00:00:00Z');
  98. asyncDelConfirm('新增确认', '是否添加新的换库?', () => {
  99. return Textbook.addLibrary(data).then(() => {
  100. asyncSMessage('添加成功!');
  101. this.refresh();
  102. });
  103. });
  104. });
  105. }
  106. submitPost() {
  107. this.props.form.validateFields(['post'], (err, fieldsValue) => {
  108. if (err) {
  109. return;
  110. }
  111. const data = fieldsValue.post;
  112. Textbook.postHistory(data).then(() => {
  113. asyncSMessage('发布成功!');
  114. this.close('post', false);
  115. this.refresh();
  116. });
  117. });
  118. }
  119. changeLibrary(id, data) {
  120. data.id = id;
  121. return Textbook.editLibrary(data).then(() => {
  122. this.refresh();
  123. });
  124. }
  125. renderView() {
  126. const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form;
  127. const { postSwitch = {} } = this.state;
  128. const quant = getFieldValue('post.quant') || null;
  129. const ir = getFieldValue('post.ir') || null;
  130. const rc = getFieldValue('post.rc') || null;
  131. return <Block flex>
  132. <Form layout="inline">
  133. <Form.Item>
  134. {getFieldDecorator('add.startDate', {
  135. initialValue: moment(new Date(), 'YYYY-mm-dd'),
  136. })(
  137. <DatePicker />,
  138. )}
  139. </Form.Item>
  140. <Form.Item><Button type='primary' onClick={() => {
  141. this.submit();
  142. }}>新增换库</Button></Form.Item>
  143. </Form>
  144. <TableLayout
  145. columns={this.tableSort(this.columns)}
  146. list={this.state.list}
  147. pagination={this.state.page}
  148. loading={this.props.core.loading}
  149. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  150. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  151. selectedKeys={this.state.selectedKeys}
  152. />
  153. {this.state.history && <Modal visible closable title='发布历史' okButtonDisabled onCancel={() => {
  154. this.close(false, 'history');
  155. }} onOk={() => {
  156. this.close(false, 'history');
  157. }}>
  158. {this.state.history.map(row => {
  159. const list = [];
  160. if (row.quant) {
  161. list.push(<p>{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')} - {row.quantContent}</p>);
  162. }
  163. if (row.ir) {
  164. list.push(<p>{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')} - {row.irContent}</p>);
  165. }
  166. if (row.rc) {
  167. list.push(<p>{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')} - {row.rcContent}</p>);
  168. }
  169. return list;
  170. })}
  171. </Modal>}
  172. {this.state.post && <Modal visible closable title='发布机经:请上传机经文件,并点击发布' onCancel={() => {
  173. this.close(false, 'post');
  174. }} onOk={() => {
  175. this.submitPost();
  176. }}>
  177. <Form>
  178. {getFieldDecorator('post.libraryId')}
  179. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 15 }} label='数学机经'>
  180. 不更新,使用上一版本
  181. <Switch checked={!postSwitch.quant} onChange={() => {
  182. postSwitch.quant = !postSwitch.quant;
  183. this.setState({ postSwitch });
  184. }} />
  185. <br />
  186. {!postSwitch.quant && !!this.state.post.quantVersion && `版本:${this.state.post.quantVersion}`}
  187. </Form.Item>
  188. {postSwitch.quant && <Form.Item>
  189. {getFieldDecorator('post.quantContent')(
  190. <Input.TextArea placeholder='更新日志' />,
  191. )}
  192. </Form.Item>}
  193. {postSwitch.quant && <Form.Item >
  194. {getFieldDecorator('post.quantDescription')(
  195. <Input placeholder='更新简介:站内信邮箱使用' />,
  196. )}
  197. </Form.Item>}
  198. {postSwitch.quant && <Form.Item>
  199. {getFieldDecorator('post.quant')(
  200. <Upload
  201. listType="text"
  202. showUploadList={false}
  203. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  204. setFieldsValue({ 'post.quant': result.url });
  205. return Promise.reject();
  206. })}
  207. onChange={this.handleChange}
  208. >
  209. {<div>
  210. <Button>上传附件</Button> {quant && '已上传'}
  211. </div>}
  212. </Upload>,
  213. )}
  214. </Form.Item>}
  215. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 15 }} label='阅读机经'>
  216. 不更新,使用上一版本
  217. <Switch checked={!postSwitch.rc} onChange={() => {
  218. postSwitch.rc = !postSwitch.rc;
  219. this.setState({ postSwitch });
  220. }} />
  221. <br />
  222. {!postSwitch.rc && !!this.state.post.rcVersion && `版本:${this.state.post.rcVersion}`}
  223. </Form.Item>
  224. {postSwitch.rc && <Form.Item>
  225. {getFieldDecorator('post.rcContent')(
  226. <Input.TextArea placeholder='更新日志' />,
  227. )}
  228. </Form.Item>}
  229. {postSwitch.rc && <Form.Item >
  230. {getFieldDecorator('post.rcDescription')(
  231. <Input placeholder='更新简介:站内信邮箱使用' />,
  232. )}
  233. </Form.Item>}
  234. {postSwitch.rc && <Form.Item>
  235. {getFieldDecorator('post.rc')(
  236. <Upload
  237. listType="text"
  238. showUploadList={false}
  239. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  240. setFieldsValue({ 'post.rc': result.url });
  241. return Promise.reject();
  242. })}
  243. onChange={this.handleChange}
  244. >
  245. {<div>
  246. <Button>上传附件</Button> {rc && '已上传'}
  247. </div>}
  248. </Upload>,
  249. )}
  250. </Form.Item>}
  251. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 15 }} label='逻辑机经'>
  252. 不更新,使用上一版本
  253. <Switch checked={!postSwitch.ir} onChange={() => {
  254. postSwitch.ir = !postSwitch.ir;
  255. this.setState({ postSwitch });
  256. }} />
  257. <br />
  258. {!postSwitch.ir && !!this.state.post.irVersion && `版本:${this.state.post.irVersion}`}
  259. </Form.Item>
  260. {postSwitch.ir && <Form.Item >
  261. {getFieldDecorator('post.irContent')(
  262. <Input.TextArea placeholder='更新日志' />,
  263. )}
  264. </Form.Item>}
  265. {postSwitch.ir && <Form.Item >
  266. {getFieldDecorator('post.irDescription')(
  267. <Input placeholder='更新简介:站内信邮箱使用' />,
  268. )}
  269. </Form.Item>}
  270. {postSwitch.ir && <Form.Item>
  271. {getFieldDecorator('post.ir')(
  272. <Upload
  273. listType="text"
  274. showUploadList={false}
  275. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  276. setFieldsValue({ 'post.ir': result.url });
  277. return Promise.reject();
  278. })}
  279. onChange={this.handleChange}
  280. >
  281. {<div>
  282. <Button>上传附件</Button> {ir && '已上传'}
  283. </div>}
  284. </Upload>,
  285. )}
  286. </Form.Item>}
  287. </Form>
  288. </Modal>}
  289. </Block>;
  290. }
  291. }