confirm.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="whole">
  3. <view class="pay">
  4. <view class="header">
  5. <div>
  6. <view class="pay">支付金额</view>
  7. <view class="payNum">
  8. <span style="font-size: 34rpx;">¥</span>{{price}}
  9. </view>
  10. </div>
  11. </view>
  12. <view class="listPay">
  13. <uni-icons type="weixin" size="60rpx" color="#00aa00"></uni-icons>
  14. <view class="text">
  15. <view class="wx">微信支付</view>
  16. <view class="subWx">推荐使用微信支付</view>
  17. </view>
  18. <view class="btn">
  19. <label class="radio">
  20. <radio value="1" :checked="boolWx"
  21. color="#FFCC33" style="transform:scale(0.7)"
  22. @click="changePayType(1)" />
  23. </label>
  24. </view>
  25. </view>
  26. <!-- <view class="listPay">
  27. <uni-icons type="weibo" size="60rpx" color="#ff5500"></uni-icons>
  28. <view class="text">
  29. <view class="wx">线下支付(到付)</view>
  30. </view>
  31. <view class="btn">
  32. <label class="radio">
  33. <radio value="2" :checked="boolWb"
  34. color="#FFCC33" style="transform:scale(0.7)"
  35. @click="changePayType(3)" />
  36. </label>
  37. </view>
  38. </view>-->
  39. <view class="bootom">
  40. <button type="warn" style="color: #fff;" @click="confirm">确认支付</button>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. boolWx: true,
  50. boolWb: false,
  51. payType: 1, //支付类型
  52. price: 0, //支付金额
  53. orderNo: "", //订单号
  54. parentOrderNo: "", //父订单号
  55. submiting: false//控制再次确认支付的弹出框
  56. }
  57. },
  58. onLoad(options) {
  59. //接受参数
  60. let orderInfo = options.params;
  61. if( orderInfo ){
  62. //解密参数
  63. orderInfo = decodeURIComponent(orderInfo);
  64. //转成js数组对象
  65. orderInfo = JSON.parse(orderInfo);
  66. }
  67. this.price = orderInfo.pay_total
  68. if (orderInfo.order_id) {
  69. this.orderNo = orderInfo.order_id
  70. } else {
  71. this.parentOrderNo = orderInfo.snowflake_id
  72. }
  73. },
  74. methods: {
  75. // 选择支付方式
  76. changePayType(type) {
  77. if(1==type){
  78. this.boolWx=true;
  79. this.boolWb=false;
  80. }else{
  81. this.boolWx=false;
  82. this.boolWb=true;
  83. }
  84. this.payType = type
  85. console.log(this.payType,"this.payType");
  86. },
  87. // 确认支付
  88. confirm() {
  89. const that = this;
  90. //微信支付
  91. if(1===that.payType){
  92. that.submiting = true;
  93. this.pay();
  94. }
  95. },
  96. //调起微信支付
  97. pay(){
  98. uni.login({
  99. provider: 'weixin',
  100. success: (loginRes) => {
  101. // 登录成功,获取用户code
  102. const { code } = loginRes;
  103. // 微信支付下单
  104. this.$http.request('api/wechat_pay/pay',{code:code,order_id:this.orderNo},'post').then((e)=>{
  105. const price = this.price
  106. // 成功的话
  107. if( e.code == 'success'){
  108. //获取openid
  109. // 授权成功以后,调用登录
  110. //调用微信官方支付接口弹出付款界面,输入密码扣款
  111. wx.requestPayment({
  112. timeStamp: e.data.timeStamp, //时间戳
  113. nonceStr: e.data.nonceStr, //随机字符串
  114. package: e.data.package, //prepay_id
  115. signType: e.data.signType, //签名算法MD5
  116. paySign: e.data.paySign, //签名
  117. success:function (res) {
  118. if (res.errMsg == "requestPayment:ok"){
  119. console.log('支付成功3', price)
  120. uni.navigateTo({url:`/pages/orders/completion?price=${price}`});
  121. }else{
  122. console.log('支付失败')
  123. uni.showToast({
  124. title: '支付失败',
  125. icon: 'none'
  126. });
  127. }
  128. },
  129. fail:function (res) {
  130. console.log('支付失败', res)
  131. uni.showToast({
  132. title: '支付失败',
  133. icon: 'none'
  134. });
  135. }
  136. })
  137. }else{
  138. console.log('支付失败2', e)
  139. uni.showToast({
  140. title: '支付失败',
  141. icon: 'none'
  142. });
  143. }
  144. });
  145. },
  146. fail: (err) => {
  147. console.log('uni.login 接口调用失败,无法获取openid', err);
  148. uni.showToast({
  149. title: '支付失败',
  150. icon: 'none'
  151. });
  152. }
  153. });
  154. },
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. .whole {
  160. display: flex;
  161. justify-content: center;
  162. .header {
  163. display: flex;
  164. justify-content: center;
  165. align-items: center;
  166. text-align: center;
  167. flex-wrap: wrap;
  168. height: 300rpx;
  169. .pay {
  170. width: 100%;
  171. color: #717171;
  172. }
  173. .payNum {
  174. width: 100%;
  175. font-size: 44rpx;
  176. margin: 10rpx 0px 20rpx;
  177. }
  178. }
  179. .pay {
  180. width: 100%;
  181. .listPay {
  182. height: 130rpx;
  183. display: flex;
  184. align-items: center;
  185. .uni-icons {
  186. margin-left: 20rpx;
  187. }
  188. .text {
  189. width: 40%;
  190. margin: 0px 20rpx 0px;
  191. }
  192. .btn {
  193. width: 40%;
  194. text-align: right;
  195. }
  196. }
  197. .bootom {
  198. width: 90%;
  199. margin: auto;
  200. margin-top: 20rpx;
  201. }
  202. }
  203. }
  204. </style>