1
0

page.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. import React from 'react';
  2. import { Tabs, Form, Row, Col, Input, InputNumber, Button, Upload, Icon } from 'antd';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import { flattenObject } from '@src/services/Tools';
  7. import { asyncSMessage } from '@src/services/AsyncTools';
  8. import { SercieParamMap } from '../../../../Constant';
  9. import { System } from '../../../stores/system';
  10. export default class extends Page {
  11. constructor(props) {
  12. super(props);
  13. this.state.tab = 'qx_cat';
  14. this.vipList = SercieParamMap.vip;
  15. }
  16. initData() {
  17. this.refresh(this.state.tab);
  18. }
  19. refresh(tab) {
  20. if (tab === 'qx_cat') {
  21. return this.refreshQxCat();
  22. }
  23. if (tab === 'textbook') {
  24. return this.refreshTextbook();
  25. }
  26. if (tab === 'vip') {
  27. return this.refreshVip();
  28. }
  29. return Promise.reject();
  30. }
  31. refreshQxCat() {
  32. return System.getServiceQxCat().then(result => {
  33. this.setState({ qx_cat: result || {} });
  34. const { form } = this.props;
  35. form.setFieldsValue(flattenObject(result, 'sentence'));
  36. });
  37. }
  38. refreshTextbook() {
  39. return System.getServiceTextbook().then(result => {
  40. this.setState({ textbook: result || {} });
  41. });
  42. }
  43. refreshVip() {
  44. return System.getServiceVip().then(result => {
  45. this.setState({ vip: result || {} });
  46. });
  47. }
  48. changeMapValue(field, index, key, value) {
  49. const data = this.state[field] || {};
  50. data[index] = data[index] || {};
  51. data[index][key] = value;
  52. this.setState({ [field]: data });
  53. }
  54. changeValue(field, key, value) {
  55. const data = this.state[field] || {};
  56. data[key] = value;
  57. this.setState({ [field]: data });
  58. }
  59. submit(tab) {
  60. let handler;
  61. if (tab === 'qx_cat') {
  62. handler = this.submitQxCat();
  63. }
  64. if (tab === 'textbook') {
  65. handler = this.submitTextbook();
  66. }
  67. if (tab === 'vip') {
  68. handler = this.submitVip();
  69. }
  70. handler.then(() => {
  71. asyncSMessage('保存成功');
  72. });
  73. }
  74. submitQxCat() {
  75. const { qx_cat } = this.state;
  76. return System.setServiceQxCat(qx_cat);
  77. }
  78. submitTextbook() {
  79. const { textbook } = this.state;
  80. return System.setServiceTextbook(textbook);
  81. }
  82. submitVip() {
  83. const { vip } = this.state;
  84. return System.setServiceVip(vip);
  85. }
  86. renderQxCat() {
  87. const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form;
  88. const image = getFieldValue('qx_cat.image') || null;
  89. return <Form>
  90. <Row>
  91. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='商品价格'>
  92. {getFieldDecorator('qx_cat[0].price', {
  93. rules: [
  94. { required: true, message: '输入千行Cat价格' },
  95. ],
  96. })(
  97. <InputNumber placeholder='请输入千行Cat价格' onChange={(value) => {
  98. this.changeMapValue('qx_cat', 0, 'price', value);
  99. }} style={{ width: '200px' }} />,
  100. )}
  101. </Form.Item>
  102. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='服务名称'>
  103. {getFieldDecorator('qx_cat[0].title', {
  104. rules: [
  105. { required: true, message: '输入千行Cat名称' },
  106. ],
  107. })(
  108. <Input placeholder='请输入千行Cat名称' onChange={(value) => {
  109. this.changeMapValue('qx_cat', 0, 'title', value);
  110. }} style={{ width: '200px' }} />,
  111. )}
  112. </Form.Item>
  113. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='服务简介'>
  114. {getFieldDecorator('qx_cat[0].description', {
  115. rules: [
  116. { required: true, message: '输入千行Cat服务简介' },
  117. ],
  118. })(
  119. <Input placeholder='请输入千行Cat服务简介' onChange={(value) => {
  120. this.changeMapValue('qx_cat', 0, 'description', value);
  121. }} style={{ width: '200px' }} />,
  122. )}
  123. </Form.Item>
  124. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='有效期说明'>
  125. {getFieldDecorator('qx_cat[0].expire_info', {
  126. rules: [
  127. { required: true, message: '输入千行Cat有效期说明' },
  128. ],
  129. })(
  130. <Input placeholder='请输入千行Cat有效期说明' onChange={(value) => {
  131. this.changeMapValue('qx_cat', 0, 'expire_info', value);
  132. }} style={{ width: '200px' }} />,
  133. )}
  134. </Form.Item>
  135. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='退款政策'>
  136. {getFieldDecorator('qx_cat[0].refund_policy', {
  137. rules: [
  138. { required: true, message: '输入千行Cat退款政策' },
  139. ],
  140. })(
  141. <Input placeholder='请输入千行Cat退款政策' onChange={(value) => {
  142. this.changeMapValue('qx_cat', 0, 'refund_policy', value);
  143. }} style={{ width: '200px' }} />,
  144. )}
  145. </Form.Item>
  146. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='版权说明'>
  147. {getFieldDecorator('qx_cat[0].copyright_notes', {
  148. rules: [
  149. { required: true, message: '输入千行Cat版权说明' },
  150. ],
  151. })(
  152. <Input placeholder='请输入千行Cat版权说明' onChange={(value) => {
  153. this.changeMapValue('qx_cat', 0, 'copyright_notes', value);
  154. }} style={{ width: '200px' }} />,
  155. )}
  156. </Form.Item>
  157. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='商品图片'>
  158. {getFieldDecorator('qx_cat.image', {
  159. rules: [
  160. { required: true, message: '上传图片' },
  161. ],
  162. })(
  163. <Upload
  164. listType="picture-card"
  165. showUploadList={false}
  166. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  167. setFieldsValue({ 'qx_cat.image': result });
  168. return Promise.reject();
  169. })}
  170. >
  171. {image ? <img src={image} alt="avatar" /> : <div>
  172. <Icon type={this.state.loading ? 'loading' : 'plus'} />
  173. <div className="ant-upload-text">Upload</div>
  174. </div>}
  175. </Upload>,
  176. )}
  177. </Form.Item>
  178. </Row>
  179. </Form>;
  180. }
  181. renderTextbook() {
  182. const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form;
  183. const image = getFieldValue('textbook.image') || null;
  184. return <Form>
  185. <Row>
  186. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='商品图片'>
  187. {getFieldDecorator('textbook.image', {
  188. rules: [
  189. { required: true, message: '上传图片' },
  190. ],
  191. })(
  192. <Upload
  193. listType="picture-card"
  194. showUploadList={false}
  195. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  196. setFieldsValue({ 'textbook.image': result });
  197. return Promise.reject();
  198. })}
  199. >
  200. {image ? <img src={image} alt="avatar" /> : <div>
  201. <Icon type={this.state.loading ? 'loading' : 'plus'} />
  202. <div className="ant-upload-text">Upload</div>
  203. </div>}
  204. </Upload>,
  205. )}
  206. </Form.Item>
  207. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='商品价格'>
  208. {getFieldDecorator('textbook[0].price', {
  209. rules: [
  210. { required: true, message: '输入数学机经价格' },
  211. ],
  212. })(
  213. <InputNumber placeholder='请输入数学机经价格' onChange={(value) => {
  214. this.changeMapValue('textbook', 0, 'price', value);
  215. }} style={{ width: '200px' }} />,
  216. )}
  217. </Form.Item>
  218. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='服务名称'>
  219. {getFieldDecorator('textbook[0].title', {
  220. rules: [
  221. { required: true, message: '输入数学机经名称' },
  222. ],
  223. })(
  224. <Input placeholder='请输入数学机经名称' onChange={(value) => {
  225. this.changeMapValue('textbook', 0, 'title', value);
  226. }} style={{ width: '200px' }} />,
  227. )}
  228. </Form.Item>
  229. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='服务简介'>
  230. {getFieldDecorator('textbook[0].description', {
  231. rules: [
  232. { required: true, message: '输入数学机经服务简介' },
  233. ],
  234. })(
  235. <Input placeholder='请输入数学机经服务简介' onChange={(value) => {
  236. this.changeMapValue('textbook', 0, 'description', value);
  237. }} style={{ width: '200px' }} />,
  238. )}
  239. </Form.Item>
  240. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='有效期说明'>
  241. {getFieldDecorator('textbook[0].expire_info', {
  242. rules: [
  243. { required: true, message: '输入数学机经有效期说明' },
  244. ],
  245. })(
  246. <Input placeholder='请输入数学机经有效期说明' onChange={(value) => {
  247. this.changeMapValue('textbook', 0, 'expire_info', value);
  248. }} style={{ width: '200px' }} />,
  249. )}
  250. </Form.Item>
  251. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='退款政策'>
  252. {getFieldDecorator('textbook[0].refund_policy', {
  253. rules: [
  254. { required: true, message: '输入数学机经退款政策' },
  255. ],
  256. })(
  257. <Input placeholder='请输入数学机经退款政策' onChange={(value) => {
  258. this.changeMapValue('textbook', 0, 'refund_policy', value);
  259. }} style={{ width: '200px' }} />,
  260. )}
  261. </Form.Item>
  262. <Form.Item labelCol={{ span: 4 }} wrapperCol={{ span: 16 }} label='版权说明'>
  263. {getFieldDecorator('textbook[0].copyright_notes', {
  264. rules: [
  265. { required: true, message: '输入数学机经版权说明' },
  266. ],
  267. })(
  268. <Input placeholder='请输入数学机经版权说明' onChange={(value) => {
  269. this.changeMapValue('textbook', 0, 'copyright_notes', value);
  270. }} style={{ width: '200px' }} />,
  271. )}
  272. </Form.Item>
  273. </Row>
  274. </Form>;
  275. }
  276. renderVip() {
  277. const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form;
  278. const image = getFieldValue('vip.image') || null;
  279. return <Form>
  280. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='商品图片'>
  281. {getFieldDecorator('vip.image', {
  282. rules: [
  283. { required: true, message: '上传图片' },
  284. ],
  285. })(
  286. <Upload
  287. listType="picture-card"
  288. showUploadList={false}
  289. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  290. setFieldsValue({ 'vip.image': result });
  291. return Promise.reject();
  292. })}
  293. >
  294. {image ? <img src={image} alt="avatar" /> : <div>
  295. <Icon type={this.state.loading ? 'loading' : 'plus'} />
  296. <div className="ant-upload-text">Upload</div>
  297. </div>}
  298. </Upload>,
  299. )}
  300. </Form.Item>
  301. <Row>
  302. {this.vipList.map((row, index) => {
  303. return <Col span={12}>
  304. <h1>{row.label}</h1>
  305. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='商品价格'>
  306. {getFieldDecorator(`vip[${index}].price`, {
  307. rules: [
  308. { required: true, message: '输入价格' },
  309. ],
  310. })(
  311. <InputNumber placeholder={'输入价格'} onChange={(value) => {
  312. this.changeMapValue('vip', index, 'price', value);
  313. }} style={{ width: '200px' }} />,
  314. )}
  315. </Form.Item>
  316. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='服务名称'>
  317. {getFieldDecorator(`vip[${index}].title`, {
  318. rules: [
  319. { required: true, message: '输入名称' },
  320. ],
  321. })(
  322. <Input placeholder={'输入名称'} onChange={(value) => {
  323. this.changeMapValue('vip', index, 'title', value);
  324. }} style={{ width: '200px' }} />,
  325. )}
  326. </Form.Item>
  327. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='服务简介'>
  328. {getFieldDecorator(`vip[${index}].description`, {
  329. rules: [
  330. { required: true, message: '输入服务简介' },
  331. ],
  332. })(
  333. <Input placeholder='请输入服务简介' onChange={(value) => {
  334. this.changeMapValue('vip', index, 'description', value);
  335. }} style={{ width: '200px' }} />,
  336. )}
  337. </Form.Item>
  338. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='有效期说明'>
  339. {getFieldDecorator(`vip[${index}].expire_info`, {
  340. rules: [
  341. { required: true, message: '输入有效期说明' },
  342. ],
  343. })(
  344. <Input placeholder='请输入有效期说明' onChange={(value) => {
  345. this.changeMapValue('vip', index, 'expire_info', value);
  346. }} style={{ width: '200px' }} />,
  347. )}
  348. </Form.Item>
  349. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='退款政策'>
  350. {getFieldDecorator(`vip[${index}].refund_policy`, {
  351. rules: [
  352. { required: true, message: '输入退款政策' },
  353. ],
  354. })(
  355. <Input placeholder='请输入退款政策' onChange={(value) => {
  356. this.changeMapValue('vip', index, 'refund_policy', value);
  357. }} style={{ width: '200px' }} />,
  358. )}
  359. </Form.Item>
  360. <Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label='版权说明'>
  361. {getFieldDecorator(`vip[${index}].copyright_notes`, {
  362. rules: [
  363. { required: true, message: '输入版权说明' },
  364. ],
  365. })(
  366. <Input placeholder='请输入版权说明' onChange={(value) => {
  367. this.changeMapValue('vip', index, 'copyright_notes', value);
  368. }} style={{ width: '200px' }} />,
  369. )}
  370. </Form.Item>
  371. </Col>;
  372. })}
  373. </Row>
  374. </Form>;
  375. }
  376. renderView() {
  377. const { tab } = this.state;
  378. return <Block><Tabs activeKey={tab} onChange={(value) => {
  379. this.setState({ tab: value, selectedKeys: [], checkedKeys: [] });
  380. this.refresh(value);
  381. }}>
  382. <Tabs.TabPane tab="千行Cat" key="qx_cat">
  383. {this.renderQxCat()}
  384. </Tabs.TabPane>
  385. <Tabs.TabPane tab="数学机经" key="textbook">
  386. {this.renderTextbook()}
  387. </Tabs.TabPane>
  388. <Tabs.TabPane tab="Vip" key="vip">
  389. {this.renderVip()}
  390. </Tabs.TabPane>
  391. </Tabs>
  392. <Row type="flex" justify="center">
  393. <Col>
  394. <Button type="primary" onClick={() => {
  395. this.submit(tab);
  396. }}>保存</Button>
  397. </Col>
  398. </Row>
  399. </Block>;
  400. }
  401. }