dingdan.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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" style="transform:scale(0.7)" />
  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. usePay
  93. } from "../usePay.js";
  94. import {
  95. getUserIsYouke
  96. } from "@/utils/common.js"
  97. import cacheManager from "@/utils/cacheManager.js";
  98. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  99. const currentPlatform = ref(null);
  100. function isIOSorAndroid() {
  101. const systemInfo = uni.getSystemInfoSync();
  102. if (systemInfo.platform == 'ios') {
  103. currentPlatform.value = 'ios'
  104. } else {
  105. currentPlatform.value = 'android'
  106. }
  107. }
  108. const data = reactive({
  109. chanpinId: null,
  110. cover: null,
  111. intro: null,
  112. name: null,
  113. taocanList: []
  114. })
  115. const activeTaocan = ref(null)
  116. const kaiRef = ref(null)
  117. const current = ref(0)
  118. const items = ref([{
  119. name: '微信',
  120. value: '0'
  121. }, {
  122. name: '支付宝',
  123. value: '1'
  124. }])
  125. const youhui = computed(() => {
  126. if (!activeTaocan.value) {
  127. return '0.00'
  128. } else {
  129. return activeTaocan.value.youhui
  130. }
  131. })
  132. const xianjia = computed(() => {
  133. if (!activeTaocan.value) {
  134. return '0.00'
  135. } else {
  136. return activeTaocan.value.xianjia
  137. }
  138. })
  139. const yuanjia = computed(() => {
  140. if (!activeTaocan.value) {
  141. return '0.00'
  142. } else {
  143. return activeTaocan.value.yuanjia
  144. }
  145. })
  146. const {
  147. OrderPay
  148. } = usePay({
  149. createOrderError: () => {}, // 创建订单失败
  150. checkError: () => {}, // 校验失败
  151. payError: () => {}, // 支付失败
  152. paySuccess: () => {
  153. // 支付成功删除contentInfo 缓存
  154. cacheManager.remove("contentInfo");
  155. // zhifu='success' 用于判断在订单页 游客模式ios支付成功情况,要去弹出弹窗
  156. uni.navigateTo({
  157. url: "/pages/chanpinMy/order?zhifu=success"
  158. })
  159. // uni.showLoading({
  160. // title: '跳转中...',
  161. // mask: true
  162. // });
  163. // uni.switchTab({
  164. // url: "/pages/chanpinMy/my" // 你的F页面实际路径(不变)
  165. // });
  166. // setTimeout(() => {
  167. // uni.navigateTo({
  168. // url: "/pages/chanpinMy/order?zhifu=success", // 你的D页面路径+保留zhifu=success传参
  169. // success: () => {
  170. // uni.hideLoading();
  171. // },
  172. // fail: () => {
  173. // uni.hideLoading();
  174. // toast("跳转失败,请重试");
  175. // }
  176. // });
  177. // }, 300);
  178. }, //支付成功
  179. applePayError: () => {}, // 苹果内购失败
  180. });
  181. onLoad(() => {
  182. isIOSorAndroid();
  183. initPage();
  184. if (currentPlatform.value == 'ios') {
  185. // ios 无微信与支付宝
  186. current.value = -1;
  187. }
  188. })
  189. function ykIoszhifu() {
  190. console.log('12311');
  191. const options = {
  192. chanpinId: data.chanpinId,
  193. taocanId: activeTaocan.value.taocanId
  194. };
  195. options.applePid = activeTaocan.value.applePid;
  196. console.log('options', options);
  197. console.log('activeTaocan.value.applePid', activeTaocan.value.applePid);
  198. OrderPay('apple', options)
  199. }
  200. function radioChange(d) {
  201. current.value = d.detail.value;
  202. }
  203. function handleSelectTaoCan(item) {
  204. activeTaocan.value = item;
  205. }
  206. function initPage() {
  207. shopHttp.getAppCp3Buy().then(res => {
  208. Object.assign(data, res.data)
  209. activeTaocan.value = res.data.taocanList[0]
  210. })
  211. }
  212. function handlePay() {
  213. if (getUserIsYouke()) {
  214. // 游客
  215. kaiRef.value.handleShow();
  216. } else {
  217. // 非游客
  218. const options = {
  219. chanpinId: data.chanpinId,
  220. taocanId: activeTaocan.value.taocanId
  221. };
  222. if (currentPlatform.value == 'ios') {
  223. options.applePid = activeTaocan.value.applePid;
  224. console.log('apple支付入参', options)
  225. // 苹果
  226. OrderPay('apple', options)
  227. } else if (currentPlatform.value != 'ios' && current.value == '0') {
  228. console.log('wx支付入参', options)
  229. // 微信
  230. OrderPay('wx', options)
  231. } else if (currentPlatform.value != 'ios' && current.value == '1') {
  232. console.log('ali支付入参', options)
  233. // 支付宝
  234. OrderPay('ali', options)
  235. }
  236. }
  237. }
  238. function handleBack() {
  239. uni.navigateBack()
  240. }
  241. </script>
  242. <style>
  243. </style>