paymentMethod.vue 6.7 KB

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