payment.vue 3.6 KB

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