From 4e97415cb80ae4e7cbece0294c2d2fbb04972ba1 Mon Sep 17 00:00:00 2001 From: yangwenhua <1289978696@qq.com> Date: Fri, 30 Sep 2022 14:40:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E9=80=9F=E5=BC=80=E5=A7=8B=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ConfirmConfig/index.jsx | 155 +++++++----------- .../components/StepsButton/index.jsx | 54 +++++- src/pages/quickStart/index.jsx | 57 +++++-- src/pages/quickStart/service.js | 8 +- 4 files changed, 160 insertions(+), 114 deletions(-) diff --git a/src/pages/quickStart/components/ConfirmConfig/index.jsx b/src/pages/quickStart/components/ConfirmConfig/index.jsx index 259235b..24ef9d5 100644 --- a/src/pages/quickStart/components/ConfirmConfig/index.jsx +++ b/src/pages/quickStart/components/ConfirmConfig/index.jsx @@ -1,121 +1,86 @@ import React, { useState, useEffect, useRef } from 'react'; - +import ReactDOM from 'react-dom'; +import { OrganizationGraph } from '@ant-design/graphs'; +import { nanoid } from 'nanoid' import quickAPI from "../../service"; import indexStyles from "../../index.less"; import { message } from 'antd'; - /** * 确认配置 * @returns */ const ConfirmConfig = (props) => { - const data = { - id: 'root', + const [orgData, setOrgData] = useState({ + // 门店 + id: props.storeConfig.id, value: { - name: '股东会', + name: props.storeConfig.name, }, + // 设备 children: [ { - id: 'joel', + id: props.deviceConfig.id, value: { - name: 'Joel Alan', + name: props.deviceConfig.deviceName, }, - children: [ - { - id: 'c1', - value: { - name: 'c1', - }, - children: [ - { - id: 'c1-1', - value: { - name: 'c1-1', - }, - }, - { - id: 'c1-2', - value: { - name: 'c1-2', - }, - children: [ - { - id: 'c1-2-1', - value: { - name: 'c1-2-1', - }, - }, - { - id: 'c1-2-2', - value: { - name: 'c1-2-2', - }, - }, - ], - }, - ], - }, - { - id: 'c2', - value: { - name: 'c2', - }, + //菜谱 + children: [] + } + ] + }); + + + const initOrgData = () => { + const tempData = JSON.parse(JSON.stringify(orgData)); + props.foodMenuConfig.forEach((foodMenu, foodMenuIndex) => { + tempData.children[0].children[foodMenuIndex] = { + id: nanoid(), + value: { + name: foodMenu.name, + }, + children: [] + } + foodMenu?.goodsConfig.forEach((foodItem, foodIndex) => { + tempData.children[0].children[foodMenuIndex].children[foodIndex] = { + id: nanoid(), + value: { + name: foodItem.name, }, - { - id: 'c3', + children: [] + } + foodItem?.bomConfig.forEach((bomItem, bomIndex) => { + tempData.children[0].children[foodMenuIndex].children[foodIndex].children[bomIndex] = { + id: nanoid(), value: { - name: 'c3', + name: bomItem.name, }, - children: [ - { - id: 'c3-1', - value: { - name: 'c3-1', - }, - }, - { - id: 'c3-2', - value: { - name: 'c3-2', - }, - children: [ - { - id: 'c3-2-1', - value: { - name: 'c3-2-1', - }, - }, - { - id: 'c3-2-2', - value: { - name: 'c3-2-2', - }, - }, - { - id: 'c3-2-3', - value: { - name: 'c3-2-3', - }, - }, - ], - }, - { - id: 'c3-3', - value: { - name: 'c3-3', - }, - }, - ], - }, - ], - }, - ], - }; + children: [] + } + bomItem?.materialConfig.forEach((materialItem, materialIndex) => { + tempData.children[0].children[foodMenuIndex].children[foodIndex].children[bomIndex].children[materialIndex] = { + id: nanoid(), + value: { + name: materialItem.name, + } + } + }); + }); + }); + }); + setOrgData(tempData); + } + + useEffect(() => { + initOrgData(); + }, []); + + return <> + } diff --git a/src/pages/quickStart/components/StepsButton/index.jsx b/src/pages/quickStart/components/StepsButton/index.jsx index 69ba52d..d0c3d99 100644 --- a/src/pages/quickStart/components/StepsButton/index.jsx +++ b/src/pages/quickStart/components/StepsButton/index.jsx @@ -1,6 +1,8 @@ import { Button } from 'antd'; import styles from "./index.less"; import { notification } from 'antd'; +import quickAPI from "../../service"; + const StepsButton = (props) => { const onClickNext = () => { @@ -93,6 +95,56 @@ const StepsButton = (props) => { } } + const onCreateConfig = async () => { + const jsonData = { + storeId: props.storeConfig.id, + deviceId: props.deviceConfig.id, + foodMenuList: [] + }; + props.foodMenuConfig.forEach((foodMenu, foodMenuIndex) => { + jsonData.foodMenuList[foodMenuIndex] = { + id: foodMenu.id, + goodsList: [] + } + foodMenu?.goodsConfig.forEach((foodItem, foodIndex) => { + jsonData.foodMenuList[foodMenuIndex].goodsList[foodIndex] = { + id: foodItem.id, + price: foodItem.price, + vipPrice: foodItem.vipPrice, + isdevice: true, + BOMList: [] + } + foodItem?.bomConfig.forEach((bomItem, bomIndex) => { + jsonData.foodMenuList[foodMenuIndex].goodsList[foodIndex].BOMList[bomIndex] = { + id: bomItem.id, + BatchingList: [] + } + bomItem?.materialConfig.forEach((materialItem, materialIndex) => { + jsonData.foodMenuList[foodMenuIndex].goodsList[foodIndex].BOMList[bomIndex].BatchingList[materialIndex] = { + id: materialItem.id, + BomQty: 10 + } + }); + }); + }); + }); + const response = await quickAPI.QuickStartAdd(jsonData); + if (response.data.isSuccess) { + notification.success({ + message: '快速开始', + description: '配置成功!', + placement: 'topRight' + }); + props.success(); + } else { + notification.error({ + message: '快速开始', + description: '配置失败!请重试!', + placement: 'topRight' + }); + } + } + return
{props.current > 0 && ( )} diff --git a/src/pages/quickStart/index.jsx b/src/pages/quickStart/index.jsx index f8ce716..487e7ff 100644 --- a/src/pages/quickStart/index.jsx +++ b/src/pages/quickStart/index.jsx @@ -1,4 +1,4 @@ -import { Steps, Card, message } from 'antd'; +import { Steps, Card, Result, Button } from 'antd'; import React, { useState, useEffect } from 'react'; import styles from "./index.less"; import { PageContainer } from '@ant-design/pro-layout'; @@ -14,7 +14,7 @@ import StepsButton from "./components/StepsButton"; const { Step } = Steps; const QuickStart = () => { - + const [isSuccess, setIsSuccess] = useState(false); const [current, setCurrent] = useState(0); const [quickStartObj, setQuickStartObj] = useState({ storeConfig: {}, @@ -108,18 +108,15 @@ const QuickStart = () => { const stepsContent = [ , , - , + , , , , - + ]; useEffect(() => { - if (current > 4) { - console.log('终极JSON对象:', JSON.stringify(quickStartObj)); - } - console.log('JSON对象更新啦', quickStartObj); + console.log('对象更新', quickStartObj) }, [quickStartObj]); return @@ -133,15 +130,41 @@ const QuickStart = () => {
- -
{stepsContent[current]}
-
- -
- - - -
+ { + isSuccess ? + + { + setQuickStartObj({ + storeConfig: {}, + deviceConfig: {}, + foodMenuConfig: [], + }) + setCurrent(0); + setIsSuccess(false); + }}> + 快速开始 + + ]} + /> + + : + <> + +
{stepsContent[current]}
+
+ +
+ + setIsSuccess(true)}> + +
+ + } } diff --git a/src/pages/quickStart/service.js b/src/pages/quickStart/service.js index 085a466..0f24e73 100644 --- a/src/pages/quickStart/service.js +++ b/src/pages/quickStart/service.js @@ -399,6 +399,12 @@ export default { method: 'POST', data: data, }); - } + }, + QuickStartAdd(data) { + return request('/kitchen/api/quickstart/add', { + method: 'POST', + data: data, + }); + } } \ No newline at end of file