dingdan.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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" @click="handleSelectTaoCan(item)"
  28. :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>
  76. <kaiTongFongShiVue ref="kaiRef" @ykIoszhifu="ykIoszhifu" @success="handlePay"></kaiTongFongShiVue>
  77. </template>
  78. <script setup>
  79. import {
  80. reactive,
  81. ref,
  82. computed,
  83. } from "vue";
  84. import {
  85. onLoad,
  86. onShow
  87. } from "@dcloudio/uni-app"
  88. import * as shopHttp from "@/api/shop.js"
  89. import kaiTongFongShiVue from "../components/kaiTongFongShi.vue";
  90. import {
  91. getAppCp1Buy
  92. } from "@/api/shop";
  93. import {
  94. usePay
  95. } from "../usePay.js";
  96. import {
  97. getUserIsYouke
  98. } from "@/utils/common.js"
  99. import cacheManager from "@/utils/cacheManager.js";
  100. const currentPlatform = ref(null);
  101. function isIOSorAndroid() {
  102. const systemInfo = uni.getSystemInfoSync();
  103. if (systemInfo.platform == 'ios') {
  104. currentPlatform.value = 'ios'
  105. } else {
  106. currentPlatform.value = 'android'
  107. }
  108. }
  109. const data = reactive({
  110. chanpinId: null,
  111. cover: null,
  112. intro: null,
  113. name: null,
  114. taocanList: []
  115. })
  116. const activeTaocan = ref(null)
  117. const kaiRef = ref(null)
  118. const current = ref(0)
  119. const items = ref([{
  120. name: '微信',
  121. value: '0'
  122. }, {
  123. name: '支付宝',
  124. value: '1'
  125. }])
  126. const youhui = computed(() => {
  127. if (!activeTaocan.value) {
  128. return '0.00'
  129. } else {
  130. return activeTaocan.value.youhui
  131. }
  132. })
  133. const xianjia = computed(() => {
  134. if (!activeTaocan.value) {
  135. return '0.00'
  136. } else {
  137. return activeTaocan.value.xianjia
  138. }
  139. })
  140. const yuanjia = computed(() => {
  141. if (!activeTaocan.value) {
  142. return '0.00'
  143. } else {
  144. return activeTaocan.value.yuanjia
  145. }
  146. })
  147. const {
  148. OrderPay
  149. } = usePay({
  150. createOrderError: () => {}, // 创建订单失败
  151. checkError: () => {}, // 校验失败
  152. payError: () => {}, // 支付失败
  153. paySuccess: () => {
  154. // 支付成功删除contentInfo 缓存
  155. cacheManager.remove("contentInfo");
  156. // zhifu='success' 用于判断在订单页 游客模式ios支付成功情况,要去弹出弹窗
  157. uni.navigateTo({
  158. url: "/pages/chanpinMy/order?zhifu=success"
  159. })
  160. }, //支付成功
  161. applePayError: () => {}, // 苹果内购失败
  162. });
  163. onLoad(() => {
  164. isIOSorAndroid();
  165. initPage();
  166. if (currentPlatform.value == 'ios') {
  167. // ios 无微信与支付宝
  168. current.value = -1;
  169. }
  170. })
  171. function ykIoszhifu() {
  172. console.log('12311');
  173. const options = {
  174. chanpinId: data.chanpinId,
  175. taocanId: activeTaocan.value.taocanId
  176. };
  177. options.applePid = activeTaocan.value.applePid;
  178. console.log('options', options);
  179. console.log('activeTaocan.value.applePid', activeTaocan.value.applePid);
  180. OrderPay('apple', options)
  181. }
  182. function radioChange(d) {
  183. current.value = d.detail.value;
  184. }
  185. function handleSelectTaoCan(item) {
  186. activeTaocan.value = item;
  187. }
  188. function initPage() {
  189. shopHttp.getAppCp1Buy().then(res => {
  190. Object.assign(data, res.data)
  191. activeTaocan.value = res.data.taocanList[0]
  192. })
  193. }
  194. function handlePay() {
  195. if (getUserIsYouke()) {
  196. // 游客
  197. kaiRef.value.handleShow();
  198. } else {
  199. // 非游客
  200. const options = {
  201. chanpinId: data.chanpinId,
  202. taocanId: activeTaocan.value.taocanId
  203. };
  204. if (currentPlatform.value == 'ios') {
  205. options.applePid = activeTaocan.value.applePid;
  206. console.log('apple支付入参', options)
  207. // 苹果
  208. OrderPay('apple', options)
  209. } else if (currentPlatform.value != 'ios' && current.value == '0') {
  210. console.log('wx支付入参', options)
  211. // 微信
  212. OrderPay('wx', options)
  213. } else if (currentPlatform.value != 'ios' && current.value == '1') {
  214. console.log('ali支付入参', options)
  215. // 支付宝
  216. OrderPay('ali', options)
  217. }
  218. }
  219. }
  220. function handleBack() {
  221. uni.navigateBack()
  222. }
  223. </script>
  224. <style>
  225. </style>