NoSystemModal.js 6.76 KB
Newer Older
DarkForst's avatar
DarkForst committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
import React, { useEffect } from 'react';
import { connect } from 'dva';
import {
  Row,
  Col,
  Form,
  Input,
  Button,
  Select,
  Switch,
  TreeSelect,
  message,
  Modal,
  Upload,
  InputNumber
} from 'antd';
import { dispatchHandle } from '@/utils/publicHandle';
import useUpdateEffect from '@/useHooks/useUpdateEffect';
// import { branchSeparate, treeSeparate } from '../treeSeparate';
import { _apiUrl_ } from '@/utils/common';
import { useState } from 'react';
import { UploadOutlined, PlusOutlined, CloseOutlined, LoadingOutlined } from '@ant-design/icons';
import UploadFile from '@/components/UploadFile';

const { TextArea } = Input;
const NoSystemModal = (props) => {
  const [form] = Form.useForm();
  const { dispatch,handleClose} = props;
  const [loading, setLoading] = useState(false);
  //当弹层关闭的时候,detail数据要清空
  useUpdateEffect(() => {
    if (addType !== 'edit') {
      form.resetFields();
    }
  }, [props.addVisible]);


  
  const handleSubmit = (e) => {
    e.preventDefault();
    const { handleClose, addType } = props;
    const { pickListTemp } = props.ware;
    let tempData = [...pickListTemp];
    form
      .validateFields()
      .then((values) => {
        values.nocodeLab = true; // 是否无料号物料 必传,这里为虚拟物料
        tempData = [...tempData, values];
        tempData = tempData.map((item, index) => {
          return {
            ...item,
            materialInfoId:item.materialInfoId && item.id ? item.materialInfoId : 0,//虚拟物料,物料信息id 必传 无物料号默认传0
            key:index
          }
        });
        props.dispatch({
          type: 'ware/setModelsState',
          payload: {
            pickListTemp: tempData,
          },
          callback: () => {
          }
        });
        handleClose();
        message.success(addType === 'edit' ? '修改成功' : '添加虚拟物料成功', 2, () => {
            form.resetFields();
          });
      })
      .catch((e) => {});
  };

  const formItemLayout = {
    labelCol: { span: 4 },
    wrapperCol: { span: 18 },
  };
  const formTailLayout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 12 },
  };
  const {
    addType,
    addVisible,
    selectArea,
  } = props;
  const calcPrice = () => {
    const materialPrice = form.getFieldValue('materialPrice');
    const totalNum = form.getFieldValue('totalNum');
    let amount = 0;
    if (materialPrice && totalNum ) {
      amount = materialPrice * totalNum;
    }
    form.setFieldsValue({
      amount
    });
  }

  // const treeData = Boolean(groupTree && groupTree.length > 0)
  //   ? treeSeparate(groupTree, 'subGroups', 'id')
  //   : [];


  return (
    <Modal
      width={848}
      title={addType === 'edit' ? '编辑无物料号' : '创建无物料号'}
      visible={addVisible}
      onCancel={handleClose}
      afterClose={handleClose}
      closable={false}
      footer={null}
    >
      <Form form={form}>
        <Row>
          <Col md={24}>
            <Form.Item
              name="materialName"
              {...formItemLayout}
              label="物料品名"
              rules={[{ required: true, message: `请输入物料品名` }]}
            >
              <Input placeholder="请输入" />
            </Form.Item>
          </Col>
          <Col md={24}>
            <Form.Item
              name="mmodel"
              {...formItemLayout}
              label="规格/型号"
              rules={[{ required: true, message: `请输入规格/型号` }]}
            >
              <Input placeholder="请输入" />
            </Form.Item>
          </Col>
           <Col md={24}>
            <Form.Item
              name="supplierName"
              {...formItemLayout}
              label="供应商"
              rules={[{ required: true, message: `请输入供应商` }]}
            >
              <Input placeholder="请输入" />
            </Form.Item>
          </Col>
          	
          {/* <Col md={24}>
            <Form.Item
              name="purchaseCycle"
              {...formItemLayout}
              label="采购周期"
              rules={[{ required: true, message: `请输入采购周期` }]}
            >
              <InputNumber min={ 0 } placeholder="请输入" style={{width:'100%'}} />
            </Form.Item>
          </Col> */}
          
          <Col md={24}>
            <Form.Item
              name="munit"
              {...formItemLayout}
              label="单位"
              rules={[{ required: true, message: `请输入单位` }]}
            >
              <Input placeholder="请输入" />
            </Form.Item>
          </Col>
           <Col md={24}>
            <Form.Item
              name="materialPrice"
              {...formItemLayout}
              label="单价(元)"
              rules={[{ required: true, message: `请输入单价` }]}
            >
              <InputNumber min ={ 0 } placeholder="请输入" style={{width:'100%'}} onChange = { calcPrice } />
            </Form.Item>
          </Col>
          <Col md={24}>
            <Form.Item
              name="totalNum"
              {...formItemLayout}
              label="领取数量"
              rules={[{ required: true, message: `请输入领取数量` }]}
            >
              <InputNumber min ={ 0 } placeholder="请输入" style={{width:'100%'}} onChange = { calcPrice } />
            </Form.Item>
          </Col>
          <Col md={24}>
            <Form.Item
              name="amount"
              {...formItemLayout}
              label=" 总领取金额"
              
              rules={[{ required: true, message: `请输入领取"金额` }]}
            >
              <Input placeholder="请输入" readOnly disabled  addonAfter="元" />
            </Form.Item>
          </Col>

          <Col md={24}>
            <Form.Item
              name="picture"
              {...formItemLayout}
              label="物料图片"
              rules={[{ required: true, message: `请上传物料图片` }]}
            >
             
            </Form.Item>
          </Col>

          <Col md={24}>
            <Form.Item name="remarks" {...formItemLayout} label="备注">
              <TextArea type="text" placeholder="请输入" rows="3" maxLength="50" showCount />
            </Form.Item>
          </Col>
        </Row>
        <Row>
          <Col offset={4} span={12}>
            <Button
              loading={props.loading}
              type="primary"
              style={{ marginRight: 30 }}
              onClick={handleSubmit}
            >
              提交
            </Button>
            <Button onClick={handleClose}>取消</Button>
          </Col>
        </Row>
      </Form>
    </Modal>
  );
};

export default connect(({ ware, loading }) => ({
  ware,
  loading: loading.models.setting,
}))(NoSystemModal);