Browse Source

优化菜谱

dev
ywh 1 year ago
parent
commit
6a3e8f6c5b
8 changed files with 228 additions and 26 deletions
  1. +1
    -1
      src/pages/device/deviceInfo/index.jsx
  2. +6
    -2
      src/pages/foodMenu/foodMenuInfo/components/CreateForm.jsx
  3. +17
    -12
      src/pages/foodMenu/foodMenuInfo/index.jsx
  4. +5
    -3
      src/pages/store/storeGoodsInfo/components/ChooseDevice.jsx
  5. +148
    -0
      src/pages/store/storeGoodsInfo/components/FranchiseeMenu.jsx
  6. +3
    -5
      src/pages/store/storeGoodsInfo/components/MenuGoods.jsx
  7. +30
    -1
      src/pages/store/storeGoodsInfo/index.jsx
  8. +18
    -2
      src/pages/store/storeGoodsInfo/services.js

+ 1
- 1
src/pages/device/deviceInfo/index.jsx View File

@@ -301,7 +301,7 @@ const GoodsTypeManage = () => {
setDeviceFoodModal(true);
}}
>
编辑商品
绑定商品
</a>,
<a
key="add"


+ 6
- 2
src/pages/foodMenu/foodMenuInfo/components/CreateForm.jsx View File

@@ -1,5 +1,6 @@
import React from 'react';
import { Modal, Form, Input, Button, Select } from 'antd';
import { nanoid } from 'nanoid';

const CreateForm = (props) => {
const { Option, OptGroup } = Select;
@@ -23,12 +24,15 @@ const CreateForm = (props) => {
<Form.Item name="id" hidden={true}>
<Input />
</Form.Item>
<Form.Item label={"菜谱编码"} name="code" rules={[{ required: true,max: 20 }]} >
<Form.Item label={"菜谱编码"} name="code" initialValue={nanoid(20)} rules={[{ required: true, max: 20 }]} >
<Input />
</Form.Item>
<Form.Item label={"菜谱名称"} name="name" rules={[{ required: true,max: 20 }]} >
<Form.Item label={"菜谱名称"} name="name" rules={[{ required: true, max: 20 }]} >
<Input />
</Form.Item>
<Form.Item label={"排序"} name="sort" rules={[{ required: true }]} >
<Input type="number" />
</Form.Item>

<Form.Item>
<Button type="primary" htmlType="submit">


+ 17
- 12
src/pages/foodMenu/foodMenuInfo/index.jsx View File

@@ -12,27 +12,30 @@ const key = 'message';

//添加
const handleAdd = async (fields) => {
let result = false;
try {
message.loading('正在添加', key);
await AddFoodMenu(JSON.stringify(fields)).then((r) => {
message.destroy(key);
if (r.data) {
message.success('添加成功');
return true;
result = true;
} else {
message.error('添加失败');
return false;
message.error(r.errors || '添加失败');
result = false;
}
});
} catch (error) {
message.error('添加失败请重试!');
return false;
result = false;
}
return result;
};


//修改
const handleUpdate = async (fields) => {
let result = false;
try {
message.loading('正在修改', key);
message.destroy(key);
@@ -40,16 +43,17 @@ const handleUpdate = async (fields) => {
message.destroy(key);
if (r.data) {
message.success('修改成功',);
return true;
result = true;
} else {
message.error('修改失败');
return false;
message.error(r.errors || '修改失败');
result = false;
}
});
} catch (error) {
message.error('修改失败请重试!');
return false;
result = false;
}
return result;
};


@@ -201,17 +205,18 @@ const GoodsTypeManage = () => {

<CreateForm
onFinish={async (value) => {
var success = false;
let success = false;
if (value.id) {
success = handleUpdate(value);
success = await handleUpdate(value);
} else {
success = handleAdd(value);
success = await handleAdd(value);
}
console.log('success', success);
if (success) {
handleModalVisible(false);
setCurrentRow(undefined);
}
actionRef.current?.reloadAndRest?.();
actionRef.current?.reload();
}}
onCancel={() => {
handleModalVisible(false);


+ 5
- 3
src/pages/store/storeGoodsInfo/components/ChooseDevice.jsx View File

@@ -39,7 +39,8 @@ const ChooseDevice = (props) => {
const onFetchDeviceList = async () => {
const response = await GetDeviceInfoPage({
current: 1,
pageSize: 999
pageSize: 999,
storeId: props.storeId
});
if (response.statusCode === 200 && response.data?.data) {
response.data.data.forEach(item => {
@@ -56,8 +57,8 @@ const ChooseDevice = (props) => {
* 根据商品 查询当前绑定的设备
*/
const onFetchChoosedDevice = async () => {
if (props.goods) {
const response = await GetGoodDevice(props.goods.goodsId);
if (props.goods && props.storeId) {
const response = await GetGoodDevice(props.goods.goodsId, props.storeId);
if (response.statusCode === 200) {
setChoosedDevice(response.data);
}
@@ -73,6 +74,7 @@ const ChooseDevice = (props) => {
<Modal
title={`【${props.goods.goods_Name}】绑定设备`}
width={640}
bodyStyle={{ height: '300px' }}
visible={props.open}
onOk={handleOk}
onCancel={props.onCancel}


+ 148
- 0
src/pages/store/storeGoodsInfo/components/FranchiseeMenu.jsx View File

@@ -0,0 +1,148 @@
import { Modal, Space, Popconfirm, message } from 'antd';
import { useEffect, useRef, useState } from "react";
import { GetFoodMenuInfoPage, GetShopFoodMenuPage, StoreAddFoodMenuNew } from '../services';
import ProTable from '@ant-design/pro-table';

/**
* 关联加盟商菜谱
* @param {*} props
* @returns
*/
const FranchiseeMenu = (props) => {
const actionRef = useRef();
/**
* 当前选中的菜谱
*/
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const columns = [
{
title: '菜谱名称',
dataIndex: 'name',
},
{
title: '菜谱编码',
dataIndex: 'code',
hideInSearch: true,
},
{
title: '菜谱排序',
dataIndex: 'sort',
hideInSearch: true
},
];

const handleOk = async () => {
const response = await StoreAddFoodMenuNew({
foodMenuIds: selectedRowKeys,
storeId: props.storeId
});
if (response.statusCode === 200) {
message.success("绑定成功!");
props.onOk();
} else {
message.error(response.errors || '绑定菜谱失败');
}
}

/**
* 获取门店已绑定的菜谱
*/
const onFetchStoreMenu = async () => {
if (!props.storeId) return [];
const response = await GetShopFoodMenuPage({
current: 1,
pageSize: 999,
storeId: props.storeId
});
if (response.statusCode === 200) {
const tempArray = [];
response.data?.data?.forEach(item => {
tempArray.push(item.id);
});
setSelectedRowKeys(tempArray);
}
}

useEffect(() => {
onFetchStoreMenu();
}, []);

return <Modal destroyOnClose width={1200} title={`绑定菜谱`} visible={props.open} onOk={handleOk} onCancel={props.onCancel}>
<ProTable
columns={columns}
actionRef={actionRef}
pagination={{
pageSize: 10
}}
request={async (params = {}, sort, filter) => {
if (props.storeId) {
const response = await GetFoodMenuInfoPage({
...params
});
if (response.statusCode === 200) {
return {
data: response.data.data,
success: true,
total: response.data.total,
};
} else {
return []
}
}
return []
}}
rowSelection={{
type: 'checkbox',
selectedRowKeys,
onSelect: (record, selected) => {
const tempArray = [...selectedRowKeys];
const findIndex = tempArray.findIndex(item => item === record.id);
if (selected) {
findIndex < 0 && tempArray.push(record.id);
} else {
findIndex > -1 && tempArray.splice(findIndex, 1);
}
setSelectedRowKeys(tempArray);
},
onSelectAll: (selected, selectedRows, changeRows) => {
const tempArray = [...selectedRowKeys];
if (selected) {
selectedRows.forEach(item => {
if (!item) return;
const findIndex = tempArray.findIndex(fItem => fItem === item.id);
if (findIndex < 0) {
tempArray.push(item.id);
}
});
} else {
changeRows.forEach(item => {
const findIndex = tempArray.findIndex(fItem => fItem === item.id);
if (findIndex > -1) {
tempArray.splice(findIndex, 1);
}
});
}
setSelectedRowKeys(tempArray);
}
}}
tableAlertOptionRender={() => {
return (
<Space size={16}>
<Popconfirm
title="此操作会取消所有选中项,确定要取消吗?"
onConfirm={() => setSelectedRowKeys([])}
okText="确定"
cancelText="取消"
>
<a>取消选择</a>
</Popconfirm>
</Space>
);
}}
rowKey="id"
headerTitle="商品列表"
/>
</Modal>
}

export default FranchiseeMenu;

+ 3
- 5
src/pages/store/storeGoodsInfo/components/MenuGoods.jsx View File

@@ -48,13 +48,12 @@ const MenuGoods = (props) => {
},

{
title: '是否设备制作',
title: '是否设备',
dataIndex: 'isDevice',
valueEnum: {
0: { text: '店铺', status: 'Processing' },
1: { text: '设备', status: 'Success' },
},
hideInSearch: true,
},
{
title: '状态',
@@ -63,7 +62,6 @@ const MenuGoods = (props) => {
0: { text: '上架', status: 'Processing' },
1: { text: '下架', status: 'Success' },
},
hideInSearch: true,
},
{
title: '估清',
@@ -72,7 +70,6 @@ const MenuGoods = (props) => {
0: { text: '销售', status: 'Processing' },
1: { text: '估清', status: 'Success' },
},
hideInSearch: true,
},
{
title: '操作',
@@ -145,7 +142,7 @@ const MenuGoods = (props) => {
setDeviceModal(true);
}}
>
{record.isDevice == 0 ? '设备制作' : '门店制作'}
修改为{record.isDevice == 0 ? '设备制作' : '门店制作'}
</a>,
<a
key="config"
@@ -216,6 +213,7 @@ const MenuGoods = (props) => {
open={deviceModal}
goods={currGoods}
foodMenu={props.foodMenu}
storeId={props.storeId}
onCancel={() => setDeviceModal(false)}
onOk={() => {
actionRef.current.reload();


+ 30
- 1
src/pages/store/storeGoodsInfo/index.jsx View File

@@ -1,5 +1,5 @@
import { PlusOutlined } from '@ant-design/icons';
import { Tabs, Card, Pagination, Table, message, Button, Popconfirm, Modal } from 'antd';
import { Tabs, message, Button } from 'antd';
const { TabPane } = Tabs;
import React, { useState, useRef, useEffect } from 'react';
import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
@@ -11,6 +11,7 @@ import { UnorderedListOutlined } from '@ant-design/icons';
import { history } from 'umi';
const key = 'message';
import MenuGoods from "./components/MenuGoods";
import FranchiseeMenu from "./components/FranchiseeMenu";

const storeGoodsInfo = (props) => {

@@ -23,6 +24,8 @@ const storeGoodsInfo = (props) => {
const [showModal, setShowModal] = useState(false);
//当前选中的菜谱
const [currFoodMenu, setCurrFoodMenu] = useState();
//是否展示 关联加盟商菜谱弹窗
const [franchiseeMenuModal, setFranchiseeMenuModal] = useState(false);

/**
* 获取店铺列表
@@ -116,6 +119,18 @@ const storeGoodsInfo = (props) => {
}}
rowKey="id"
headerTitle="菜谱列表"
toolBarRender={() => [
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setFranchiseeMenuModal(true);
}}
type="primary"
>
关联加盟商菜谱
</Button>
]}
/>
{
showModal && currStore && currFoodMenu && <MenuGoods
@@ -128,6 +143,20 @@ const storeGoodsInfo = (props) => {

</MenuGoods>
}

{
franchiseeMenuModal && currStore && <FranchiseeMenu
open={franchiseeMenuModal}
storeId={currStore}
onCancel={() => setFranchiseeMenuModal(false)}
onOk={() => {
setFranchiseeMenuModal(false);
actionRef.current?.reload();
}}
>

</FranchiseeMenu>
}
</PageContainer>;
};



+ 18
- 2
src/pages/store/storeGoodsInfo/services.js View File

@@ -134,8 +134,24 @@ export async function AddGoodDevice(data) {
}

/** 查询商品绑定的所有设备 */
export async function GetGoodDevice(goodsId) {
return request(`/kitchen/api/goodes/GetGoodDevice?foodId=${goodsId}`, {
export async function GetGoodDevice(goodsId, storeId) {
return request(`/kitchen/api/goodes/GetGoodDevice?foodId=${goodsId}&storeId=${storeId}`, {
method: 'GET',
});
}

/** 菜谱列表 */
export async function GetFoodMenuInfoPage(data) {
return request(`/kitchen/api/FoodMenu/GetFoodMenuInfoPage`, {
method: 'POST',
data: data,
});
}

/** 店铺添加菜谱 */
export async function StoreAddFoodMenuNew(data) {
return request(`/kitchen/api/FoodMenu/StoreAddFoodMenuNew`, {
method: 'POST',
data: data,
});
}

Loading…
Cancel
Save