index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!-- 编辑菜单 -->
  2. <script>
  3. import useColumns from "./columns";
  4. import { MENUEDIT, MENUDETAIL } from "@/api/canteen/basic.js";
  5. export default {
  6. name: "MenuEdit",
  7. dicts: ["canteen_mealtime"],
  8. props: {
  9. data: {
  10. type: Array,
  11. default: () => [],
  12. },
  13. },
  14. components: {
  15. ElSuperForm: () => import("@/components/super-form/index.vue"),
  16. },
  17. data() {
  18. const { FormColumns } = useColumns();
  19. const rules = this.$init.rules(FormColumns);
  20. const params = this.$init.params(FormColumns);
  21. return {
  22. rules,
  23. params,
  24. width: "50%",
  25. title: "编 辑",
  26. visible: false,
  27. FormColumns,
  28. };
  29. },
  30. computed: {
  31. disabled: {
  32. get() {
  33. let { data } = this.$props;
  34. if (data.length === 1) {
  35. return false;
  36. }
  37. return true;
  38. },
  39. set() {},
  40. },
  41. },
  42. methods: {
  43. open() {
  44. this.visible = true;
  45. },
  46. //
  47. async beforeOpen() {
  48. try {
  49. this.loading = true;
  50. let { id } = this.$props.data[0];
  51. let { code, data } = await MENUDETAIL(id);
  52. if (code === 200) {
  53. this.params = data;
  54. }
  55. } catch (error) {
  56. } finally {
  57. this.loading = false;
  58. }
  59. },
  60. // 提交
  61. useSubmit(form) {
  62. this.$refs[form].validate(async (valid) => {
  63. if (valid) {
  64. try {
  65. this.$modal.loading("处理中...");
  66. let { code, msg } = await MENUEDIT({ ...this.params });
  67. if (code === 200) {
  68. this.$notify.success(msg);
  69. this.cancel();
  70. }
  71. } catch (error) {
  72. } finally {
  73. this.$modal.closeLoading();
  74. }
  75. }
  76. });
  77. },
  78. cancel() {
  79. this.params = this.$init.params(this.FormColumns);
  80. this.visible = false;
  81. this.$emit("close");
  82. },
  83. },
  84. created() {},
  85. };
  86. </script>
  87. <template>
  88. <el-button
  89. v-bind="$attrs"
  90. v-on="$listeners"
  91. :size="$attrs.size"
  92. @click="open"
  93. :disabled="disabled"
  94. >
  95. {{ title }}
  96. <el-dialog
  97. :width="width"
  98. :visible.sync="visible"
  99. append-to-body
  100. :show-close="false"
  101. @open="beforeOpen"
  102. >
  103. <template #title>
  104. <el-row type="flex" justify="space-between">
  105. <el-col>{{ title }}</el-col>
  106. <el-col style="text-align: right">
  107. <el-button
  108. :size="$attrs.size"
  109. type="primary"
  110. @click="useSubmit('superForm')"
  111. >保存</el-button
  112. >
  113. <el-button :size="$attrs.size" @click="cancel">取消</el-button>
  114. </el-col>
  115. </el-row>
  116. </template>
  117. <el-super-form
  118. v-model="params"
  119. :dict="dict"
  120. :rules="rules"
  121. :size="$attrs.size"
  122. :columns="FormColumns"
  123. ref="superForm"
  124. label-width="auto"
  125. label-position="right"
  126. style="padding: 20px"
  127. >
  128. </el-super-form>
  129. </el-dialog>
  130. </el-button>
  131. </template>