mallPage.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="ezy-mall-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">鹅状元进阶营</text>
  6. </view>
  7. <view class="ezy-tab-border">
  8. <uni-segmented-control :current="productData.current" :values="productData.items" active-color="#3A7FE9"
  9. @clickItem="onChangeTab" class="ezy-tab-box" />
  10. <view>
  11. <view v-if="productData.current === 0">
  12. <scroll-view scroll-y="true" :scroll-into-view="scrollIntoId" class="order-scroll-view">
  13. <!--数学-->
  14. <view :id="'item-' + item.id" v-for="item in productData.list" :key="`${item.id}-${isItemSelected(item.id)}`" class="mall-list-item">
  15. <view class="mall-content-box">
  16. <!-- 需要换成从接口中取得 wgy -->
  17. <img :src='item.cover' class="mall-image" />
  18. <view class="content-body-box">
  19. <view class="content-name">
  20. <view class="name-text">{{item.name}}</view>
  21. </view>
  22. <view class="content-text">{{item.intro}}</view>
  23. <view class="content-row">
  24. <view class="content-yuanjia">原价:{{item.yuanjia}}</view>
  25. <view class="shop-car-box" @click="addProduct(item.id)">
  26. <!-- 购物车上的对号需控制 wgy-->
  27. <icon v-if="isItemSelected(item.id)" class="car-change"></icon>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="mall-bottom-row">
  33. <!-- 组合课程显示课程包明细按钮 wgy -->
  34. <view v-if="item.type ==1" class="kcb-btn" @click="productBtn">课程包明细<icon>
  35. </icon>
  36. </view>
  37. <view class="hdj-text">活动价:{{item.xianjia}}</view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </view>
  42. <view v-if="productData.current === 1">
  43. <view>英语</view>
  44. </view>
  45. <!-- <view v-if="productData.current === 2">
  46. <view>语文</view>
  47. </view> -->
  48. </view>
  49. </view>
  50. <view class="footer-mall-pay-box">
  51. <view class="mall-left-box" @click="detailBtn">
  52. <!-- 需要换成从接口中取得 wgy -->
  53. <view class="price-icon-box">
  54. <text class="red-price fh-text">¥</text>
  55. <text class="red-price">1999.8</text>明细
  56. <icon :class="mxjtClass"></icon>
  57. </view>
  58. <view>购买即同意虚拟产品不支持退订</view>
  59. </view>
  60. <!-- 微信 -->
  61. <view class="pay-status-box" v-if="showPayWay" @click="switchPayWay">
  62. <icon class="wx-icon"></icon>微信
  63. </view>
  64. <!-- 支付宝 -->
  65. <view class="pay-status-box" v-if="!showPayWay" @click="switchPayWay">
  66. <icon class="zfb-icon"></icon>支付宝
  67. </view>
  68. <!-- 苹果 -->
  69. <view class="pay-status-box apple-status-box" v-if="false">
  70. <icon class="apple-icon"></icon>apple
  71. </view>
  72. <view class="pay-btn">立即支付</view>
  73. </view>
  74. <detail-dialog ref="mallDetailPopup" @payBtn="payBtn"></detail-dialog>
  75. <product-dialog ref="mallProductPopup" @payBtn="payBtn"></product-dialog>
  76. </view>
  77. </template>
  78. <script setup>
  79. import {
  80. reactive,
  81. nextTick,
  82. ref
  83. } from "vue";
  84. import {
  85. getMallist
  86. } from "@/api/productMall.js";
  87. import {
  88. onLoad
  89. } from "@dcloudio/uni-app";
  90. import {
  91. toast,
  92. getUserIdentity
  93. } from "@/utils/common";
  94. import cacheManager from '@/utils/cacheManager.js';
  95. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  96. import detailDialog from './detailDialog.vue'
  97. import productDialog from './productDialog.vue'
  98. const showPayWay = ref(true)
  99. const showDetail = ref(false)
  100. const mxjtClass = ref('mxjt-sq-icon')
  101. const mallDetailPopup = ref(null);
  102. const mallProductPopup = ref(null);
  103. let scrollIntoId = ref(null)
  104. const productData = reactive({
  105. items: ['数学', '英语'],
  106. current: 1,
  107. from: '',
  108. cardId: '',
  109. list: [],
  110. selectedIds: [] // 新增选中状态存储
  111. })
  112. function switchPayWay() {
  113. showPayWay.value = !showPayWay.value
  114. }
  115. function productBtn() {
  116. mallProductPopup.value.detailShow();
  117. }
  118. function detailBtn() {
  119. showDetail.value = !showDetail.value;
  120. if (showDetail.value) {
  121. mxjtClass.value = 'mxjt-zk-icon';
  122. mallDetailPopup.value.detailShow();
  123. } else {
  124. mxjtClass.value = 'mxjt-sq-icon';
  125. mallDetailPopup.value.detailCloseBtn();
  126. }
  127. }
  128. function handlePay(item) {
  129. uni.redirectTo({
  130. url: `/pages/pay/svip?cardId=${item.cardId}&formPage=my&orderId=${item.id}`
  131. })
  132. }
  133. function onChangeTab(e) {
  134. console.log('e', e);
  135. productData.current = e.currentIndex
  136. getMore()
  137. }
  138. function getMore() {
  139. const opt = {
  140. subjectId: productData.current + 1
  141. }
  142. getMallist(opt).then(res => {
  143. if (res.code == 0) {
  144. productData.list = res.data
  145. // 初始化选中状态(当有外部cardId时)
  146. if (productData.cardId) {
  147. const exist = res.data.some(item => item.id == productData.cardId)
  148. if (exist) {
  149. productData.selectedIds = [productData.cardId]
  150. }
  151. }
  152. nextTick(() => {
  153. scrollToIdFun(productData.cardId)
  154. })
  155. }
  156. }).catch(err => {
  157. toast("获取产品数据失败")
  158. return false
  159. })
  160. }
  161. function scrollToIdFun(targetId) {
  162. const index = productData.list.findIndex(item => item.id == targetId)
  163. console.log('index', index);
  164. if (index > -1) {
  165. // 安卓设备需要双保险
  166. scrollIntoId.value = `item-${targetId}`
  167. setTimeout(() => {
  168. scrollIntoId.value = `item-${targetId}`
  169. }, 300)
  170. }
  171. }
  172. function addProduct(id) {
  173. // 当存在外部cardId时禁止操作
  174. // if (productData.cardId) return
  175. // const index = productData.selectedIds.indexOf(id)
  176. // if (index > -1) {
  177. // productData.selectedIds.splice(index, 1)
  178. // } else {
  179. // productData.selectedIds.push(id)
  180. // }
  181. const temp = [...productData.selectedIds]
  182. const index = temp.indexOf(id)
  183. index > -1 ? temp.splice(index, 1) : temp.push(id)
  184. productData.selectedIds = temp
  185. }
  186. function isItemSelected(id) {
  187. return productData.cardId ?
  188. id == productData.cardId // 有外部cardId时严格匹配
  189. :
  190. productData.selectedIds.includes(id) // 无cardId时检查选中列表
  191. }
  192. function goBack() {
  193. if (productData.from == 'daoPage') {
  194. uni.redirectTo({
  195. url: '/pages/study/index'
  196. })
  197. } else {
  198. uni.redirectTo({
  199. url: '/pages/my/index'
  200. })
  201. }
  202. }
  203. onLoad((options) => {
  204. productData.current = Number(options.subjectId) - 1
  205. productData.cardId = options.cardId
  206. productData.from = options.from
  207. getMore();
  208. })
  209. </script>
  210. <style>
  211. </style>