index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div id="buy-course-modal">
  3. <el-dialog
  4. width="800px"
  5. class="select-class"
  6. :visible.sync="selectClassModal"
  7. >
  8. <div
  9. class="select-class__content"
  10. v-for="(it, ik) in copyDetail"
  11. :key="ik"
  12. >
  13. <h3>{{ it.name }}</h3>
  14. <div class="selection" v-if="it.specialGoods || sign">
  15. <el-select
  16. class="select"
  17. v-model="it.gradeId"
  18. placeholder="请选择班级"
  19. size="small"
  20. @click.native="selectClick(it, 'class')"
  21. >
  22. <el-option
  23. v-for="item in it.gradeList"
  24. :key="item.gradeId"
  25. :disabled="
  26. item.studentNum > 0 && item.studentNum == item.studentUpper
  27. "
  28. :label="item.className"
  29. :value="item.gradeId"
  30. >
  31. {{ item.className }}
  32. <Class-time-tip :classInfo="item"></Class-time-tip>
  33. </el-option>
  34. </el-select>
  35. </div>
  36. <div
  37. class="selection"
  38. v-if="it.templateType == 'apply' && it.goodsType == 1"
  39. >
  40. <el-select
  41. v-model="it.educationId"
  42. placeholder="请选择考期"
  43. size="small"
  44. @click.native="selectClick(it, 'exam')"
  45. >
  46. <el-option
  47. v-for="item in it.examineList"
  48. :key="item.educationId"
  49. :label="item.examineName"
  50. :value="item.educationId"
  51. >
  52. </el-option>
  53. </el-select>
  54. <el-cascader
  55. size="small"
  56. :props="props"
  57. :ref="'cascader' + ik"
  58. :options="provinceList"
  59. v-model="it.area"
  60. @change="areaChange(it, ik)"
  61. clearable
  62. placeholder="请选择报考地区"
  63. ></el-cascader>
  64. </div>
  65. </div>
  66. <div slot="footer" class="dialog-footer">
  67. <el-button type="primary" @click="pay">确 定</el-button>
  68. </div>
  69. </el-dialog>
  70. </div>
  71. </template>
  72. <script>
  73. import { mapGetters } from "vuex";
  74. import ClassTimeTip from "@/components/common/ClassTimeTip.vue";
  75. export default {
  76. name: "BuyCourseModal",
  77. computed: {
  78. ...mapGetters(["userInfo"])
  79. },
  80. data() {
  81. return {
  82. selectClassModal: false,
  83. copyDetail: [], //备份
  84. provinceList: [],
  85. gradeList: [],
  86. gradeMap: new Map(),
  87. gradeId: "",
  88. examineList: [],
  89. examArea: [],
  90. educationId: "",
  91. sign: 0, //是否继教七大员商品
  92. props: {
  93. lazy: true,
  94. lazyLoad: this.lazyLoad
  95. }
  96. };
  97. },
  98. mounted() {},
  99. methods: {
  100. showModal(item, sign) {
  101. this.selectClassModal = true;
  102. this.getProvinceList();
  103. if (Array.isArray(item)) {
  104. this.copyDetail = JSON.parse(JSON.stringify(item));
  105. } else {
  106. this.copyDetail = JSON.parse(JSON.stringify([item]));
  107. }
  108. this.sign = sign || 0;
  109. for (let i = 0; i < this.copyDetail.length; i++) {
  110. this.copyDetail[i].gradeId = "";
  111. this.copyDetail[i].gradeList = [];
  112. this.copyDetail[i].educationId = "";
  113. this.copyDetail[i].examineList = [];
  114. if (this.copyDetail[i].specialGoods || this.sign) {
  115. this.selectClick(this.copyDetail[i], "class", true);
  116. }
  117. if (
  118. this.copyDetail[i].templateType == "apply" &&
  119. this.copyDetail[i].goodsType == 1
  120. ) {
  121. this.selectClick(this.copyDetail[i], "exam", true);
  122. }
  123. }
  124. },
  125. selectClick(goodsDetail, type, status) {
  126. if (type == "class") {
  127. //选择班级
  128. if (!goodsDetail.gradeList.length) {
  129. this.$request
  130. .goodsGradeList({ goodsId: goodsDetail.goodsId })
  131. .then(res => {
  132. goodsDetail.gradeList = res.rows;
  133. if (goodsDetail.gradeList.length == 0) {
  134. let item = {
  135. className: "系统分班",
  136. gradeId: 0
  137. };
  138. goodsDetail.gradeList.push(item);
  139. } else {
  140. let isGradeFull = goodsDetail.gradeList.every(
  141. item =>
  142. item.studentNum > 0 && item.studentNum == item.studentUpper
  143. );
  144. //所有班级都满了
  145. if (isGradeFull) {
  146. let item = {
  147. className: "系统分班",
  148. gradeId: 0
  149. };
  150. goodsDetail.gradeList.unshift(item);
  151. }
  152. }
  153. if (status) {
  154. goodsDetail.gradeId = goodsDetail.gradeList[0].gradeId;
  155. }
  156. this.$forceUpdate();
  157. });
  158. }
  159. } else if (type == "apply") {
  160. //选择考试地点
  161. } else if (type == "exam") {
  162. //选择考期
  163. this.$request
  164. .getExamineList({ projectId: goodsDetail.projectId })
  165. .then(res => {
  166. goodsDetail.examineList = res.rows;
  167. if (status && res.rows.length > 0) {
  168. goodsDetail.educationId = res.rows[0].educationId;
  169. }
  170. this.$forceUpdate();
  171. });
  172. }
  173. },
  174. async pay() {
  175. try {
  176. let itCopyDetail = JSON.parse(JSON.stringify(this.copyDetail));
  177. itCopyDetail.forEach(i => {
  178. if (
  179. (i.specialGoods == 1 || this.sign) &&
  180. !i.gradeId &&
  181. i.gradeId !== 0
  182. ) {
  183. throw new Error("请选择班级");
  184. }
  185. if (i.templateType == "apply" && i.goodsType == 1 && !i.educationId) {
  186. throw new Error("请选择考期");
  187. }
  188. if (i.goodsType == 1) {
  189. if (i.specialGoods == 1 || this.sign) {
  190. let goodsInputData = {
  191. type: "class",
  192. gradeId: i.gradeId,
  193. gradeJson: JSON.stringify(
  194. i.gradeList.find(grade => grade.gradeId == i.gradeId)
  195. )
  196. };
  197. i.goodsInputData = goodsInputData;
  198. }
  199. if (i.templateType == "apply") {
  200. let goodsInputData = {
  201. type: "apply",
  202. applyAreasJson: JSON.stringify(i.applyAreas),
  203. examDateJson: JSON.stringify(
  204. i.examineList.find(exam => exam.educationId == i.educationId)
  205. )
  206. };
  207. i.goodsInputData = goodsInputData;
  208. }
  209. }
  210. });
  211. localStorage.setItem("checkGoodsList", JSON.stringify(itCopyDetail));
  212. this.$router.push({
  213. path: "/payment"
  214. });
  215. } catch (error) {
  216. this.$message({
  217. message: error,
  218. type: "warning"
  219. });
  220. }
  221. },
  222. /**
  223. * 获取所有省份
  224. */
  225. getProvinceList() {
  226. this.$request.getProvinceList().then(res => {
  227. this.provinceList = res.rows.map(item => ({
  228. value: item.areaId,
  229. label: `${item.areaName}`,
  230. leaf: false
  231. }));
  232. });
  233. },
  234. areaChange(row, index) {
  235. let node = this.$refs["cascader" + index][0].getCheckedNodes()[0]; //选中的根节点
  236. console.log(node);
  237. row.applyAreas = {
  238. areaName: node.parent.label,
  239. areaId: node.parent.value,
  240. cityId: node.value,
  241. cityName: node.label
  242. };
  243. },
  244. lazyLoad(node, resolve) {
  245. const { level } = node;
  246. if (level == 0) {
  247. // this.$request.getProvinceList().then((res) => {
  248. // const nodes = res.rows.map((item) => ({
  249. // value: item.areaId,
  250. // label: `${item.areaName}`,
  251. // leaf: level >= 1,
  252. // }));
  253. // resolve(nodes);
  254. // });
  255. } else if (level == 1) {
  256. this.$request.getCityList({ parentId: node.value }).then(res => {
  257. const nodes = res.rows.map(item => ({
  258. value: item.areaId,
  259. label: `${item.areaName}`,
  260. leaf: level >= 1
  261. }));
  262. resolve(nodes);
  263. });
  264. }
  265. }
  266. },
  267. computed: {
  268. text() {
  269. let str = "";
  270. return str;
  271. }
  272. },
  273. components: {
  274. ClassTimeTip
  275. }
  276. };
  277. </script>
  278. <!-- Add "scoped" attribute to limit CSS to this component only -->
  279. <style scoped lang="scss">
  280. .select-class {
  281. &__content {
  282. .selection {
  283. .el-select {
  284. width: 100%;
  285. }
  286. }
  287. }
  288. }
  289. </style>