index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 class="select-class__content">
  9. <div
  10. class="selection"
  11. v-if="
  12. goodsDetail.templateType == 'class' && goodsDetail.goodsType == 1
  13. "
  14. >
  15. <el-select
  16. class="select"
  17. v-model="gradeId"
  18. placeholder="请选择班级"
  19. size="small"
  20. @click.native="selectClick(goodsDetail, 'class')"
  21. >
  22. <el-option
  23. v-for="item in gradeList"
  24. :key="item.gradeId"
  25. :disabled="
  26. item.studentNum > 0 && item.studentNum == item.studentUpper
  27. "
  28. :label="
  29. item.classEndTime
  30. ? `${item.className} 有效期至:${$tools.timestampToTime(
  31. item.classEndTime
  32. )},本班还剩${$tools.GetRTime(
  33. item.classEndTime
  34. )}天将结束学习`
  35. : `${item.className}`
  36. "
  37. :value="item.gradeId"
  38. >
  39. </el-option>
  40. </el-select>
  41. </div>
  42. <div
  43. class="selection"
  44. v-if="
  45. goodsDetail.templateType == 'apply' && goodsDetail.goodsType == 1
  46. "
  47. >
  48. <el-select
  49. v-model="educationId"
  50. placeholder="请选择考期"
  51. size="small"
  52. @click.native="selectClick(goodsDetail, 'exam')"
  53. >
  54. <el-option
  55. v-for="item in examineList"
  56. :key="item.educationId"
  57. :label="item.examineName"
  58. :value="item.educationId"
  59. >
  60. </el-option>
  61. </el-select>
  62. <el-cascader
  63. size="small"
  64. :props="props"
  65. ref="cascader"
  66. :options="provinceList"
  67. v-model="examArea"
  68. @change="areaChange(goodsDetail)"
  69. clearable
  70. placeholder="请选择报考地区"
  71. ></el-cascader>
  72. </div>
  73. </div>
  74. <div slot="footer" class="dialog-footer">
  75. <el-button type="primary" @click="pay">确 定</el-button>
  76. </div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. import { mapGetters } from "vuex";
  82. export default {
  83. name: "BuyCourseModal",
  84. computed: {
  85. ...mapGetters(["userInfo"]),
  86. },
  87. data() {
  88. return {
  89. selectClassModal: false,
  90. goodsDetail: {},
  91. provinceList: [],
  92. gradeList: [],
  93. gradeId: "",
  94. examineList: [],
  95. examArea: [],
  96. educationId: "",
  97. props: {
  98. lazy: true,
  99. lazyLoad: this.lazyLoad,
  100. },
  101. };
  102. },
  103. mounted() {},
  104. methods: {
  105. showModal(item) {
  106. this.gradeId = ''
  107. this.gradeList = []
  108. this.selectClassModal = true;
  109. this.goodsDetail = item;
  110. },
  111. selectClick(goodsDetail, type) {
  112. if (type == "class") {
  113. //选择班级
  114. if (!this.gradeList.length) {
  115. this.$request
  116. .goodsGradeList({ goodsId: goodsDetail.goodsId })
  117. .then((res) => {
  118. this.gradeList = res.rows;
  119. if (this.gradeList.length == 0) {
  120. let item = {
  121. className: "系统分班",
  122. gradeId: 0,
  123. };
  124. this.gradeList.push(item);
  125. } else {
  126. let isGradeFull = this.gradeList.every(
  127. (item) =>
  128. item.studentNum > 0 && item.studentNum == item.studentUpper
  129. );
  130. //所有班级都满了
  131. if (isGradeFull) {
  132. let item = {
  133. className: "系统分班",
  134. gradeId: 0,
  135. };
  136. this.gradeList.unshift(item);
  137. }
  138. }
  139. });
  140. }
  141. } else if (type == "apply") {
  142. //选择考试地点
  143. } else if (type == "exam") {
  144. //选择考期
  145. this.$request
  146. .getExamineList({ projectId: goodsDetail.projectId })
  147. .then((res) => {
  148. this.examineList = res.rows;
  149. });
  150. }
  151. },
  152. pay() {
  153. if (
  154. this.goodsDetail.templateType == "class" &&
  155. this.goodsDetail.goodsType == 1
  156. ) {
  157. if (!this.gradeId && this.gradeId !== 0) {
  158. this.$message({
  159. message: "请选择班级",
  160. type: "warning",
  161. });
  162. return;
  163. }
  164. }
  165. if (
  166. this.goodsDetail.templateType == "apply" &&
  167. this.goodsDetail.goodsType == 1
  168. ) {
  169. // if (!item.applyAreas.areaName) {
  170. // uni.showModal({
  171. // title: '提示',
  172. // content: '请选择报考地区',
  173. // showCancel: false
  174. // });
  175. // return false;
  176. // }
  177. if (!this.educationId) {
  178. this.$message({
  179. message: "请选择考期",
  180. type: "warning",
  181. });
  182. return false;
  183. }
  184. }
  185. let selectGoodsList = JSON.parse(JSON.stringify([this.goodsDetail]));
  186. selectGoodsList.forEach((item) => {
  187. if (item.goodsType == 1) {
  188. if (item.templateType == "class") {
  189. let goodsInputData = {
  190. type: "class",
  191. gradeId: this.gradeId,
  192. gradeJson: JSON.stringify(
  193. this.gradeList.find((grade) => grade.gradeId == this.gradeId)
  194. ),
  195. };
  196. item.goodsInputData = goodsInputData;
  197. }
  198. if (item.templateType == "apply") {
  199. let goodsInputData = {
  200. type: "apply",
  201. applyAreasJson: JSON.stringify(this.applyAreas),
  202. examDateJson: JSON.stringify(
  203. this.examineList.find(
  204. (exam) => exam.educationId == this.educationId
  205. )
  206. ),
  207. };
  208. item.goodsInputData = goodsInputData;
  209. }
  210. }
  211. });
  212. localStorage.setItem("checkGoodsList", JSON.stringify(selectGoodsList));
  213. this.$router.push({
  214. path: "/payment",
  215. });
  216. },
  217. /**
  218. * 获取所有省份
  219. */
  220. getProvinceList() {
  221. this.$request.getProvinceList().then((res) => {
  222. this.provinceList = res.rows.map((item) => ({
  223. value: item.areaId,
  224. label: `${item.areaName}`,
  225. leaf: false,
  226. }));
  227. });
  228. },
  229. areaChange() {
  230. let node = this.$refs["cascader"].getCheckedNodes()[0]; //选中的根节点
  231. console.log(node);
  232. this.applyAreas = {
  233. areaName: node.parent.label,
  234. areaId: node.parent.value,
  235. cityId: node.value,
  236. cityName: node.label,
  237. };
  238. },
  239. },
  240. };
  241. </script>
  242. <!-- Add "scoped" attribute to limit CSS to this component only -->
  243. <style scoped lang="scss">
  244. .select-class {
  245. &__content {
  246. .selection {
  247. .el-select {
  248. width: 100%;
  249. }
  250. }
  251. }
  252. }
  253. </style>