Ver Fonte

fix: 食物管理

sh há 4 anos atrás
pai
commit
f6df0642f7
1 ficheiros alterados com 59 adições e 0 exclusões
  1. 59 0
      src/views/food/index.vue

+ 59 - 0
src/views/food/index.vue

@@ -440,6 +440,43 @@
             <div style="margin-top:5px;">
               <p v-for="nv in calc.rsp.nvList" :key="nv.name">{{ nv.name }} 摄入:{{ nv.nvIn }}{{ nv.nvUnit }}, ({{ nv.nv }}{{ nv.nvUnit }}/{{ nv.nvSpec }}{{ nv.nvSpecUnit }})</p>
             </div>
+
+            <div style="margin-top:5px;">
+              <el-input v-model="cf.req.fromAmt" placeholder="源单位数量" style="width:100px;margin-right:10px;" />
+              <DataSelect
+                url="/api/units"
+                placeholder="源单位"
+                :value.sync="cf.req.fromUnitId"
+                :label.sync="cf.req.fromUnit"
+                :initOptions="dlg.form.modifierUnitOptions"
+                width="110px"
+              />
+              -
+              <DataSelect
+                url="/api/units"
+                placeholder="目标单位"
+                :value.sync="cf.req.toUnitId"
+                :label.sync="cf.req.toUnit"
+                :initOptions="dlg.form.modifierUnitOptions"
+                width="110px"
+              />
+              <el-button :loading="cf.loading" size="mini" type="success" style="margin-left:15px;" @click="calcCf">计算转换</el-button>
+            </div>
+
+            <div>
+              <span v-if="!!cf.rsp.error">
+                {{ cf.rsp.error }}
+              </span>
+              <span v-else-if="cf.rsp.steps.length>0">
+                <div style="margin-bottom:5px;">
+                  {{ cf.rsp.fromAmt }}{{ cf.rsp.fromUnit }} * {{ cf.rsp.cf }} =  {{ cf.rsp.toAmt }}{{ cf.rsp.toUnit }}
+                </div>
+                <div v-for="step in cf.rsp.steps" :key="step.convert.fromUnit" style="margin-bottom:5px;">
+                  【1{{ step.convert.fromUnit }} * {{ step.convert.cf }} = 1{{ step.convert.toUnit }},{{ step.cf }}】
+                  {{ step.fromAmt }}{{ step.convert.fromUnit }} * {{ step.convert.cf }} = {{ step.toAmt }}{{ step.convert.toUnit }}
+                </div>
+              </span>
+            </div>
           </el-tab-pane>
         </el-tabs>
       </el-form>
@@ -515,6 +552,19 @@ export default {
           nvList: []
         }
       },
+      cf: {
+        loading: false,
+        req: {
+          fromAmt: undefined,
+          fromUnitId: undefined,
+          fromUnit: undefined,
+          toUnitId: undefined,
+          toUnit: undefined
+        },
+        rsp: {
+          steps: []
+        }
+      },
       dlg: {
         form: {
           infoTab: 'base',
@@ -652,6 +702,15 @@ export default {
         this.calc.loading = false
       })
     },
+    // 计算单位转换
+    calcCf() {
+      this.cf.loading = true
+      fPost(`/api/foods/${this.dlg.form.data.id}/unit-cf`, this.cf.req).then(res => {
+        this.cf.rsp = res
+      }).finally(() => {
+        this.cf.loading = false
+      })
+    },
     // 刷新 CF
     refreshCf() {
       fGet(`/api/foods/${this.dlg.form.data.id}/cfs`).then(res => {