From e404c3be1a8774db1c9970683af3ff98d666536b Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Thu, 18 Feb 2021 17:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=8F=9C=E5=93=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stdiet-ui/jsconfig.json | 10 + stdiet-ui/package.json | 4 +- .../src/components/AutoHideInfo/index.vue | 2 +- .../src/components/AutoHideMessage/index.vue | 2 +- stdiet-ui/src/components/Editor/index.vue | 4 +- .../components/PhysicalSignsDialog/index.vue | 2 +- .../components/PhysicalSignsEdit/index.vue | 2 +- .../components/PhysicalSignsRemark/index.vue | 2 +- stdiet-ui/src/components/RecipesCom/index.vue | 87 ----- .../TextInfo/index.vue} | 0 stdiet-ui/src/store/modules/recipes.js | 163 ++++++++- stdiet-ui/src/utils/echarts/myShine.js | 257 ++++++++++++++ stdiet-ui/src/views/custom/dishes/index.vue | 14 +- .../custom/recipesBuild/BodySignView.vue | 2 +- .../views/custom/recipesBuild/HealthyView.vue | 3 +- .../views/custom/recipesBuild/RecipesView.vue | 17 - .../RecipesView/RecipesAspectCom/BarChart.vue | 146 ++++++++ .../RecipesView/RecipesAspectCom/PieChart.vue | 200 +++++++++++ .../RecipesView/RecipesAspectCom/index.vue | 62 ++++ .../RecipesCom/EditableText/index.vue | 69 ++++ .../RecipesCom/EditableUnit/index.vue | 147 ++++++++ .../RecipesView/RecipesCom/index.vue | 321 ++++++++++++++++++ .../custom/recipesBuild/RecipesView/index.vue | 44 +++ .../src/views/custom/recipesBuild/index.vue | 49 +-- 24 files changed, 1462 insertions(+), 147 deletions(-) create mode 100644 stdiet-ui/jsconfig.json delete mode 100644 stdiet-ui/src/components/RecipesCom/index.vue rename stdiet-ui/src/{views/custom/recipesBuild/TextInfo.vue => components/TextInfo/index.vue} (100%) create mode 100644 stdiet-ui/src/utils/echarts/myShine.js delete mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/BarChart.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/PieChart.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/index.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableText/index.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableUnit/index.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue create mode 100644 stdiet-ui/src/views/custom/recipesBuild/RecipesView/index.vue diff --git a/stdiet-ui/jsconfig.json b/stdiet-ui/jsconfig.json new file mode 100644 index 000000000..f87334d48 --- /dev/null +++ b/stdiet-ui/jsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + } + } +} diff --git a/stdiet-ui/package.json b/stdiet-ui/package.json index 29bdfa9f3..f69302144 100644 --- a/stdiet-ui/package.json +++ b/stdiet-ui/package.json @@ -46,13 +46,15 @@ "clipboard": "^2.0.6", "core-js": "3.6.5", "dayjs": "^1.9.1", - "echarts": "4.2.1", + "echarts": "4.7.0", "element-ui": "2.13.2", "file-saver": "2.0.1", "fuse.js": "3.4.4", + "immer": "^8.0.1", "js-beautify": "1.10.2", "js-cookie": "2.2.0", "jsencrypt": "3.0.0-rc.1", + "lodash": "^4.17.20", "normalize.css": "7.0.0", "nprogress": "0.2.0", "path-to-regexp": "2.4.0", diff --git a/stdiet-ui/src/components/AutoHideInfo/index.vue b/stdiet-ui/src/components/AutoHideInfo/index.vue index c583838c6..20457e1f4 100644 --- a/stdiet-ui/src/components/AutoHideInfo/index.vue +++ b/stdiet-ui/src/components/AutoHideInfo/index.vue @@ -38,7 +38,7 @@ }; - \ No newline at end of file + diff --git a/stdiet-ui/src/components/PhysicalSignsDialog/index.vue b/stdiet-ui/src/components/PhysicalSignsDialog/index.vue index a21c58626..102568317 100644 --- a/stdiet-ui/src/components/PhysicalSignsDialog/index.vue +++ b/stdiet-ui/src/components/PhysicalSignsDialog/index.vue @@ -473,7 +473,7 @@ export default { }; - diff --git a/stdiet-ui/src/views/custom/recipesBuild/TextInfo.vue b/stdiet-ui/src/components/TextInfo/index.vue similarity index 100% rename from stdiet-ui/src/views/custom/recipesBuild/TextInfo.vue rename to stdiet-ui/src/components/TextInfo/index.vue diff --git a/stdiet-ui/src/store/modules/recipes.js b/stdiet-ui/src/store/modules/recipes.js index be63473b5..e0ef51672 100644 --- a/stdiet-ui/src/store/modules/recipes.js +++ b/stdiet-ui/src/store/modules/recipes.js @@ -3,11 +3,17 @@ import { getCustomerPhysicalSignsByCusId } from "@/api/custom/customer"; import { dealHealthy } from "@/utils/healthyData"; import { getRecipesPlan } from "@/api/custom/recipesPlan"; import { getRecipes } from "@/api/custom/recipes"; +import { getDicts } from "@/api/system/dict/data"; +import produce from "immer"; const oriState = { healthyData: {}, healthyDataType: 0, - recipesData: [] + recipesData: [], + cusUnitOptions: [], + cusWeightOptions: [], + typeOptions: [], + currentDay: -1 }; const mutations = { @@ -17,6 +23,46 @@ const mutations = { }, setRecipesData(state, payload) { state.recipesData = payload.recipesData; + console.log(payload.recipesData); + }, + updateRecipesDishesWeight(state, payload) { + const tarDishes = state.recipesData[payload.num].dishes.find( + obj => obj.id === payload.dishesId + ); + if (tarDishes) { + const tarIgd = tarDishes.igdList.find(obj => obj.id === payload.igdId); + if (tarIgd) { + tarIgd.weight = payload.weight; + } + } + }, + updateRecipesDishesCustomWeight(state, payload) { + const tarDishes = state.recipesData[payload.num].dishes.find( + obj => obj.id === payload.dishesId + ); + if (tarDishes) { + const tarIgd = tarDishes.igdList.find(obj => obj.id === payload.igdId); + if (tarIgd) { + tarIgd.cusWeight = payload.cusWeight; + tarIgd.cusUnit = payload.cusUnit; + } + } + }, + updateOptions(state, payload) { + payload.cusUnitOptions && (state.cusUnitOptions = payload.cusUnitOptions); + payload.cusWeightOptions && + (state.cusWeightOptions = payload.cusWeightOptions); + payload.typeOptions && (state.typeOptions = payload.typeOptions); + }, + setCurrentDay(state, payload) { + state.currentDay = + payload.currentDay === state.currentDay ? -1 : payload.currentDay; + }, + deleteSomeDayDishes(state, payload) { + // console.log(payload); + state.recipesData[payload.num].dishes = state.recipesData[ + payload.num + ].dishes.filter(obj => obj.id !== payload.dishesId); }, clean(state) { // console.log("clean"); @@ -32,12 +78,25 @@ const actions = { if (!orderResult.data.cusId) { throw new Error("未找到用户id"); } + // + getDicts("cus_cus_unit").then(response => { + commit("updateOptions", { cusUnitOptions: response.data }); + }); + getDicts("cus_cus_weight").then(response => { + commit("updateOptions", { cusWeightOptions: response.data }); + }); + getDicts("cus_dishes_type").then(response => { + commit("updateOptions", { typeOptions: response.data }); + }); // 健康数据 const healthyDataResult = await getCustomerPhysicalSignsByCusId( orderResult.data.cusId ); if (healthyDataResult.code === 200) { + if (!healthyDataResult.data.customerHealthy) { + throw new Error("客户还没填写健康评估表"); + } commit("setHealtyData", { healthyDataType: healthyDataResult.data.type, healthyData: dealHealthy(healthyDataResult.data.customerHealthy) @@ -51,7 +110,56 @@ const actions = { const recipesDataResult = await getRecipes(payload.recipesId); if (recipesDataResult.code === 200) { commit("setRecipesData", { - recipesData: recipesDataResult.data + recipesData: recipesDataResult.data.map(dayData => { + return { + id: dayData.id, + numDay: dayData.numDay, + dishes: dayData.dishes.reduce((arr, cur) => { + if ( + cur.id > -1 && + cur.name && + cur.igdList.length > 0 && + cur.type !== "0" + ) { + arr.push({ + id: cur.id, + name: cur.name, + methods: cur.methods, + type: cur.type, + isMain: cur.isMain, + igdList: cur.igdList.reduce((igdArr, igdData) => { + if (igdData.id > 0) { + const tarDetail = cur.detail.find( + obj => obj.id === igdData.id + ); + igdArr.push({ + id: igdData.id, + name: igdData.name, + carbonRatio: igdData.carbonRatio, + fatRatio: igdData.fatRatio, + proteinRatio: igdData.proteinRatio, + cusUnit: tarDetail + ? tarDetail.cus_unit + : igdData.cusUnit, + cusWeight: tarDetail + ? parseFloat(tarDetail.cus_weight) + : igdData.cusWeight, + weight: tarDetail + ? parseFloat(tarDetail.weight) + : igdData.weight, + notRec: igdData.notRec, + rec: igdData.rec, + type: igdData.type + }); + } + return igdArr; + }, []) + }); + } + return arr; + }, []) + }; + }) }); } else { throw new Error(recipesDataResult.msg); @@ -60,7 +168,56 @@ const actions = { } }; -const getters = {}; +const getters = { + analyseData: state => { + const datas = + state.currentDay > -1 + ? [state.recipesData[state.currentDay]] + : state.recipesData; + + const nutriData = datas.map(data => + data.dishes.reduce( + (obj, cur) => { + cur.igdList.forEach(igd => { + obj.pWeight += (igd.weight / 100) * igd.proteinRatio; + obj.pHeat = obj.pWeight * 4; + obj.fWeight += (igd.weight / 100) * igd.fatRatio; + obj.fHeat = obj.fWeight * 9; + obj.cWeight += (igd.weight / 100) * igd.carbonRatio; + obj.cHeat = obj.cWeight * 4; + }); + return obj; + }, + { + name: `第${data.numDay}天`, + pWeight: 0, + fWeight: 0, + cWeight: 0, + pHeat: 0, + fHeat: 0, + cHeat: 0 + } + ) + ); + // console.log(nutriData); + return nutriData; + }, + cusUnitDict: state => + state.cusUnitOptions.reduce((obj, cur) => { + obj[cur.dictValue] = cur.dictLabel; + return obj; + }, {}), + cusWeightDict: state => + state.cusWeightOptions.reduce((obj, cur) => { + obj[cur.dictValue] = cur.dictLabel; + return obj; + }, {}), + typeDict: state => + state.typeOptions.reduce((obj, cur) => { + obj[cur.dictValue] = cur.dictLabel; + return obj; + }, {}) +}; export default { namespaced: true, diff --git a/stdiet-ui/src/utils/echarts/myShine.js b/stdiet-ui/src/utils/echarts/myShine.js new file mode 100644 index 000000000..01ce1abe6 --- /dev/null +++ b/stdiet-ui/src/utils/echarts/myShine.js @@ -0,0 +1,257 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if ( + typeof exports === 'object' && + typeof exports.nodeName !== 'string' + ) { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +})(this, function(exports, echarts) { + var log = function(msg) { + if (typeof console !== 'undefined') { + console && console.error && console.error(msg); + } + }; + if (!echarts) { + log('ECharts is not Loaded'); + return; + } + + var colorPalette = [ + '#c12e34', + '#e6b600', + '#0098d9', + '#2b821d', + '#005eaa', + '#339ca8', + '#cda819', + '#32a487' + ]; + + var theme = { + color: colorPalette, + + title: { + textStyle: { + fontWeight: 'normal', + fontSize: 14 + } + }, + + visualMap: { + color: ['#1790cf', '#a2d4e6'] + }, + + toolbox: { + iconStyle: { + normal: { + borderColor: '#06467c' + } + } + }, + + tooltip: { + textStyle: { + color: '#262626', + fontSize: 12 + }, + backgroundColor: 'rgba(255,255,255,0.9)', + borderWidth: 1, + padding: 10, + borderColor: '#ccc', + extraCssText: 'box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);', + }, + + categoryAxis: { + axisLine: { + show: true, + lineStyle: { + color: '#ebebeb', + }, + }, + axisTick: { + show: false, + lineStyle: { + color: '#ebebeb', + }, + }, + axisLabel: { + show: true, + textStyle: { + color: '#262626', + }, + }, + splitLine: { + show: false, + lineStyle: { + color: ['#ccc'], + }, + }, + splitArea: { + show: false, + areaStyle: { + color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)'], + }, + }, + }, + valueAxis: { + axisLine: { + show: true, + lineStyle: { + color: '#ebebeb', + }, + }, + axisTick: { + show: false, + lineStyle: { + color: '#ebebeb', + }, + }, + axisLabel: { + show: true, + textStyle: { + color: '#262626', + }, + }, + splitLine: { + show: false, + lineStyle: { + color: ['#ccc'], + }, + }, + splitArea: { + show: false, + areaStyle: { + color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)'], + }, + }, + }, + + dataZoom: { + dataBackgroundColor: '#dedede', + fillerColor: 'rgba(154,217,247,0.2)', + handleColor: '#005eaa' + }, + + timeline: { + lineStyle: { + color: '#005eaa' + }, + controlStyle: { + color: '#005eaa', + borderColor: '#005eaa' + } + }, + + candlestick: { + itemStyle: { + color: '#c12e34', + color0: '#2b821d' + }, + lineStyle: { + width: 1, + color: '#c12e34', + color0: '#2b821d' + }, + areaStyle: { + color: '#e6b600', + color0: '#005eaa' + } + }, + + graph: { + itemStyle: { + color: '#e6b600' + }, + linkStyle: { + color: '#005eaa' + } + }, + + map: { + itemStyle: { + color: '#f2385a', + borderColor: '#eee', + areaColor: '#ddd' + }, + areaStyle: { + color: '#ddd' + }, + label: { + color: '#c12e34' + } + }, + + gauge: { + axisLine: { + show: true, + lineStyle: { + color: [ + [0.2, '#2b821d'], + [0.8, '#005eaa'], + [1, '#c12e34'] + ], + width: 5 + } + }, + axisTick: { + splitNumber: 10, + length: 8, + lineStyle: { + color: 'auto' + } + }, + axisLabel: { + textStyle: { + color: 'auto' + } + }, + splitLine: { + length: 12, + lineStyle: { + color: 'auto' + } + }, + pointer: { + length: '90%', + width: 3, + color: 'auto' + }, + title: { + textStyle: { + color: '#333' + } + }, + detail: { + textStyle: { + color: 'auto' + } + } + } + }; + echarts.registerTheme('myShine', theme); +}); diff --git a/stdiet-ui/src/views/custom/dishes/index.vue b/stdiet-ui/src/views/custom/dishes/index.vue index ba013d2c2..35330533b 100644 --- a/stdiet-ui/src/views/custom/dishes/index.vue +++ b/stdiet-ui/src/views/custom/dishes/index.vue @@ -675,13 +675,13 @@ export default { .catch(function () {}); }, handleChange(value, direction, movedKeys) { - console.log({ - oriIgdList: this.oriDataList, - selIgdList: this.form.igdList, - ingDataList: this.ingDataList, - value, - ingType: this.ingType, - }); + // console.log({ + // oriIgdList: this.oriDataList, + // selIgdList: this.form.igdList, + // ingDataList: this.ingDataList, + // value, + // ingType: this.ingType, + // }); const newTableData = []; this.selRec = []; this.selNotRec = []; diff --git a/stdiet-ui/src/views/custom/recipesBuild/BodySignView.vue b/stdiet-ui/src/views/custom/recipesBuild/BodySignView.vue index 039b409e2..89b1f13bf 100644 --- a/stdiet-ui/src/views/custom/recipesBuild/BodySignView.vue +++ b/stdiet-ui/src/views/custom/recipesBuild/BodySignView.vue @@ -15,7 +15,7 @@ - diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/BarChart.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/BarChart.vue new file mode 100644 index 000000000..6c9ca5d12 --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/BarChart.vue @@ -0,0 +1,146 @@ + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/PieChart.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/PieChart.vue new file mode 100644 index 000000000..9ae52dad5 --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/PieChart.vue @@ -0,0 +1,200 @@ + + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/index.vue new file mode 100644 index 000000000..a8cd827c1 --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesAspectCom/index.vue @@ -0,0 +1,62 @@ + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableText/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableText/index.vue new file mode 100644 index 000000000..48b8b1824 --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableText/index.vue @@ -0,0 +1,69 @@ + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableUnit/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableUnit/index.vue new file mode 100644 index 000000000..4b90c69d8 --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/EditableUnit/index.vue @@ -0,0 +1,147 @@ + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue new file mode 100644 index 000000000..ac198febf --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesCom/index.vue @@ -0,0 +1,321 @@ + + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/index.vue new file mode 100644 index 000000000..dba5cd95e --- /dev/null +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/index.vue @@ -0,0 +1,44 @@ + + + diff --git a/stdiet-ui/src/views/custom/recipesBuild/index.vue b/stdiet-ui/src/views/custom/recipesBuild/index.vue index 3ebf30274..ad3a9e2b6 100644 --- a/stdiet-ui/src/views/custom/recipesBuild/index.vue +++ b/stdiet-ui/src/views/custom/recipesBuild/index.vue @@ -1,26 +1,30 @@ -