123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <!-- 编辑菜单 -->
- <script>
- import useColumns from "./columns";
- import { MENUEDIT, MENUDETAIL } from "@/api/canteen/basic.js";
- export default {
- name: "MenuEdit",
- dicts: ["canteen_mealtime"],
- props: {
- data: {
- type: Array,
- default: () => [],
- },
- },
- components: {
- ElSuperForm: () => import("@/components/super-form/index.vue"),
- },
- data() {
- const { FormColumns } = useColumns();
- const rules = this.$init.rules(FormColumns);
- const params = this.$init.params(FormColumns);
- return {
- rules,
- params,
- width: "50%",
- title: "编 辑",
- visible: false,
- FormColumns,
- };
- },
- computed: {
- disabled: {
- get() {
- let { data } = this.$props;
- if (data.length === 1) {
- return false;
- }
- return true;
- },
- set() {},
- },
- },
- methods: {
- open() {
- this.visible = true;
- },
- //
- async beforeOpen() {
- try {
- this.loading = true;
- let { id } = this.$props.data[0];
- let { code, data } = await MENUDETAIL(id);
- if (code === 200) {
- this.params = data;
- }
- } catch (error) {
- } finally {
- this.loading = false;
- }
- },
- // 提交
- useSubmit(form) {
- this.$refs[form].validate(async (valid) => {
- if (valid) {
- try {
- this.$modal.loading("处理中...");
- let { code, msg } = await MENUEDIT({ ...this.params });
- if (code === 200) {
- this.$notify.success(msg);
- this.cancel();
- }
- } catch (error) {
- } finally {
- this.$modal.closeLoading();
- }
- }
- });
- },
- cancel() {
- this.params = this.$init.params(this.FormColumns);
- this.visible = false;
- this.$emit("close");
- },
- },
- created() {},
- };
- </script>
- <template>
- <el-button
- v-bind="$attrs"
- v-on="$listeners"
- :size="$attrs.size"
- @click="open"
- :disabled="disabled"
- >
- {{ title }}
- <el-dialog
- :width="width"
- :visible.sync="visible"
- append-to-body
- :show-close="false"
- @open="beforeOpen"
- >
- <template #title>
- <el-row type="flex" justify="space-between">
- <el-col>{{ title }}</el-col>
- <el-col style="text-align: right">
- <el-button
- :size="$attrs.size"
- type="primary"
- @click="useSubmit('superForm')"
- >保存</el-button
- >
- <el-button :size="$attrs.size" @click="cancel">取消</el-button>
- </el-col>
- </el-row>
- </template>
- <el-super-form
- v-model="params"
- :dict="dict"
- :rules="rules"
- :size="$attrs.size"
- :columns="FormColumns"
- ref="superForm"
- label-width="auto"
- label-position="right"
- style="padding: 20px"
- >
- </el-super-form>
- </el-dialog>
- </el-button>
- </template>
|