page.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react';
  2. import { Form, Button, Select } from 'antd';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import { formatFormError } from '@src/services/Tools';
  7. import { asyncSMessage } from '@src/services/AsyncTools';
  8. import { QuestionType } from '../../../../Constant';
  9. import { System } from '../../../stores/system';
  10. export default class extends Page {
  11. initData() {
  12. System.getPlace().then(result => {
  13. const { form } = this.props;
  14. form.setFieldsValue(result);
  15. this.setState({ load: true, data: result });
  16. });
  17. }
  18. submit() {
  19. const { form } = this.props;
  20. form.validateFields((err) => {
  21. if (!err) {
  22. const data = form.getFieldsValue();
  23. System.setPlace(data)
  24. .then(() => {
  25. this.setState(data);
  26. asyncSMessage('保存成功');
  27. }).catch((e) => {
  28. form.setFields(formatFormError(data, e.result));
  29. });
  30. }
  31. });
  32. }
  33. renderView() {
  34. const { getFieldDecorator } = this.props.form;
  35. return <Block>
  36. <Form>
  37. {QuestionType.map(row => {
  38. return <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label={row.label}>
  39. {getFieldDecorator(row.value, {
  40. rules: [
  41. { required: false, message: '请输入跳转地址' },
  42. ],
  43. })(
  44. <Select mode='tags' maxTagCount={200} notFoundContent={null} placeholder='输入多个考点, 逗号分隔' tokenSeparators={[',', ',']} />,
  45. )}
  46. </Form.Item>;
  47. })}
  48. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16, offset: 5 }}>
  49. <Button type="primary" onClick={() => {
  50. this.submit();
  51. }}>保存</Button>
  52. </Form.Item>
  53. </Form>
  54. </Block>;
  55. }
  56. }