price.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { PureComponent } from 'react';
  2. import { Modal, Form, Select, InputNumber } from 'antd';
  3. import { chargeUnit } from '../../../utils/config';
  4. const Option = Select.Option;
  5. @Form.create()
  6. export default class NewPriceModal extends PureComponent {
  7. handleModalOnOk = () => {
  8. const {
  9. form: {
  10. validateFields,
  11. getFieldsValue,
  12. },
  13. data,
  14. onSubmit,
  15. } = this.props;
  16. validateFields((errors) => {
  17. if (errors) return;
  18. const formData = getFieldsValue();
  19. const newData = { ...formData };
  20. newData.duration = chargeUnit[formData.chargeUnit];
  21. data.id ? newData.id = data.id : null;
  22. onSubmit(newData);
  23. });
  24. }
  25. handleTest = (value) => {
  26. console.log(value);
  27. }
  28. render() {
  29. const { form, data, onSubmit, ...modalProps } = this.props;
  30. const { getFieldDecorator } = form;
  31. const formItemLayout = {
  32. labelCol: { span: 9 },
  33. wrapperCol: { span: 10 },
  34. };
  35. return (
  36. <Modal { ...modalProps } onOk={this.handleModalOnOk} >
  37. <Form layout="horizontal" >
  38. <Form.Item label="计价单位" { ...formItemLayout }>
  39. {getFieldDecorator('chargeUnit', {
  40. rules: [{ required: true, type: 'string', message: '请选择一种计价单位!' }],
  41. initialValue: data.chargeUnit,
  42. })(
  43. <Select placeholder="请选择" style={{ width: '80%' }}>
  44. {Object.keys(chargeUnit).map(key => <Option value={key} key={key}>{key}</Option>)}
  45. </Select>
  46. )}
  47. </Form.Item>
  48. <Form.Item label="供应商价格" { ...formItemLayout }>
  49. {getFieldDecorator('cpPrice', {
  50. initialValue: data.cpPrice,
  51. })(
  52. <InputNumber
  53. min={0}
  54. style={{ width: '80%' }}
  55. placeholder="请填写"
  56. onChange={this.handleTest}
  57. formatter={value => `¥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
  58. parser={value => value.replace(/\¥\s?|(,*)/g, '')}
  59. />
  60. )}
  61. </Form.Item>
  62. <Form.Item label="渠道方价格" { ...formItemLayout }>
  63. {getFieldDecorator('merchantPrice', {
  64. initialValue: data.merchantPrice,
  65. })(
  66. <InputNumber
  67. min={0}
  68. style={{ width: '80%' }}
  69. placeholder="请填写"
  70. formatter={value => `¥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
  71. parser={value => value.replace(/\¥\s?|(,*)/g, '')}
  72. />
  73. )}
  74. </Form.Item>
  75. <Form.Item label="终端价格" { ...formItemLayout }>
  76. {getFieldDecorator('terminalPrice', {
  77. initialValue: data.terminalPrice,
  78. })(
  79. <InputNumber
  80. min={0}
  81. style={{ width: '80%' }}
  82. placeholder="请填写"
  83. formatter={value => `¥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
  84. parser={value => value.replace(/\¥\s?|(,*)/g, '')}
  85. />
  86. )}
  87. </Form.Item>
  88. </Form>
  89. </Modal>
  90. );
  91. }
  92. }