paymentMethod.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. uni.showLoading({
  102. title: '加载中'
  103. });
  104. const params = {
  105. orderList: this.curOrderList,
  106. deviceNo: this.deviceNo,
  107. jumpUrl: this.jumpUrl,
  108. payeeId: this.payeeId,
  109. payeeName: this.payeeName
  110. };
  111. this.$u.api
  112. .payGzbank(params)
  113. .then(res => {
  114. if (res.data.needPay) {
  115. let payUrl = res.data.url;
  116. location.href = payUrl;
  117. } else {
  118. this.$refs.uToast.show({
  119. title: '无需支付',
  120. type: 'info'
  121. });
  122. setTimeout(() => {
  123. uni.hideLoading();
  124. location.reload();
  125. }, 1000);
  126. }
  127. })
  128. .catch(err => {
  129. this.$refs.uToast.show({
  130. title: err.msg,
  131. type: 'error'
  132. });
  133. });
  134. },
  135. /**
  136. * 聚合支付
  137. * 判断vuex中是否存在openId
  138. * 存在直接调起微信支付
  139. * 不存在则通过微信登录去获取用户的code
  140. * 完成后通过code去获取用户的openId等信息
  141. * 最后再调起微信支付
  142. * */
  143. juhePay() {
  144. uni.showLoading({
  145. title: '加载中'
  146. });
  147. this.getWXPayByJava(this.curOrderList, this.deviceNo);
  148. },
  149. /**
  150. * 微信支付
  151. */
  152. wechatPay() {
  153. this.$u.api.wechatPayApi({
  154. orderList: this.curOrderList,
  155. openid: this.vuex_wxinfo.openId,
  156. deviceNo: this.deviceNo || undefined,
  157. payeeId: this.payeeId || undefined,
  158. payeeName: this.payeeName || undefined
  159. }).then(res => {
  160. if (res.code === 200) {
  161. $wxPay.wexinPay(res.data.wx).then(res1 => {
  162. switch (Number(res1.code)) {
  163. case 0: // 成功
  164. //#ifdef H5
  165. window.location.reload();
  166. //#endif
  167. break;
  168. case 1: // 取消
  169. this.$refs.uToast.show({
  170. title: '已取消支付',
  171. type: 'info'
  172. });
  173. break;
  174. case 2: // 支付失败
  175. this.$refs.uToast.show({
  176. title: '支付失败,请检查!',
  177. type: 'error'
  178. });
  179. break;
  180. }
  181. })
  182. }
  183. })
  184. },
  185. /**
  186. * 直接通过后台获取贵阳银行微信支付地址
  187. * @param {Array} list 需要支付的订单组合数组
  188. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  189. * */
  190. getWXPayByJava(orderList, deviceNo) {
  191. let params = {
  192. orderList: orderList,
  193. openid: '',
  194. jumpUrl: this.jumpUrl,
  195. deviceNo: deviceNo ? deviceNo : null,
  196. payeeId: this.payeeId,
  197. payeeName: this.payeeName
  198. };
  199. this.$u.api
  200. .ordinaryWxPay(params)
  201. .then(res => {
  202. if (res.code === 200) {
  203. // if (getEnvIsWx()) {
  204. // location.href = res.data.qrCodeUrl + '&jump_url=' + encodeURIComponent(this.jumpUrl)
  205. // } else {
  206. // location.href = res.data.qrCodeUrl
  207. // }
  208. localStorage.setItem('jumpUrl', this.jumpUrl);
  209. location.href = res.data.qrCodeUrl;
  210. // this.cookie.set("jumpUrl",this.jumpUrl);
  211. } else {
  212. uni.hideLoading();
  213. }
  214. })
  215. .catch(err => {
  216. this.$refs.uToast.show({
  217. title: '无法调起微信支付!',
  218. type: 'error'
  219. });
  220. });
  221. },
  222. /**
  223. * 关闭弹框
  224. * */
  225. closePaymentMethod() {
  226. this.$emit('closePaymentMethod');
  227. }
  228. }
  229. };
  230. </script>
  231. <style lang="scss" scoped>
  232. @import './paymentMethod.scss';
  233. </style>