index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="">
  3. <view
  4. style="height: 155rpx;padding:0 30rpx;background: #FFFFFF;display: flex;align-items: center;justify-content: space-between;">
  5. <view style="display: flex;align-items: center;">
  6. <image src="/static/images/shoppingCart/1061@2x.png"
  7. style="width: 25rpx;height: 30rpx;margin-right: 2rpx;" mode="scaleToFill">
  8. </image>
  9. <view style="margin-left: 10rpx;">
  10. <view style="font-size: 32rpx;">
  11. <text>市南区旺角大厦12楼</text>
  12. </view>
  13. <view
  14. style="font-size: 28rpx;color: #3B3B3B;font-weight: 400;display: flex;align-items: center;margin-top: 10rpx;">
  15. <text>李某某</text>
  16. <text style="margin-left: 35rpx;">131****0000</text>
  17. </view>
  18. </view>
  19. </view>
  20. <uni-icons type="forward" size="14" color="#c5c5c5"></uni-icons>
  21. </view>
  22. <uni-card style="margin: 30rpx 0;border-radius: 20rpx;">
  23. <view v-for="(item,index) in dataList" :key="index">
  24. <view style="display: flex;margin: 20rpx 0;">
  25. <view class="">
  26. <image :src="item.url"
  27. style="width: 140rpx;height: 140rpx;background-color: #e9e9eb;border-radius: 8rpx;"
  28. mode="scaleToFill">
  29. </image>
  30. </view>
  31. <view
  32. style="display: flex;flex-direction: column;justify-content: space-between;width: 100%;padding-left: 20rpx;">
  33. <text style="font-size: 30rpx;color: #000;">{{item.goodsName}}</text>
  34. <view style="display: flex;justify-content: space-between;">
  35. <view class="">
  36. <text style="color:#e43d33;font-size: 20rpx;">¥</text><text
  37. style="color:#e43d33;font-size: 30rpx;font-weight: 600;">{{item.price}}</text>
  38. </view>
  39. <text style="font-size: 30rpx;font-weight: 600;">x{{item.number}}</text>
  40. </view>
  41. </view>
  42. </view>
  43. <view v-if="dataList[index+1]" style="background-color:#e5e5e5;height:1rpx;"></view>
  44. </view>
  45. </uni-card>
  46. <uni-card style="margin: 30rpx 0;border-radius: 20rpx;">
  47. <view style="display: flex;justify-content: space-between;">
  48. <view style="color: #000;font-size: 28rpx;">
  49. 商品金额
  50. </view>
  51. <view style="color: #000;font-size: 28rpx;margin-right: 28rpx;font-weight: 600;">
  52. ¥300.00
  53. </view>
  54. </view>
  55. <view style="display: flex;justify-content: space-between;margin-top: 30rpx;">
  56. <view style="display: flex;align-items: center;">
  57. <image style="height:40rpx;width: 40rpx;" src="/static/images/pay/coupon.png" mode="scaleToFill">
  58. </image>
  59. <view style="color: #000;font-size: 28rpx;">
  60. 优惠券
  61. </view>
  62. </view>
  63. <view style="display: flex;align-items: center;">
  64. <view style="color: #e43d33;font-size: 28rpx;font-weight: 600;">
  65. ¥30.00
  66. </view>
  67. <uni-icons type="forward" size="14" color="#c5c5c5"></uni-icons>
  68. </view>
  69. </view>
  70. <view style="background-color:#e5e5e5;height:1rpx;margin-top: 30rpx;"></view>
  71. <view style="margin-top: 30rpx;display: flex;justify-content: flex-end;">
  72. <text style="color: #000;font-size: 26rpx;">合计:</text><text
  73. style="color: #e43d33;font-size: 34rpx;font-weight: 600;margin-right: 28rpx;">¥270.00</text>
  74. </view>
  75. </uni-card>
  76. <uni-card style="margin: 30rpx 0;border-radius: 20rpx;">
  77. <view style="display: flex;justify-content: space-between;margin:20rpx 0;">
  78. <view style="display: flex;align-items: center;">
  79. <image style="height: 40rpx;width: 40rpx;" src="/static/images/pay/pay.png" mode="scaleToFill">
  80. </image>
  81. <text style="color: #3a3a3a;margin-left: 20rpx;">
  82. 在线支付
  83. </text>
  84. </view>
  85. <view style="display: flex;align-items: center;width: 40rpx;">
  86. <uni-data-checkbox v-model="payType" :localdata="[{'value':'wechat'}]"></uni-data-checkbox>
  87. </view>
  88. </view>
  89. </uni-card>
  90. <view class="dynamic-bottom">
  91. </view>
  92. <view style="position: fixed;bottom: 30rpx;width: 100%;">
  93. <view style="margin:0 30rpx;">
  94. <debounce-button bgColor='#03803B' @click="goPay">确认支付</debounce-button>
  95. </view>
  96. </view>
  97. </view>
  98. </template>
  99. <script>
  100. import {
  101. v4 as uuidv4
  102. } from 'uuid';
  103. import {
  104. getPhoneVerifyCode
  105. } from '@/api/user.js'
  106. import PaymentUtils from '@/utils/payment.js'
  107. export default {
  108. data() {
  109. return {
  110. orderData: {
  111. orderNo: 'DD20241104134733',
  112. productName: '高级会员服务',
  113. amount: 199.00,
  114. createTime: '2024-11-04 13:47:33'
  115. },
  116. isProcessing: false,
  117. payType: 'wechat',
  118. dataList: [{
  119. url: '/static/images/lt.png',
  120. goodsName: '轮胎1',
  121. number: 1,
  122. price: 100,
  123. },
  124. {
  125. url: '/static/images/lt.png',
  126. goodsName: '轮胎2',
  127. number: 1,
  128. price: 100,
  129. },
  130. {
  131. url: '/static/images/lt.png',
  132. goodsName: '轮胎2',
  133. number: 1,
  134. price: 100,
  135. }
  136. ]
  137. };
  138. },
  139. onLoad() {},
  140. methods: {
  141. // 根据支付方式获取AppID
  142. getAppIdByMethod(method) {
  143. const appIds = {
  144. wechat: 'gh_xxxxxxxxxxxx', // 通联小程序微信AppID
  145. alipay: '2021002186688888' // 通联小程序支付宝AppID
  146. }
  147. return appIds[method] || ''
  148. },
  149. async goPay() {
  150. if (!this.payType) {
  151. uni.showToast({
  152. title: '请选择支付方式',
  153. icon: 'none'
  154. })
  155. return
  156. }
  157. this.isProcessing = true
  158. try {
  159. // 1. 检查应用是否安装
  160. const appInstalled = await PaymentUtils.checkAppInstalled(this.payType)
  161. if (!appInstalled) {
  162. uni.showModal({
  163. title: '提示',
  164. content: '未检测到应用,请先安装',
  165. showCancel: false
  166. })
  167. return
  168. }
  169. // 2. 构建跳转URL
  170. const jumpConfig = {
  171. appId: this.getAppIdByMethod('wechat'),
  172. path: 'pages/payment/index',
  173. extraData: {
  174. orderNo: this.orderData.orderNo,
  175. amount: this.orderData.amount
  176. }
  177. }
  178. let urlScheme
  179. if (this.payType == 'wechat') {
  180. urlScheme = PaymentUtils.buildWechatURLScheme(jumpConfig)
  181. }
  182. // 3. 执行跳转
  183. await PaymentUtils.launchApp(urlScheme)
  184. // 4. 启动支付状态监控
  185. // this.startPaymentMonitoring()
  186. } catch (error) {
  187. console.error('支付流程异常', error)
  188. uni.showToast({
  189. title: '支付启动失败',
  190. icon: 'none'
  191. })
  192. } finally {
  193. this.isProcessing = false
  194. }
  195. }
  196. },
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .dynamic-bottom {
  201. padding-bottom: calc(env(safe-area-inset-bottom) + 140rpx);
  202. }
  203. </style>