paymentMethod.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <!--
  2. * @Description: 支付方式选择 微信or快捷支付or聚合支付
  3. * @Author: 空白格
  4. * @Date: 2022-08-01 11:45:20
  5. * @LastEditors: 空白格
  6. * @LastEditTime: 2023-01-03 10:21:16
  7. * @FilePath: \parking_h5\pages\choosePayment\choosePayment.vue
  8. * @Copyright: Copyright (c) 2016~2022 by 空白格, All Rights Reserved.
  9. -->
  10. <template>
  11. <view>
  12. <u-modal v-model="payWayPop" :title-style="{ color: '#404040' }" title="缴费方式" width="660rpx"
  13. :show-confirm-button="false" :show-cancel-button="false">
  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"
  26. @click="$u.debounce(gyBankPay, 1000, (immediate = true))">
  27. <image src="/static/img/gyyh-icon.svg" mode=""></image>
  28. <view class="title">贵州银行</view>
  29. </view>
  30. <!-- #ifdef H5 || MP-WEIXIN -->
  31. <view class="pay-way-item pay-way-item-wx" @click="$u.debounce(wechatPay, 1000, (immediate = true))"
  32. v-if="wxEnv">
  33. <image src="/static/img/weixin-icon.svg" mode=""></image>
  34. <view class="title">微信支付</view>
  35. </view>
  36. <!-- #endif -->
  37. <view class="pay-way-item pay-way-item-jh" @click="$u.debounce(juhePay, 1000, (immediate = true))">
  38. <image src="/static/img/juhe-icon.svg" mode=""></image>
  39. <view class="title">聚合支付</view>
  40. </view>
  41. </view>
  42. <view class="pay-way-subtitle">
  43. <view class="pay-way-subtitle-item">前三个月每天首次一分钱,长期八折优惠</view>
  44. <!-- #ifdef H5 || MP-WEIXIN -->
  45. <view class="pay-way-subtitle-item" v-if="wxEnv">&nbsp;</view>
  46. <!-- #endif -->
  47. <view class="pay-way-subtitle-item">&nbsp;</view>
  48. </view>
  49. <button class="pay-way-close-btn" @click="closePaymentMethod">关闭</button>
  50. </view>
  51. </u-modal>
  52. <u-toast ref="uToast" />
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. getEnvIsWx
  58. } from '@/utils/judgEnvironment.js';
  59. import $wxPay from '@/utils/wxPay.js';
  60. export default {
  61. props: {
  62. // 弹框显示
  63. payWayPop: {
  64. type: Boolean,
  65. default: false
  66. },
  67. // 订单数组
  68. curOrderList: {
  69. type: Array,
  70. default: null
  71. },
  72. // 设备编号
  73. deviceNo: {
  74. type: String,
  75. default: null
  76. },
  77. // 地磁支付需要字段
  78. payeeId: {
  79. type: String,
  80. default: undefined
  81. },
  82. // 地磁支付需要字段
  83. payeeName: {
  84. type: String,
  85. default: undefined
  86. },
  87. // 扫码支付需要字段
  88. sanPay: {
  89. type: Boolean,
  90. default: false
  91. },
  92. // 追缴类型
  93. pursueType: {
  94. type: String,
  95. default: undefined
  96. },
  97. // 车牌号
  98. vehicleNo: {
  99. type: String,
  100. default: undefined
  101. },
  102. // 跳转页面
  103. jumpUrl: {
  104. type: String,
  105. default: null
  106. },
  107. // 出口扫码 接口不一样
  108. exportFlag: {
  109. type: Boolean,
  110. default: false
  111. }
  112. },
  113. data() {
  114. return {
  115. wxEnv: true
  116. };
  117. },
  118. created() {
  119. this.wxEnv = getEnvIsWx();
  120. },
  121. methods: {
  122. /**
  123. * 贵阳银行支付
  124. * @param {Array} orderList 需要支付的订单号组成的数组
  125. * @param {String} deviceNo 设备编号(只有车位锁部分有)
  126. * */
  127. gyBankPay() {
  128. const params = {
  129. orderList: this.curOrderList,
  130. deviceNo: this.deviceNo,
  131. jumpUrl: this.jumpUrl,
  132. payeeId: this.payeeId,
  133. payeeName: this.payeeName,
  134. pursueType: this.pursueType,
  135. vehicleNo: this.vehicleNo,
  136. sanPay: this.sanPay
  137. };
  138. if (this.exportFlag == true) {
  139. this.$u.api
  140. .quickPayExportApi(params)
  141. .then((res) => {
  142. if (res.data.needPay) {
  143. let payUrl = res.data.url;
  144. location.href = payUrl;
  145. } else {
  146. this.$refs.uToast.show({
  147. title: '无需支付',
  148. type: 'info'
  149. });
  150. setTimeout(() => {
  151. uni.hideLoading();
  152. location.reload();
  153. }, 1000);
  154. }
  155. })
  156. .catch((err) => {
  157. this.$refs.uToast.show({
  158. title: err.msg,
  159. type: 'error'
  160. });
  161. });
  162. } else {
  163. this.$u.api
  164. .payGzbank(params)
  165. .then((res) => {
  166. if (res.data.needPay) {
  167. let payUrl = res.data.url;
  168. location.href = payUrl;
  169. } else {
  170. this.$refs.uToast.show({
  171. title: '无需支付',
  172. type: 'info'
  173. });
  174. setTimeout(() => {
  175. uni.hideLoading();
  176. location.reload();
  177. }, 1000);
  178. }
  179. })
  180. .catch((err) => {
  181. this.$refs.uToast.show({
  182. title: err.msg,
  183. type: 'error'
  184. });
  185. });
  186. }
  187. },
  188. /**
  189. * 聚合支付
  190. * */
  191. juhePay() {
  192. this.getWXPayByJava(this.curOrderList, this.deviceNo);
  193. },
  194. /**
  195. * 微信支付
  196. */
  197. wechatPay() {
  198. const params = {
  199. orderList: this.curOrderList,
  200. openid: this.vuex_wxinfo.openId,
  201. deviceNo: this.deviceNo || undefined,
  202. payeeId: this.payeeId || undefined,
  203. payeeName: this.payeeName || undefined,
  204. vehicleNo: this.vehicleNo,
  205. sanPay: this.sanPay
  206. };
  207. if (this.exportFlag) {
  208. this.$u.api.parkingWechatPayApi(params).then((res) => {
  209. if (res.code === 200) {
  210. if (res.data.needPay) {
  211. $wxPay.wexinPay(res.data.wx).then((r) => {
  212. switch (Number(r.code)) {
  213. case 0: // 成功
  214. //#ifdef H5
  215. window.location.reload();
  216. //#endif
  217. break;
  218. case 1: // 取消
  219. this.$u.api.updateCouponStatusApi({
  220. orderList: this.curOrderList
  221. }).then(res => {
  222. if (res.code === 200) {
  223. this.$refs.uToast.show({
  224. title: '已取消支付',
  225. type: 'info'
  226. });
  227. window.location.reload();
  228. }
  229. })
  230. break;
  231. case 2: // 支付失败
  232. this.$refs.uToast.show({
  233. title: '支付失败,请检查!',
  234. type: 'error'
  235. });
  236. break;
  237. }
  238. });
  239. } else {
  240. this.$refs.uToast.show({
  241. title: '无需支付',
  242. type: 'info'
  243. });
  244. setTimeout(() => {
  245. uni.hideLoading();
  246. location.reload();
  247. }, 1000);
  248. }
  249. }
  250. });
  251. } else {
  252. this.$u.api.wechatPayApi(params).then((res) => {
  253. if (res.code === 200) {
  254. if (res.data.needPay) {
  255. $wxPay.wexinPay(res.data.wx).then((r) => {
  256. switch (Number(r.code)) {
  257. case 0: // 成功
  258. //#ifdef H5
  259. window.location.reload();
  260. //#endif
  261. break;
  262. case 1: // 取消
  263. this.$u.api.updateCouponStatusApi({
  264. orderList: this.curOrderList
  265. }).then(res => {
  266. if (res.code === 200) {
  267. this.$refs.uToast.show({
  268. title: '已取消支付',
  269. type: 'info'
  270. });
  271. window.location.reload();
  272. }
  273. })
  274. break;
  275. case 2: // 支付失败
  276. this.$refs.uToast.show({
  277. title: '支付失败,请检查!',
  278. type: 'error'
  279. });
  280. break;
  281. }
  282. });
  283. } else {
  284. this.$refs.uToast.show({
  285. title: '无需支付',
  286. type: 'info'
  287. });
  288. setTimeout(() => {
  289. uni.hideLoading();
  290. location.reload();
  291. }, 1000);
  292. }
  293. }
  294. });
  295. }
  296. },
  297. /**
  298. * 直接通过后台获取贵阳银行微信支付地址
  299. * @param {Array} list 需要支付的订单组合数组
  300. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  301. * */
  302. getWXPayByJava(orderList, deviceNo) {
  303. let params = {
  304. orderList: orderList,
  305. openid: this.vuex_wxinfo.openId,
  306. jumpUrl: this.jumpUrl,
  307. deviceNo: deviceNo ? deviceNo : null,
  308. payeeId: this.payeeId,
  309. payeeName: this.payeeName,
  310. pursueType: this.pursueType,
  311. vehicleNo: this.vehicleNo,
  312. sanPay: this.sanPay
  313. };
  314. if (this.exportFlag) {
  315. this.$u.api
  316. .polyPayExportApi(params)
  317. .then((res) => {
  318. if (res.code === 200) {
  319. if (res.data.needPay) {
  320. localStorage.setItem('jumpUrl', this.jumpUrl);
  321. location.href = res.data.qrCodeUrl;
  322. } else {
  323. this.$refs.uToast.show({
  324. title: '无需支付',
  325. type: 'info'
  326. });
  327. setTimeout(() => {
  328. uni.hideLoading();
  329. location.href = this.jumpUrl;
  330. }, 1000);
  331. }
  332. } else {
  333. uni.hideLoading();
  334. }
  335. })
  336. .catch((err) => {
  337. this.$refs.uToast.show({
  338. title: '无法调起微信支付!',
  339. type: 'error'
  340. });
  341. });
  342. } else {
  343. this.$u.api
  344. .ordinaryWxPay(params)
  345. .then((res) => {
  346. if (res.code === 200) {
  347. if (res.data.needPay) {
  348. localStorage.setItem('jumpUrl', this.jumpUrl);
  349. location.href = res.data.qrCodeUrl;
  350. } else {
  351. this.$refs.uToast.show({
  352. title: '无需支付',
  353. type: 'info'
  354. });
  355. setTimeout(() => {
  356. uni.hideLoading();
  357. location.href = this.jumpUrl;
  358. }, 1000);
  359. }
  360. } else {
  361. uni.hideLoading();
  362. }
  363. })
  364. .catch((err) => {
  365. this.$refs.uToast.show({
  366. title: '无法调起微信支付!',
  367. type: 'error'
  368. });
  369. });
  370. }
  371. },
  372. /**
  373. * 关闭弹框
  374. * */
  375. closePaymentMethod() {
  376. this.$emit('closePaymentMethod');
  377. }
  378. }
  379. };
  380. </script>
  381. <style lang="scss" scoped>
  382. @import './paymentMethod.scss';
  383. </style>