|
@@ -16,19 +16,20 @@
|
|
|
style="margin: 0 10px 20px 0; float: right;"
|
|
style="margin: 0 10px 20px 0; float: right;"
|
|
|
type="success"
|
|
type="success"
|
|
|
icon="el-icon-circle-plus-outline"
|
|
icon="el-icon-circle-plus-outline"
|
|
|
- @click="handleCreateOrUpdate('create')">
|
|
|
|
|
|
|
+ @click="handleCreateOrUpdate('create')"
|
|
|
|
|
+ >
|
|
|
新建
|
|
新建
|
|
|
</el-button>
|
|
</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<el-table
|
|
<el-table
|
|
|
|
|
+ ref="table"
|
|
|
:key="tableKey"
|
|
:key="tableKey"
|
|
|
v-loading="listLoading"
|
|
v-loading="listLoading"
|
|
|
:data="list"
|
|
:data="list"
|
|
|
border
|
|
border
|
|
|
fit
|
|
fit
|
|
|
highlight-current-row
|
|
highlight-current-row
|
|
|
- ref="table"
|
|
|
|
|
>
|
|
>
|
|
|
<el-table-column type="index" label="序号" align="center" width="60" />
|
|
<el-table-column type="index" label="序号" align="center" width="60" />
|
|
|
<el-table-column label="名称" align="center" width="150">
|
|
<el-table-column label="名称" align="center" width="150">
|
|
@@ -57,33 +58,42 @@
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
<el-table-column label="操作" align="center">
|
|
<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)">
|
|
|
|
|
|
|
+ <template slot-scope="{row}">
|
|
|
|
|
+ <el-button type="primary" size="mini" :disabled="!canUpdate(row.userId)" @click="handleCreateOrUpdate('update', row)">
|
|
|
更新
|
|
更新
|
|
|
</el-button>
|
|
</el-button>
|
|
|
- <el-button type="primary" size="mini" @click="manageNutrients(row)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
|
|
+ <el-button type="primary" size="mini" :disabled="!canUpdate(row.userId)" @click="manageNutrients(row)">
|
|
|
管理营养素
|
|
管理营养素
|
|
|
</el-button>
|
|
</el-button>
|
|
|
- <el-button type="primary" size="mini" @click="updateSort(row, 0)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
|
|
+ <el-button type="primary" size="mini" :disabled="!canUpdate(row.userId)" @click="updateSort(row, 0)">
|
|
|
上移
|
|
上移
|
|
|
</el-button>
|
|
</el-button>
|
|
|
- <el-button type="primary" size="mini" @click="updateSort(row, 1)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
|
|
+ <el-button type="primary" size="mini" :disabled="!canUpdate(row.userId)" @click="updateSort(row, 1)">
|
|
|
下移
|
|
下移
|
|
|
</el-button>
|
|
</el-button>
|
|
|
- <el-button type="primary" size="mini" @click="updateSort(row, 2)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
|
|
+ <el-button type="primary" size="mini" :disabled="!canUpdate(row.userId)" @click="updateSort(row, 2)">
|
|
|
置顶
|
|
置顶
|
|
|
</el-button>
|
|
</el-button>
|
|
|
- <el-button size="mini" type="danger" @click="handleDelete(row, $index)" :disabled="!canUpdate(row.userId)">
|
|
|
|
|
|
|
+ <el-button type="primary" size="mini" :disabled="!canUpdate(row.userId)" @click="updateSort(row, 3)">
|
|
|
|
|
+ 置底
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button size="mini" type="danger" :disabled="!canUpdate(row.userId)" @click="handleDelete(row)">
|
|
|
删除
|
|
删除
|
|
|
</el-button>
|
|
</el-button>
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
</el-table>
|
|
</el-table>
|
|
|
|
|
|
|
|
- <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
|
|
|
|
|
|
|
+ <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-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 ref="dataForm" :rules="rules" :model="params" label-position="left" label-width="80px" style="width: 400px; margin-left:50px;">
|
|
|
<el-form-item label="名称" prop="name">
|
|
<el-form-item label="名称" prop="name">
|
|
|
<el-input v-model="params.name" placeholder="请输入名称" />
|
|
<el-input v-model="params.name" placeholder="请输入名称" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
@@ -95,7 +105,7 @@
|
|
|
<el-button @click="dialogFormVisible = false">
|
|
<el-button @click="dialogFormVisible = false">
|
|
|
取消
|
|
取消
|
|
|
</el-button>
|
|
</el-button>
|
|
|
- <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
|
|
|
|
|
|
|
+ <el-button type="primary" @click="createOrUpdateData">
|
|
|
提交
|
|
提交
|
|
|
</el-button>
|
|
</el-button>
|
|
|
</div>
|
|
</div>
|
|
@@ -104,105 +114,92 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
- import store from '@/store'
|
|
|
|
|
- import Pagination from '@/components/Pagination'
|
|
|
|
|
- import { getNutrientTemplates, createTemplate, updateSort, updateTemplate, removeTemplate } from '@/api/nutrientTemplate'
|
|
|
|
|
- import {create} from "@/api/nutrient";
|
|
|
|
|
|
|
+import store from '@/store'
|
|
|
|
|
+import Pagination from '@/components/Pagination'
|
|
|
|
|
+import { getNutrientTemplates, createTemplate, updateSort, updateTemplate, removeTemplate } from '@/api/nutrientTemplate'
|
|
|
|
|
|
|
|
- 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)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+export default {
|
|
|
|
|
+ name: 'NutrientTemplateList',
|
|
|
|
|
+ components: { Pagination },
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ tableKey: 0,
|
|
|
|
|
+ listQuery: {
|
|
|
|
|
+ query: '',
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 20
|
|
|
},
|
|
},
|
|
|
- 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()
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ listLoading: false,
|
|
|
|
|
+ list: [],
|
|
|
|
|
+ total: 0,
|
|
|
|
|
+ textMap: {
|
|
|
|
|
+ update: '更新',
|
|
|
|
|
+ create: '新建'
|
|
|
},
|
|
},
|
|
|
- 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` })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ dialogStatus: '',
|
|
|
|
|
+ dialogFormVisible: false,
|
|
|
|
|
+ rules: {},
|
|
|
|
|
+ params: {}
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ created() {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ },
|
|
|
|
|
+ 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' ? {} : Object.assign(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) {
|
|
|
|
|
+ removeTemplate(row.id).then(res => {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.$message.success('提交成功')
|
|
|
|
|
+ }).catch(res => {
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.$message.error(res.data.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ createOrUpdateData() {
|
|
|
|
|
+ const resultPromise = this.dialogStatus === 'create' ? createTemplate(this.params) : updateTemplate(this.params.id,
|
|
|
|
|
+ this.params)
|
|
|
|
|
+ resultPromise.then(res => {
|
|
|
|
|
+ this.$message.success('提交成功')
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ this.dialogFormVisible = false
|
|
|
|
|
+ }).catch(res => {
|
|
|
|
|
+ this.$message.error(res.data.message)
|
|
|
|
|
+ this.fetchData()
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ canUpdate(userId) {
|
|
|
|
|
+ return store.getters.isAdmin || store.getters.userId === userId
|
|
|
|
|
+ },
|
|
|
|
|
+ manageNutrients(row) {
|
|
|
|
|
+ this.$router.push({ path: `nutrient-template/${row.id}/detail` })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|