page.js 16 KB

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