index.vue 6.8 KB

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