paymentMethod.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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"
  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. pursueType: this.pursueType,
  124. sanPay: this.sanPay
  125. };
  126. if (this.exportFlag == true) {
  127. this.$u.api.quickPayExportApi(params).then(res => {
  128. if (res.data.needPay) {
  129. let payUrl = res.data.url;
  130. location.href = payUrl;
  131. } else {
  132. this.$refs.uToast.show({
  133. title: '无需支付',
  134. type: 'info',
  135. });
  136. setTimeout(() => {
  137. uni.hideLoading();
  138. location.reload()
  139. }, 1000)
  140. }
  141. }).catch(err => {
  142. this.$refs.uToast.show({
  143. title: err.msg,
  144. type: 'error',
  145. });
  146. });
  147. } else {
  148. this.$u.api.payGzbank(params).then(res => {
  149. if (res.data.needPay) {
  150. let payUrl = res.data.url;
  151. location.href = payUrl;
  152. } else {
  153. this.$refs.uToast.show({
  154. title: '无需支付',
  155. type: 'info',
  156. });
  157. setTimeout(() => {
  158. uni.hideLoading();
  159. location.reload()
  160. }, 1000)
  161. }
  162. }).catch(err => {
  163. this.$refs.uToast.show({
  164. title: err.msg,
  165. type: 'error',
  166. });
  167. });
  168. }
  169. },
  170. /**
  171. * 聚合支付
  172. * 判断vuex中是否存在openId
  173. * 存在直接调起微信支付
  174. * 不存在则通过微信登录去获取用户的code
  175. * 完成后通过code去获取用户的openId等信息
  176. * 最后再调起微信支付
  177. * */
  178. juhePay() {
  179. this.getWXPayByJava(this.curOrderList, this.deviceNo);
  180. },
  181. /**
  182. * 微信支付
  183. */
  184. wechatPay() {
  185. if (this.exportFlag) {
  186. this.$refs.uToast.show({
  187. title: '停车场暂不支持微信支付!',
  188. type: 'warning'
  189. });
  190. } else {
  191. this.$u.api
  192. .wechatPayApi({
  193. orderList: this.curOrderList,
  194. openid: this.vuex_wxinfo.openId,
  195. deviceNo: this.deviceNo || undefined,
  196. payeeId: this.payeeId || undefined,
  197. payeeName: this.payeeName || undefined
  198. })
  199. .then((res) => {
  200. if (res.code === 200) {
  201. $wxPay.wexinPay(res.data.wx).then((res1) => {
  202. switch (Number(res1.code)) {
  203. case 0: // 成功
  204. //#ifdef H5
  205. window.location.reload();
  206. //#endif
  207. break;
  208. case 1: // 取消
  209. this.$refs.uToast.show({
  210. title: '已取消支付',
  211. type: 'info'
  212. });
  213. break;
  214. case 2: // 支付失败
  215. this.$refs.uToast.show({
  216. title: '支付失败,请检查!',
  217. type: 'error'
  218. });
  219. break;
  220. }
  221. });
  222. }
  223. });
  224. }
  225. },
  226. /**
  227. * 直接通过后台获取贵阳银行微信支付地址
  228. * @param {Array} list 需要支付的订单组合数组
  229. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  230. * */
  231. getWXPayByJava(orderList, deviceNo) {
  232. let params = {
  233. orderList: orderList,
  234. openid: this.vuex_wxinfo.openId,
  235. jumpUrl: this.jumpUrl,
  236. deviceNo: deviceNo ? deviceNo : null,
  237. payeeId: this.payeeId,
  238. payeeName: this.payeeName,
  239. pursueType: this.pursueType,
  240. sanPay: this.sanPay
  241. };
  242. if (this.exportFlag) {
  243. this.$u.api.polyPayExportApi(params)
  244. .then(res => {
  245. if (res.code === 200) {
  246. localStorage.setItem('jumpUrl', this.jumpUrl)
  247. location.href = res.data.qrCodeUrl
  248. } else {
  249. uni.hideLoading();
  250. }
  251. })
  252. .catch(err => {
  253. this.$refs.uToast.show({
  254. title: '无法调起微信支付!',
  255. type: 'error',
  256. });
  257. })
  258. } else {
  259. this.$u.api.ordinaryWxPay(params)
  260. .then(res => {
  261. if (res.code === 200) {
  262. localStorage.setItem('jumpUrl', this.jumpUrl)
  263. location.href = res.data.qrCodeUrl
  264. } else {
  265. uni.hideLoading();
  266. }
  267. })
  268. .catch(err => {
  269. this.$refs.uToast.show({
  270. title: '无法调起微信支付!',
  271. type: 'error',
  272. });
  273. })
  274. }
  275. },
  276. /**
  277. * 关闭弹框
  278. * */
  279. closePaymentMethod() {
  280. this.$emit('closePaymentMethod');
  281. }
  282. }
  283. };
  284. </script>
  285. <style lang="scss" scoped>
  286. @import './paymentMethod.scss';
  287. </style>