|
|
@@ -1,443 +1,286 @@
|
|
|
<template>
|
|
|
- <div v-loading="uploadLoading" class="app-container">
|
|
|
+ <div class="app-container">
|
|
|
<div class="filter-container">
|
|
|
- <el-row>
|
|
|
- <el-input
|
|
|
- v-model="listQuery.query"
|
|
|
- placeholder="请输入检索词"
|
|
|
- style="width: 200px;"
|
|
|
- class="filter-item"
|
|
|
- @keyup.enter.native="fetchData()"
|
|
|
- />
|
|
|
- <el-select v-if="isUsda" v-model="selectType" style="width: 160px;" class="filter-item">
|
|
|
- <el-option v-for="item in usdaTypes" :key="item.value" :label="item.label" :value="item.value" />
|
|
|
- </el-select>
|
|
|
- <el-select v-if="foodSourceIsAll" v-model="selectType" clearable style="width: 160px;" 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" type="primary" icon="el-icon-search" @click="fetchData">
|
|
|
- 检索
|
|
|
- </el-button>
|
|
|
- <el-select v-model="listQuery.orderBy" style="width: 160px;margin-left: 10px;" class="filter-item" @change="fetchData">
|
|
|
- <el-option v-for="item in sortOptions" :key="item.key" :label="item.label" :value="item.key" />
|
|
|
- </el-select>
|
|
|
-
|
|
|
- <!-- <span style="color:gray;font-size:14px;margin-left:15px;">营养物语环境</span>
|
|
|
- <el-select v-model="yywyEnv" style="width:100px;margin-left:10px;" class="filter-item" placeholder="营养物语环境">
|
|
|
- <el-option label="dev" value="dev" />
|
|
|
- <el-option label="prod" value="prod" />
|
|
|
- <el-option label="test" value="test" />
|
|
|
- <el-option label="local" value="local" />
|
|
|
- </el-select> -->
|
|
|
+ <el-select v-model="list.main.query.baseUnit" class="filter-item" size="mini" placeholder="食物类型" style="width:150px;margin-right:5px;" clearable>
|
|
|
+ <el-option label="是" :value="true" />
|
|
|
+ <el-option label="否" :value="false" />
|
|
|
+ </el-select>
|
|
|
+ <el-select v-model="list.main.query.baseUnit" class="filter-item" size="mini" placeholder="食物类别" style="width:150px;margin-right:5px;" clearable>
|
|
|
+ <el-option label="是" :value="true" />
|
|
|
+ <el-option label="否" :value="false" />
|
|
|
+ </el-select>
|
|
|
+ <el-input v-model="list.main.query.name" class="filter-item" size="mini" placeholder="名称" style="width:150px;margin-right:5px;" clearable />
|
|
|
+ <el-input v-model="list.main.query.enName" class="filter-item" size="mini" placeholder="英文名称" style="width:150px;margin-right:5px;" clearable />
|
|
|
+ <el-select v-model="list.main.query.baseUnit" class="filter-item" size="mini" placeholder="状态" style="width:150px;margin-right:5px;" clearable>
|
|
|
+ <el-option label="是" :value="true" />
|
|
|
+ <el-option label="否" :value="false" />
|
|
|
+ </el-select>
|
|
|
+ <el-button class="filter-item" size="mini" type="primary" @click="M.list()">查询</el-button>
|
|
|
+ <el-button class="filter-item" size="mini" @click="() => {M.reset({ data: { page: 1, limit: list.main.query.limit } })}">重置</el-button>
|
|
|
|
|
|
- <el-button size="mini" class="filter-item" @click="queryToYYWYProgrees">查询最后一条同步结果(F12查看详情)</el-button>
|
|
|
-
|
|
|
- <el-button
|
|
|
- class="filter-item"
|
|
|
- style="float: right;"
|
|
|
- type="success"
|
|
|
- icon="el-icon-circle-plus-outline"
|
|
|
- @click="handleCreate"
|
|
|
- >
|
|
|
- 新建
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- class="filter-item"
|
|
|
- style="margin-right: 10px; float: right;"
|
|
|
- type="primary"
|
|
|
- @click="handleImport"
|
|
|
- >
|
|
|
- 食物导入
|
|
|
- </el-button>
|
|
|
- </el-row>
|
|
|
+ <div style="float:right;">
|
|
|
+ <el-button class="filter-item" size="mini" type="success" style="margin-right:15px;" @click="create">新增</el-button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
-
|
|
|
- <el-table
|
|
|
- :key="tableKey"
|
|
|
- v-loading="listLoading"
|
|
|
- :data="list"
|
|
|
- border
|
|
|
- fit
|
|
|
- highlight-current-row
|
|
|
- style="width: 100%;"
|
|
|
- :max-height="maxHeight"
|
|
|
- @row-dblclick="handleFoodClick"
|
|
|
- >
|
|
|
- <el-table-column type="index" label="序号" align="center" fixed width="60px" />
|
|
|
- <el-table-column label="名称" fixed width="200px">
|
|
|
+ <el-table v-loading="list.main.loading" :data="list.main.list" border fit highlight-current-row style="width:100%" :max-height="maxHeight">
|
|
|
+ <el-table-column width="50" header-align="center" label="权重">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.name }}</span>
|
|
|
- <br>
|
|
|
- <el-button :loading="row._to_yywy" size="mini" @click="toYYWY(row)">同步至营养物语</el-button>
|
|
|
+ <span>{{ row.sortOrder }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="图片" align="center" width="180">
|
|
|
+ <el-table-column width="70" align="center" label="图片">
|
|
|
<template slot-scope="{row}">
|
|
|
- <el-image
|
|
|
- v-if="row.mainImage"
|
|
|
- style="width: 150px; height: 100px"
|
|
|
- :src="row.mainImage"
|
|
|
- fit="contain"
|
|
|
- />
|
|
|
+ <el-image v-if="row.mainImage" style="width:50px;height:50px;" :src="row.mainImage" fit="contain" />
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="自定义ID" align="center" width="100px">
|
|
|
+ <el-table-column min-width="150" header-align="center" label="名称">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.id2 }}</span>
|
|
|
+ <el-tag size="mini" effect="plain">类型</el-tag><span>{{ row.name }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="描述" align="center" width="200">
|
|
|
+ <el-table-column min-width="180" header-align="center" label="英文名称">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.description }}</span>
|
|
|
+ <span>{{ row.enName }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="食物类型" align="center" width="80">
|
|
|
+ <el-table-column width="80" header-align="center" align="right" label="可食部(%)">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.foodType | foodTypeFilter }}</span>
|
|
|
+ <span v-if="row.ep>0">{{ row.ep }}%</span>
|
|
|
+ <span v-else>-</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="ep(%)" align="center" width="70px">
|
|
|
+ <el-table-column width="80" header-align="center" align="right" label="GI">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.ep }}</span>
|
|
|
+ <span>{{ row.gi }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="GI" align="center" width="70px">
|
|
|
+ <el-table-column width="80" header-align="center" align="right" label="GL">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.gi }}</span>
|
|
|
+ <span>{{ row.gl }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="GL" align="center" width="70px">
|
|
|
+ <el-table-column width="100" align="center" label="来源">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.gl ? row.gl : row.glCalcd }}</span>
|
|
|
+ <span>{{ row.source }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="数据来源" align="center" width="100px">
|
|
|
+ <el-table-column width="60" align="center" label="状态">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.dataSource }}</span>
|
|
|
+ <span v-if="row.shelfStatus=='ONLINE'" style="color:green;">上架</span>
|
|
|
+ <span v-else style="color:gray;">下架</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="创建人" align="center" width="100px">
|
|
|
+ <el-table-column width="80" align="center" label="创建人">
|
|
|
<template slot-scope="{row}">
|
|
|
- <span>{{ row.userName }}</span>
|
|
|
+ <span>{{ row.userName || '-' }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="创建时间" width="180px" align="center">
|
|
|
+ <el-table-column width="140" align="center" label="创建时间">
|
|
|
<template slot-scope="{row}">
|
|
|
<span>{{ row.createTime }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="更新时间" width="180px" align="center">
|
|
|
+ <el-table-column width="140" align="center" label="更新时间">
|
|
|
<template slot-scope="{row}">
|
|
|
<span>{{ row.updateTime }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="操作" align="center" class-name="small-padding" fixed="right" width="90">
|
|
|
+ <el-table-column width="60" align="center" label="操作" fixed="right">
|
|
|
<template slot-scope="{row}">
|
|
|
- <el-dropdown @command="handleCommand">
|
|
|
- <el-button type="primary" @click.stop="{}">
|
|
|
- 操作<i class="el-icon-arrow-down el-icon--right" />
|
|
|
- </el-button>
|
|
|
- <el-dropdown-menu slot="dropdown">
|
|
|
- <el-dropdown-item :command="{row: row, command: 'update'}">更新/查看</el-dropdown-item>
|
|
|
- <el-dropdown-item :command="{row: row, command: 'copy'}">复制</el-dropdown-item>
|
|
|
- <el-dropdown-item :command="{row: row, command: 'manageNutrients'}">营养素关联</el-dropdown-item>
|
|
|
- <el-dropdown-item :command="{row: row, command: 'manageUnits'}">单位管理</el-dropdown-item>
|
|
|
- <el-dropdown-item :command="{row: row, command: 'manageModifiers'}">规格管理</el-dropdown-item>
|
|
|
- <el-dropdown-item :disabled="!canDelete(row)" :command="{row: row, command: 'delete'}">删除</el-dropdown-item>
|
|
|
- </el-dropdown-menu>
|
|
|
- </el-dropdown>
|
|
|
+ <i class="el-icon-edit" style="cursor:pointer;color:#999999;margin-right:5px;" @click="edit(row)"></i>
|
|
|
+
|
|
|
+ <i class="el-icon-delete" style="cursor:pointer;color:#999999;m"></i>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
+ <pagination v-show="list.main.total>0" :total="list.main.total" :page.sync="list.main.query.page" :limit.sync="list.main.query.limit" @pagination="M.list()" />
|
|
|
|
|
|
- <pagination
|
|
|
- v-show="total>0"
|
|
|
- :total="total"
|
|
|
- :page.sync="listQuery.pageNum"
|
|
|
- :limit.sync="listQuery.pageSize"
|
|
|
- @pagination="fetchData"
|
|
|
- />
|
|
|
-
|
|
|
- <el-dialog title="食物导入" width="40%" :visible.sync="dialogFormVisible">
|
|
|
- <el-upload
|
|
|
- ref="upload"
|
|
|
- action=""
|
|
|
- :auto-upload="false"
|
|
|
- :multiple="false"
|
|
|
- drag
|
|
|
- :limit="1"
|
|
|
- :show-file-list="true"
|
|
|
- :on-change="fileChanged"
|
|
|
- >
|
|
|
- <i class="el-icon-upload" />
|
|
|
- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
|
- </el-upload>
|
|
|
- <div slot="footer">
|
|
|
- <el-button @click="dialogFormVisible = false">
|
|
|
- 取消
|
|
|
- </el-button>
|
|
|
- <el-button type="primary" @click="importFoods">
|
|
|
- 开始导入
|
|
|
- </el-button>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
-
|
|
|
- <el-dialog title="复制食物" width="40%" :visible.sync="copyDialogVisible">
|
|
|
- <el-form ref="dialogForm" label-position="left" label-width="90px" style="width: 80%; margin-left:50px;">
|
|
|
- <el-form-item label="新食物名称: " prop="foodName">
|
|
|
- <el-input v-model="params.foodName" placeholder="请输入新食物名称" />
|
|
|
- </el-form-item>
|
|
|
+ <el-dialog :title="dlg.form.title" :visible.sync="dlg.form.visible" width="80%" top="3vh">
|
|
|
+ <el-form ref="form" :rules="dlg.form.rules" :model="dlg.form.data" size="mini" label-position="right" label-width="100px">
|
|
|
+ <el-tabs v-model="dlg.form.infoTab">
|
|
|
+ <el-tab-pane label="食物基本信息" name="base">
|
|
|
+ <el-form-item label="主/辅材" prop="category">
|
|
|
+ <el-input v-model="dlg.form.data.category" placeholder="请输入单位类别" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="食物类别" prop="name">
|
|
|
+ <el-input v-model="dlg.form.data.name" placeholder="请输入单位名称,不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="名称" prop="name">
|
|
|
+ <el-input v-model="dlg.form.data.name" placeholder="请输入单位名称,不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="描述">
|
|
|
+ <el-input v-model="dlg.form.data.code" type="textarea" rows="3" placeholder="请输入单位编码,可为空,但不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item v-if="!dlg.form.data.baseUnit" label="可食部" required>
|
|
|
+ <el-input v-model="dlg.form.data.ratio" placeholder="百分比">
|
|
|
+ <span slot="append">%</span>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="GI">
|
|
|
+ <el-input v-model="dlg.form.data.name" placeholder="请输入单位名称,不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="GL">
|
|
|
+ <el-input v-model="dlg.form.data.name" placeholder="请输入单位名称,不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="密度">
|
|
|
+ <el-input v-model="dlg.form.data.name" placeholder="请输入单位名称,不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="堆密度">
|
|
|
+ <el-input v-model="dlg.form.data.name" placeholder="请输入单位名称,不能重复" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="食物图">
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="营养素图">
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="其他图">
|
|
|
+ </el-form-item>
|
|
|
+ </el-tab-pane>
|
|
|
+ <el-tab-pane label="规格" name="modifier">
|
|
|
+ <div style="margin-bottom:5px;">
|
|
|
+ <el-button size="mini" type="primary" plain>添加</el-button>
|
|
|
+ </div>
|
|
|
+ <el-table :data="tempList" :show-header="true" border fit highlight-current-row style="width:100%">
|
|
|
+ <el-table-column type="index" width="50" align="center" />
|
|
|
+ <el-table-column label="包装名称" width="70" align="center">
|
|
|
+ <el-input size="mini" />
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="包装单位" width="70" align="center">
|
|
|
+ <el-select size="mini" style="width:100%;">
|
|
|
+ </el-select>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="CNVR" width="70" align="center">
|
|
|
+ <el-input size="mini" />
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="规格转换" width="180" align="center">
|
|
|
+ <el-input size="mini">
|
|
|
+ <span slot="prepend">1随身包装=</span>
|
|
|
+ </el-input>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="净含量" width="70" align="center">
|
|
|
+ <el-input size="mini" />
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="状态" width="70" align="center">
|
|
|
+ <el-input size="mini" />
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="卡尺" width="70" align="center">
|
|
|
+ <el-input size="mini" />
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="规格图片" width="70" align="center">
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column width="70" align="center">
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-tab-pane>
|
|
|
+ <el-tab-pane label="营养素" name="nutrient">
|
|
|
+ <el-table :data="tempList" :show-header="false" border fit highlight-current-row style="width:100%">
|
|
|
+ <el-table-column type="index" width="50" align="center" />
|
|
|
+ <el-table-column>
|
|
|
+ <template slot-scope="{row}">
|
|
|
+ 名称选择<br>
|
|
|
+ 计量方式<br>
|
|
|
+ 计量单位<br>
|
|
|
+ 转换关系<br>
|
|
|
+ NVR(%)<br>
|
|
|
+ nv_spec<br>
|
|
|
+ nv_spec_unit<br>
|
|
|
+ 来源
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-tab-pane>
|
|
|
+ <el-tab-pane label="CF" name="cf">
|
|
|
+ </el-tab-pane>
|
|
|
+ <el-tab-pane label="营养素含量计算" name="calc">
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
</el-form>
|
|
|
- <div slot="footer">
|
|
|
- <el-button @click="copyDialogVisible = false">
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button size="mini" @click="dlg.form.visible = false">
|
|
|
取消
|
|
|
</el-button>
|
|
|
- <el-button type="primary" @click="copyFood">
|
|
|
+ <el-button :loading="dlg.form.saveLoading" size="mini" type="primary" @click="M.save()">
|
|
|
确认
|
|
|
</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
-
|
|
|
- <el-dialog title="食物二维码" width="250" :visible.sync="foodQRDialogVisible">
|
|
|
- <vue-qr
|
|
|
- :text="foodQRParams.url"
|
|
|
- :bg-src="foodQRParams.bgImg"
|
|
|
- :logo-src="foodQRParams.logoImg"
|
|
|
- :size="200"
|
|
|
- :correct-level="3"
|
|
|
- color-dark="#000"
|
|
|
- color-light="#fff"
|
|
|
- :dot-scale="1"
|
|
|
- />
|
|
|
- </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import Pagination from '@/components/Pagination'
|
|
|
-import { getList, remove, copyFromSimilarFood } from '@/api/food'
|
|
|
-import axios from 'axios'
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
-import { getFoodSourceByUrl, isUsda } from '@/utils/food-utils'
|
|
|
-import store from '@/store'
|
|
|
-import VueQr from 'vue-qr'
|
|
|
-
|
|
|
-const foodTypes = { 0: '主材', 1: '辅材' }
|
|
|
+import { fGet, fPost } from '@/api/rest'
|
|
|
+import { M } from '@/api/op'
|
|
|
|
|
|
export default {
|
|
|
- name: 'FoodList',
|
|
|
- components: { Pagination, VueQr },
|
|
|
- filters: {
|
|
|
- foodTypeFilter(value) {
|
|
|
- return foodTypes[value]
|
|
|
- }
|
|
|
- },
|
|
|
+ components: { Pagination },
|
|
|
data() {
|
|
|
return {
|
|
|
- tableKey: 0,
|
|
|
- total: 0,
|
|
|
- dialogStatus: '',
|
|
|
- dialogFormVisible: false,
|
|
|
- sortOptions: [{ key: 0, label: '按创建时间倒序排列' }, { key: 1, label: '按ID顺序排列' }],
|
|
|
- list: [],
|
|
|
- listLoading: true,
|
|
|
+ M: new M(this),
|
|
|
+ URI: '/api/foods',
|
|
|
maxHeight: 600,
|
|
|
- listQuery: {
|
|
|
- query: '',
|
|
|
- orderBy: 0,
|
|
|
- pageNum: 1,
|
|
|
- pageSize: 20
|
|
|
+ baseUnitOptions: [],
|
|
|
+ tempList: [{},{}],
|
|
|
+ list: {
|
|
|
+ main: {
|
|
|
+ loading: true,
|
|
|
+ total: 0,
|
|
|
+ list: [],
|
|
|
+ render(row) {
|
|
|
+ return row
|
|
|
+ },
|
|
|
+ query: {
|
|
|
+ page: 1,
|
|
|
+ limit: 50
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
- uploadFile: null,
|
|
|
- uploadLoading: false,
|
|
|
- copyDialogVisible: false,
|
|
|
- params: {},
|
|
|
- foodSource: '',
|
|
|
- foodQRDialogVisible: false,
|
|
|
- foodQRParams: {},
|
|
|
- isUsda: false,
|
|
|
- foodSourceIsAll: false,
|
|
|
- usdaTypes: [{ '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: '',
|
|
|
- yywyEnv: 'dev'
|
|
|
+ dlg: {
|
|
|
+ form: {
|
|
|
+ infoTab: 'modifier',
|
|
|
+ visible: false,
|
|
|
+ title: '',
|
|
|
+ data: {},
|
|
|
+ saveLoading: false,
|
|
|
+ rules: {
|
|
|
+ category: [{ required: true, message: '类别不能为空', trigger: 'blur' }],
|
|
|
+ name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
- this.maxHeight = document.documentElement.clientHeight - 205
|
|
|
- this.foodSource = getFoodSourceByUrl(this.$route.path)
|
|
|
- if (this.foodSource === 'ENTRY' || this.foodSource === '') {
|
|
|
- this.listQuery.orderBy = 0
|
|
|
- } else {
|
|
|
- this.listQuery.orderBy = 1
|
|
|
- }
|
|
|
- this.isUsda = isUsda(this.foodSource)
|
|
|
- if (this.isUsda) {
|
|
|
- this.foodSource = this.foodSource === 'USDA' ? 'USDA_SR_LEGACY' : this.foodSource
|
|
|
- this.selectType = this.foodSource
|
|
|
- } else {
|
|
|
- this.foodSourceIsAll = this.foodSource === ''
|
|
|
- }
|
|
|
- this.fetchData()
|
|
|
- if (location.href.indexOf('test') > 0) {
|
|
|
- this.yywyEnv = 'test'
|
|
|
- }
|
|
|
+ this.maxHeight = document.documentElement.clientHeight - 135
|
|
|
+ this.M.list()
|
|
|
+ this.dlg.form.visible = true
|
|
|
},
|
|
|
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.map(v => {
|
|
|
- v._to_yywy = false
|
|
|
- return v
|
|
|
+ loadBaseUnit() {
|
|
|
+ fGet(this.URI, { baseUnit: true, size: 10000 }).then(res => {
|
|
|
+ this.baseUnitOptions = res.data.map(v => {
|
|
|
+ return {
|
|
|
+ label: v.name,
|
|
|
+ value: v.id
|
|
|
+ }
|
|
|
})
|
|
|
- this.total = response.data.count
|
|
|
- this.listLoading = false
|
|
|
- })
|
|
|
- },
|
|
|
- toYYWY(row) {
|
|
|
- row._to_yywy = true
|
|
|
- const headers = {
|
|
|
- headers: { 'Authorization': getToken() },
|
|
|
- timeout: 1000 * 60 * 3
|
|
|
- }
|
|
|
- axios.post(`/api/foods/${row.id}/to-yywy?env=${this.yywyEnv}`, {}, headers).then(res => {
|
|
|
- const data = res.data || {}
|
|
|
- this.$notify.success(`同步结果:${res.status};` + (data.foodId || '') + ',' + (data.rsp || ''))
|
|
|
- }).catch(res => {
|
|
|
- this.$message.error(res.response.data.message)
|
|
|
- }).finally(() => {
|
|
|
- row._to_yywy = false
|
|
|
- })
|
|
|
- },
|
|
|
- queryToYYWYProgrees() {
|
|
|
- const headers = {
|
|
|
- headers: { 'Authorization': getToken() },
|
|
|
- timeout: 1000 * 60 * 3
|
|
|
- }
|
|
|
- axios.get(`/api/foods/last-to-yywy`, headers).then(res => {
|
|
|
- const data = res.data || {}
|
|
|
- console.log(data)
|
|
|
- this.$notify.success(`同步结果:${res.status};` + (data.foodId || '') + ',' + (data.rsp || ''))
|
|
|
})
|
|
|
},
|
|
|
- handleCreate() {
|
|
|
- this.$router.push({ path: '/food/create' })
|
|
|
- },
|
|
|
- handleUpdate(row) {
|
|
|
- this.$router.push({ path: '/food/edit/' + row.id })
|
|
|
- },
|
|
|
- manageNutrients(row) {
|
|
|
- this.$router.push({ path: `/food/${row.id}/nutrient` })
|
|
|
- },
|
|
|
- manageUnits(row) {
|
|
|
- this.$router.push({ path: `/food/${row.id}/unit` })
|
|
|
+ create() {
|
|
|
+ this.M.create({ form: 'form', title: '新增', data: {} })
|
|
|
},
|
|
|
- manageModifiers(row) {
|
|
|
- this.$router.push({ path: `/food/${row.id}/modifier` })
|
|
|
+ edit(row) {
|
|
|
+ this.M.edit({ form: 'form', title: 'name', row: row })
|
|
|
},
|
|
|
- handleDelete(row, index) {
|
|
|
- remove(row.id).then(res => {
|
|
|
- this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
|
|
|
- this.list.splice(index, 1)
|
|
|
- this.fetchData()
|
|
|
- }).catch(res => {
|
|
|
- this.$message.error(res.data.message)
|
|
|
- })
|
|
|
- },
|
|
|
- handleImport() {
|
|
|
- if (this.$refs.upload) {
|
|
|
- this.$refs.upload.clearFiles()
|
|
|
- }
|
|
|
- this.uploadFile = null
|
|
|
- this.dialogFormVisible = true
|
|
|
- },
|
|
|
- importFoods() {
|
|
|
- const reqConfig = { headers: { 'Authorization': getToken(), 'Content-Type': 'multipart/form-data' },
|
|
|
- timeout: 1000 * 60 * 3 }
|
|
|
- const importUrl = process.env.VUE_APP_BASE_API + '/api/foods/import'
|
|
|
- this.uploadLoading = true
|
|
|
- this.dialogFormVisible = false
|
|
|
- axios.post(importUrl, this.uploadFile, reqConfig).then(res => {
|
|
|
- this.$notify.success('导入成功')
|
|
|
- this.uploadLoading = false
|
|
|
- }).catch(res => {
|
|
|
- this.$message.error(res.response.data.message)
|
|
|
- this.uploadLoading = false
|
|
|
- })
|
|
|
- },
|
|
|
- fileChanged(file, fileList) {
|
|
|
- const fromData = new FormData()
|
|
|
- fromData.append('file', file.raw)
|
|
|
- this.uploadFile = fromData
|
|
|
- },
|
|
|
- handleCopy(data) {
|
|
|
- this.params = { foodId: data.id }
|
|
|
- this.copyDialogVisible = true
|
|
|
- },
|
|
|
- copyFood() {
|
|
|
- copyFromSimilarFood(this.params).then(res => {
|
|
|
- this.$notify.success('提交成功')
|
|
|
- this.$router.push({ path: `/food/edit/${res.data}` })
|
|
|
- }).catch(res => {
|
|
|
- this.$message.error(res.data.message)
|
|
|
- })
|
|
|
- },
|
|
|
- handleCommand(data) {
|
|
|
- switch (data.command) {
|
|
|
- case 'update':
|
|
|
- this.handleUpdate(data.row)
|
|
|
- break
|
|
|
- case 'copy':
|
|
|
- this.handleCopy(data.row)
|
|
|
- break
|
|
|
- case 'manageNutrients':
|
|
|
- this.manageNutrients(data.row)
|
|
|
- break
|
|
|
- case 'manageUnits':
|
|
|
- this.manageUnits(data.row)
|
|
|
- break
|
|
|
- case 'manageModifiers':
|
|
|
- this.manageModifiers(data.row)
|
|
|
- break
|
|
|
- case 'delete':
|
|
|
- this.handleDelete(data.row)
|
|
|
- break
|
|
|
- }
|
|
|
- },
|
|
|
- canDelete(data) {
|
|
|
- return store.getters.isAdmin || data && data.userId === store.getters.userId
|
|
|
- },
|
|
|
- handleFoodClick(row) {
|
|
|
- this.foodQRParams = { url: process.env.VUE_APP_H5_URL + `/food/index.html?id=${row.id}`,
|
|
|
- bgImg: row.mainImage ? row.mainImage : '',
|
|
|
- logoImg: row.mainImage ? row.mainImage : ''
|
|
|
+ baseUnitChange() {
|
|
|
+ if (!!this.dlg.form.data.baseUnitId) {
|
|
|
+ const baseUnit = this.baseUnitOptions.find(v => v.value == this.dlg.form.data.baseUnitId)
|
|
|
+ if (!!baseUnit) {
|
|
|
+ this.dlg.form.data.baseUnitName = baseUnit.label
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.dlg.form.data.baseUnitName = undefined
|
|
|
}
|
|
|
- this.foodQRDialogVisible = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
-
|
|
|
-<style scoped>
|
|
|
-
|
|
|
-</style>
|