payPage.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="wrap">
  3. <view class="order-info">
  4. <view class="order-info-top">
  5. <view class="addr u-flex">
  6. <u-icon name="map-fill" color="#fff" size="28"></u-icon>
  7. <view class="addr-text">{{orderInfo.roadName}}</view>
  8. </view>
  9. <view class="car u-flex">
  10. <view class="car-no">{{orderInfo.vehicleNo}}</view>
  11. <view class="car-type">临时车</view>
  12. </view>
  13. <view class="time in-time">进场时间:{{orderInfo.inTime}}</view>
  14. <view class="time out-time">进场时间:{{orderInfo.outTime}}</view>
  15. <view class="duration">已停放 {{orderInfo.duration}}</view>
  16. <view class="total-amount">¥{{orderInfo.totalAmount}}</view>
  17. </view>
  18. <view class="order-info-bottom">
  19. <u-cell-item
  20. center
  21. :border-bottom="false"
  22. :value="orderInfo.preferentialAmount"
  23. :title-style="{color:'#8A8A8A'}"
  24. :icon-style="{color:'#D8D8D8'}"
  25. title="已优惠"></u-cell-item>
  26. <view class="pay-amount u-flex u-row-between">
  27. <view class="title">应付金额</view>
  28. <view class="amount"><span class="rmb">¥</span>{{orderInfo.payAmount}}</view>
  29. </view>
  30. <view class="tip">停车费不超过30元,可先离场后在付费</view>
  31. </view>
  32. </view>
  33. <view class="bottom-btn static" @click="handlewxpay">去支付</view>
  34. <u-toast ref="uToast" />
  35. </view>
  36. </template>
  37. <script>
  38. import getUrlParams from "../../utils/getUrlParams.js";
  39. export default{
  40. data(){
  41. return{
  42. orderId:null,
  43. orderInfo:[],
  44. }
  45. },
  46. onLoad(){
  47. let locationLocaturl = window.location.hash;
  48. this.orderId = getUrlParams(locationLocaturl,"orderId"); // 截取orderId
  49. console.log('this.orderId',this.orderId);
  50. this.handleGetOrderinfo(this.orderId);
  51. },
  52. methods:{
  53. handleGetOrderinfo(orderId){
  54. this.$u.api.getOrderinfo({id:orderId})
  55. .then(res=>{
  56. // this.$refs.uToast.show({
  57. // title: res.msg,
  58. // type: 'success',
  59. // });
  60. this.orderInfo = res.data;
  61. console.log('handleGetOrderinfo',JSON.parse(JSON.stringify(res)));
  62. }).catch(err=>{
  63. this.$refs.uToast.show({
  64. title: err.msg,
  65. type: 'error',
  66. });
  67. console.log('handleGetOrderinfo ',err)
  68. });
  69. },
  70. getCode () {
  71. var local = window.location.href // 获取页面url
  72. let locationLocaturl = window.location.search;
  73. this.code = getUrlParams(locationLocaturl,"code"); // 截取code
  74. if (this.code == null || this.code === '') { // 如果没有code,则去请求
  75. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wxAppid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`
  76. } else {
  77. this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
  78. }
  79. },
  80. handleGetWXInfo (code) { // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
  81. let _this = this
  82. this.$u.api.getWXInfo(code).then((res) => {
  83. if (res.code === 200 ) {
  84. this.$u.vuex('vuex_wxinfo',res.data);
  85. // 继续支付
  86. }
  87. }).catch((err) => {
  88. this.$refs.uToast.show({
  89. title: err.msg,
  90. type: 'error',
  91. });
  92. })
  93. },
  94. handlewxpay(){;
  95. if(!this.$store.state.vuex_wxinfo.openId){ // 如果微信openId,则需用code去后台获取
  96. this.$refs.uToast.show({
  97. title: '请登录后重试!',
  98. type: 'info',
  99. // url: '/pages/user/index'
  100. });
  101. this.getCode();
  102. } else {
  103. // 别的业务逻辑
  104. this.getWXPay();
  105. }
  106. },
  107. async getWXPay(id){
  108. let params = {
  109. orderId:this.orderId,
  110. openid:this.$store.state.vuex_wxinfo.openId,
  111. tradeType:"test"
  112. };
  113. await this.$wxApi.config();
  114. this.$pay.wxPay(params).then(res =>{
  115. console.log('wxPay',res.code);
  116. if(res.code == 0){
  117. // 成功
  118. this.$u.route({
  119. url:'pages/index/index',
  120. // params: {
  121. // keyword: this.keyword
  122. // }
  123. });
  124. }else if(res.code == 1){
  125. // 取消
  126. // uni.redirectTo({
  127. // url: '/pages/userCenter/myOrder/myOrder'
  128. // })
  129. }else if(res.code == 2){
  130. this.$refs.uToast.show({
  131. title: '支付失败,请检查!',
  132. type: 'error',
  133. // url: '/pages/user/index'
  134. });
  135. }
  136. });
  137. },
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. @import "./payPage.scss";
  143. </style>