buyDialog.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.getDetail()
  74. }
  75. },
  76. },
  77. methods: {
  78. ...mapMutations(["setCurrentRouter", "getCartCount"]),
  79. cancel() {
  80. this.$emit('update:buyModal', false)
  81. },
  82. selectSku(item, index) {
  83. console.log('defhd', item, index)
  84. this.skuItem = item
  85. this.skuIndex = index
  86. },
  87. getDetail() {
  88. this.loading = true
  89. this.skuItem = {}
  90. this.skuIndex = -1
  91. this.$axios({
  92. url: '/app/common/get/goodsList',
  93. method: 'get',
  94. noToken: true,
  95. params: {
  96. subjectType: this.subjectType,
  97. topicId: this.topicId || 1,
  98. type: this.type
  99. }
  100. }).then((res) => {
  101. if (res.code == 200) {
  102. this.courseSku = res.data || []
  103. if (this.courseSku.length) {
  104. this.skuItem = this.courseSku[0]
  105. this.skuIndex = 0
  106. }
  107. } else {
  108. this.$message.warning(res.msg)
  109. }
  110. console.log('---courseSku: ', this.courseSku)
  111. this.loading = false
  112. }).catch(err => {
  113. this.loading = false
  114. })
  115. },
  116. rightNowBuy() {
  117. if (Object.keys(this.skuItem).length == 0) {
  118. this.$message.warning('请选择科目')
  119. return
  120. }
  121. console.log('this.$tools.isLogin()', this.$tools.isLogin())
  122. if (!this.$tools.isLogin()) {
  123. this.setCurrentRouter(this.$route)
  124. this.$router.push({
  125. path: "/login",
  126. })
  127. return
  128. }
  129. this.getGoodsDetail(this.skuItem.goodsId).then((res) => {
  130. console.log('res.templateType', res,res.templateType)
  131. if (res.templateType) {
  132. if (res.goodsType === 1) {
  133. this.$refs.selectClassModal.showModal(res);
  134. }
  135. if (res.goodsType === 2 || res.goodsType === 6) {
  136. let selectGoodsList = JSON.parse(JSON.stringify([res]));
  137. localStorage.setItem(
  138. "checkGoodsList",
  139. JSON.stringify(selectGoodsList)
  140. );
  141. this.$router.push({
  142. path: "/payment",
  143. });
  144. }
  145. } else {
  146. let selectGoodsList = JSON.parse(JSON.stringify([res]));
  147. localStorage.setItem(
  148. "checkGoodsList",
  149. JSON.stringify(selectGoodsList)
  150. );
  151. this.$router.push({
  152. path: "/payment",
  153. });
  154. }
  155. });
  156. },
  157. getGoodsDetail(goodsId) {
  158. return new Promise((resolve) => {
  159. this.$request.commonGoodsDetail(goodsId).then((res) => {
  160. resolve(res.data);
  161. });
  162. });
  163. },
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .contentts {
  169. width: 100%;
  170. .pop_prices {
  171. .price {
  172. font-size: 28px;
  173. font-weight: 500;
  174. color: #FC3F3F;
  175. }
  176. .lin_price {
  177. color: #999999;
  178. font-size: 18px;
  179. text-decoration:line-through;
  180. margin-left: 5px;
  181. }
  182. }
  183. .checks {
  184. font-size: 14px;
  185. color: #606266;
  186. margin: 31px 0px 16px 0px;
  187. >span {
  188. color: #409EFF;
  189. }
  190. }
  191. .check_con {
  192. display: flex;
  193. .course_items {
  194. min-width: 190px;
  195. padding: 13px 16px;
  196. border-radius: 8px;
  197. margin-right: 16px;
  198. margin-bottom: 16px;
  199. background: #F8F8F8;
  200. font-size: 14px;
  201. font-weight: 500;
  202. color: #222222;
  203. text-align: center;
  204. cursor: pointer;
  205. &.nactive {
  206. background: #D5E4FF;
  207. color: #3F8DFD;
  208. }
  209. }
  210. }
  211. .nodata {
  212. text-align: center;
  213. margin-bottom: 20px;
  214. }
  215. }
  216. </style>