|
@@ -0,0 +1,274 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <section>
|
|
|
|
|
+ <el-col :span="24" class="toolbar" style="padding-bottom: 0px;position:sticky;top:0;z-index:1002">
|
|
|
|
|
+ <el-form :inline="true">
|
|
|
|
|
+ <el-form-item label="餐别设置">
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ </el-form>
|
|
|
|
|
+ </el-col>
|
|
|
|
|
+
|
|
|
|
|
+ <div style="padding: 20px;">
|
|
|
|
|
+ <div style="margin-bottom: 20px;">
|
|
|
|
|
+ <el-button type="primary" @click="handleAdd">新增厂区</el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <el-table :data="tableData" border style="width: 100%;">
|
|
|
|
|
+ <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
|
|
|
|
|
+ <el-table-column prop="name" label="餐别名称" align="center"></el-table-column>
|
|
|
|
|
+ <el-table-column label="是否启用" width="120" align="center">
|
|
|
|
|
+ <template slot-scope="scope">
|
|
|
|
|
+ <el-tag :type="scope.row.isActive === 1 ? 'success' : 'danger'">
|
|
|
|
|
+ {{ scope.row.isActive === 1 ? '启用' : '未启用' }}
|
|
|
|
|
+ </el-tag>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ <el-table-column label="操作" width="250" align="center">
|
|
|
|
|
+ <template slot-scope="scope">
|
|
|
|
|
+ <el-button size="mini" @click="handleEdit(scope.row)">修改</el-button>
|
|
|
|
|
+ <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
|
|
|
|
|
+ <el-button
|
|
|
|
|
+ size="mini"
|
|
|
|
|
+ :type="scope.row.isActive === 1 ? 'warning' : 'success'"
|
|
|
|
|
+ @click="toggleisActive(scope.row)">
|
|
|
|
|
+ {{ scope.row.isActive === 1 ? '禁用' : '启用' }}
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
|
|
+ </el-table>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 新增/编辑对话框 -->
|
|
|
|
|
+ <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="500px">
|
|
|
|
|
+ <el-form :model="formData" :rules="formRules" ref="formRef" label-width="100px">
|
|
|
|
|
+ <el-form-item label="餐别名称" prop="name">
|
|
|
|
|
+ <el-input v-model="formData.name" placeholder="请输入餐别名称"></el-input>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item label="是否启用">
|
|
|
|
|
+ <el-switch
|
|
|
|
|
+ v-model="formData.isActive"
|
|
|
|
|
+ :active-value=1
|
|
|
|
|
+ :inactive-value=0
|
|
|
|
|
+ active-text="启用"
|
|
|
|
|
+ inactive-text="禁用">
|
|
|
|
|
+ </el-switch>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ </el-form>
|
|
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
|
|
+ <el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
|
|
+ <el-button type="primary" @click="handleSubmit">确 定</el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-dialog>
|
|
|
|
|
+ </section>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script>export default {
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ tableData: [],
|
|
|
|
|
+ dialogVisible: false,
|
|
|
|
|
+ dialogTitle: '',
|
|
|
|
|
+ isEdit: false,
|
|
|
|
|
+ formData: {
|
|
|
|
|
+ id: null,
|
|
|
|
|
+ name: '',
|
|
|
|
|
+ isActive: 1
|
|
|
|
|
+ },
|
|
|
|
|
+ formRules: {
|
|
|
|
|
+ name: [
|
|
|
|
|
+ { required: true, message: '请输入餐别名称', trigger: 'blur' }
|
|
|
|
|
+ ]
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ mounted() {
|
|
|
|
|
+ this.fetchData();
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ // 获取数据
|
|
|
|
|
+ fetchData() {
|
|
|
|
|
+ this.http.post('/meal-types/getMeals', {},
|
|
|
|
|
+ res => {
|
|
|
|
|
+ if (res.code == "ok") {
|
|
|
|
|
+ this.tableData = res.data;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ error => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: error,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 新增按钮点击事件
|
|
|
|
|
+ handleAdd() {
|
|
|
|
|
+ this.dialogTitle = '新增餐别';
|
|
|
|
|
+ this.isEdit = false;
|
|
|
|
|
+ this.formData = { id: null, name: '', isActive: 1 };
|
|
|
|
|
+ this.dialogVisible = true;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 编辑按钮点击事件
|
|
|
|
|
+ handleEdit(row) {
|
|
|
|
|
+ this.dialogTitle = '编辑餐别';
|
|
|
|
|
+ this.isEdit = true;
|
|
|
|
|
+ this.formData = { ...row };
|
|
|
|
|
+ this.dialogVisible = true;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 删除按钮点击事件
|
|
|
|
|
+ handleDelete(row) {
|
|
|
|
|
+ this.$confirm(`确定要删除餐别"${row.name}"吗?`, '提示', {
|
|
|
|
|
+ confirmButtonText: '确定',
|
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
|
+ type: 'warning'
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ this.http.post('/meal-types/deleteMealType', {
|
|
|
|
|
+ id: row.id,
|
|
|
|
|
+ }, res => {
|
|
|
|
|
+ if (res.code == "ok") {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: '删除成功',
|
|
|
|
|
+ type: "success"
|
|
|
|
|
+ });
|
|
|
|
|
+ this.fetchData();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, error => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: error,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ type: 'info',
|
|
|
|
|
+ message: '已取消删除'
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 切换启用状态
|
|
|
|
|
+ toggleisActive(row) {
|
|
|
|
|
+ const newisActive = row.isActive === 1 ? 0 : 1;
|
|
|
|
|
+ const action = newisActive === 1 ? '启用' : '禁用';
|
|
|
|
|
+
|
|
|
|
|
+ this.$confirm(`确定要${action}餐别"${row.name}"吗?`, '提示', {
|
|
|
|
|
+ confirmButtonText: '确定',
|
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
|
+ type: 'warning'
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ this.http.post('/meal-types/updateMeal', {
|
|
|
|
|
+ id: row.id,
|
|
|
|
|
+ isActive: newisActive
|
|
|
|
|
+ }, res => {
|
|
|
|
|
+ if (res.code == "ok") {
|
|
|
|
|
+ row.isActive = newisActive;
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ type: 'success',
|
|
|
|
|
+ message: `${action}成功!`
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, error => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: error,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ type: 'info',
|
|
|
|
|
+ message: `已取消${action}`
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 提交表单
|
|
|
|
|
+ handleSubmit() {
|
|
|
|
|
+ this.$refs.formRef.validate((valid) => {
|
|
|
|
|
+ if (valid) {
|
|
|
|
|
+ if (this.isEdit) {
|
|
|
|
|
+ this.http.post('/meal-types/updateMeal', {
|
|
|
|
|
+ id: this.formData.id,
|
|
|
|
|
+ name: this.formData.name,
|
|
|
|
|
+ isActive: this.formData.isActive
|
|
|
|
|
+ },
|
|
|
|
|
+ res => {
|
|
|
|
|
+ if (res.code == "ok") {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: '编辑成功',
|
|
|
|
|
+ type: "success"
|
|
|
|
|
+ });
|
|
|
|
|
+ this.dialogVisible = false;
|
|
|
|
|
+ this.fetchData();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ error => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: error,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ this.http.post('/meal-types/addMealType', this.formData,
|
|
|
|
|
+ res => {
|
|
|
|
|
+ if (res.code == "ok") {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: '新增成功',
|
|
|
|
|
+ type: "success"
|
|
|
|
|
+ });
|
|
|
|
|
+ this.dialogVisible = false;
|
|
|
|
|
+ this.fetchData();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ error => {
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: error,
|
|
|
|
|
+ type: "error"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ this.dialogVisible = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>.toolbar {
|
|
|
|
|
+ background: #f5f5f5;
|
|
|
|
|
+ padding: 15px;
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|