|
|
@@ -0,0 +1,536 @@ |
|
|
|
import React, { useState, useEffect, useRef } from 'react'; |
|
|
|
import ProTable from '@ant-design/pro-table'; |
|
|
|
import { Form, Input, Select, InputNumber, TreeSelect, message, Button, Modal, Radio, Upload, Switch, Row, Col } from 'antd'; |
|
|
|
import ProForm, { ProFormSelect, ProFormText, ProFormDigit } from '@ant-design/pro-form'; |
|
|
|
import quickAPI from "../../service"; |
|
|
|
import indexStyles from "../../index.less"; |
|
|
|
import StepsButton from "../StepsButton"; |
|
|
|
const { Option, OptGroup } = Select; |
|
|
|
|
|
|
|
const fieldLabels = { |
|
|
|
name: '物料名称', |
|
|
|
stockUint: '库存单位', |
|
|
|
specs: '物料规格', |
|
|
|
code: '物料编码', |
|
|
|
aittribute: '物料属性', |
|
|
|
typeID: '物料类别', |
|
|
|
status: '物料状态', |
|
|
|
price: '成本价', |
|
|
|
netrecovery: '净料率(%)', |
|
|
|
OutstockUint: '出库单位', |
|
|
|
proportion: '换算比例(%)', |
|
|
|
}; |
|
|
|
|
|
|
|
const MaterialConfig = (props) => { |
|
|
|
|
|
|
|
const [materialForm] = Form.useForm(); |
|
|
|
|
|
|
|
const [currentPage, setCurrentPage] = useState(0); |
|
|
|
const [pageSize, setPageSize] = useState(5); |
|
|
|
|
|
|
|
const [selectedRowsState, setSelectedRows] = useState(props.materialConfig.id ? [props.materialConfig] : []); |
|
|
|
const [selectedRowKeys, setSelectRowKeys] = useState(props.materialConfig.id ? [props.materialConfig.id] : []); |
|
|
|
|
|
|
|
const optionsWithDisabled = [ |
|
|
|
{ |
|
|
|
label: '新建物料', |
|
|
|
value: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: '选择物料', |
|
|
|
value: false, |
|
|
|
} |
|
|
|
]; |
|
|
|
|
|
|
|
const [isCreate, setIsCreate] = useState(props.materialConfig.id ? false : true); |
|
|
|
|
|
|
|
const onChangeState = ({ target: { value } }) => { |
|
|
|
setIsCreate(value); |
|
|
|
let emptyObj = { |
|
|
|
id: "", |
|
|
|
code: "", |
|
|
|
name: "", |
|
|
|
specs: "", |
|
|
|
aittribute: "", |
|
|
|
price: 0, |
|
|
|
netrecovery: 0, |
|
|
|
typeID: "", |
|
|
|
stockUint: "", |
|
|
|
outstockUint: "", |
|
|
|
proportion: 1, |
|
|
|
status: "" |
|
|
|
} |
|
|
|
props.onFinishForm('materialConfig', emptyObj); |
|
|
|
materialForm.setFieldsValue(emptyObj); |
|
|
|
setSelectRowKeys([]); |
|
|
|
setSelectedRows([]); |
|
|
|
} |
|
|
|
|
|
|
|
const onFinish = (values) => { |
|
|
|
props.onFinishForm('materialConfig', values, true); |
|
|
|
} |
|
|
|
|
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
title: '物料名称', |
|
|
|
dataIndex: 'name', |
|
|
|
ellipsis: true, |
|
|
|
formItemProps: { |
|
|
|
rules: [ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '名称为必填项', |
|
|
|
}, |
|
|
|
], |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '物料属性', |
|
|
|
dataIndex: 'aittribute', |
|
|
|
valueEnum: { |
|
|
|
0: { |
|
|
|
text: '成品', |
|
|
|
}, |
|
|
|
1: { |
|
|
|
text: '半成品', |
|
|
|
}, |
|
|
|
2: { |
|
|
|
text: '易耗品', |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '状态', |
|
|
|
dataIndex: 'status', |
|
|
|
hideInForm: true, |
|
|
|
valueEnum: { |
|
|
|
0: { |
|
|
|
text: '正常', |
|
|
|
status: 'Processing', |
|
|
|
}, |
|
|
|
1: { |
|
|
|
text: '停用', |
|
|
|
status: 'Success', |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
]; |
|
|
|
|
|
|
|
const [materialTypeList, setMaterialTypeList] = useState([]); |
|
|
|
const [materialUnitList, setMaterialUnitList] = useState([]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取物料类别 |
|
|
|
*/ |
|
|
|
const onFetchMaterialTypeList = async () => { |
|
|
|
const response = await quickAPI.GetMaterialTypeList(); |
|
|
|
if (response.statusCode === 200) { |
|
|
|
response.data.forEach(item => { |
|
|
|
item.value = item.id, |
|
|
|
item.label = item.name; |
|
|
|
}) |
|
|
|
setMaterialTypeList(response.data); |
|
|
|
} else { |
|
|
|
message.error(response.errors || '获取物料类别出错'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取物料单位 |
|
|
|
*/ |
|
|
|
const onFetchMaterialUnit = async () => { |
|
|
|
const response = await quickAPI.GetMaterialUintList(); |
|
|
|
if (response.statusCode === 200) { |
|
|
|
response.data.forEach(item => { |
|
|
|
item.value = item.id, |
|
|
|
item.label = item.name; |
|
|
|
}) |
|
|
|
setMaterialUnitList(response.data); |
|
|
|
} else { |
|
|
|
message.error(response.errors || '获取物料类别出错'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const [showMaterialTypeModal, setShowMaterialTypeModal] = useState(false); |
|
|
|
const [showMaterialUnitModal, setShowMaterialUnitModal] = useState(false); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
onFetchMaterialTypeList(); |
|
|
|
onFetchMaterialUnit(); |
|
|
|
}, []); |
|
|
|
|
|
|
|
return <> |
|
|
|
<div className={indexStyles.choose_change_state}> |
|
|
|
<Radio.Group |
|
|
|
options={optionsWithDisabled} |
|
|
|
onChange={onChangeState} |
|
|
|
value={isCreate} |
|
|
|
optionType="button" |
|
|
|
buttonStyle="solid" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div className={indexStyles.common_row}> |
|
|
|
<ProForm |
|
|
|
form={materialForm} |
|
|
|
labelCol={{ span: 6 }} |
|
|
|
layout="horizontal" |
|
|
|
hideRequiredMark |
|
|
|
initialValues={props.materialConfig} |
|
|
|
onFinish={onFinish} |
|
|
|
submitter={false} |
|
|
|
style={{ width: '800px', marginRight: '30px', flexShrink: 0 }} |
|
|
|
> |
|
|
|
<Row gutter={16}> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormText |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.code} |
|
|
|
name="code" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
max: 50, |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请输入原料编码" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormText name="id" hidden={true} /> |
|
|
|
<ProFormText |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.name} |
|
|
|
name="name" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
max: 50, |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请输入原料名称" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormText |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.specs} |
|
|
|
name="specs" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
max: 500, |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请输入规格型号" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormSelect |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.aittribute} |
|
|
|
name="aittribute" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择物料属性', |
|
|
|
}, |
|
|
|
]} |
|
|
|
options={[ |
|
|
|
{ |
|
|
|
value: '0', |
|
|
|
label: '成品', |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: '1', |
|
|
|
label: '半成品', |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: '2', |
|
|
|
label: '易耗品', |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请选择物料属性" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormDigit |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.price} |
|
|
|
name="price" |
|
|
|
placeholder="请输入成本价" |
|
|
|
min={1} |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormDigit |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.netrecovery} |
|
|
|
name="netrecovery" |
|
|
|
min={1} |
|
|
|
max={100} |
|
|
|
placeholder="请输入净料率" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<div className={indexStyles.add_row_content}> |
|
|
|
<ProFormSelect |
|
|
|
style={{ width: '65%' }} |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.typeID} |
|
|
|
name="typeID" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择物料类别', |
|
|
|
}, |
|
|
|
]} |
|
|
|
options={materialTypeList} |
|
|
|
placeholder="请选择物料类别" |
|
|
|
/> |
|
|
|
<Button onClick={() => setShowMaterialTypeModal(true)} disabled={!isCreate || props.materialConfig.id} type="primary" className={indexStyles.add_row_btn}>添加类别</Button> |
|
|
|
</div> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<div className={indexStyles.add_row_content}> |
|
|
|
<ProFormSelect |
|
|
|
style={{ width: '65%' }} |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.stockUint} |
|
|
|
name="stockUint" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择单位', |
|
|
|
}, |
|
|
|
]} |
|
|
|
options={materialUnitList} |
|
|
|
placeholder="请选择单位" |
|
|
|
/> |
|
|
|
<Button onClick={() => setShowMaterialUnitModal(true)} disabled={!isCreate || props.materialConfig.id} type="primary" className={indexStyles.add_row_btn}>添加单位</Button> |
|
|
|
</div> |
|
|
|
|
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<div className={indexStyles.add_row_content}> |
|
|
|
<ProFormSelect |
|
|
|
style={{ width: '65%' }} |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.OutstockUint} |
|
|
|
name="outstockUint" |
|
|
|
options={materialUnitList} |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择出库单位', |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请选择出库单位" |
|
|
|
/> |
|
|
|
<Button onClick={() => setShowMaterialUnitModal(true)} disabled={!isCreate || props.materialConfig.id} type="primary" className={indexStyles.add_row_btn}>添加单位</Button> |
|
|
|
</div> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormDigit |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.proportion} |
|
|
|
name="proportion" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入出入库换算比例', |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请输入换算比例" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
<Col lg={12} md={12} sm={24}> |
|
|
|
<ProFormSelect |
|
|
|
disabled={!isCreate || props.materialConfig.id} |
|
|
|
label={fieldLabels.status} |
|
|
|
name="status" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请选择状态', |
|
|
|
}, |
|
|
|
]} |
|
|
|
options={[ |
|
|
|
{ |
|
|
|
value: '0', |
|
|
|
label: '正常', |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: '1', |
|
|
|
label: '停用', |
|
|
|
}, |
|
|
|
]} |
|
|
|
placeholder="请选择状态" |
|
|
|
/> |
|
|
|
</Col> |
|
|
|
</Row> |
|
|
|
<Form.Item> |
|
|
|
<StepsButton current={props.current} steps={props.steps} prev={props.prev}></StepsButton> |
|
|
|
</Form.Item> |
|
|
|
</ProForm> |
|
|
|
|
|
|
|
{ |
|
|
|
!isCreate && <ProTable |
|
|
|
headerTitle="物料列表" |
|
|
|
rowKey="id" |
|
|
|
search={{ |
|
|
|
labelWidth: 120, |
|
|
|
}} |
|
|
|
request={async (params) => { |
|
|
|
let UserData = []; |
|
|
|
let total = 0; |
|
|
|
await quickAPI.GetMaterialPage(params).then((r) => { |
|
|
|
UserData = r.data.data; |
|
|
|
total = r.data.total; |
|
|
|
}); |
|
|
|
return { |
|
|
|
data: UserData, |
|
|
|
success: true, |
|
|
|
total: total, |
|
|
|
}; |
|
|
|
}} |
|
|
|
columns={columns} |
|
|
|
rowSelection={{ |
|
|
|
type: 'radio', |
|
|
|
onChange: (selectedRowKeys, selectedRows) => { |
|
|
|
setSelectRowKeys(selectedRowKeys); |
|
|
|
setSelectedRows(selectedRows); |
|
|
|
if (selectedRows.length > 0) { |
|
|
|
props.onFinishForm('materialConfig', selectedRows[0]); |
|
|
|
materialForm.setFieldsValue(selectedRows[0]); |
|
|
|
} else { |
|
|
|
let emptyObj = { |
|
|
|
id: "", |
|
|
|
code: "", |
|
|
|
name: "", |
|
|
|
specs: "", |
|
|
|
aittribute: "", |
|
|
|
price: 0, |
|
|
|
netrecovery: 0, |
|
|
|
typeID: "", |
|
|
|
stockUint: "", |
|
|
|
outstockUint: "", |
|
|
|
proportion: 1, |
|
|
|
status: "" |
|
|
|
} |
|
|
|
materialForm.setFieldsValue(emptyObj); |
|
|
|
props.onFinishForm('materialConfig', emptyObj); |
|
|
|
} |
|
|
|
}, |
|
|
|
selectedRowKeys: selectedRowKeys |
|
|
|
}} |
|
|
|
/> |
|
|
|
} |
|
|
|
<Modal |
|
|
|
title="添加物料单位" |
|
|
|
width={640} |
|
|
|
visible={showMaterialUnitModal} |
|
|
|
bodyStyle={{ padding: '32px 40px 48px' }} |
|
|
|
footer={null} |
|
|
|
onCancel={() => { |
|
|
|
setShowMaterialUnitModal(false) |
|
|
|
}} |
|
|
|
destroyOnClose |
|
|
|
maskClosable={false} |
|
|
|
> |
|
|
|
<Form |
|
|
|
layout="vertical" |
|
|
|
preserve={false} |
|
|
|
onFinish={async (values) => { |
|
|
|
const response = await quickAPI.AddMaterialUnit(values); |
|
|
|
if (response.data) { |
|
|
|
message.success('添加成功'); |
|
|
|
setShowMaterialUnitModal(false); |
|
|
|
onFetchMaterialUnit(); |
|
|
|
} else { |
|
|
|
message.error(response.errors || '物料单位添加失败'); |
|
|
|
} |
|
|
|
}} |
|
|
|
> |
|
|
|
<Form.Item name="id" hidden={true}> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="name" label="物料单位名称" rules={[{ required: true, max: 64 }]}> |
|
|
|
<Input placeholder="物料单位名称" /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
name="status" |
|
|
|
label="状态" |
|
|
|
rules={[{ required: true, message: '请选择状态' }]} |
|
|
|
> |
|
|
|
<Select placeholder="请选择状态"> |
|
|
|
<OptGroup> |
|
|
|
<Select.Option value="0">正常</Select.Option> |
|
|
|
<Select.Option value="1">停用</Select.Option> |
|
|
|
</OptGroup> |
|
|
|
</Select> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item> |
|
|
|
<Button type="primary" htmlType="submit"> |
|
|
|
保存 |
|
|
|
</Button> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
</Modal> |
|
|
|
<Modal |
|
|
|
title="添加物料分类" |
|
|
|
width={640} |
|
|
|
visible={showMaterialTypeModal} |
|
|
|
bodyStyle={{ padding: '32px 40px 48px' }} |
|
|
|
footer={null} |
|
|
|
onCancel={() => { |
|
|
|
setShowMaterialTypeModal(false); |
|
|
|
}} |
|
|
|
destroyOnClose |
|
|
|
maskClosable={false} |
|
|
|
> |
|
|
|
<Form |
|
|
|
layout="vertical" |
|
|
|
preserve={false} |
|
|
|
onFinish={async (values) => { |
|
|
|
const response = await quickAPI.AddMaterialType(values); |
|
|
|
if (response.data) { |
|
|
|
message.success('添加成功'); |
|
|
|
setShowMaterialTypeModal(false); |
|
|
|
onFetchMaterialTypeList(); |
|
|
|
} else { |
|
|
|
message.error(response.errors || '物料分类添加失败'); |
|
|
|
} |
|
|
|
}} |
|
|
|
> |
|
|
|
<Form.Item name="id" hidden={true}> |
|
|
|
<Input /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="name" label="物料分类名称" rules={[{ required: true, max: 64, whitespace: true }]}> |
|
|
|
<Input placeholder="请输入物物料分类称" /> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item |
|
|
|
name="status" |
|
|
|
label="状态" |
|
|
|
rules={[{ required: true, message: '请选择物料分类状态' }]} |
|
|
|
> |
|
|
|
<Select placeholder="请选择物料分类状态"> |
|
|
|
<OptGroup> |
|
|
|
<Select.Option value="0">正常</Select.Option> |
|
|
|
<Select.Option value="1">停用</Select.Option> |
|
|
|
</OptGroup> |
|
|
|
</Select> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item> |
|
|
|
<Button type="primary" htmlType="submit"> |
|
|
|
保存 |
|
|
|
</Button> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
</Modal> |
|
|
|
</div> |
|
|
|
</> |
|
|
|
} |
|
|
|
|
|
|
|
export default MaterialConfig; |