baseFormAddEdit.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. :size="'small'"
  24. :rules="rulesThis"
  25. label-width="80px"
  26. class="demo-ruleForm"
  27. >
  28. <el-form-item label="规格类型" prop="active_name">
  29. <search-spec
  30. :value="ruleForm.active_name"
  31. :disabled="false"
  32. :size="'mini'"
  33. :isDetail="false"
  34. :placeholder="'规格类型'"
  35. @searchChange="active_namesearchChange"
  36. />
  37. </el-form-item>
  38. <el-form-item label="规格值" prop="logo_url">
  39. <el-radio-group v-model="ruleForm.logo_url">
  40. <el-radio
  41. v-for="item in specVlist"
  42. :key="item.id + item.name"
  43. :label="item.id"
  44. >{{ item.name }}</el-radio
  45. >
  46. </el-radio-group>
  47. </el-form-item>
  48. <div style="width: 100%; padding: 0 0 0 80px">
  49. <el-input
  50. style="width: 209px"
  51. v-model="sinput"
  52. :disabled="id == 'edit'"
  53. :size="'small'"
  54. placeholder="规格值名称,如红色"
  55. maxlength="20"
  56. />
  57. <el-button
  58. style="margin: 0 0 0 10px"
  59. icon="el-icon-plus"
  60. :size="'small'"
  61. >新增规格值</el-button
  62. >
  63. </div>
  64. </el-form>
  65. </el-col>
  66. <el-col :span="24" style="text-align: right; padding-top: 18px">
  67. <el-button
  68. v-if="id !== 'edit'"
  69. :size="'small'"
  70. type="primary"
  71. @click="submitForm"
  72. >保 存
  73. </el-button>
  74. <el-button @click="showModelThis = false" :size="'small'">{{
  75. id == "edit" ? "关 闭" : "取 消"
  76. }}</el-button>
  77. </el-col>
  78. </el-row>
  79. </el-card>
  80. </el-dialog>
  81. </template>
  82. <script>
  83. import asyncRequest from "@/apis/service/goodStore/active";
  84. import resToken from "@/mixins/resToken";
  85. export default {
  86. name: "active",
  87. props: ["showModel", "id", "sitem"],
  88. mixins: [resToken],
  89. data() {
  90. return {
  91. loading: false,
  92. title: "",
  93. sinput: "",
  94. showModelThis: this.showModel,
  95. select: "1",
  96. specVlist: [
  97. { id: "1", name: "111" },
  98. { id: "2", name: "222" },
  99. ],
  100. activeOptions: [],
  101. actionList: [],
  102. ruleForm: {
  103. id: "",
  104. active_name: "",
  105. logo_url: "",
  106. },
  107. rulesThis: this.rules,
  108. rules: {
  109. active_name: [
  110. { required: true, message: "品牌名称不能为空", trigger: "change" },
  111. ],
  112. logo_url: [
  113. { required: true, message: "品牌名称不能为空", trigger: "change" },
  114. ],
  115. },
  116. };
  117. },
  118. watch: {
  119. showModel: function (val) {
  120. this.showModelThis = val;
  121. if (val) {
  122. this.initForm();
  123. }
  124. },
  125. showModelThis(val) {
  126. if (!val) {
  127. this.$emit("cancel");
  128. }
  129. },
  130. },
  131. methods: {
  132. async initForm() {
  133. this.loading = true;
  134. if (this.id === "add") {
  135. this.title = "添加商品类型";
  136. this.rulesThis = this.rules;
  137. } else if (this.id === "005") {
  138. this.title = "修改商品类型";
  139. this.rulesThis = this.rules;
  140. } else {
  141. this.title = "品牌商品类型";
  142. this.rulesThis = {};
  143. }
  144. await this.resetForm();
  145. this.loading = false;
  146. },
  147. async resetForm() {
  148. // 重置
  149. await this.$nextTick(() => {
  150. if (this.$refs.ruleForm) {
  151. this.$refs.ruleForm.resetFields();
  152. this.$refs.ruleForm.clearValidate();
  153. const { id, active_name, logo_url } = this.sitem;
  154. this.ruleForm = {
  155. id: id || "",
  156. active_name: active_name || "",
  157. logo_url: logo_url || "",
  158. };
  159. }
  160. });
  161. },
  162. active_namesearchChange(e) {
  163. const { id, code, label } = e;
  164. if (id) {
  165. this.ruleForm.active_name = code;
  166. } else {
  167. this.ruleForm.active_name = "";
  168. }
  169. this.$refs.ruleForm.validateField("active_name");
  170. this.getlist();
  171. },
  172. async getlist() {
  173. const { active_name } = this.ruleForm;
  174. const { code, data, message } = await asyncRequest.list({
  175. active_name: active_name,
  176. });
  177. if (code === 0) {
  178. this.options = data;
  179. } else if (code >= 100 && code <= 104) {
  180. await this.logout();
  181. } else {
  182. this.$message.warning(message);
  183. }
  184. },
  185. async submitForm() {
  186. await this.$refs.ruleForm.validate(async (valid) => {
  187. if (valid) {
  188. this.loading = true;
  189. let model = JSON.parse(JSON.stringify(this.ruleForm));
  190. let res = {};
  191. if (this.id === "003") {
  192. delete model["id"];
  193. res = await asyncRequest.add(model);
  194. } else {
  195. res = await asyncRequest.update(model);
  196. }
  197. this.loading = false;
  198. if (res && res.code === 0) {
  199. const title = this.id === "add" ? "添加成功!" : "修改成功!";
  200. this.$notify.success({
  201. title,
  202. message: "",
  203. });
  204. this.showModelThis = false;
  205. // 刷新
  206. this.$emit("refresh");
  207. } else if (res && res.code >= 100 && res.code <= 104) {
  208. await this.logout();
  209. } else {
  210. this.$message.warning(res.message);
  211. }
  212. } else {
  213. console.log("error submit!!");
  214. return false;
  215. }
  216. });
  217. },
  218. async submitForm1() {
  219. await this.$refs.ruleForm.validate(async (valid) => {
  220. if (valid) {
  221. this.loading = true;
  222. let model = JSON.parse(JSON.stringify(this.ruleForm));
  223. let res = {};
  224. if (this.id === "003") {
  225. delete model["id"];
  226. res = await asyncRequest.add(model);
  227. } else {
  228. res = await asyncRequest.update(model);
  229. }
  230. this.loading = false;
  231. if (res && res.code === 0) {
  232. const title = this.id === "add" ? "添加成功!" : "修改成功!";
  233. this.$notify.success({
  234. title,
  235. message: "",
  236. });
  237. this.showModelThis = false;
  238. // 刷新
  239. this.$emit("refresh");
  240. } else if (res && res.code >= 100 && res.code <= 104) {
  241. await this.logout();
  242. } else {
  243. this.$message.warning(res.message);
  244. }
  245. } else {
  246. console.log("error submit!!");
  247. return false;
  248. }
  249. });
  250. },
  251. },
  252. };
  253. </script>
  254. <style lang="scss" scoped>
  255. .active {
  256. }
  257. </style>