addEdit.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="12vh"
  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. @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="pid">
  28. <el-input
  29. v-model="ruleForm.pid"
  30. placeholder="上级分类"
  31. minlength="20"
  32. disabled
  33. />
  34. </el-form-item>
  35. <el-form-item label="分类名称" prop="cat_name">
  36. <el-input
  37. v-model="ruleForm.cat_name"
  38. :disabled="id == '007'"
  39. placeholder="分类名称"
  40. minlength="20"
  41. />
  42. </el-form-item>
  43. <el-form-item label="分类规格" prop="specs_id">
  44. <el-select
  45. v-model="ruleForm.specs_id"
  46. multiple
  47. style="width: 100%"
  48. placeholder="分类规格"
  49. >
  50. <el-option
  51. v-for="item in specOptions"
  52. :key="item.id"
  53. :label="item.spec_name"
  54. :value="item.id"
  55. >
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item label="科目代码" prop="科目代码">
  60. <el-input
  61. v-model="ruleForm.fund_code"
  62. :disabled="id == '007'"
  63. placeholder="科目代码"
  64. minlength="50"
  65. />
  66. </el-form-item>
  67. <el-form-item label="售后说明" prop="cat_desc">
  68. <el-input
  69. v-model="ruleForm.cat_desc"
  70. :disabled="id == '007'"
  71. placeholder="售后说明"
  72. type="textarea"
  73. :rows="5"
  74. minlength="2000"
  75. />
  76. </el-form-item>
  77. </el-form>
  78. </el-col>
  79. <el-col :span="24" style="text-align: right">
  80. <el-button v-if="id !== '007'" type="primary" @click="submitForm"
  81. >保 存
  82. </el-button>
  83. <el-button @click="showModelThis = false">{{
  84. id == "007" ? "关 闭" : "取 消"
  85. }}</el-button>
  86. </el-col>
  87. </el-row>
  88. </el-card>
  89. </el-dialog>
  90. </template>
  91. <script>
  92. import asyncRequest from "@/apis/service/goodStore/sort";
  93. import resToken from "@/mixins/resToken";
  94. export default {
  95. name: "sort",
  96. props: ["showModel", "id", "sitem"],
  97. mixins: [resToken],
  98. data() {
  99. return {
  100. loading: false,
  101. title: "添加分类",
  102. showModelThis: this.showModel,
  103. specOptions: [],
  104. ruleForm: {
  105. id: "",
  106. cat_name: "",
  107. specs_id: [],
  108. cat_desc: "",
  109. },
  110. rulesThis: this.rules,
  111. rules: {
  112. cat_name: [
  113. { required: true, message: "分类名称不能为空", trigger: "blur" },
  114. ],
  115. specs_id: [
  116. {
  117. type: "array",
  118. required: true,
  119. message: "请至少选择一个分类规格",
  120. trigger: "change",
  121. },
  122. ],
  123. cat_desc: [{ required: false, message: "", trigger: "blur" }],
  124. },
  125. };
  126. },
  127. watch: {
  128. showModel: function (val) {
  129. this.showModelThis = val;
  130. if (val) {
  131. this.initForm();
  132. }
  133. },
  134. showModelThis(val) {
  135. if (!val) {
  136. this.$emit("cancel");
  137. }
  138. },
  139. },
  140. methods: {
  141. async initForm() {
  142. this.loading = true;
  143. if (this.id === "003") {
  144. this.title = "添加分类";
  145. this.rulesThis = this.rules;
  146. } else if (this.id === "005") {
  147. this.title = "修改分类";
  148. this.rulesThis = this.rules;
  149. } else {
  150. this.title = "分类详情";
  151. this.rulesThis = {};
  152. }
  153. await this.resetForm();
  154. await this.getAllSpecs();
  155. this.loading = false;
  156. },
  157. async resetForm() {
  158. // 重置
  159. await this.$nextTick(() => {
  160. if (this.$refs.ruleForm) {
  161. this.$refs.ruleForm.resetFields();
  162. this.$refs.ruleForm.clearValidate();
  163. const { pid, id, cat_name, cat_desc, specs_id } = this.sitem;
  164. this.ruleForm = {
  165. pid: pid || "",
  166. id: id || "",
  167. cat_name: cat_name || "",
  168. specs_id: specs_id || [],
  169. cat_desc: cat_desc || "",
  170. };
  171. }
  172. });
  173. },
  174. async getAllSpecs() {
  175. this.specOptions = [];
  176. let res = await asyncRequest.specstitle({});
  177. if (res && res.code === 0) {
  178. this.specOptions = res.data;
  179. } else if (res && res.code >= 100 && res.code <= 104) {
  180. this.specOptions = [];
  181. await this.logout();
  182. } else {
  183. this.specOptions = [];
  184. this.$message.warning(res.message);
  185. }
  186. },
  187. async submitForm() {
  188. await this.$refs.ruleForm.validate(async (valid) => {
  189. if (valid) {
  190. this.loading = true;
  191. let model = JSON.parse(JSON.stringify(this.ruleForm));
  192. let res = {};
  193. if (this.id === "003") {
  194. delete model["id"];
  195. res = await asyncRequest.add(model);
  196. } else {
  197. res = await asyncRequest.update(model);
  198. }
  199. this.loading = false;
  200. if (res && res.code === 0) {
  201. const title = this.id === "add" ? "添加成功!" : "修改成功!";
  202. this.$notify.success({
  203. title,
  204. message: "",
  205. });
  206. this.showModelThis = false;
  207. // 刷新
  208. this.$emit("refresh");
  209. } else if (res && res.code >= 100 && res.code <= 104) {
  210. await this.logout();
  211. } else {
  212. this.$message.warning(res.message);
  213. }
  214. } else {
  215. console.log("error submit!!");
  216. return false;
  217. }
  218. });
  219. },
  220. },
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .sort {
  225. }
  226. </style>