From a717802a6f63d0b21d3f812c838292f53862594e Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Mon, 19 Feb 2024 11:14:13 +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 --- config/routes.js | 7 + .../goods/goodsbom/components/BomBatching.jsx | 148 +++++++++ .../goods/goodsbom/components/CreateBom.jsx | 302 ++++++++++++++++++ src/pages/database/goods/goodsbom/index.jsx | 296 +++++++++++++++++ src/pages/database/goods/goodsbom/service.js | 47 +++ src/pages/database/goods/newgoods/index.jsx | 2 +- 6 files changed, 801 insertions(+), 1 deletion(-) create mode 100644 src/pages/database/goods/goodsbom/components/BomBatching.jsx create mode 100644 src/pages/database/goods/goodsbom/components/CreateBom.jsx create mode 100644 src/pages/database/goods/goodsbom/index.jsx create mode 100644 src/pages/database/goods/goodsbom/service.js diff --git a/config/routes.js b/config/routes.js index 557381e..f9d4629 100644 --- a/config/routes.js +++ b/config/routes.js @@ -158,6 +158,13 @@ export default [ component: './database/goods/goodsInfo', access: 'k7', }, + { + name: '商品配方', + icon: 'smile', + path: '/database/goods/goodsbom', + component: './database/goods/goodsbom', + access: 'k7', + }, ] }, ], diff --git a/src/pages/database/goods/goodsbom/components/BomBatching.jsx b/src/pages/database/goods/goodsbom/components/BomBatching.jsx new file mode 100644 index 0000000..4435a14 --- /dev/null +++ b/src/pages/database/goods/goodsbom/components/BomBatching.jsx @@ -0,0 +1,148 @@ +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 '../service'; +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/goods/goodsbom/components/CreateBom.jsx b/src/pages/database/goods/goodsbom/components/CreateBom.jsx new file mode 100644 index 0000000..6600c04 --- /dev/null +++ b/src/pages/database/goods/goodsbom/components/CreateBom.jsx @@ -0,0 +1,302 @@ +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 { AddBomType,getproductpage } from '../service'; +import { + EditableProTable, + ProTable +} from '@ant-design/pro-table'; +const GoodsbomFrom = (props) => { + const { Option, OptGroup } = Select; + const [checkvalue, setCheckvalue] = useState([]); + const [dataSource, setDataSource] = useState([]); + const [editableKeys, setEditableRowKeys] = useState([]); + const [form] = Form.useForm(); + const [typename, settypename] = useState(''); + const inputRef = useRef(null); + const onNameChange=(event)=>{ + settypename(event.target.value); + } + const addItem=(e)=>{ + e.preventDefault(); + + if(typename.length==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); + } + }) + } + + } + useEffect(() => { + console.log("111111111") + console.log(props.defaultmatedata) + form.setFieldsValue({ + bomName: props.goodsname, + // bomType:1 + }); + if(props.defaultmatedata){ + let soredata=[]; + props.defaultmatedata.forEach((item,index)=>{ + var data={ + id:index, + batchingId:item, + dosage:0 + } + + soredata.push(data) + }) + + setEditableRowKeys(soredata.map((item) => item.id)) + setDataSource(soredata); + } + },[props]) + const columns=[ + { + 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=()=>{ + form + .validateFields() + .then((values) => { + var check=true; + var data=values; + console.log(dataSource) + if(checkvalue.length==0){ + check=false; + message.error("请选择商品属性") + }else{ + data.shuxing=checkvalue; + } + if(dataSource.length==0){ + check=false; + message.error("请选择物料") + }else{ + data.mate=dataSource.map(x=>{return {batchingId:x.batchingId,dosage:x.dosage}}); + } + if(check){ + form.resetFields(); + props.onFinish(data); + setDataSource([]) + } + + }) + .catch((info) => { + message.error("请填写必填信息") + }); + } + const onChangevalue=(data)=>{ + const { name, value } = data.target; + let names=""; + let updatedValues = [...checkvalue]; + for (let index = 0; index < props.goodsAttriburteData.length; index++) { + if (name === 'radiogroup'+index) { + // 将第一组的值累加到数组中 + updatedValues[index] = value; + + } + } + props.goodsAttriburteData.forEach(item=>{ + for (let index = 0; index < updatedValues.length; index++) { + var bs=item.goodsAttributeValueList.find(x=>x.goodsAttributeValuId==updatedValues[index])?.attributeValue + if(bs){ + names=names+bs; + if(index< updatedValues.length-1){ + names=names+"-" + } + } + + } + }) + + + form.setFieldsValue({ + bomName: props.goodsname+"("+names+")" + }); + setCheckvalue(updatedValues) + } + + return ( + { + props.onCancel(); + }} + maskClosable={false} + destroyOnClose + > +
+ + + + + e.stopPropagation()} + /> + + + + )} + /> + + + + +
+ *商品属性 + { + props.goodsAttriburteData == undefined ? '' :( + props.goodsAttriburteData.map((item, index) => { + return ( +
+
+ {item.attributeName} + + + { + item.goodsAttributeValueList.map((item, index)=>{ + return ( + {item.attributeValue} + ) + }) + } + + +
+
+ ); + }) + ) + } + *配方详情} + columns={columns} + rowKey="id" + value={dataSource} + onChange={setDataSource} + recordCreatorProps={{ + newRecordType: 'dataSource', + record: () => ({ + id: Date.now(), + }), + }} + + 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, + }}/> + {/* { + let Data = []; + var total = 0; + await getproductpage(params).then((r) => { + Data = r.data.data; + total = r.data.total; + }); + return { + data: Data, + success: true, + total: total, + }; + }} + columns={columns} + rowSelection={{ + onChange: (_, selectedRows) => { + setSelectedRows(selectedRows); + }, + }}/> */} +
+ //vessels + ); +}; + +export default GoodsbomFrom; diff --git a/src/pages/database/goods/goodsbom/index.jsx b/src/pages/database/goods/goodsbom/index.jsx new file mode 100644 index 0000000..ac365b5 --- /dev/null +++ b/src/pages/database/goods/goodsbom/index.jsx @@ -0,0 +1,296 @@ +import { PlusOutlined, UploadOutlined,ArrowLeftOutlined } from '@ant-design/icons'; +import { Button, Card, message, Steps, Empty, Form, Input, Upload, Select, InputNumber, Switch,TreeSelect,Divider,Space,Popconfirm } from 'antd'; +import { GridContent, PageContainer, RouteContext } from '@ant-design/pro-layout'; +import React, { Fragment, useRef, useState, useEffect } from 'react'; +import ProTable from '@ant-design/pro-table'; +import CreateBom from './components/CreateBom'; +// import UpdateBom from './components/UpdateBom' +// import BomBatching from './components/BomBatching' +import { addGoods} from '../newgoods/service'; +import { GetGoodsBom, DelGoodsBom,getbygoodsidattribute,addgoodsbomattribute,GetbomTypelist,getproductpage,getbomlist } from './service' +import axios from 'axios'; +import { history } from 'umi'; +const { Step } = Steps; +const { Option, OptGroup } = Select; +const { TextArea } = Input; +const Advanced = (props) => { + const [form] = Form.useForm(); + const [goodsTypes, setGoodsTypes] = useState([]); + const [goodsUnit, setGoodsUnit] = useState([]); + const [goodsBigTypes, setGoodsBigTypes] = useState([]); + const [goodsTaste, setGoodsTaste] = useState([]); + const [setGoodsBomModalVisible, handleGoodsBomModalVisible] = useState(); + const [handleCreateoodsBomModalVisible,setHandleCreateoodsBomModalVisible] = useState(false); + const [selectedRowsState, setSelectedRows] = useState([]); + const actionRef = useRef(); + const [currTabKey, SetCurrTabKey] = useState("basis") + const [url, setUrl] = useState(props.location.query.values ? props.location.query.values.imgUrl : null); + const [currentGoodsProp, setCurrentGoodsProp] = useState(0); + const [goodsAttriburteData, setGoodsAttriburteData] = useState([]); + const [bomtype, setBomtype] = useState([]); + const [matedata, setMatedata] = useState([]); + const [treeData, setTreeData] = useState(); + const [unitname, setunitname] = useState(''); + const [bomTypeData,setbomTypeData]= useState([]); + const inputRef = useRef(null); + const [Bomdata, setBomdata] = useState([]); + const [BomIds, setBomIds] = useState([]); + const [BomId, setBomId] = useState(); + const [UpdateBomVisible, setUpdateBomVisible] = useState(false); + const [BomBatchingVisible,setBomBatchingVisible]= useState(false); + const [goodsTypeIdvalue, setgoodsTypeIdvalue] = useState(); + //设置 + const [tabStatus, seTabStatus] = useState({ + operationKey: props.location.query.tabStatus ? props.location.query.tabStatus : 'basis', + tabActiveKey: props.location.query.tabStatus ? props.location.query.tabStatus : 'basis', + }); + useEffect(() => { + // if(!props.location?.query?.values){ + // history.push({ + // pathname: '/database/goods/newgoods', + // }); + // }else{ + SetCurrTabKey(tabStatus.tabActiveKey); + initGetbomType(); + intBatching();//默认原料 + //} + + }, [tabStatus]) + const onTabChange = (key) => { + if (currentGoodsProp === 1) { + message.info('套餐不能设置配方'); + return; + } + seTabStatus({ operationKey: key, tabActiveKey: key }); + + //initGoodsType() + }; + + function initGetbomType(){ + GetbomTypelist().then((r)=>{ + var list = []; + if (r.data.length > 0) { + r.data.forEach((item) => { + list.push({ text: item.name, value: item.id, label: item.name }); + }); + } + setbomTypeData(list) + }) + + } + function intBatching(){ + getproductpage().then((r) => { + setMatedata(r.data); + }); + } + function initTypeList(){ + initGetbomType(); + } + + const operationTabList = [ + { + key: 'goodsbom', + tab: '商品配方', + }, + + ]; + const bomcolumns = + [ + { + title: '主键', + dataIndex: 'id', + key: 'id', + hideInTable: true, + hideInSearch: true, + tip: '规则名称是唯一的 key', + }, + { + title: '配方名称', + key: 'name', + dataIndex: 'name', + valueType: 'textarea', + }, + { + title: '配方类型', + dataIndex: 'isMain', + hideInForm: true, + valueEnum: { + false: { + text: '辅料', + status: 'Processing', + }, + true: { + text: '主料', + status: 'Success', + }, + }, + }, + { + title: '操作', + dataIndex: 'option', + valueType: 'option', + render: (_, record) => [ + { + setUpdateBomVisible(true); + setBomId(record.bomId) + }} + > + 更新 + , + { + setBomBatchingVisible(true); + setBomId(record.bomId) + }} + > + 配方详情 + , + { + const hide = message.loading('正在删除'); + try { + DelGoodsBom(record.id); + hide(); + message.success('删除成功,即将刷新'); + actionRef.current.reload(); + return true; + } catch (error) { + hide(); + message.error('删除失败,请重试'); + actionRef.current.reload(); + return false; + } + }} + onCancel={() => {}} + > + 删除 + , + ], + } + ] + const contentList = { + goodsbom: ( + + [ + , + ]} + request={async (params) => { + if (props.location.query.values.id == undefined || props.location.query.values.id == null) { + + } else { + params.GoodsId = props.location.query.values.id; + var total = 0; + const msg = await GetGoodsBom(params); + if(msg.data.data.length>0){ + var nom=msg.data.data.map(x=>{ + return x.bomId; + }) + setBomIds(nom) + } + + return { + data: msg.data.data, + success: true, + total: total, + }; + } + + }} + rowSelection={{ + onChange: (_, selectedRows) => setSelectedRows(selectedRows), + }} + + /> + { + value.goodsId=props.location.query.values.id; + console.log(value) + await addgoodsbomattribute(value).then((r)=>{ + console.log(r) + if(r.data){ + message.success("添加成功") + setHandleCreateoodsBomModalVisible(false); + }else{ + message.error("添加失败") + } + actionRef.current.reload(); + }) + }} + goodsid={props.location.query.values?.id} + goodsname={props.location.query.values?.name} + goodsAttriburteData={goodsAttriburteData} + matedata={matedata} + bomtype={bomtype} + defaultmatedata={props.location.query.values?.defaultMate} + onCancel={() => { + setHandleCreateoodsBomModalVisible(false); + }} + /> + {/* + */} + + + ), + }; + return ( + { + history.push({ + pathname: '/database/goods/newgoods', + }); + }}>返回], + breadcrumb: {}, + }} + title={props.location.query.isAdd ? '商品新增' : '详情'} + tabActiveKey={currTabKey} + onTabChange={onTabChange} + tabList={operationTabList} + > + + {contentList[tabStatus.operationKey]} + + ); +}; + +export default Advanced; diff --git a/src/pages/database/goods/goodsbom/service.js b/src/pages/database/goods/goodsbom/service.js new file mode 100644 index 0000000..51157d7 --- /dev/null +++ b/src/pages/database/goods/goodsbom/service.js @@ -0,0 +1,47 @@ +import { request } from 'umi'; +import { getDataBaseUrl } from '@/global_data'; +export async function GetbomTypelist (data) { + return request(getDataBaseUrl()+`/api/bom/getbomtypelist`, { + method: 'Get', + // params: { ...params }, + // ...(options || {}), + }); + } + export async function getproductpage(params) { + return request(getDataBaseUrl()+'/api/batching/getbatchingselectlist', { + method: 'Get', + }); + } + export async function addgoodsbomattribute(data) { + return request(getDataBaseUrl()+`/api/goods/addgoodsbomattribute`, { + method: 'Post', + data: data, + }); + } + export async function getbygoodsidattribute (data) { + return request(getDataBaseUrl()+`/api/goodsattribute/getbygoodsidattribute?id=`+data, { + method: 'Get', + // params: { ...params }, + // ...(options || {}), + }); +} +export async function GetGoodsBom(data) { + return request(getDataBaseUrl()+`/api/goods/getgoodsbompage`, { + method: 'Post', + data: data, + }); + } + export async function DelGoodsBom (data) { + return request(getDataBaseUrl()+`/api/goods/delgoodsbom?Ids=${data}`, { + method: 'GET', + //data: data, + }); + } + export async function AddBomType (data) { + return request(getDataBaseUrl()+`/api/bom/addbomtype`, { + method: 'Post', + data: data, + // params: { ...params }, + // ...(options || {}), + }); + } diff --git a/src/pages/database/goods/newgoods/index.jsx b/src/pages/database/goods/newgoods/index.jsx index 7f2e840..3b74a1e 100644 --- a/src/pages/database/goods/newgoods/index.jsx +++ b/src/pages/database/goods/newgoods/index.jsx @@ -235,7 +235,7 @@ const GoodsManage = () => { type="primary" onClick={() => { history.push({ - pathname: '/database/goods/goodsInfo', + pathname: '/database/goods/goodsbom', query: { isAdd: false, values: record,