payment.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="wrap">
  3. <uv-cell-group :customStyle="{
  4. background:'#fff'
  5. }">
  6. <uv-cell icon="bag" title="订单编号" :arrow="false" :value="orderSn" size="large"></uv-cell>
  7. <uv-cell icon="red-packet" title="应付金额" :arrow="false" :value="totalPriceFmt" size="large"></uv-cell>
  8. </uv-cell-group>
  9. <uv-radio-group v-model="payType" :customStyle="{
  10. background:'#fff'
  11. }">
  12. <view class="item" v-for="(res, index) in payWayList" :key="res.name">
  13. <uv-row>
  14. <uv-col :span="11">
  15. <view class="top">
  16. <view class="name">
  17. <uv-icon name="weixin-fill" size="60" color="#6cac3e"></uv-icon>
  18. </view>
  19. <view class="label">
  20. 微信支付
  21. </view>
  22. </view>
  23. </uv-col>
  24. <uv-col :span="1">
  25. <uv-radio :name="res.name" iconSize="32" size="36"></uv-radio>
  26. </uv-col>
  27. </uv-row>
  28. </view>
  29. </uv-radio-group>
  30. <view class="button">
  31. <uv-button type="primary" @click="submit">立即支付</uv-button>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. getOrderResult,
  38. getPaymentInformation
  39. } from '@/request/api/shop.js'
  40. export default {
  41. data() {
  42. return {
  43. orderSn: '',
  44. totalPrice: '',
  45. payType: 'wxpay',
  46. payWayList: [{
  47. name: 'wxpay',
  48. text: '微信支付'
  49. }]
  50. }
  51. },
  52. computed: {
  53. totalPriceFmt() {
  54. return '¥' + (this.totalPrice / 100).toFixed(2)
  55. }
  56. },
  57. onLoad(body) {
  58. this.orderSn = body.orderSn
  59. this.totalPrice = body.totalPrice;
  60. this.init();
  61. },
  62. methods: {
  63. init() {
  64. getOrderResult(this.orderSn).then(res => {
  65. //如果当前订单已经支付成功跳转到订单详情页
  66. if (res.data) {}
  67. })
  68. },
  69. submit() {
  70. if ('wxpay' === this.payType) {
  71. getPaymentInformation(this.orderSn).then(response => {
  72. if (response.state) {
  73. let res = response.data;
  74. uni.requestPayment({
  75. provider: 'wxpay',
  76. timeStamp: res.timeStamp, //时间戳
  77. nonceStr: res.nonceStr, //随机字符串
  78. package: res.packageValue, //统一下单接口返回的 prepay_id 参数值
  79. signType: res.signType,
  80. paySign: res.paySign, //签名内容
  81. success: (e) => {
  82. getOrderResult(this.orderSn).then(res => {
  83. //如果当前订单已经支付成功跳转到订单详情页
  84. if (res.data) {
  85. this.$u.route({
  86. url: '/pages/order/detail',
  87. params: {
  88. orderSn: orderSn
  89. }
  90. })
  91. }
  92. })
  93. },
  94. fail: (e) => {
  95. this.$toast('取消支付');
  96. }
  97. })
  98. }
  99. });
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .wrap {
  107. padding: 30rpx 0rpx;
  108. .top {
  109. display: flex;
  110. align-items: center;
  111. }
  112. .item {
  113. width: 100%;
  114. padding: 20rpx 20rpx;
  115. }
  116. .label {
  117. color: #6cac3e;
  118. margin-left: 10rpx;
  119. }
  120. .button {
  121. padding: 30rpx;
  122. }
  123. }
  124. </style>