2 次代碼提交 5d8d8e83fa ... c985889f08

作者 SHA1 備註 提交日期
  wangyang c985889f08 update 4 年之前
  wangyang 6898fcb63b 完成usda数据相关前端调整 4 年之前
共有 3 個文件被更改,包括 47 次插入4 次删除
  1. 6 0
      src/router/config.js
  2. 6 0
      src/utils/food-utils.js
  3. 35 4
      src/views/food/index.vue

+ 6 - 0
src/router/config.js

@@ -65,6 +65,12 @@ export const asyncRouterMap = [
         component: () => import('@/views/food/index'),
         meta: { title: 'CFCT', admin: true  }
       },
+      {
+        path: 'usda',
+        name: 'USDA',
+        component: () => import('@/views/food/index'),
+        meta: { title: 'USDA', admin: true  }
+      },
       {
         path: 'create',
         name: '食物创建',

+ 6 - 0
src/utils/food-utils.js

@@ -24,7 +24,13 @@ export function getFoodSourceByUrl(url='') {
     return 'ENTRY'
   } else if (url.indexOf('cfct') > -1) {
     return 'CFCT'
+  } else if (url.indexOf('usda') > -1) {
+    return 'USDA'
   } else {
     return ''
   }
 }
+
+export function isUsda(dataSource) {
+  return dataSource && dataSource.indexOf('USDA') > -1
+}

+ 35 - 4
src/views/food/index.vue

@@ -5,10 +5,16 @@
         <el-input
           v-model="listQuery.query"
           placeholder="请输入检索词"
-          style="width: 60%;"
+          style="width: 40%;"
           class="filter-item"
           @keyup.enter.native="fetchData()"
         />
+        <el-select v-model="selectType" v-if="isUsda" clearable style="width: 160px;margin-left: 10px;" class="filter-item">
+          <el-option v-for="item in usdaTypes" :key="item.value" :label="item.label" :value="item.value" />
+        </el-select>
+        <el-select v-model="selectType" v-if="foodSourceIsAll" clearable style="width: 160px;margin-left: 10px;" class="filter-item">
+          <el-option v-for="item in allTypes" :key="item.value" :label="item.label" :value="item.value" />
+        </el-select>
         <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search" @click="fetchData">
           检索
         </el-button>
@@ -45,7 +51,7 @@
       fit
       highlight-current-row
       style="width: 100%;"
-      @row-click="handleFoodClick"
+      @row-dblclick="handleFoodClick"
     >
       <el-table-column type="index" label="序号" align="center" fixed width="60px" />
       <el-table-column label="名称" align="center" fixed width="200px">
@@ -200,7 +206,7 @@ import Pagination from '@/components/Pagination'
 import { getList, remove, copyFromSimilarFood } from '@/api/food'
 import axios from 'axios'
 import { getToken } from '@/utils/auth'
-import { getFoodSourceByUrl } from '@/utils/food-utils'
+import { getFoodSourceByUrl, isUsda } from '@/utils/food-utils'
 import store from '@/store'
 import VueQr from 'vue-qr'
 
@@ -235,7 +241,17 @@ export default {
       params: {},
       foodSource: '',
       foodQRDialogVisible: false,
-      foodQRParams: {}
+      foodQRParams: {},
+      isUsda: false,
+      foodSourceIsAll: false,
+      usdaTypes: [{ 'label': '全部', 'value': 'ALL' }, { 'label': 'Foundation', 'value': 'USDA_FOUNDATION' },
+                  { 'label': 'SR Legacy', 'value': 'USDA_SR_LEGACY' }, { 'label': 'Branded', 'value': 'USDA_BRANDED' },
+                  { 'label': 'FNDDS', 'value': 'USDA_FNDDS' }],
+      allTypes: [{ 'label': '全部', 'value': 'ALL' }, { 'label': '录入', 'value': 'ENTRY' },
+        { 'label': 'CFCT', 'value': 'CFCT' }, { 'label': 'Foundation', 'value': 'USDA_FOUNDATION' },
+        { 'label': 'SR Legacy', 'value': 'USDA_SR_LEGACY' }, { 'label': 'Branded', 'value': 'USDA_BRANDED' },
+        { 'label': 'FNDDS', 'value': 'USDA_FNDDS' }],
+      selectType: ''
     }
   },
   created() {
@@ -245,12 +261,27 @@ export default {
     } else {
       this.listQuery.orderBy = 1
     }
+    this.isUsda = isUsda(this.foodSource)
+    this.foodSourceIsAll = this.foodSource === ''
     this.fetchData()
   },
   methods: {
     fetchData() {
       this.listLoading = true
       this.listQuery.foodSource = this.foodSource
+      if (this.isUsda) {
+        if (!this.selectType || this.selectType === 'ALL'){
+          this.listQuery.foodSource = 'USDA'
+        } else {
+          this.listQuery.foodSource = this.selectType
+        }
+      } else if (this.foodSourceIsAll) {
+        if (!this.selectType || this.selectType === 'ALL') {
+          this.listQuery.foodSource = ''
+        } else {
+          this.listQuery.foodSource = this.selectType
+        }
+      }
       getList(this.listQuery).then(response => {
         this.list = response.data.list
         this.total = response.data.count