addSoftWritingPrice.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React,{Component} from "react";
  2. import {Form, Input, Button, Checkbox, Select, Spin} from 'antd';
  3. import $ from "jquery/src/ajax";
  4. import {message, Modal} from "antd";
  5. class AddSoftWritingPrice extends Component{
  6. constructor(props) {
  7. super(props);
  8. this.state={
  9. loading: false
  10. }
  11. }
  12. //增加 修改
  13. addSoftWritingPriceFn(e) {
  14. e.preventDefault();
  15. this.props.form.validateFields((err, values) => {
  16. if (!err) {
  17. this.setState({
  18. loading: true
  19. });
  20. let api ;
  21. if(Object.keys(this.props.infor).length){
  22. api = '/api/admin/company/updateSoftWritingPrice';
  23. values.id = this.props.infor.id;
  24. } else {
  25. api = '/api/admin/company/addSoftWritingPrice';
  26. }
  27. $.ajax({
  28. method: "post",
  29. dataType: "json",
  30. crossDomain: false,
  31. url:globalConfig.context + api,
  32. data:values,
  33. }).done(function (data) {
  34. this.setState({
  35. loading: false
  36. });
  37. if (!data.error.length) {
  38. message.success(Object.keys(this.props.infor).length ? '修改成功!' : '新增成功!');
  39. this.props.successFn();
  40. } else {
  41. message.warning(data.error[0].message);
  42. }
  43. }.bind(this));
  44. }
  45. });
  46. }
  47. render() {
  48. const { getFieldDecorator } = this.props.form;
  49. return (
  50. <Modal
  51. className="customeDetails"
  52. title={Object.keys(this.props.infor).length ? "修改" : "新增"}
  53. width='350px'
  54. visible={this.props.visible}
  55. onCancel={this.props.onCancel}
  56. footer={null}
  57. >
  58. <Spin spinning={this.state.loading}>
  59. <Form onSubmit={(e)=>{
  60. this.addSoftWritingPriceFn(e)
  61. }}>
  62. <Form.Item label="单价">
  63. {getFieldDecorator('unitPrice', {
  64. initialValue: this.props.infor.unitPrice,
  65. rules: [{ required: true, message: '请输入单价!' }],
  66. })(
  67. <Input placeholder="请输入单价" type={'number'} style={{width:'250px'}}/>
  68. )}
  69. </Form.Item>
  70. <Form.Item label="材料">
  71. {getFieldDecorator('material', {
  72. initialValue: this.props.infor.material,
  73. rules: [{ required: true, message: '请选择是否有材料!' }],
  74. })(
  75. <Select style={{ width:'200px'}}>
  76. <Select.Option value={0}>无</Select.Option>
  77. <Select.Option value={1}>有</Select.Option>
  78. </Select>
  79. )}
  80. </Form.Item>
  81. <Form.Item label="加急天数">
  82. {getFieldDecorator('urgent', {
  83. initialValue: this.props.infor.urgent,
  84. rules: [{ required: true, message: '请选择加急天数!' }],
  85. })(
  86. <Select style={{ width:'200px'}}>
  87. <Select.Option value={0}>无加急</Select.Option>
  88. <Select.Option value={1}>加急3天</Select.Option>
  89. <Select.Option value={2}>加急4天</Select.Option>
  90. <Select.Option value={3}>加急5-10天</Select.Option>
  91. <Select.Option value={4}>加急11-15天</Select.Option>
  92. <Select.Option value={5}>加急16-20天</Select.Option>
  93. <Select.Option value={6}>加急21-25天</Select.Option>
  94. <Select.Option value={7}>加急26-30天</Select.Option>
  95. </Select>
  96. )}
  97. </Form.Item>
  98. {Object.keys(this.props.infor).length ? <Form.Item label="状态">
  99. {getFieldDecorator('status', {
  100. initialValue: this.props.infor.status,
  101. rules: [{ required: true, message: '请输选择状态!' }],
  102. })(
  103. <Select style={{ width:'200px'}}>
  104. <Select.Option value={0}>正常</Select.Option>
  105. <Select.Option value={1}>停用</Select.Option>
  106. <Select.Option value={2}>删除</Select.Option>
  107. </Select>
  108. )}
  109. </Form.Item> : <div/>}
  110. <Form.Item label="备注">
  111. {getFieldDecorator('remarks', {
  112. initialValue: this.props.infor.remarks,
  113. rules: [{ required: true, message: '请输入备注!' }],
  114. })(
  115. <Input placeholder="请输入备注" type={'textarea'} style={{width:'250px'}}/>
  116. )}
  117. </Form.Item>
  118. <Form.Item>
  119. <Button style={{
  120. width: '100%',
  121. marginTop: '18px',
  122. }} type="primary" htmlType="submit">
  123. {
  124. Object.keys(this.props.infor).length ? '确定修改' : '确定添加'
  125. }
  126. </Button>
  127. </Form.Item>
  128. </Form>
  129. </Spin>
  130. </Modal>
  131. )
  132. }
  133. }
  134. const WrappedHorizontalLoginForm = Form.create()(AddSoftWritingPrice);
  135. export default WrappedHorizontalLoginForm