paymentMethod.vue 6.9 KB

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