index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.selectClassModal = true;
  107. this.goodsDetail = item;
  108. },
  109. selectClick(goodsDetail, type) {
  110. if (type == "class") {
  111. //选择班级
  112. if (!this.gradeList.length) {
  113. this.$request
  114. .goodsGradeList({ goodsId: goodsDetail.goodsId })
  115. .then((res) => {
  116. this.gradeList = res.rows;
  117. if (this.gradeList.length == 0) {
  118. let item = {
  119. className: "系统分班",
  120. gradeId: 0,
  121. };
  122. this.gradeList.push(item);
  123. } else {
  124. let isGradeFull = this.gradeList.every(
  125. (item) =>
  126. item.studentNum > 0 && item.studentNum == item.studentUpper
  127. );
  128. //所有班级都满了
  129. if (isGradeFull) {
  130. let item = {
  131. className: "系统分班",
  132. gradeId: 0,
  133. };
  134. this.gradeList.unshift(item);
  135. }
  136. }
  137. });
  138. }
  139. } else if (type == "apply") {
  140. //选择考试地点
  141. } else if (type == "exam") {
  142. //选择考期
  143. this.$request
  144. .getExamineList({ projectId: goodsDetail.projectId })
  145. .then((res) => {
  146. this.examineList = res.rows;
  147. });
  148. }
  149. },
  150. pay() {
  151. if (
  152. this.goodsDetail.templateType == "class" &&
  153. this.goodsDetail.goodsType == 1
  154. ) {
  155. if (!this.gradeId && this.gradeId !== 0) {
  156. this.$message({
  157. message: "请选择班级",
  158. type: "warning",
  159. });
  160. return;
  161. }
  162. }
  163. if (
  164. this.goodsDetail.templateType == "apply" &&
  165. this.goodsDetail.goodsType == 1
  166. ) {
  167. // if (!item.applyAreas.areaName) {
  168. // uni.showModal({
  169. // title: '提示',
  170. // content: '请选择报考地区',
  171. // showCancel: false
  172. // });
  173. // return false;
  174. // }
  175. if (!this.educationId) {
  176. this.$message({
  177. message: "请选择考期",
  178. type: "warning",
  179. });
  180. return false;
  181. }
  182. }
  183. let selectGoodsList = JSON.parse(JSON.stringify([this.goodsDetail]));
  184. selectGoodsList.forEach((item) => {
  185. if (item.goodsType == 1) {
  186. if (item.templateType == "class") {
  187. let goodsInputData = {
  188. type: "class",
  189. gradeId: this.gradeId,
  190. gradeJson: JSON.stringify(
  191. this.gradeList.find((grade) => grade.gradeId == this.gradeId)
  192. ),
  193. };
  194. item.goodsInputData = goodsInputData;
  195. }
  196. if (item.templateType == "apply") {
  197. let goodsInputData = {
  198. type: "apply",
  199. applyAreasJson: JSON.stringify(this.applyAreas),
  200. examDateJson: JSON.stringify(
  201. this.examineList.find(
  202. (exam) => exam.educationId == this.educationId
  203. )
  204. ),
  205. };
  206. item.goodsInputData = goodsInputData;
  207. }
  208. }
  209. });
  210. localStorage.setItem("checkGoodsList", JSON.stringify(selectGoodsList));
  211. this.$router.push({
  212. path: "/payment",
  213. });
  214. },
  215. /**
  216. * 获取所有省份
  217. */
  218. getProvinceList() {
  219. this.$request.getProvinceList().then((res) => {
  220. this.provinceList = res.rows.map((item) => ({
  221. value: item.areaId,
  222. label: `${item.areaName}`,
  223. leaf: false,
  224. }));
  225. });
  226. },
  227. areaChange() {
  228. let node = this.$refs["cascader"].getCheckedNodes()[0]; //选中的根节点
  229. console.log(node);
  230. this.applyAreas = {
  231. areaName: node.parent.label,
  232. areaId: node.parent.value,
  233. cityId: node.value,
  234. cityName: node.label,
  235. };
  236. },
  237. },
  238. };
  239. </script>
  240. <!-- Add "scoped" attribute to limit CSS to this component only -->
  241. <style scoped lang="scss">
  242. .exercises-modal {
  243. &__content {
  244. > div {
  245. font-size: 16px;
  246. line-height: 30px;
  247. text-align: center;
  248. img {
  249. display: inline;
  250. }
  251. }
  252. }
  253. }
  254. </style>