buyDialog.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="buyDialog">
  3. <el-dialog
  4. :title="titles"
  5. :visible.sync="buyModal"
  6. width="452px"
  7. class="appoint-modal"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. :before-close="cancel"
  11. >
  12. <div v-loading="loading" class="contentts">
  13. <div class="pop_prices">
  14. <span v-if="skuItem.standPrice || skuItem.standPrice == 0" class="price">¥ {{ skuItem.standPrice || 0 }}</span>
  15. <span v-if="skuItem.linePrice" class="lin_price">¥ {{ skuItem.linePrice }}</span>
  16. </div>
  17. <div v-if="courseSku.length" class="checks">
  18. 请在下方
  19. <span>选择科目:</span>
  20. </div>
  21. <div v-if="courseSku.length" class="check_con">
  22. <div class="course_items" v-for="(item, index) in courseSku" :key="index" :class="{nactive: skuIndex == index}" @click="selectSku(item, index)">
  23. {{ item.goodsName }}
  24. </div>
  25. </div>
  26. <div v-else class="nodata">暂无科目选择</div>
  27. </div>
  28. <span v-if="courseSku.length" slot="footer" class="dialog-footer">
  29. <el-button type="primary" size="small" @click="rightNowBuy()">立即购买</el-button>
  30. </span>
  31. </el-dialog>
  32. <BuyCourseModal ref="selectClassModal"></BuyCourseModal>
  33. </div>
  34. </template>
  35. <script>
  36. import { mapGetters, mapMutations } from "vuex";
  37. import BuyCourseModal from "@/components/buyCourseModal/index";
  38. export default {
  39. name: 'buyDialog',
  40. components: { BuyCourseModal },
  41. props: {
  42. buyModal: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. subjectType: {
  47. type: Number,
  48. default: 1
  49. },
  50. type: { // 1黄金班,2钻石班,3至尊班
  51. type: Number,
  52. default: 1
  53. },
  54. topicId: {
  55. type: [String, Number],
  56. default: '1'
  57. }
  58. },
  59. data() {
  60. return {
  61. applyId: "",
  62. courseSku: [],
  63. skuItem: {},
  64. skuIndex: -1,
  65. loading: false,
  66. titles: '黄金班',
  67. }
  68. },
  69. watch: {
  70. buyModal(newV, oldV) {
  71. if (newV) {
  72. console.log('监听')
  73. this.titles = ['黄金班', '钻石班', '至尊班'][this.type - 1]
  74. this.getDetail()
  75. }
  76. },
  77. },
  78. methods: {
  79. ...mapMutations(["setCurrentRouter", "getCartCount"]),
  80. cancel() {
  81. this.$emit('update:buyModal', false)
  82. },
  83. selectSku(item, index) {
  84. console.log('defhd', item, index)
  85. this.skuItem = item
  86. this.skuIndex = index
  87. },
  88. getDetail() {
  89. this.loading = true
  90. this.skuItem = {}
  91. this.skuIndex = -1
  92. this.$axios({
  93. url: '/app/common/get/goodsList',
  94. method: 'get',
  95. noToken: true,
  96. params: {
  97. subjectType: this.subjectType,
  98. topicId: this.topicId || 1,
  99. type: this.type
  100. }
  101. }).then((res) => {
  102. if (res.code == 200) {
  103. this.courseSku = res.data || []
  104. } else {
  105. this.$message.warning(res.msg)
  106. }
  107. this.loading = false
  108. }).catch(err => {
  109. this.loading = false
  110. })
  111. },
  112. rightNowBuy() {
  113. if (Object.keys(this.skuItem).length == 0) {
  114. this.$message.warning('请选择科目')
  115. return
  116. }
  117. console.log('this.$tools.isLogin()', this.$tools.isLogin())
  118. if (!this.$tools.isLogin()) {
  119. this.setCurrentRouter(this.$route)
  120. this.$router.push({
  121. path: "/login",
  122. })
  123. return
  124. }
  125. this.getGoodsDetail(this.skuItem.goodsId).then((res) => {
  126. console.log('res.templateType', res,res.templateType)
  127. if (res.templateType) {
  128. if (res.goodsType === 1) {
  129. this.$refs.selectClassModal.showModal(res);
  130. }
  131. if (res.goodsType === 2 || res.goodsType === 6) {
  132. let selectGoodsList = JSON.parse(JSON.stringify([res]));
  133. localStorage.setItem(
  134. "checkGoodsList",
  135. JSON.stringify(selectGoodsList)
  136. );
  137. this.$router.push({
  138. path: "/payment",
  139. });
  140. }
  141. } else {
  142. let selectGoodsList = JSON.parse(JSON.stringify([res]));
  143. localStorage.setItem(
  144. "checkGoodsList",
  145. JSON.stringify(selectGoodsList)
  146. );
  147. this.$router.push({
  148. path: "/payment",
  149. });
  150. }
  151. });
  152. },
  153. getGoodsDetail(goodsId) {
  154. return new Promise((resolve) => {
  155. this.$request.commonGoodsDetail(goodsId).then((res) => {
  156. resolve(res.data);
  157. });
  158. });
  159. },
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .contentts {
  165. width: 100%;
  166. .pop_prices {
  167. .price {
  168. font-size: 28px;
  169. font-weight: 500;
  170. color: #FC3F3F;
  171. }
  172. .lin_price {
  173. color: #999999;
  174. font-size: 24px;
  175. text-decoration:line-through;
  176. margin-left: 5px;
  177. }
  178. }
  179. .checks {
  180. font-size: 14px;
  181. color: #606266;
  182. margin: 31px 0px 16px 0px;
  183. >span {
  184. color: #409EFF;
  185. }
  186. }
  187. .check_con {
  188. display: flex;
  189. .course_items {
  190. min-width: 190px;
  191. padding: 13px 16px;
  192. border-radius: 8px;
  193. margin-right: 16px;
  194. margin-bottom: 16px;
  195. background: #F8F8F8;
  196. font-size: 14px;
  197. font-weight: 500;
  198. color: #222222;
  199. text-align: center;
  200. cursor: pointer;
  201. &.nactive {
  202. background: #D5E4FF;
  203. color: #3F8DFD;
  204. }
  205. }
  206. }
  207. .nodata {
  208. text-align: center;
  209. margin-bottom: 20px;
  210. }
  211. }
  212. </style>