edit.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <el-dialog
  4. class="ele-dialog-form"
  5. :title="title"
  6. :visible.sync="visible"
  7. :before-close="handleClose"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. width="450px"
  11. >
  12. <el-form ref="form" :model="form" :rules="rules" label-width="50px">
  13. <el-row>
  14. <el-col :span="24">
  15. <el-form-item
  16. label="名称"
  17. prop="name">
  18. <el-input
  19. clearable
  20. :maxlength="20"
  21. v-model="form.name"
  22. placeholder="请输入分类名"
  23. />
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="24">
  27. <el-form-item
  28. label="备注"
  29. prop="remark">
  30. <el-input
  31. type="textarea"
  32. clearable
  33. :maxlength="20"
  34. v-model="form.remark"
  35. />
  36. </el-form-item>
  37. </el-col>
  38. </el-row>
  39. </el-form>
  40. <template v-slot:footer>
  41. <el-button type="primary" :loading="loading" @click="save">保存</el-button>
  42. <el-button @click="handleClose">取消</el-button>
  43. </template>
  44. </el-dialog>
  45. </template>
  46. <script>
  47. import {getProcessTypeGetByIdAPI, processTypeSaveAPI, processTypeUpdateAPI} from "@/api/bpm/processClass";
  48. import {deepClone} from "@/utils";
  49. export default {
  50. data() {
  51. const defaultForm = function () {
  52. return {
  53. id: '',
  54. name: '',
  55. remark: '',
  56. };
  57. };
  58. return {
  59. defaultForm,
  60. // 表单数据
  61. form: {...defaultForm()},
  62. // 表单验证规则
  63. rules: {
  64. name: [{required: true, message: '请输入名称', trigger: 'blur'}],
  65. },
  66. visible: false,
  67. type: '', // add/edit
  68. loading: false,
  69. };
  70. },
  71. computed: {
  72. title() {
  73. switch (this.type) {
  74. case 'add':
  75. return '新增';
  76. break;
  77. case 'edit':
  78. return '编辑';
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. },
  85. methods: {
  86. open(type, row) {
  87. this.type = type;
  88. this.visible = true;
  89. if (type == 'edit') {
  90. this.getInfo(row.id)
  91. }
  92. },
  93. async getInfo(id) {
  94. const res = await getProcessTypeGetByIdAPI(id)
  95. this.form = deepClone(res)
  96. },
  97. /* 保存编辑 */
  98. save() {
  99. this.$refs.form.validate((valid) => {
  100. if (!valid) {
  101. return false;
  102. }
  103. this.loading = true;
  104. if (this.type == 'add') {
  105. delete this.form.id;
  106. }
  107. let API = this.type == 'add' ? processTypeSaveAPI : processTypeUpdateAPI
  108. API(this.form)
  109. .then((msg) => {
  110. this.loading = false;
  111. this.$message.success('操作成功');
  112. this.handleClose();
  113. this.$emit('done');
  114. })
  115. .catch((e) => {
  116. this.loading = false;
  117. this.$message.error(e.message);
  118. });
  119. });
  120. },
  121. restForm() {
  122. this.form = {...this.defaultForm()};
  123. this.$nextTick(() => {
  124. this.$refs.form.clearValidate();
  125. });
  126. },
  127. handleClose() {
  128. this.restForm();
  129. this.visible = false;
  130. },
  131. }
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. </style>