dingdan.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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" @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. const currentPlatform = ref(null);
  77. function isIOSorAndroid() {
  78. const systemInfo = uni.getSystemInfoSync();
  79. if (systemInfo.platform == 'ios') {
  80. currentPlatform.value = 'ios'
  81. } else {
  82. currentPlatform.value = 'android'
  83. }
  84. }
  85. const data = reactive({
  86. chanpinId: null,
  87. cover: null,
  88. intro: null,
  89. name: null,
  90. taocanList: []
  91. })
  92. const activeTaocan = ref(null)
  93. const kaiRef = ref(null)
  94. const current = ref(0)
  95. const items = ref([{
  96. name: '微信',
  97. value: '0'
  98. }, {
  99. name: '支付宝',
  100. value: '1'
  101. }])
  102. const youhui = computed(() => {
  103. if (!activeTaocan.value) {
  104. return '0.00'
  105. } else {
  106. return activeTaocan.value.youhui
  107. }
  108. })
  109. const xianjia = computed(() => {
  110. if (!activeTaocan.value) {
  111. return '0.00'
  112. } else {
  113. return activeTaocan.value.xianjia
  114. }
  115. })
  116. const yuanjia = computed(() => {
  117. if (!activeTaocan.value) {
  118. return '0.00'
  119. } else {
  120. return activeTaocan.value.yuanjia
  121. }
  122. })
  123. const {
  124. OrderPay
  125. } = usePay({
  126. createOrderError: () => {}, // 创建订单失败
  127. checkError: () => {}, // 校验失败
  128. payError: () => {}, // 支付失败
  129. paySuccess: () => {
  130. uni.navigateTo({
  131. url: "/pages/chanpinMy/order"
  132. })
  133. }, //支付成功
  134. applePayError: () => {}, // 苹果内购失败
  135. });
  136. onLoad(() => {
  137. isIOSorAndroid();
  138. initPage();
  139. if (currentPlatform.value == 'ios') {
  140. // ios 无微信与支付宝
  141. current.value = -1;
  142. }
  143. })
  144. function radioChange(d) {
  145. current.value = d.detail.value;
  146. }
  147. function handleSelectTaoCan(item) {
  148. activeTaocan.value = item;
  149. }
  150. function initPage() {
  151. shopHttp.getAppCp1Buy().then(res => {
  152. Object.assign(data, res.data)
  153. activeTaocan.value = res.data.taocanList[0]
  154. })
  155. }
  156. function handlePay() {
  157. if (getUserIsYouke()) {
  158. // 游客
  159. kaiRef.value.handleShow();
  160. } else {
  161. // 非游客
  162. const options = {
  163. chanpinId: data.chanpinId,
  164. taocanId: activeTaocan.value.taocanId
  165. };
  166. if (currentPlatform.value == 'ios') {
  167. options.applePid = activeTaocan.value.applePid;
  168. console.log('apple支付入参', options)
  169. // 苹果
  170. OrderPay('apple', options)
  171. } else if (currentPlatform.value != 'ios' && current.value == '0') {
  172. console.log('wx支付入参', options)
  173. // 微信
  174. OrderPay('wx', options)
  175. } else if (currentPlatform.value != 'ios' && current.value == '1') {
  176. console.log('ali支付入参', options)
  177. // 支付宝
  178. OrderPay('ali', options)
  179. }
  180. }
  181. }
  182. function handleBack() {
  183. uni.navigateBack()
  184. }
  185. </script>
  186. <style>
  187. </style>