浏览代码

增加了规格导入

Yu Kong 4 年之前
父节点
当前提交
095e2b6230
共有 3 个文件被更改,包括 81 次插入12 次删除
  1. 0 1
      src/api/rest.js
  2. 80 11
      src/views/food/index.vue
  3. 1 0
      src/views/login/index.vue

+ 0 - 1
src/api/rest.js

@@ -63,7 +63,6 @@ export function fDelete(uri, data) {
 
 export function fSave(uri, data) {
   data = data || {}
-  console.log(data.modifiers)
   if (data.id !== undefined && !!(data.id)) {
     return fPut(`${uri}/${data.id}`, data)
   }

+ 80 - 11
src/views/food/index.vue

@@ -254,7 +254,7 @@
                       <span>{{ row.key || '' }}</span>
                       <span style="color:red;font-size:14px;font-weight:700;">&nbsp;=&nbsp;</span>
                       <el-input v-model="row.toModifierAmt" placeholder="数量" style="width:60px;margin-right:10px;" />
-                      <el-select v-model="row.toModifierName" placeholder="规格单位" style="width:120px" clearable>
+                      <el-select v-model="row.toModifierName" class="filter-item" placeholder="规格单位" style="width:120px" clearable>
                         <el-option v-for="opt in dlg.form.modifierUnitOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
                       </el-select>
                     ]
@@ -295,6 +295,7 @@
                   <span v-else>
                     -
                   </span>
+
                 </template>
               </el-table-column>
               <el-table-column width="90" align="center">
@@ -310,7 +311,14 @@
           </el-tab-pane>
           <el-tab-pane label="营养素" name="nutrient">
             <div style="margin-bottom:5px;">
-              <el-button size="mini" type="primary" plain @click="addNutrient(dlg.form.data)">添加</el-button>
+              <span>
+                <el-button size="mini" type="primary" plain @click="addNutrient(dlg.form.data)">添加</el-button>
+              </span>
+              <el-select v-model="dlg.form.selectedNutrientTemplate" style="margin-left: 10%; display: float" @input.native="getNutrienttemplateList($event)"  filterable placeholder="请输入检索词">
+                <el-option v-for="opt in dlg.form.nutrientTemplateOptions" :key="opt.id" :label="opt.value" :value="opt.name" />
+              </el-select>
+              <el-button v-model="dlg.form.nutrientTemplateTable" size="mini" type="primary" plain @click="importNutrientTemplate()">导入营养素模版</el-button>
+
             </div>
             <el-table :data="dlg.form.data.nutrients" :show-header="false" border fit highlight-current-row style="width:100%">
               <el-table-column type="index" width="50" align="center" />
@@ -348,15 +356,8 @@
                     <el-select v-model="row.nvUnitId" placeholder="营养素单位" style="width:100px" clearable>
                       <el-option v-if="!!row.nvUnitId && row._nutrientUnitOptions && !row._nutrientUnitOptions.find(v => v.value == row.nvUnitId)" :key="row.nvUnitId" :label="row.nvUnit" :value="row.nvUnitId" />
                       <el-option v-for="opt in row._nutrientUnitOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
+                      <el-option v-for="opt in dlg.form.data.nutrients" :key="opt.nvUnitId" :label="opt.nvUnit" :value="opt.nvUnitId" />
                     </el-select>
-                    <!-- <DataSelect
-                      url="/api/units"
-                      placeholder="营养素单位"
-                      :value.sync="row.nvUnitId"
-                      :label.sync="row.nvUnitName"
-                      :clearable="true"
-                      width="100px"
-                    /> -->
                     <span style="color:red;font-weight:700;">&nbsp;/&nbsp;</span>
                     <el-input v-model="row.nvSpec" placeholder="nv_spec" style="width:70px;margin-right:10px;" />
                     <DataSelect
@@ -611,7 +612,7 @@ export default {
     // 添加规格
     addModifier(row) {
       row.modifiers.push({
-        _edit: true
+      _edit: true,
       })
     },
     // 删除规格
@@ -629,6 +630,74 @@ export default {
     removeNutrient(row, index) {
       row.nutrients.splice(index, 1)
     },
+    // 导入营养素模版
+    importNutrientTemplate() {
+      console.log(this.dlg.form.selectedNutrientTemplate)
+
+      if (this.dlg.form.selectedNutrientTemplate == undefined) {
+        return
+      }
+      this.dlg.form.nutrientTemplateOptions.forEach(opt => {
+        if (opt.name == this.dlg.form.selectedNutrientTemplate) {
+          this.dlg.form.selectedNutrientTemplateId = opt.id
+        }
+      })
+
+      fGet(`/api/nutrient-templates/${this.dlg.form.selectedNutrientTemplateId}/nutrients`, {}).then(res => {
+        console.log(res)
+
+        if (res == undefined) {return}
+        
+        let existed = false
+        // 渲染营养素
+        res.forEach(nv => {
+          // 筛选营养素
+          this.dlg.form.data.nutrients.forEach(existNv => {
+            console.log(nv.nutrientId)
+            console.log(existNv)
+            if (nv.nutrientId == existNv.nutrientId) {
+              existed = true
+            }
+          })
+
+          if (! existed) {
+            this.dlg.form.data.nutrients.push({
+              _edit: true,
+              _nutrientUnitOptions: [],
+              nutrientId: nv.nutrientId, 
+              nutrientName: nv.nutrientName, 
+              nvUnit: nv.unit, 
+              nvSpec: nv.nvSpec, 
+              nvSpecUnit: nv.nvSpecUnit,
+              nvSpecUnitId: nv.nvSpecUnitId,
+              nvUnitId: nv.unitId
+            })
+          }
+
+        })
+
+        console.log(this.dlg.form.data.nutrients)
+        
+      })
+
+    },
+    // 导入营养素
+    importNutrientFromTemplate(row) {
+      row.nutrients.push({
+        _edit: true,
+        _nutrientUnitOptions: []
+      })
+    },
+    getNutrienttemplateList(e) {
+      console.log(1)
+      fGet(`/api/nutrient-templates`, {keyword: e.target.value}).then(res => {
+        console.log(2)
+        this.dlg.form.nutrientTemplateOptions = res
+        console.log(res)
+        
+      })
+      this.$forceUpdate()
+    },
     // 营养素选择
     nutrientSelect(nutrient, row) {
       row._nutrientUnitOptions = []

+ 1 - 0
src/views/login/index.vue

@@ -150,6 +150,7 @@ export default {
     // 获取验证码
     getCaptcha() {
       this.loginForm.reqId = getUUID()
+      console.log(this.loginForm.reqId)
       this.captchaPath = process.env.VUE_APP_BASE_API + `/api/captcha.jpg?reqId=${this.loginForm.reqId}`
     }
   }