addEdit.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="18vh"
  8. width="500px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="showModelThis = false"
  15. >
  16. <el-card style="margin: -20px 0 0 0">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. :rules="rulesThis"
  24. label-width="80px"
  25. class="demo-ruleForm"
  26. >
  27. <el-form-item label="单位名称" prop="unit">
  28. <el-input
  29. v-model="ruleForm.unit"
  30. :disabled="id == '007'"
  31. placeholder="单位名称"
  32. minlength="20"
  33. />
  34. </el-form-item>
  35. </el-form>
  36. </el-col>
  37. <el-col :span="24" style="text-align: right">
  38. <el-button v-if="id !== '007'" type="primary" @click="submitForm"
  39. >保 存
  40. </el-button>
  41. <el-button @click="showModelThis = false">{{
  42. id == "007" ? "关 闭" : "取 消"
  43. }}</el-button>
  44. </el-col>
  45. </el-row>
  46. </el-card>
  47. </el-dialog>
  48. </template>
  49. <script>
  50. import asyncRequest from "@/apis/service/goodStore/unit";
  51. import resToken from "@/mixins/resToken";
  52. export default {
  53. name: "brand",
  54. props: ["showModel", "id", "sitem"],
  55. mixins: [resToken],
  56. data() {
  57. return {
  58. loading: false,
  59. title: "添加单位",
  60. showModelThis: this.showModel,
  61. select: "1",
  62. activeOptions: [],
  63. actionList: [],
  64. ruleForm: {
  65. id: "",
  66. unit: "",
  67. },
  68. rulesThis: this.rules,
  69. rules: {
  70. unit: [
  71. { required: true, message: "单位名称不能为空", trigger: "blur" },
  72. ],
  73. },
  74. };
  75. },
  76. watch: {
  77. showModel: function (val) {
  78. this.showModelThis = val;
  79. if (val) {
  80. this.initForm();
  81. }
  82. },
  83. showModelThis(val) {
  84. if (!val) {
  85. this.$emit("cancel");
  86. }
  87. },
  88. },
  89. methods: {
  90. async initForm() {
  91. this.loading = true;
  92. if (this.id === "003") {
  93. this.title = "添加单位";
  94. this.rulesThis = this.rules;
  95. } else if (this.id === "005") {
  96. this.title = "修改单位";
  97. this.rulesThis = this.rules;
  98. } else {
  99. this.title = "单位详情";
  100. this.rulesThis = {};
  101. }
  102. await this.resetForm();
  103. this.loading = false;
  104. },
  105. async resetForm() {
  106. // 重置
  107. await this.$nextTick(() => {
  108. if (this.$refs.ruleForm) {
  109. this.$refs.ruleForm.resetFields();
  110. this.$refs.ruleForm.clearValidate();
  111. const { id, unit} = this.sitem;
  112. this.ruleForm = {
  113. id: id || "",
  114. unit: unit || "",
  115. };
  116. }
  117. });
  118. },
  119. async submitForm() {
  120. await this.$refs.ruleForm.validate(async (valid) => {
  121. if (valid) {
  122. this.loading = true;
  123. let model = JSON.parse(JSON.stringify(this.ruleForm));
  124. let res = {};
  125. if (this.id === "003") {
  126. delete model["id"];
  127. res = await asyncRequest.add(model);
  128. } else {
  129. res = await asyncRequest.update(model);
  130. }
  131. this.loading = false;
  132. if (res && res.code === 0) {
  133. const title = this.id === "003" ? "添加成功!" : "修改成功!";
  134. this.$notify.success({
  135. title,
  136. message: "",
  137. });
  138. this.showModelThis = false;
  139. // 刷新
  140. this.$emit("refresh");
  141. } else if (res && res.code >= 100 && res.code <= 104) {
  142. await this.logout();
  143. } else {
  144. this.$message.warning(res.message);
  145. }
  146. } else {
  147. console.log("error submit!!");
  148. return false;
  149. }
  150. });
  151. },
  152. },
  153. };
  154. </script>
  155. <style lang="scss" scoped>
  156. .brand {
  157. }
  158. </style>