edit.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="app">
  3. <view>
  4. <view class="label">充值金额(单位:元 ):</view>
  5. <view><input v-model.number="total_fee" type="number" /></view>
  6. </view>
  7. <button type="primary" @click="createOrder('wxpay')">发起支付(微信)</button>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. total_fee: 10, // 金额
  15. transaction_id:"", // 查询订单接口的查询条件
  16. getOrderRes:{}, // 查询订单支付成功后的返回值
  17. }
  18. },
  19. methods: {
  20. /**
  21. * 发起支付(不唤起收银台,手动指定支付方式)
  22. * 在调用此api前,你应该先创建自己的业务系统订单,并获得订单号 order_no,把order_no当参数传给此api,而示例中为了简化跟支付插件无关的代码,这里直接已时间戳生成了order_no
  23. */
  24. createOrder(provider){
  25. this.http.request({
  26. url: '/level-one-server/app/WalletManage/topupSave',
  27. data: {
  28. amount: this.total_fee, // 支付金额,单位分 100 = 1元
  29. goodsName: '服务点充值'
  30. },
  31. success: res => {
  32. console.log('WxPayAppOrderResult:',res)
  33. // 调起支付
  34. this.orderPayment(res.data.data);
  35. this.transaction_id = res.data.data.prepayId;
  36. }
  37. });
  38. },
  39. // 调起支付
  40. orderPayment(data){
  41. console.log('fff',data)
  42. uni.requestPayment({
  43. "provider": "wxpay",
  44. "orderInfo": data,
  45. success:(res)=>{
  46. this.user.wallet = this.user.wallet + this.total_fee;
  47. console.log("this.user",this.user)
  48. uni.setStorageSync('info', this.user);
  49. uni.navigateTo({
  50. url: '/pages/wallet/topup/detail?transaction_id=' + data.prepayId
  51. })
  52. },
  53. fail:(err)=>{
  54. // 发起支付失败
  55. uni.showToast({title: '发起支付失败!'+err.errMsg,});
  56. }
  57. });
  58. },
  59. // 查询支付状态
  60. async getOrder() {
  61. this.getOrderRes = {};
  62. let res = await this.$refs.pay.getOrder({
  63. //out_trade_no: this.out_trade_no, // 插件支付单号 两者传1个即可
  64. transaction_id: this.transaction_id, // 第三方单号 两者传1个即可
  65. await_notify: true
  66. });
  67. if (res) {
  68. this.getOrderRes = res.pay_order;
  69. let obj = {
  70. "-1": "已关闭",
  71. "1": "已支付",
  72. "0": "未支付",
  73. "2": "已部分退款",
  74. "3": "已全额退款"
  75. };
  76. uni.showToast({
  77. title: obj[res.status] || res.errMsg,
  78. icon: "none"
  79. });
  80. }
  81. },
  82. },
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .app{
  87. padding: 30rpx;
  88. }
  89. input {
  90. border: 1px solid #f3f3f3;
  91. padding: 10rpx;
  92. width: 100%;
  93. box-sizing: border-box;
  94. height: 80rpx;
  95. }
  96. button {
  97. margin-top: 20rpx;
  98. }
  99. .label{
  100. margin: 10rpx 0;
  101. }
  102. .tips{
  103. margin-top: 20rpx;
  104. font-size: 24rpx;
  105. color: #565656;
  106. }
  107. .get-order-popup{
  108. background-color: #ffffff;
  109. padding: 30rpx;
  110. height: 60vh;
  111. border-radius: 30rpx 30rpx 0 0;
  112. overflow: hidden;
  113. }
  114. .mt20{
  115. margin-top: 20rpx;
  116. }
  117. .pd2030{
  118. padding: 20rpx 30rpx;
  119. }
  120. .table{
  121. font-size: 24rpx;
  122. }
  123. .align-left{
  124. text-align: left;
  125. width: 50%;
  126. }
  127. .align-right{
  128. text-align: right;
  129. width: 50%;
  130. }
  131. </style>