paymentMethod.vue 6.3 KB

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