dingdan.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view>
  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. <!-- 卡片 -->
  8. <view>
  9. <view>
  10. <image :src="data.cover"></image>
  11. </view>
  12. <view>名称:{{data.name}}</view>
  13. <view>简介:{{data.intro}}</view>
  14. <view>价格:{{xianjia}}</view>
  15. </view>
  16. <!-- 等级 -->
  17. <view>
  18. <view>课程学习等级</view>
  19. <view>
  20. <!-- 套餐 -->
  21. <view v-for="item in data.taocanList" @click="handleSelectTaoCan(item)"
  22. :class="{active: item.taocanId == activeTaocan.taocanId}">
  23. {{item.name}}
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 商品总价 -->
  28. <view>
  29. <view>商品总价 ¥{{yuanjia}}</view>
  30. <view>优惠券 -¥{{youhui}}</view>
  31. <view>合计 ¥{{xianjia}}</view>
  32. </view>
  33. <!-- 支付模式 -->
  34. <template v-if="currentPlatform != 'ios'">
  35. <radio-group @change="radioChange">
  36. <label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
  37. <view>
  38. <radio :value="item.value" :checked="index === current" />
  39. </view>
  40. <view>{{item.name}}</view>
  41. </label>
  42. </radio-group>
  43. </template>
  44. <!-- 支付区 -->
  45. <view>
  46. <view>
  47. <view>合计:¥{{xianjia}}</view>
  48. <view>共优惠¥{{youhui}}</view>
  49. </view>
  50. <view @click="handlePay">立即支付</view>
  51. </view>
  52. </view>
  53. <kaiTongFongShiVue ref="kaiRef" @ykIoszhifu="ykIoszhifu" @success="handlePay"></kaiTongFongShiVue>
  54. </template>
  55. <script setup>
  56. import {
  57. reactive,
  58. ref,
  59. computed,
  60. } from "vue";
  61. import {
  62. onLoad,
  63. onShow
  64. } from "@dcloudio/uni-app"
  65. import * as shopHttp from "@/api/shop.js"
  66. import kaiTongFongShiVue from "../components/kaiTongFongShi.vue";
  67. import {
  68. getAppCp1Buy
  69. } from "@/api/shop";
  70. import {
  71. usePay
  72. } from "../usePay.js";
  73. import {
  74. getUserIsYouke
  75. } from "@/utils/common.js"
  76. import cacheManager from "@/utils/cacheManager.js";
  77. const currentPlatform = ref(null);
  78. function isIOSorAndroid() {
  79. const systemInfo = uni.getSystemInfoSync();
  80. if (systemInfo.platform == 'ios') {
  81. currentPlatform.value = 'ios'
  82. } else {
  83. currentPlatform.value = 'android'
  84. }
  85. }
  86. const data = reactive({
  87. chanpinId: null,
  88. cover: null,
  89. intro: null,
  90. name: null,
  91. taocanList: []
  92. })
  93. const activeTaocan = ref(null)
  94. const kaiRef = ref(null)
  95. const current = ref(0)
  96. const items = ref([{
  97. name: '微信',
  98. value: '0'
  99. }, {
  100. name: '支付宝',
  101. value: '1'
  102. }])
  103. const youhui = computed(() => {
  104. if (!activeTaocan.value) {
  105. return '0.00'
  106. } else {
  107. return activeTaocan.value.youhui
  108. }
  109. })
  110. const xianjia = computed(() => {
  111. if (!activeTaocan.value) {
  112. return '0.00'
  113. } else {
  114. return activeTaocan.value.xianjia
  115. }
  116. })
  117. const yuanjia = computed(() => {
  118. if (!activeTaocan.value) {
  119. return '0.00'
  120. } else {
  121. return activeTaocan.value.yuanjia
  122. }
  123. })
  124. const {
  125. OrderPay
  126. } = usePay({
  127. createOrderError: () => {}, // 创建订单失败
  128. checkError: () => {}, // 校验失败
  129. payError: () => {}, // 支付失败
  130. paySuccess: () => {
  131. // 支付成功删除contentInfo 缓存
  132. cacheManager.remove("contentInfo");
  133. // zhifu='success' 用于判断在订单页 游客模式ios支付成功情况,要去弹出弹窗
  134. uni.navigateTo({
  135. url: "/pages/chanpinMy/order?zhifu=success"
  136. })
  137. }, //支付成功
  138. applePayError: () => {}, // 苹果内购失败
  139. });
  140. onLoad(() => {
  141. isIOSorAndroid();
  142. initPage();
  143. if (currentPlatform.value == 'ios') {
  144. // ios 无微信与支付宝
  145. current.value = -1;
  146. }
  147. })
  148. function ykIoszhifu() {
  149. console.log('12311');
  150. const options = {
  151. chanpinId: data.chanpinId,
  152. taocanId: activeTaocan.value.taocanId
  153. };
  154. options.applePid = activeTaocan.value.applePid;
  155. console.log('options', options);
  156. console.log('activeTaocan.value.applePid', activeTaocan.value.applePid);
  157. OrderPay('apple', options)
  158. }
  159. function radioChange(d) {
  160. current.value = d.detail.value;
  161. }
  162. function handleSelectTaoCan(item) {
  163. activeTaocan.value = item;
  164. }
  165. function initPage() {
  166. shopHttp.getAppCp1Buy().then(res => {
  167. Object.assign(data, res.data)
  168. activeTaocan.value = res.data.taocanList[0]
  169. })
  170. }
  171. function handlePay() {
  172. if (getUserIsYouke()) {
  173. // 游客
  174. kaiRef.value.handleShow();
  175. } else {
  176. // 非游客
  177. const options = {
  178. chanpinId: data.chanpinId,
  179. taocanId: activeTaocan.value.taocanId
  180. };
  181. if (currentPlatform.value == 'ios') {
  182. options.applePid = activeTaocan.value.applePid;
  183. console.log('apple支付入参', options)
  184. // 苹果
  185. OrderPay('apple', options)
  186. } else if (currentPlatform.value != 'ios' && current.value == '0') {
  187. console.log('wx支付入参', options)
  188. // 微信
  189. OrderPay('wx', options)
  190. } else if (currentPlatform.value != 'ios' && current.value == '1') {
  191. console.log('ali支付入参', options)
  192. // 支付宝
  193. OrderPay('ali', options)
  194. }
  195. }
  196. }
  197. function handleBack() {
  198. uni.navigateBack()
  199. }
  200. </script>
  201. <style>
  202. </style>