addEdit.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="25vh"
  8. width="600px"
  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. append-to-body
  15. @close="closeModel"
  16. >
  17. <el-card style="margin-top: -20px">
  18. <el-row>
  19. <el-col :span="24">
  20. <el-form
  21. ref="ruleForm"
  22. :model="ruleForm"
  23. is_show-icon
  24. :rules="rulesThis"
  25. label-width="100px"
  26. class="demo-ruleForm"
  27. >
  28. <el-form-item label="分类名称:" prop="className">
  29. <el-input
  30. v-model="ruleForm.className"
  31. :disabled="isDetail"
  32. placeholder="请输入分类名称"
  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="!isDetail" type="primary" @click="submitForm">
  39. 保 存
  40. </el-button>
  41. <el-button @click="showModelThis = false">{{
  42. isDetail ? "关 闭" : "取 消"
  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/purchaseIn/goodsClass";
  51. import btnList from "@/assets/js/btnList";
  52. import resToken from "@/mixins/resToken";
  53. export default {
  54. mixins: [resToken],
  55. props: [
  56. "showModel",
  57. "id",
  58. "isDetail",
  59. "pid",
  60. "level",
  61. "isAdd",
  62. "type",
  63. "formData",
  64. "goodsName",
  65. ],
  66. data() {
  67. return {
  68. loading: false,
  69. showIconModel: false,
  70. title: "",
  71. btnList,
  72. showModelThis: this.showModel,
  73. ruleForm: {
  74. className: "", //分类名称
  75. },
  76. rulesThis: this.rules,
  77. rules: {
  78. className: [
  79. {
  80. required: true,
  81. message: "请输入分类名称",
  82. trigger: "blur",
  83. },
  84. {
  85. min: 1,
  86. max: 50,
  87. message: "长度在 1 到 50 个字符",
  88. trigger: "blur",
  89. },
  90. ],
  91. },
  92. };
  93. },
  94. watch: {
  95. showModel: function (val) {
  96. this.showModelThis = val;
  97. if (val) {
  98. this.initForm();
  99. }
  100. },
  101. showModelThis(val) {
  102. if (!val) {
  103. this.$emit("cancel");
  104. }
  105. },
  106. },
  107. methods: {
  108. closeModel() {
  109. console.log("closeModel!!");
  110. },
  111. async initForm() {
  112. if (this.isAdd) {
  113. this.title = "添加商品分类";
  114. this.loading = false;
  115. this.rulesThis = this.rules;
  116. } else {
  117. if (this.isDetail) {
  118. this.title = "商品分类详情";
  119. this.rulesThis = {};
  120. } else {
  121. this.title = "修改商品分类";
  122. this.rulesThis = this.rules;
  123. }
  124. }
  125. await this.resetForm();
  126. },
  127. async resetForm() {
  128. this.ruleForm = {
  129. id: this.id,
  130. pid: this.pid,
  131. className: this.goodsName || "", // 名称
  132. };
  133. await this.$nextTick(() => {
  134. if (this.$refs.ruleForm) {
  135. // 去掉验证信息
  136. this.$refs.ruleForm.clearValidate();
  137. }
  138. });
  139. },
  140. async submitForm() {
  141. if (this.loading) {
  142. return false;
  143. }
  144. this.loading = true;
  145. await this.$refs.ruleForm.validate(async (valid) => {
  146. if (valid) {
  147. let model = {};
  148. let res = {};
  149. const { className } = this.ruleForm;
  150. model = {
  151. id: this.id,
  152. pid: this.pid,
  153. cat_name: className,
  154. };
  155. if (this.level === 1) {
  156. // delete model["pid"];
  157. // delete model["menuid"];
  158. // delete model["url"];
  159. // delete model["action_code"];
  160. // delete model["status"];
  161. } else if (this.level === 2) {
  162. delete model["menuid"];
  163. delete model["action_code"];
  164. delete model["status"];
  165. } else {
  166. delete model["pid"];
  167. delete model["img"];
  168. delete model["is_show"];
  169. delete model["weight"];
  170. delete model["route"];
  171. delete model["is_display"];
  172. delete model["url"];
  173. }
  174. if (this.isAdd) {
  175. delete model["id"];
  176. }
  177. if (this.isAdd) {
  178. res = await asyncRequest.add(model);
  179. } else {
  180. res = await asyncRequest.update(model);
  181. // if (this.isAdd) {
  182. // res = await asyncRequest.actionadd(model);
  183. // } else {
  184. // res = await asyncRequest.actionedit(model);
  185. // }
  186. }
  187. this.loading = false;
  188. if (res && res.code === 0) {
  189. this.ruleForm = {};
  190. const title = this.isAdd ? "添加成功" : "修改成功";
  191. this.$notify.success({
  192. title,
  193. message: "",
  194. });
  195. this.showModelThis = false;
  196. // 刷新
  197. let pids = this.pid;
  198. if (this.id === 0) {
  199. // 添加组织
  200. pids = "0";
  201. }
  202. this.$emit("refresh", this.id, pids, this.level);
  203. } else if (res && res.code >= 100 && res.code <= 104) {
  204. await this.logout();
  205. } else {
  206. this.$message.warning(res.message);
  207. }
  208. } else {
  209. this.loading = false;
  210. console.log("error submit!!");
  211. return false;
  212. }
  213. });
  214. },
  215. },
  216. };
  217. </script>
  218. <style lang="scss" scoped>
  219. .g-block {
  220. display: inline-block;
  221. padding: 10px 5px;
  222. text-align: center;
  223. border: 1px #ccc dashed;
  224. margin: 1px;
  225. font-size: 0px;
  226. cursor: pointer;
  227. i {
  228. font-size: 30px;
  229. line-height: 30px;
  230. display: block;
  231. margin: 0 auto;
  232. width: 30px;
  233. }
  234. }
  235. </style>