dingdan.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="ezy-qrdd-page">
  3. <view class="icon-title-navBar-box">
  4. <view class="nav-bar-icon" @click="handleBack"></view>
  5. <text class="nav-bar-title">确认订单</text>
  6. </view>
  7. <view class="qrdd-body-box">
  8. <!-- 卡片 -->
  9. <view class="dd-item-box">
  10. <!-- 封面 -->
  11. <image class="item-img-box" :src="data.cover" mode=""></image>
  12. <view class="item-content-box">
  13. <!-- 名称 -->
  14. <view class="item-name">{{data.name}}</view>
  15. <!-- 简介 -->
  16. <view class="item-intro">{{data.intro}}</view>
  17. <!-- 价格 -->
  18. <view class="item-xianjia">¥{{xianjia}}</view>
  19. </view>
  20. <view class="item-play-btn"></view>
  21. </view>
  22. <!-- 等级 -->
  23. <view class="qrdd-border-box">
  24. <view class="kcxxdj-title">课程学习等级</view>
  25. <view class="kcxxdj-tc-box">
  26. <!-- 套餐 -->
  27. <ezyActiveVue class="ezy-btn-active tc-item" v-for="item in data.taocanList"
  28. @click="handleSelectTaoCan(item)" :class="{active: item.taocanId == activeTaocan.taocanId}">
  29. {{item.name}}
  30. </ezyActiveVue>
  31. </view>
  32. </view>
  33. <!-- 商品总价 -->
  34. <view class="qrdd-border-box">
  35. <view class="border-row">
  36. <view>商品总价</view>
  37. <view>¥{{yuanjia}}</view>
  38. </view>
  39. <view class="border-row">
  40. <view>优惠券</view>
  41. <view class="jg-text">-¥{{youhui}}</view>
  42. </view>
  43. <view class="border-row sum-row">
  44. <view class="sum-text">合计</view>
  45. <view class="jg-text">¥{{xianjia}}</view>
  46. </view>
  47. </view>
  48. <!-- 支付模式 -->
  49. <template v-if="currentPlatform != 'ios'">
  50. <radio-group @change="radioChange" class="qrdd-border-box">
  51. <label class="border-row" v-for="(item, index) in items" :key="item.value">
  52. <view class="zzfs-name-box">
  53. <icon :class="{
  54. 'wechat-icon': item.name === '微信',
  55. 'alipay-icon': item.name === '支付宝'
  56. }"></icon>
  57. <text>{{item.name}}</text>
  58. </view>
  59. <radio :value="item.value" :checked="index === current" class="qrdd-radio-item"/>
  60. </label>
  61. </radio-group>
  62. </template>
  63. </view>
  64. <!-- 支付区 -->
  65. <view class="qrdd-footer-box">
  66. <view class="jg-box">
  67. <view class="sum-row">
  68. <text class="sum-text">合计:</text>
  69. <text class="xj-text-text">¥{{xianjia}}</text>
  70. </view>
  71. <view class="yh-text">共优惠¥{{youhui}}</view>
  72. </view>
  73. <view @click="handlePay" class="ljzf-btn">立即支付</view>
  74. </view>
  75. <!-- <view class="shop-mask">遮盖层</view> -->
  76. </view>
  77. <kaiTongFongShiVue ref="kaiRef" @ykIoszhifu="ykIoszhifu" @success="handlePay"></kaiTongFongShiVue>
  78. </template>
  79. <script setup>
  80. import {
  81. reactive,
  82. ref,
  83. computed,
  84. } from "vue";
  85. import {
  86. onLoad,
  87. onShow
  88. } from "@dcloudio/uni-app"
  89. import * as shopHttp from "@/api/shop.js"
  90. import kaiTongFongShiVue from "../components/kaiTongFongShi.vue";
  91. import {
  92. getAppCp1Buy
  93. } from "@/api/shop";
  94. import {
  95. usePay
  96. } from "../usePay.js";
  97. import {
  98. getUserIsYouke
  99. } from "@/utils/common.js"
  100. import cacheManager from "@/utils/cacheManager.js";
  101. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  102. const currentPlatform = ref(null);
  103. function isIOSorAndroid() {
  104. const systemInfo = uni.getSystemInfoSync();
  105. if (systemInfo.platform == 'ios') {
  106. currentPlatform.value = 'ios'
  107. } else {
  108. currentPlatform.value = 'android'
  109. }
  110. }
  111. const data = reactive({
  112. chanpinId: null,
  113. cover: null,
  114. intro: null,
  115. name: null,
  116. taocanList: []
  117. })
  118. const activeTaocan = ref(null)
  119. const kaiRef = ref(null)
  120. const current = ref(0)
  121. const items = ref([{
  122. name: '微信',
  123. value: '0'
  124. }, {
  125. name: '支付宝',
  126. value: '1'
  127. }])
  128. const youhui = computed(() => {
  129. if (!activeTaocan.value) {
  130. return '0.00'
  131. } else {
  132. return activeTaocan.value.youhui
  133. }
  134. })
  135. const xianjia = computed(() => {
  136. if (!activeTaocan.value) {
  137. return '0.00'
  138. } else {
  139. return activeTaocan.value.xianjia
  140. }
  141. })
  142. const yuanjia = computed(() => {
  143. if (!activeTaocan.value) {
  144. return '0.00'
  145. } else {
  146. return activeTaocan.value.yuanjia
  147. }
  148. })
  149. const {
  150. OrderPay
  151. } = usePay({
  152. createOrderError: () => {}, // 创建订单失败
  153. checkError: () => {}, // 校验失败
  154. payError: () => {}, // 支付失败
  155. paySuccess: () => {
  156. // 支付成功删除contentInfo 缓存
  157. cacheManager.remove("contentInfo");
  158. // zhifu='success' 用于判断在订单页 游客模式ios支付成功情况,要去弹出弹窗
  159. uni.navigateTo({
  160. url: "/pages/chanpinMy/order?zhifu=success"
  161. })
  162. // uni.showLoading({
  163. // title: '跳转中...',
  164. // mask: true
  165. // });
  166. // uni.switchTab({
  167. // url: "/pages/chanpinMy/my" // 你的F页面实际路径(不变)
  168. // });
  169. // setTimeout(() => {
  170. // uni.navigateTo({
  171. // url: "/pages/chanpinMy/order?zhifu=success", // 你的D页面路径+保留zhifu=success传参
  172. // success: () => {
  173. // uni.hideLoading();
  174. // },
  175. // fail: () => {
  176. // uni.hideLoading();
  177. // toast("跳转失败,请重试");
  178. // }
  179. // });
  180. // }, 300);
  181. }, //支付成功
  182. applePayError: () => {}, // 苹果内购失败
  183. });
  184. onLoad(() => {
  185. isIOSorAndroid();
  186. initPage();
  187. if (currentPlatform.value == 'ios') {
  188. // ios 无微信与支付宝
  189. current.value = -1;
  190. }
  191. })
  192. function ykIoszhifu() {
  193. console.log('12311');
  194. const options = {
  195. chanpinId: data.chanpinId,
  196. taocanId: activeTaocan.value.taocanId
  197. };
  198. options.applePid = activeTaocan.value.applePid;
  199. console.log('options', options);
  200. console.log('activeTaocan.value.applePid', activeTaocan.value.applePid);
  201. OrderPay('apple', options)
  202. }
  203. function radioChange(d) {
  204. current.value = d.detail.value;
  205. }
  206. function handleSelectTaoCan(item) {
  207. activeTaocan.value = item;
  208. }
  209. function initPage() {
  210. shopHttp.getAppCp1Buy().then(res => {
  211. Object.assign(data, res.data)
  212. activeTaocan.value = res.data.taocanList[0]
  213. })
  214. }
  215. function handlePay() {
  216. if (getUserIsYouke()) {
  217. // 游客
  218. kaiRef.value.handleShow();
  219. } else {
  220. // 非游客
  221. const options = {
  222. chanpinId: data.chanpinId,
  223. taocanId: activeTaocan.value.taocanId
  224. };
  225. if (currentPlatform.value == 'ios') {
  226. options.applePid = activeTaocan.value.applePid;
  227. console.log('apple支付入参', options)
  228. // 苹果
  229. OrderPay('apple', options)
  230. } else if (currentPlatform.value != 'ios' && current.value == '0') {
  231. console.log('wx支付入参', options)
  232. // 微信
  233. OrderPay('wx', options)
  234. } else if (currentPlatform.value != 'ios' && current.value == '1') {
  235. console.log('ali支付入参', options)
  236. // 支付宝
  237. OrderPay('ali', options)
  238. }
  239. }
  240. }
  241. function handleBack() {
  242. uni.navigateBack()
  243. }
  244. </script>
  245. <style>
  246. </style>