paymentMethod.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <!--
  3. 支付方式选择 微信or贵阳银行
  4. -->
  5. <view>
  6. <u-modal v-model="payWayPop" :title-style="{ color: '#404040' }" title="缴费方式" width="660rpx"
  7. :show-confirm-button="false" :show-cancel-button="false">
  8. <view class="slot-content">
  9. <view class="pay-way-new">
  10. <!-- <view class="pay-way-item pay-way-item-hy" @click="gyBankPay">
  11. <image src="../../static/img/guiyang-bank-icon.png" mode=""></image>
  12. <view class="title">贵州银行</view>
  13. <view class="subtitle">前三个月每天首次一分钱<br/>长期八折优惠</view>
  14. </view>
  15. <view class="pay-way-item pay-way-item-jh" @click="wechatPay">
  16. <image src="../../static/img/juhe-icon.png" mode=""></image>
  17. <view class="title">微信/支付宝</view>
  18. </view> -->
  19. <view class="pay-way-item pay-way-item-hy" @click="gyBankPay">
  20. <image src="/static/img/gyyh-icon.svg" mode=""></image>
  21. <view class="title">贵州银行</view>
  22. </view>
  23. <!-- #ifdef H5 || MP-WEIXIN -->
  24. <view class="pay-way-item pay-way-item-wx" @click="wechatPay" v-if="wxEnv">
  25. <image src="/static/img/weixin-icon.svg" mode=""></image>
  26. <view class="title">微信支付</view>
  27. </view>
  28. <!-- #endif -->
  29. <view class="pay-way-item pay-way-item-jh" @click="juhePay">
  30. <image src="/static/img/juhe-icon.svg" mode=""></image>
  31. <view class="title">聚合支付</view>
  32. </view>
  33. </view>
  34. <view class="pay-way-subtitle">
  35. <view class="pay-way-subtitle-item">前三个月每天首次一分钱,长期八折优惠</view>
  36. <!-- #ifdef H5 || MP-WEIXIN -->
  37. <view class="pay-way-subtitle-item" v-if="wxEnv">&nbsp;</view>
  38. <!-- #endif -->
  39. <view class="pay-way-subtitle-item">&nbsp;</view>
  40. </view>
  41. <button class="pay-way-close-btn" @click="closePaymentMethod">关闭</button>
  42. </view>
  43. </u-modal>
  44. <u-toast ref="uToast" />
  45. </view>
  46. </template>
  47. <script>
  48. import getUrlParams from '@/utils/getUrlParams.js';
  49. import {
  50. getEnvIsWx
  51. } from '@/utils/judgEnvironment.js';
  52. import $wxPay from '@/utils/wxPay.js'
  53. export default {
  54. props: {
  55. // 弹框显示
  56. payWayPop: {
  57. type: Boolean,
  58. default: false
  59. },
  60. // 订单数组
  61. curOrderList: {
  62. type: Array,
  63. default: null
  64. },
  65. // 设备编号
  66. deviceNo: {
  67. type: String,
  68. default: null
  69. },
  70. // 地磁支付需要字段
  71. payeeId: {
  72. type: String,
  73. default: undefined
  74. },
  75. // 地磁支付需要字段
  76. payeeName: {
  77. type: String,
  78. default: undefined
  79. },
  80. // 跳转页面
  81. jumpUrl: {
  82. type: String,
  83. default: null
  84. }
  85. },
  86. data() {
  87. return {
  88. wxEnv: true
  89. };
  90. },
  91. created() {
  92. this.wxEnv = getEnvIsWx();
  93. },
  94. methods: {
  95. /**
  96. * 贵阳银行支付
  97. * @param {Array} orderList 需要支付的订单号组成的数组
  98. * @param {String} deviceNo 设备编号(只有车位锁部分有)
  99. * */
  100. gyBankPay() {
  101. const params = {
  102. orderList: this.curOrderList,
  103. deviceNo: this.deviceNo,
  104. jumpUrl: this.jumpUrl,
  105. payeeId: this.payeeId,
  106. payeeName: this.payeeName
  107. };
  108. this.$u.api
  109. .payGzbank(params)
  110. .then(res => {
  111. if (res.data.needPay) {
  112. let payUrl = res.data.url;
  113. location.href = payUrl;
  114. } else {
  115. this.$refs.uToast.show({
  116. title: '无需支付',
  117. type: 'info'
  118. });
  119. setTimeout(() => {
  120. uni.hideLoading();
  121. location.reload();
  122. }, 1000);
  123. }
  124. })
  125. .catch(err => {
  126. this.$refs.uToast.show({
  127. title: err.msg,
  128. type: 'error'
  129. });
  130. });
  131. },
  132. /**
  133. * 聚合支付
  134. * 判断vuex中是否存在openId
  135. * 存在直接调起微信支付
  136. * 不存在则通过微信登录去获取用户的code
  137. * 完成后通过code去获取用户的openId等信息
  138. * 最后再调起微信支付
  139. * */
  140. juhePay() {
  141. this.getWXPayByJava(this.curOrderList, this.deviceNo);
  142. },
  143. /**
  144. * 微信支付
  145. */
  146. wechatPay() {
  147. this.$u.api.wechatPayApi({
  148. orderList: this.curOrderList,
  149. openid: this.vuex_wxinfo.openId,
  150. deviceNo: this.deviceNo || undefined,
  151. payeeId: this.payeeId || undefined,
  152. payeeName: this.payeeName || undefined
  153. }).then(res => {
  154. if (res.code === 200) {
  155. $wxPay.wexinPay(res.data.wx).then(res1 => {
  156. switch (Number(res1.code)) {
  157. case 0: // 成功
  158. //#ifdef H5
  159. window.location.reload();
  160. //#endif
  161. break;
  162. case 1: // 取消
  163. this.$refs.uToast.show({
  164. title: '已取消支付',
  165. type: 'info'
  166. });
  167. break;
  168. case 2: // 支付失败
  169. this.$refs.uToast.show({
  170. title: '支付失败,请检查!',
  171. type: 'error'
  172. });
  173. break;
  174. }
  175. })
  176. }
  177. })
  178. },
  179. /**
  180. * 直接通过后台获取贵阳银行微信支付地址
  181. * @param {Array} list 需要支付的订单组合数组
  182. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  183. * */
  184. getWXPayByJava(orderList, deviceNo) {
  185. let params = {
  186. orderList: orderList,
  187. openid: '',
  188. jumpUrl: this.jumpUrl,
  189. deviceNo: deviceNo ? deviceNo : null,
  190. payeeId: this.payeeId,
  191. payeeName: this.payeeName
  192. };
  193. this.$u.api
  194. .ordinaryWxPay(params)
  195. .then(res => {
  196. if (res.code === 200) {
  197. // if (getEnvIsWx()) {
  198. // location.href = res.data.qrCodeUrl + '&jump_url=' + encodeURIComponent(this.jumpUrl)
  199. // } else {
  200. // location.href = res.data.qrCodeUrl
  201. // }
  202. localStorage.setItem('jumpUrl', this.jumpUrl);
  203. location.href = res.data.qrCodeUrl;
  204. } else {
  205. uni.hideLoading();
  206. }
  207. })
  208. .catch(err => {
  209. this.$refs.uToast.show({
  210. title: '无法调起微信支付!',
  211. type: 'error'
  212. });
  213. });
  214. },
  215. /**
  216. * 关闭弹框
  217. * */
  218. closePaymentMethod() {
  219. this.$emit('closePaymentMethod');
  220. }
  221. }
  222. };
  223. </script>
  224. <style lang="scss" scoped>
  225. @import './paymentMethod.scss';
  226. </style>