paymentMethod.vue 7.0 KB

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