diff --git a/src/pages/database/bom/components/CreateBom.jsx b/src/pages/database/bom/components/CreateBom.jsx new file mode 100644 index 0000000..0e88c7f --- /dev/null +++ b/src/pages/database/bom/components/CreateBom.jsx @@ -0,0 +1,145 @@ +import React, { useState, useRef } from 'react'; +import { Button, Modal, Form, Input, Select, Divider, Space, message } from 'antd'; +import { PlusOutlined } from '@ant-design/icons'; +import { EditableProTable } from '@ant-design/pro-table'; +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); + } + + 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 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); + } + }) + } + + } + + return ( + <> + + +
+ + + + + + + e.stopPropagation()} + /> + + + + )} + /> + +
+ *配方详情} + 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, + }} /> + +
+ + ); +}; +export default App; \ No newline at end of file diff --git a/src/pages/database/bom/index.jsx b/src/pages/database/bom/index.jsx index 564af0a..3da88cb 100644 --- a/src/pages/database/bom/index.jsx +++ b/src/pages/database/bom/index.jsx @@ -1,18 +1,54 @@ 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 } 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} from './services'; +import { bomPage, getproductpage,GetbomTypelist } from './services'; +import CreateBom from './components/CreateBom'; const GoodsBomsManage = (props) => { const actionRef = useRef(); const [modalVisible, setModalVisible] = useState(false); + const [matedata, setMatedata] = useState([]); + const [bomTypeData,setbomTypeData]= useState([]); useEffect(() => { + intBatching();//默认原料 }, []); + function intBatching() { + getproductpage().then((r) => { + setMatedata(r.data); + }); + } + function initTypeList() { + initGetbomType(); + } + 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 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) + }) + + } const columns = [ { @@ -76,7 +112,7 @@ const GoodsBomsManage = (props) => { okText="是" cancelText="否" onConfirm={async () => { - + }} onCancel={() => { }} > @@ -92,42 +128,50 @@ const GoodsBomsManage = (props) => { title: '', breadcrumb: {}, }}> - [ - , - ]} + [ + , + ]} + + request={async (params) => { + var total = 0; + var data = []; + const res = await bomPage(params); + if (res.statusCode == 200) { + data = res.data.data; + total = res.data.total; + } + return { + data: data, + success: true, + total: total, + }; + + }} + rowSelection={{ + onChange: (_, selectedRows) => setSelectedRows(selectedRows), + }} + /> + + {/* 新增菜谱 */} + { setModalVisible(false); }} + /> - request={async (params) => { - var total = 0; - var data=[]; - const res = await bomPage(params); - if(res.statusCode==200){ - data=res.data.data; - total=res.data.total; - } - return { - data: data, - success: true, - total: total, - }; - }} - rowSelection={{ - onChange: (_, selectedRows) => setSelectedRows(selectedRows), - }} - /> - ); }; diff --git a/src/pages/database/bom/services.js b/src/pages/database/bom/services.js index d6df3e0..2120a38 100644 --- a/src/pages/database/bom/services.js +++ b/src/pages/database/bom/services.js @@ -8,4 +8,26 @@ export async function bomPage(data) { }); } + export async function AddBomType (data) { + return request(getDataBaseUrl()+`/api/bom/addbomtype`, { + method: 'Post', + data: data, + // params: { ...params }, + // ...(options || {}), + }); + } + + export async function getproductpage(params) { + return request(getDataBaseUrl()+'/api/batching/getbatchingselectlist', { + method: 'Get', + }); + } + + export async function GetbomTypelist (data) { + return request(getDataBaseUrl()+`/api/bom/getbomtypelist`, { + method: 'Get', + // params: { ...params }, + // ...(options || {}), + }); + } diff --git a/src/pages/database/goods/goodsInfo/components/CreateBom.jsx b/src/pages/database/goods/goodsInfo/components/CreateBom.jsx index 6600c04..d1a973d 100644 --- a/src/pages/database/goods/goodsInfo/components/CreateBom.jsx +++ b/src/pages/database/goods/goodsInfo/components/CreateBom.jsx @@ -214,6 +214,8 @@ const GoodsbomFrom = (props) => { + + *商品属性 { props.goodsAttriburteData == undefined ? '' :( diff --git a/src/pages/database/goods/goodsbom/components/CreateBom.jsx b/src/pages/database/goods/goodsbom/components/CreateBom.jsx index 6600c04..7dab94e 100644 --- a/src/pages/database/goods/goodsbom/components/CreateBom.jsx +++ b/src/pages/database/goods/goodsbom/components/CreateBom.jsx @@ -1,5 +1,5 @@ import React, { useState,useRef,useEffect } from 'react'; -import { PlusOutlined} from '@ant-design/icons'; +import { PlusOutlined,CheckOutlined} from '@ant-design/icons'; import { Modal, Form, Input, Button, Select,Radio,message,Tag,Divider,Space } from 'antd'; import { AddBomType,getproductpage } from '../service'; import { @@ -14,6 +14,8 @@ const GoodsbomFrom = (props) => { const [form] = Form.useForm(); const [typename, settypename] = useState(''); const inputRef = useRef(null); + const [disaenumbled, setdisaenumbled] = useState('block'); + const [disnewd, setdisnewd] = useState('none'); const onNameChange=(event)=>{ settypename(event.target.value); } @@ -37,8 +39,8 @@ const GoodsbomFrom = (props) => { } useEffect(() => { - console.log("111111111") - console.log(props.defaultmatedata) + console.log("props.Bomdata",props.Bomdata) + console.log(props.goodsname) form.setFieldsValue({ bomName: props.goodsname, // bomType:1 @@ -97,21 +99,30 @@ const GoodsbomFrom = (props) => { .then((values) => { var check=true; var data=values; - console.log(dataSource) + console.log("values",values) 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(disnewd=="block"){ + 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(); + if(disaenumbled=="block"){ + data.Type="check" + }else{ + data.Type="add" + } + data.bomType=1; props.onFinish(data); setDataSource([]) } @@ -151,7 +162,13 @@ const GoodsbomFrom = (props) => { }); setCheckvalue(updatedValues) } - + const handleChange = (value) => { + console.log(`selected ${value}`); + form.setFieldsValue({ + bomId: value, + // bomType:1 + }); + }; return ( { maskClosable={false} destroyOnClose > -
- - + *商品属性 + { + props.goodsAttriburteData == undefined ? '' :( + props.goodsAttriburteData.map((item, index) => { + return ( +
+
+ {item.attributeName} + + + { + item.goodsAttributeValueList.map((item, index)=>{ + return ( + {item.attributeValue} + ) + }) + } + + +
+
+ ); + }) + ) + } + + + + + + + + - + { @@ -212,34 +283,10 @@ const GoodsbomFrom = (props) => { 辅料配方 - + */} - *商品属性 - { - props.goodsAttriburteData == undefined ? '' :( - props.goodsAttriburteData.map((item, index) => { - return ( -
-
- {item.attributeName} - - - { - item.goodsAttributeValueList.map((item, index)=>{ - return ( - {item.attributeValue} - ) - }) - } - - -
-
- ); - }) - ) - } - *配方详情} columns={columns} rowKey="id" diff --git a/src/pages/database/goods/goodsbom/index.jsx b/src/pages/database/goods/goodsbom/index.jsx index ac365b5..46fbe55 100644 --- a/src/pages/database/goods/goodsbom/index.jsx +++ b/src/pages/database/goods/goodsbom/index.jsx @@ -39,33 +39,19 @@ const Advanced = (props) => { 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 = []; @@ -86,14 +72,6 @@ const Advanced = (props) => { function initTypeList(){ initGetbomType(); } - - const operationTabList = [ - { - key: 'goodsbom', - tab: '商品配方', - }, - - ]; const bomcolumns = [ { @@ -130,26 +108,26 @@ const Advanced = (props) => { dataIndex: 'option', valueType: 'option', render: (_, record) => [ - { - setUpdateBomVisible(true); - setBomId(record.bomId) - }} - > - 更新 - , - { - setBomBatchingVisible(true); - setBomId(record.bomId) - }} - > - 配方详情 - , + // { + // setUpdateBomVisible(true); + // setBomId(record.bomId) + // }} + // > + // 更新 + // , + // { + // setBomBatchingVisible(true); + // setBomId(record.bomId) + // }} + // > + // 配方详情 + // , { ], } ] - const contentList = { - goodsbom: ( - - { + history.push({ + pathname: '/database/goods/newgoods', + }); + }}>返回], + breadcrumb: {}, + }} + > + + { // }} > - 选择配方 + 关联配方 , ]} request={async (params) => { @@ -224,7 +207,20 @@ const Advanced = (props) => { }) setBomIds(nom) } - + getbomlist().then((r)=>{ + console.log("nom",nom) + if(nom.length>0){ + var da=[] + r.data.map(x=>{ + var dif=nom.find(p=>p==x.id); + if(!dif){ + da.push(x) + } + }) + } + console.log("da",da) + setBomdata(da) + }) return { data: msg.data.data, success: true, @@ -240,6 +236,7 @@ const Advanced = (props) => { /> { value.goodsId=props.location.query.values.id; @@ -265,30 +262,6 @@ const Advanced = (props) => { setHandleCreateoodsBomModalVisible(false); }} /> - {/* - */} - - - ), - }; - return ( - { - history.push({ - pathname: '/database/goods/newgoods', - }); - }}>返回], - breadcrumb: {}, - }} - title={props.location.query.isAdd ? '商品新增' : '详情'} - tabActiveKey={currTabKey} - onTabChange={onTabChange} - tabList={operationTabList} - > - - {contentList[tabStatus.operationKey]} ); }; diff --git a/src/pages/database/goods/goodsbom/service.js b/src/pages/database/goods/goodsbom/service.js index 51157d7..648ec6c 100644 --- a/src/pages/database/goods/goodsbom/service.js +++ b/src/pages/database/goods/goodsbom/service.js @@ -45,3 +45,8 @@ export async function GetGoodsBom(data) { // ...(options || {}), }); } + export async function getbomlist() { + return request(getDataBaseUrl()+'/api/bom/getbomlist', { + method: 'Get', + }); + } diff --git a/src/pages/database/goods/newgoods/index.jsx b/src/pages/database/goods/newgoods/index.jsx index 3b74a1e..5527c14 100644 --- a/src/pages/database/goods/newgoods/index.jsx +++ b/src/pages/database/goods/newgoods/index.jsx @@ -217,7 +217,7 @@ const GoodsManage = () => { type="primary" onClick={() => { history.push({ - pathname: '/database/goods/goodsInfo', + pathname: '/database/goods/goodsbom', query: { isAdd: false, values: record,