|
@@ -0,0 +1,210 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div class="app-container">
|
|
|
|
|
+ <div class="filter-container">
|
|
|
|
|
+ <el-input
|
|
|
|
|
+ v-model="listQuery.query"
|
|
|
|
|
+ placeholder="请输入检索词"
|
|
|
|
|
+ style="width: 60%;"
|
|
|
|
|
+ class="filter-item"
|
|
|
|
|
+ @keyup.enter.native="fetchData()"
|
|
|
|
|
+ />
|
|
|
|
|
+ <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search" @click="fetchData">
|
|
|
|
|
+ 检索
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button
|
|
|
|
|
+ class="filter-item"
|
|
|
|
|
+ style="margin: 0 10px 20px 0; float: right;"
|
|
|
|
|
+ type="success"
|
|
|
|
|
+ icon="el-icon-circle-plus-outline"
|
|
|
|
|
+ @click="handleCreateOrUpdate('create')">
|
|
|
|
|
+ 新建
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <el-table
|
|
|
|
|
+ :key="tableKey"
|
|
|
|
|
+ v-loading="listLoading"
|
|
|
|
|
+ :data="list"
|
|
|
|
|
+ border
|
|
|
|
|
+ fit
|
|
|
|
|
+ highlight-current-row
|
|
|
|
|
+ ref="table"
|
|
|
|
|
+ >
|
|
|
|
|
+ <el-table-column type="index" label="序号" align="center" width="60" />
|
|
|
|
|
+ <el-table-column label="名称" align="center" width="150">
|
|
|
|
|
+ <template slot-scope="{row}">
|
|
|
|
|
+ <span>{{ row.name }}</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ <el-table-column label="描述" align="center" width="300">
|
|
|
|
|
+ <template slot-scope="{row}">
|
|
|
|
|
+ <span>{{ row.description }}</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ <el-table-column label="创建人" align="center" width="150">
|
|
|
|
|
+ <template slot-scope="{row}">
|
|
|
|
|
+ <span>{{ row.userName }}</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ <el-table-column label="创建时间" width="180px" align="center">
|
|
|
|
|
+ <template slot-scope="{row}">
|
|
|
|
|
+ <span>{{ row.createTime }}</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ <el-table-column label="更新时间" width="180px" align="center">
|
|
|
|
|
+ <template slot-scope="{row}">
|
|
|
|
|
+ <span>{{ row.updateTime }}</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ <el-table-column label="操作" align="center">
|
|
|
|
|
+ <template slot-scope="{row,$index}">
|
|
|
|
|
+ <el-button type="primary" size="mini" @click="handleCreateOrUpdate('update', row)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
+ 更新
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button type="primary" size="mini" @click="manageNutrients(row)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
+ 管理营养素
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button type="primary" size="mini" @click="updateSort(row, 0)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
+ 上移
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button type="primary" size="mini" @click="updateSort(row, 1)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
+ 下移
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button type="primary" size="mini" @click="updateSort(row, 2)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
+ 置顶
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button size="mini" type="danger" @click="handleDelete(row, $index)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
+ 删除
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ </el-table>
|
|
|
|
|
+
|
|
|
|
|
+ <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
|
|
|
|
|
+
|
|
|
|
|
+ <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
|
|
|
|
|
+ <el-form ref="dataForm" :rules="rules" :model="params" label-position="left" label-width="200px" style="width: 400px; margin-left:50px;">
|
|
|
|
|
+ <el-form-item label="名称" prop="name">
|
|
|
|
|
+ <el-input v-model="params.name" placeholder="请输入名称" />
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item label="描述" prop="description">
|
|
|
|
|
+ <el-input v-model="params.description" placeholder="请输入描述" type="textarea" :rows="2" />
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ </el-form>
|
|
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
|
|
+ <el-button @click="dialogFormVisible = false">
|
|
|
|
|
+ 取消
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
|
|
|
|
|
+ 提交
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-dialog>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script>
|
|
|
|
|
+ import store from '@/store'
|
|
|
|
|
+ import Pagination from '@/components/Pagination'
|
|
|
|
|
+ import { getNutrientTemplates, createTemplate, updateSort, updateTemplate, removeTemplate } from '@/api/nutrientTemplate'
|
|
|
|
|
+ import {create} from "@/api/nutrient";
|
|
|
|
|
+
|
|
|
|
|
+ export default {
|
|
|
|
|
+ name: 'NutrientTemplateList',
|
|
|
|
|
+ components: { Pagination },
|
|
|
|
|
+ created() {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ },
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ tableKey: 0,
|
|
|
|
|
+ listQuery: {
|
|
|
|
|
+ query: '',
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 20
|
|
|
|
|
+ },
|
|
|
|
|
+ listLoading: false,
|
|
|
|
|
+ list: [],
|
|
|
|
|
+ total: 0,
|
|
|
|
|
+ textMap: {
|
|
|
|
|
+ update: '更新',
|
|
|
|
|
+ create: '新建'
|
|
|
|
|
+ },
|
|
|
|
|
+ dialogStatus: '',
|
|
|
|
|
+ dialogFormVisible: false,
|
|
|
|
|
+ rules: {},
|
|
|
|
|
+ params: {}
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ fetchData() {
|
|
|
|
|
+ this.listLoading = true
|
|
|
|
|
+ getNutrientTemplates(this.listQuery).then(res => {
|
|
|
|
|
+ this.list = res.data.list
|
|
|
|
|
+ this.total = res.data.count
|
|
|
|
|
+ this.listLoading = false
|
|
|
|
|
+ }).catch(res => {
|
|
|
|
|
+ this.$message.error("获取数据失败")
|
|
|
|
|
+ this.listLoading = false
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ handleCreateOrUpdate(type, row) {
|
|
|
|
|
+ this.dialogStatus = type
|
|
|
|
|
+ this.params = type === 'create' ? {} : row
|
|
|
|
|
+ this.dialogFormVisible = true
|
|
|
|
|
+ },
|
|
|
|
|
+ updateSort(row, type) {
|
|
|
|
|
+ updateSort(row.id, { type }).then(res => {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.$message.success("提交成功")
|
|
|
|
|
+ }).catch(res => {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.$message.error(res.data.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ handleDelete(row, index) {
|
|
|
|
|
+ removeTemplate(row.id).then(res => {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.$message.success("提交成功")
|
|
|
|
|
+ }).catch(res => {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.$message.error(res.data.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ createData() {
|
|
|
|
|
+ if (this.params) {
|
|
|
|
|
+ createTemplate(this.params).then(res => {
|
|
|
|
|
+ this.$notify({ title: '成功', message: '提交成功', type: 'success', duration: 2000 })
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.dialogFormVisible = false
|
|
|
|
|
+ }).catch(error => {
|
|
|
|
|
+ this.$notify({ title: '失败', message: error.response.data.message, type: 'error', duration: 2000 })
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ updateData() {
|
|
|
|
|
+ if (this.params) {
|
|
|
|
|
+ updateTemplate(this.params.id, this.params).then(res => {
|
|
|
|
|
+ this.$notify({ title: '成功', message: '提交成功', type: 'success', duration: 2000 })
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.dialogFormVisible = false
|
|
|
|
|
+ }).catch(error => {
|
|
|
|
|
+ this.$notify({ title: '失败', message: error.response.data.message, type: 'error', duration: 2000 })
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ canUpdate(userId) {
|
|
|
|
|
+ return store.getters.isAdmin || store.getters.userId === userId
|
|
|
|
|
+ },
|
|
|
|
|
+ manageNutrients(row) {
|
|
|
|
|
+ this.$router.push({ path: `nutrient-template/${row.id}/detail` })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+
|
|
|
|
|
+</style>
|