specAdd.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div id="specAdd">
  3. <el-form
  4. :model="ruleForm"
  5. :rules="rules"
  6. ref="ruleForm"
  7. label-width="170px"
  8. hide-required-asterisk
  9. >
  10. <template v-if="!isNext">
  11. <el-form-item label="使用的业务层次" required>
  12. <div style="display: flex">
  13. <el-form-item prop="educationTypeId">
  14. <el-select
  15. style="margin-right: 24px"
  16. v-model="ruleForm.educationTypeId"
  17. placeholder="请选择教育类型"
  18. :disabled="isNext"
  19. @change="changeEduType"
  20. >
  21. <el-option
  22. v-for="(item, index) in eduTypeOptions"
  23. :key="index"
  24. :label="item.educationName"
  25. :value="item.id"
  26. >
  27. </el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item prop="businessId">
  31. <el-select
  32. :disabled="isNext"
  33. v-model="ruleForm.businessId"
  34. placeholder="请选择业务层次"
  35. >
  36. <el-option
  37. v-for="(item, index) in newCourTypeOptions"
  38. :key="index"
  39. :label="item.projectName + '-' + item.businessName"
  40. :value="item.id"
  41. >
  42. </el-option>
  43. </el-select>
  44. </el-form-item>
  45. </div>
  46. </el-form-item>
  47. <el-form-item label="名称" prop="name">
  48. <el-input v-model.trim="ruleForm.name" style="width: 220px"></el-input>
  49. </el-form-item>
  50. <el-form-item label="商品规格" class="eee" prop="specList">
  51. <div class="spec-title">最多添加两个商品规格类型</div>
  52. <Spec-box
  53. ref="specBox"
  54. v-for="(item, index) in ruleForm.specList"
  55. :key="index"
  56. v-model="ruleForm.specList"
  57. :num="index"
  58. >
  59. </Spec-box>
  60. <el-button
  61. :disabled="ruleForm.specList.length >= 2"
  62. size="mini"
  63. style="margin: 20px"
  64. type="primary"
  65. icon="el-icon-plus"
  66. @click="addSpec"
  67. >添加规则</el-button
  68. >
  69. </el-form-item>
  70. <el-form-item label=" " style="margin-top: 40px">
  71. <el-button type="primary" @click="submitForm">下一步</el-button>
  72. </el-form-item></template
  73. >
  74. <template v-else>
  75. <el-form-item label="商品配置">
  76. <Config-table
  77. :businessId="ruleForm.businessId"
  78. :educationTypeId="ruleForm.educationTypeId"
  79. :tableData="tableData"
  80. :specList="ruleForm.specList"
  81. ></Config-table>
  82. </el-form-item>
  83. <el-form-item label=" " style="margin-top: 40px">
  84. <el-button type="primary" @click="isNext = false">上一步</el-button>
  85. <el-button type="primary" @click="back">返回</el-button>
  86. </el-form-item>
  87. </template>
  88. </el-form>
  89. </div>
  90. </template>
  91. <script>
  92. import SpecBox from "./compoent/SpecBox.vue";
  93. import ConfigTable from "./compoent/configTable.vue";
  94. import { getSpecDetail, changeSpec } from "@/api/resource/good";
  95. export default {
  96. data() {
  97. var checkList = (rule, value, callback) => {
  98. if (!this.ruleForm.specList.length) {
  99. callback(new Error("请先添加规则"));
  100. } else {
  101. callback();
  102. }
  103. };
  104. return {
  105. ruleForm: {},
  106. rules: {
  107. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  108. educationTypeId: [
  109. { required: true, message: "请选择教育类型", trigger: "change" },
  110. ],
  111. businessId: [
  112. { required: true, message: "请选择业务层次", trigger: "change" },
  113. ],
  114. specList: [{ validator: checkList }],
  115. },
  116. isNext: false,
  117. eduTypeOptions: [],
  118. newCourTypeOptions: [],
  119. tableData: [],
  120. };
  121. },
  122. methods: {
  123. changeEduType() {
  124. this.ruleForm.businessId = undefined;
  125. this.newCourTypeOptions = [];
  126. this.$api
  127. .inquirebusinessList({
  128. status: 1,
  129. educationId: this.ruleForm.educationTypeId,
  130. })
  131. .then((res) => {
  132. this.newCourTypeOptions = res.rows;
  133. });
  134. },
  135. resetFrom() {
  136. this.ruleForm = {
  137. educationTypeId: undefined,
  138. businessId: undefined,
  139. specTemplateId: "",
  140. name: "",
  141. specList: [],
  142. };
  143. this.addSpec();
  144. },
  145. addSpec() {
  146. if (this.ruleForm.specList.length == 2) {
  147. return this.$message({
  148. message: "最多添加两个商品规格",
  149. type: "warning",
  150. });
  151. }
  152. this.ruleForm.specList.push({
  153. name: "",
  154. specAttrList: [{ name: "", sort: undefined }],
  155. });
  156. },
  157. submitForm() {
  158. this.checkSpecBox() &&
  159. changeSpec(this.ruleForm).then((res) => {
  160. this.isNext = true;
  161. // this.ruleForm.specTemplateId = res.data[0].specTemplateId;
  162. this.getSpecDetail(res.data[0].specTemplateId)
  163. res.data.map((ele) => {
  164. ele.attrListVos.map((e, i) => {
  165. ele["value" + i] = e.value;
  166. });
  167. });
  168. this.tableData = res.data;
  169. });
  170. },
  171. checkSpecBox() {
  172. let boxs = [this, ...this.$refs.specBox];
  173. let result = true;
  174. for (const box of boxs) {
  175. box.$refs["ruleForm"].validate((valid) => {
  176. if (!valid) result = false;
  177. });
  178. }
  179. return result;
  180. },
  181. getSpecDetail(id) {
  182. getSpecDetail(id).then((res) => {
  183. Object.keys(this.ruleForm).map((e) => {
  184. this.ruleForm[e] = res.data[e];
  185. });
  186. });
  187. },
  188. back() {
  189. this.$router.go(-1);
  190. },
  191. },
  192. computed: {},
  193. created() {
  194. this.resetFrom();
  195. this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
  196. this.eduTypeOptions = res.rows;
  197. });
  198. },
  199. components: {
  200. SpecBox,
  201. ConfigTable,
  202. },
  203. };
  204. </script>
  205. <style lang="scss" scoped>
  206. #specAdd {
  207. padding-top: 30px;
  208. .spec-title {
  209. padding-left: 20px;
  210. height: 20px;
  211. color: #999;
  212. }
  213. .el-form {
  214. /deep/ {
  215. .eee {
  216. .el-form-item__content {
  217. margin-top: 20px;
  218. background: #eee;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. </style>