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