From 31c8e3384c1c7ab1d3794979f6c20d5e6051f6cc Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Mon, 19 Feb 2024 20:11:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/bom/components/BomBatching.jsx | 147 ++++++++++++++ .../database/bom/components/CreateBom.jsx | 37 +++- .../database/bom/components/UpdateBom.jsx | 96 +++++++++ src/pages/database/bom/index.jsx | 185 ++++++++++++++---- src/pages/database/bom/services.js | 37 ++++ .../components/CreateAttribute.jsx | 2 +- src/pages/database/goods/newgoods/index.jsx | 4 +- 7 files changed, 466 insertions(+), 42 deletions(-) create mode 100644 src/pages/database/bom/components/BomBatching.jsx create mode 100644 src/pages/database/bom/components/UpdateBom.jsx diff --git a/src/pages/database/bom/components/BomBatching.jsx b/src/pages/database/bom/components/BomBatching.jsx new file mode 100644 index 0000000..bcade1e --- /dev/null +++ b/src/pages/database/bom/components/BomBatching.jsx @@ -0,0 +1,147 @@ +import React, { useState,useRef,useEffect } from 'react'; +import { PlusOutlined} from '@ant-design/icons'; +import { Modal, Form, Input, Button, Select,Radio,message,Tag,Divider,Space } from 'antd'; +import { GetByidBomList } from '../services'; +import { + EditableProTable, + ProTable +} from '@ant-design/pro-table'; +const GoodsbomFrom = (props) => { + const { Option, OptGroup } = Select; + const [dataSource, setDataSource] = useState([]); + const [editableKeys, setEditableRowKeys] = useState([]); + const [form] = Form.useForm(); + + useEffect(() => { + let soredata=[]; + if(props.BomId){ + GetByidBomList(props.BomId).then((t)=>{ + var data=t.data + if(data.bomEntry.length>0){ + data.bomEntry.map(x=>{ + var item={ + id:x.id, + bomId:x.bomId, + batchingId:x.batchingId, + dosage:x.bomQty + } + console.log("item",item) + soredata.push(item) + }) + } + console.log("soredata",soredata) + if(soredata.length>0){ + setEditableRowKeys(soredata.map((item) => item.id)) + setDataSource(soredata); + } + }) + } + + },[props]) + const columns=[ + { + title: '主键', + dataIndex: 'id', + key: 'id', + hideInTable: true, + hideInSearch: true, + tip: '规则名称是唯一的 key', + }, + { + title: '配方', + dataIndex: 'bomId', + hideInTable: true, + hideInSearch: true, + }, + { + title: '物料名称', + dataIndex: 'batchingId', + formItemProps: (form, { rowIndex }) => { + return { + rules: + rowIndex > 1 ? [{ required: true, message: '此项为必填项' }] : [], + }; + }, + valueType: 'select', + fieldProps: { + showSearch:true, + options: props.matedata.map((item, index) => {return {label:item.name,value:item.id}}) + }, + width: '25%', + }, + { + title: '用量', + dataIndex: 'dosage', + valueType:'digit', + width: '15%', + }, + { + title: '操作', + valueType: 'option', + width: '15%', + render: () => { + return null; + }, + }, +] + const headleOk=()=>{ + if(dataSource.length==0){ + check=false; + message.error("请选择物料") + }else{ + props.onBomBatchingFinish(dataSource); + //setDataSource([]) + } + + + } + return ( + { + props.onBomBatchingCancel(); + }} + destroyOnClose + > + ({ + id: Date.now(), + bomId:props.BomId + }), + }} + + editable={{ + type: 'multiple', + editableKeys, + actionRender: (row, config, defaultDoms) => { + return [defaultDoms.delete,defaultDoms.Button]; + }, + onValuesChange: (record, recordList) => { + setDataSource(recordList); + }, + onDelete:async (key, row) =>{ + console.log(key) + console.log(row) + + }, + onChange: setEditableRowKeys, + }}/> + + + //vessels + ); +}; + +export default GoodsbomFrom; diff --git a/src/pages/database/bom/components/CreateBom.jsx b/src/pages/database/bom/components/CreateBom.jsx index 0e88c7f..b47800d 100644 --- a/src/pages/database/bom/components/CreateBom.jsx +++ b/src/pages/database/bom/components/CreateBom.jsx @@ -6,12 +6,11 @@ import { AddBomType } from '../services'; const App = (props) => { - const [form] = Form.useForm(); const inputRef = useRef(null); const [typename, settypename] = useState(''); const [dataSource, setDataSource] = useState([]); const [editableKeys, setEditableRowKeys] = useState([]); - + const onNameChange = (event) => { settypename(event.target.value); } @@ -69,13 +68,39 @@ const App = (props) => { } + const headleOk = () => { + props.form.validateFields().then((values) => { + var check = true; + var data = values; + debugger + if (dataSource.length == 0) { + check = false; + message.error("请选择物料") + } else { + data.mate = dataSource.map(x => { return { batchingId: x.batchingId, dosage: x.dosage } }); + } + if (check) { + props.form.resetFields(); + props.onFinish(data); + setDataSource([]) + } + + }).catch((info) => { + message.error("请填写必填信息") + }); + } + return ( <> - -
+ + diff --git a/src/pages/database/bom/components/UpdateBom.jsx b/src/pages/database/bom/components/UpdateBom.jsx new file mode 100644 index 0000000..9d4b2e5 --- /dev/null +++ b/src/pages/database/bom/components/UpdateBom.jsx @@ -0,0 +1,96 @@ +import React, { useState, useEffect, useRef } from 'react'; +import { Modal, Form, Input, Button, Select, Switch, InputNumbe, Divider, Space } from 'antd'; +import { PlusOutlined } from '@ant-design/icons'; + +const UpdateBom = (props) => { + const { Option, OptGroup } = Select; + const [typename, settypename] = useState(''); + const inputRef = useRef(null); + + + const onNameChange = (event) => { + settypename(event.target.value); + } + + const addItem = (e) => { + e.preventDefault(); + + if (typename == 0) { + message.error("请输入名称"); + } else { + var parm = { name: typename } + AddBomType(parm).then((r) => { + if (r.succeeded) { + message.success('添加成功'); + props.initTypeList(); + settypename(''); + } else { + message.error(r.errors); + } + }) + } + + } + + const headleOk = () => { + props.onUpdateBomSave() + } + + + return ( + { + props.onCancel(); + }} + onOk={headleOk} + destroyOnClose + > + + + + + + + e.stopPropagation()} + /> + + + + )} + /> + + + + ); +}; + +export default UpdateBom; diff --git a/src/pages/database/bom/index.jsx b/src/pages/database/bom/index.jsx index 3da88cb..22647fd 100644 --- a/src/pages/database/bom/index.jsx +++ b/src/pages/database/bom/index.jsx @@ -1,20 +1,31 @@ import { PlusOutlined } from '@ant-design/icons'; -import { Button, message, Input, Drawer, Modal, Space, Tag, Popconfirm } from 'antd'; +import { Button, message, Input, Drawer, Modal, Space, Tag, Popconfirm, Form } from 'antd'; import React, { useState, useRef, useEffect } from 'react'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import ProTable from '@ant-design/pro-table'; -import { bomPage, getproductpage,GetbomTypelist } from './services'; +import { bomPage, getproductpage, GetbomTypelist, AddBom, UpdateBomInfo, UpdateBomBatcing,DelBom } from './services'; import CreateBom from './components/CreateBom'; +import UpdateBom from './components/UpdateBom'; +import BomBatching from './components/BomBatching' + const GoodsBomsManage = (props) => { const actionRef = useRef(); const [modalVisible, setModalVisible] = useState(false); + const [updateModalVisible, setupdateModalVisible] = useState(false); const [matedata, setMatedata] = useState([]); - const [bomTypeData,setbomTypeData]= useState([]); + const [bomTypeData, setbomTypeData] = useState([]); + const [selectedRowsState, setSelectedRows] = useState([]); + const [BomId, setBomId] = useState(); + const [form] = Form.useForm(); + const [form2] = Form.useForm(); + const [currentRow, setCurrentRow] = useState(); + const [BomBatchingVisible, setBomBatchingVisible] = useState(false); + useEffect(() => { + initGetbomType(); intBatching();//默认原料 - }, []); function intBatching() { @@ -37,8 +48,8 @@ const GoodsBomsManage = (props) => { }) } - function initGetbomType(){ - GetbomTypelist().then((r)=>{ + function initGetbomType() { + GetbomTypelist().then((r) => { var list = []; if (r.data.length > 0) { r.data.forEach((item) => { @@ -47,60 +58,79 @@ const GoodsBomsManage = (props) => { } setbomTypeData(list) }) - + } const columns = [ { title: '主键', dataIndex: 'id', - key: 'id', hideInTable: true, hideInSearch: true, tip: '规则名称是唯一的 key', + render: (dom, entity) => { + return ( + { + setCurrentRow(entity); + setShowDetail(true); + }} + > + {dom} + + ); + }, }, { title: '配方名称', - key: 'name', dataIndex: 'name', - valueType: 'textarea', + width: 300, + hideInForm: true, + hideInSearch: false, }, { - title: '配方类型', - dataIndex: 'isMain', - hideInForm: true, - valueEnum: { - false: { - text: '辅料', - status: 'Processing', - }, - true: { - text: '主料', - status: 'Success', - }, - }, + title: '配方分类', + dataIndex: 'bomTypeList', + search: false, + + render: (_, record) => ( + + { + bomTypeData.filter((x) => { + let findId = record.bomTypeList.find((findItem) => findItem === x.value); + let findBomType = bomTypeData.find((bomItem) => bomItem.value === findId); + return findBomType != null || undefined; + }).map((item) => ( + + {item.text} + + ))} + + ), }, { title: '操作', dataIndex: 'option', valueType: 'option', + width: 250, render: (_, record) => [ { - setUpdateBomVisible(true); - setBomId(record.bomId) + setCurrentRow(record); + form2.setFieldsValue(record); + setupdateModalVisible(true); }} > 更新 , { setBomBatchingVisible(true); - setBomId(record.bomId) + setBomId(record.id) }} > 配方详情 @@ -108,19 +138,72 @@ const GoodsBomsManage = (props) => { { - + const hide = message.loading('正在删除'); + try { + DelBom(record.id); + hide(); + message.success('删除成功,即将刷新'); + actionRef.current.reloadAndRest(); + return true; + } catch (error) { + hide(); + message.error('删除失败,请重试'); + actionRef.current.reloadAndRest(); + return false; + } }} onCancel={() => { }} > 删除 , + ], - } - ] + }, + ]; + + const onUpdateBomSave = () => { + form2 + .validateFields() + .then((values) => { + console.log(values) + var parm = { id: values.id, name: values.bomName, IsMain: values.bomType == '1' ? true : false, bomTypeIds: values.bomTypeList } + UpdateBomInfo(parm).then((r) => { + if (r.data) { + message.success('修改成功'); + setupdateModalVisible(false); + actionRef.current.reload(); + setBomId('') + } else { + message.error(r.errors || "修改失败"); + } + }) + }) + } + + + const onBomBatchingCancel = () => { + setBomBatchingVisible(false); + setBomId('') + } + + const onBomBatchingFinish = (form) => { + console.log("form", form) + var parm = { bomId: BomId, bomEntry: form }; + UpdateBomBatcing(parm).then((r) => { + if (r.succeeded) { + message.success('修改成功'); + setBomBatchingVisible(false); + actionRef.current.reload(); + setBomId('') + } else { + message.error(r.errors); + } + }) + } return ( @@ -167,10 +250,46 @@ const GoodsBomsManage = (props) => { {/* 新增菜谱 */} { setModalVisible(false); }} + onFinish={async (value) => { + await AddBom(value).then((r) => { + if (r.data) { + message.success("添加成功") + setModalVisible(false); + } else { + message.error("添加失败") + } + actionRef.current.reloadAndRest(); + }) + }} + onCancel={() => { setModalVisible(false); form.resetFields(); }} /> + {/* 修改菜谱 */} + { + + }} + onCancel={() => { + setupdateModalVisible(false); + setCurrentRow(undefined); + }} + /> + + {/* 配方详情 */} + + ); diff --git a/src/pages/database/bom/services.js b/src/pages/database/bom/services.js index 2120a38..f3e713a 100644 --- a/src/pages/database/bom/services.js +++ b/src/pages/database/bom/services.js @@ -7,6 +7,14 @@ export async function bomPage(data) { data:data, }); } + export async function AddBom(data) { + return request(getDataBaseUrl()+'/api/bom/AddBom', { + method: 'POST', + data:data, + }); + } + + export async function AddBomType (data) { return request(getDataBaseUrl()+`/api/bom/addbomtype`, { @@ -31,3 +39,32 @@ export async function bomPage(data) { }); } + + export async function GetByidBomList(data) { + return request(getDataBaseUrl()+`/api/bom/getbyidbomlist?bomId=`+data, { + method: 'Get', + }); + } + + export async function UpdateBomInfo(data) { + return request(getDataBaseUrl()+`/api/bom/update`, { + method: 'Post', + data: data, + }); + } + + export async function UpdateBomBatcing(data) { + return request(getDataBaseUrl()+`/api/bom/updatebombatcing`, { + method: 'Post', + data: data, + }); + } + + export async function DelBom (data) { + return request(getDataBaseUrl()+`/api/bom/DelBom?id=${data}`, { + method: 'post', + //data: data, + }); + } + + diff --git a/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx b/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx index c481b40..b53e670 100644 --- a/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx +++ b/src/pages/database/goods/goodstypemanage/components/CreateAttribute.jsx @@ -273,7 +273,7 @@ const handleUpdate = async (fields) => { onClick={async () => { await handleRemove(selectedRowsState); setSelectedRows([]); - actionRef.current?.reloadAndRest?.(); + actionRef.current?.AndRest?.(); }} > 删除 diff --git a/src/pages/database/goods/newgoods/index.jsx b/src/pages/database/goods/newgoods/index.jsx index 3b74a1e..1db631a 100644 --- a/src/pages/database/goods/newgoods/index.jsx +++ b/src/pages/database/goods/newgoods/index.jsx @@ -378,7 +378,7 @@ const GoodsManage = () => { // cancelText="否" // onConfirm={() => { // handleRemove([record.id]); - // actionRef.current?.reloadAndRest(); + // actionRef.current?.AndRest(); // }} // onCancel={() => {}} // > @@ -444,7 +444,7 @@ const GoodsManage = () => { onClick={async () => { await handleRemove(selectedRowsState); setSelectedRows([]); - actionRef.current?.reloadAndRest?.(); + actionRef.current?.AndRest?.(); }} > 删除