浏览代码

Merge branch 'master' of http://10.2.1.24:10244/zhaoy/BPA.SAAS.Web

storemanagementweb
gwbvipvip 10 个月前
父节点
当前提交
b4c15cc2b8
共有 6 个文件被更改,包括 801 次插入1 次删除
  1. +7
    -0
      config/routes.js
  2. +148
    -0
      src/pages/database/goods/goodsbom/components/BomBatching.jsx
  3. +302
    -0
      src/pages/database/goods/goodsbom/components/CreateBom.jsx
  4. +296
    -0
      src/pages/database/goods/goodsbom/index.jsx
  5. +47
    -0
      src/pages/database/goods/goodsbom/service.js
  6. +1
    -1
      src/pages/database/goods/newgoods/index.jsx

+ 7
- 0
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',
},
]
},
],


+ 148
- 0
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 (
<Modal
title={'配方详情'}
width={1040}
visible={props.BomBatchingVisible}
bodyStyle={{ padding: '32px 40px 1px 48px' }}
okText="确认"
cancelText="取消"
onOk={headleOk}
onCancel={() => {
props.onBomBatchingCancel();
}}
destroyOnClose
>
<EditableProTable
columns={columns}
rowKey="id"
value={dataSource}
onChange={setDataSource}
recordCreatorProps={{
newRecordType: 'dataSource',
record: () => ({
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,
}}/>
</Modal>
//vessels
);
};

export default GoodsbomFrom;

+ 302
- 0
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 (
<Modal
title={'新建配方'}
width={1040}
visible={props.handleCreateoodsBomModalVisible}
bodyStyle={{ padding: '32px 40px 1px 48px' }}
okText="确认"
cancelText="取消"
onOk={headleOk}
onCancel={() => {
props.onCancel();
}}
maskClosable={false}
destroyOnClose
>
<Form layout="horizontal" preserve={false} form={form}
>
<Form.Item name="bomName" label="配方名称" rules={[{ required: true, message: '配方名称' }]}>
<Input placeholder="请输入配方名称"/>
</Form.Item>
<Form.Item name="bomTypeList" rules={[{ required: true, message: '配方分类' }]} label="配方分类" >
<Select
style={{width: '100%'}}
mode="tags"
placeholder="请选配方分类"
options={props.bomTypeData}
dropdownRender={(menu) => (
<>
{menu}
<Divider style={{margin: '8px 0'}}/>
<Space style={{padding: '0 8px 4px'}}>
<Input
placeholder="请输入配方分类"
ref={inputRef}
value={typename}
onChange={onNameChange}
onKeyDown={(e) => e.stopPropagation()}
/>
<Button type="text" icon={<PlusOutlined />} onClick={addItem}>
新增
</Button>
</Space>
</>
)}
/>
</Form.Item>
<Form.Item name="bomType" label="配方类型" initialValue='1' rules={[{ required: true, message: '配方类型' }]}>
<Select
placeholder="请选配方类型"
onChange={(value) => {
form.setFieldsValue({
bomType:value
});
}}
>
<OptGroup>
<Select.Option value="1">主料配方</Select.Option>
<Select.Option value="0">辅料配方</Select.Option>
</OptGroup>
</Select>
</Form.Item>
</Form>
<span><span style={{color:'red',marginRight: 3}}>*</span>商品属性</span>
{
props.goodsAttriburteData == undefined ? '' :(
props.goodsAttriburteData.map((item, index) => {
return (
<div style={{marginLeft: 80}}>
<div>
<span style={{marginRight: 10}}> <Tag color="blue">{item.attributeName}</Tag>:</span>
<span>
<Radio.Group name={"radiogroup"+index} buttonStyle="solid" size="small" onChange={onChangevalue}>
{
item.goodsAttributeValueList.map((item, index)=>{
return (
<Radio.Button name={index} value={item.goodsAttributeValuId} style={{marginRight: 22, marginTop: 16}}>{item.attributeValue}</Radio.Button>
)
})
}
</Radio.Group>
</span>
</div>
</div>
);
})
)
}
<EditableProTable
headerTitle={ <span><span style={{color:'red',marginRight: 3}}>*</span>配方详情</span>}
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,
}}/>
{/* <ProTable
headerTitle="选择物料"
actionRef={actionRef}
size="small"
scroll={{x:200,y:200}}
rowKey="id"
search={false}
request={async (params) => {
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);
},
}}/> */}
</Modal>
//vessels
);
};

export default GoodsbomFrom;

+ 296
- 0
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) => [
<a
key="primary"
type="primary"
onClick={() => {
setUpdateBomVisible(true);
setBomId(record.bomId)
}}
>
更新
</a>,
<a
key="primary"
type="primary"
onClick={() => {
setBomBatchingVisible(true);
setBomId(record.bomId)
}}
>
配方详情
</a>,
<Popconfirm
type="primary"
key="primary"
title="确认删除吗?"
okText="是"
cancelText="否"
onConfirm={async () => {
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={() => {}}
>
<a href="#">删除</a>
</Popconfirm>,
],
}
]
const contentList = {
goodsbom: (
<Card
title="商品配方"
style={{
marginBottom: 24,
}}
bordered={false}
>
<ProTable
columns={bomcolumns}
actionRef={actionRef}
rowKey="id"
search={false}
toolBarRender={() => [
<Button
type="primary"
key="primary"
onClick={ async() => {
if (props.location.query.values?.id == undefined || props.location.query.values?.id == null) {
message.info('请先添加商品基础信息!');
} else {
await getbygoodsidattribute(props.location.query.values.id).then((r)=>{
setGoodsAttriburteData(r.data);
})
setHandleCreateoodsBomModalVisible(true);
}
//
}}
>
<PlusOutlined /> 选择配方
</Button>,
]}
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),
}}

/>
<CreateBom handleCreateoodsBomModalVisible={handleCreateoodsBomModalVisible}
bomTypeData={bomTypeData}
initTypeList={initTypeList}
onFinish={async (value) => {
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);
}}
/>
{/* <UpdateBom onUpdateBomCancel={onUpdateBomCancel} bomtype={bomtype} BomId={BomId} UpdateBomVisible={UpdateBomVisible} bomTypeData={bomTypeData} onUpdateBomSave={onUpdateBomSave}/>
<BomBatching matedata={matedata} onBomBatchingCancel={onBomBatchingCancel} BomId={BomId} BomBatchingVisible={BomBatchingVisible} onBomBatchingFinish={onBomBatchingFinish}/> */}
</Card>
),
};
return (
<PageContainer
host header={{
title: [<a key="back"
onClick={() => {
history.push({
pathname: '/database/goods/newgoods',
});
}}><ArrowLeftOutlined />返回</a>],
breadcrumb: {},
}}
title={props.location.query.isAdd ? '商品新增' : '详情'}
tabActiveKey={currTabKey}
onTabChange={onTabChange}
tabList={operationTabList}
>
{contentList[tabStatus.operationKey]}
</PageContainer>
);
};

export default Advanced;

+ 47
- 0
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 || {}),
});
}

+ 1
- 1
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,


正在加载...
取消
保存