choosePayment.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <template>
  2. <view>
  3. <u-modal
  4. v-model="payWayPop"
  5. :title-style="{ color: '#1E1E1E', fontSize: '34rpx' }"
  6. title="选择支付方式"
  7. width="600rpx"
  8. :show-confirm-button="false"
  9. :show-cancel-button="false"
  10. :mask-close-able="true"
  11. @input="modalClose"
  12. >
  13. <view class="pay-content">
  14. <view class="pay-list">
  15. <radio-group @change="payRadioChange">
  16. <!-- #ifdef H5 || MP-WEIXIN -->
  17. <view class="pay-list-item" v-if="wxEnv">
  18. <view class="pay-list-item-image">
  19. <image class="image" src="/static/img/wechat-icon-new.png" mode="aspectFit" />
  20. <view>微信支付</view>
  21. </view>
  22. <view class="radioBox">
  23. <radio color="#2DCF8C" value="weixin" :checked="'weixin' === radioCurrent" />
  24. </view>
  25. </view>
  26. <!-- #endif -->
  27. <template v-if="alipayEnv">
  28. <view class="pay-list-item">
  29. <view class="pay-list-item-image">
  30. <image class="image" src="/static/img/alipay-icon-new.png" mode="aspectFit" />
  31. <view>支付宝支付<text>随机立减最高10元</text></view>
  32. </view>
  33. <view class="radioBox">
  34. <radio color="#2DCF8C" value="juhe" :checked="'juhe' === radioCurrent" />
  35. </view>
  36. </view>
  37. </template>
  38. <view class="pay-list-item">
  39. <view class="pay-list-item-image">
  40. <image class="image" src="/static/img/gy-icon-new.png" mode="aspectFit" />
  41. <view>贵州银行</view>
  42. </view>
  43. <view class="radioBox">
  44. <radio color="#2DCF8C" value="gzyh" :checked="'gzyh' === radioCurrent" />
  45. </view>
  46. </view>
  47. <template v-if="!alipayEnv">
  48. <view class="pay-list-item">
  49. <view class="pay-list-item-image">
  50. <image class="image" src="/static/img/juhe-icon-new.png" mode="aspectFit" />
  51. <view>聚合支付</view>
  52. </view>
  53. <view class="radioBox">
  54. <radio color="#2DCF8C" value="juhe" :checked="'juhe' === radioCurrent" />
  55. </view>
  56. </view>
  57. </template>
  58. </radio-group>
  59. </view>
  60. <view class="pay-coupon" v-if="radioCurrent === 'weixin' && isShowCoupon">
  61. <u-cell-group :border="false">
  62. <u-cell-item
  63. icon=""
  64. title="优惠券"
  65. :value="couponPopup.currentCoupon.couponName || (couponPopup.couponList.length ? '暂未选择优惠券' : '无可用优惠券')"
  66. :border-bottom="false"
  67. @click="chooseCoupon"
  68. ></u-cell-item>
  69. </u-cell-group>
  70. </view>
  71. <view class="pay-money">
  72. <text class="discount-money" v-if="couponPopup.currentCoupon.couponContent && radioCurrent === 'weixin'"
  73. >¥ {{ getDifference(orderMoney, couponPopup.currentCoupon.couponContent).toFixed(2) }}</text
  74. >
  75. <text class="original-money" :class="couponPopup.currentCoupon.couponContent && radioCurrent === 'weixin' && 'original-discount-money'"
  76. >¥ {{ orderMoney }}</text
  77. >
  78. </view>
  79. <view class="pay-btn">
  80. <u-button type="primary" shape="circle" :disabled="!radioCurrent" @click="immediatePayment">立即支付</u-button>
  81. </view>
  82. </view>
  83. </u-modal>
  84. <!-- 选择优惠券弹框 -->
  85. <u-popup v-model="couponPopup.show" mode="top" length="100%">
  86. <view class="coupon-popup">
  87. <u-navbar
  88. back-text=""
  89. title="我的优惠券"
  90. :background="couponPopup.background"
  91. title-color="#fff"
  92. back-icon-color="#fff"
  93. :custom-back="customBack"
  94. />
  95. <view class="coupon-popup-list">
  96. <template v-if="couponPopup.couponList.length">
  97. <radio-group @change="couponRadioChange">
  98. <view class="coupon-popup-list-item" v-for="(item, index) in couponPopup.couponList" :key="index">
  99. <view class="coupon-popup-list-item-top">
  100. <view class="coupon-popup-list-item-top-left">
  101. <view class="cplitl-left">
  102. <view>
  103. <text>¥</text>
  104. <text>{{ item.couponContent }}</text>
  105. </view>
  106. <view class="cplitl-left-bottom">{{ Number(item.threshold) > 0 ? `停车时长满${item.threshold}分钟` : '无门槛' }}</view>
  107. </view>
  108. <view class="cplitl-right">
  109. <view>{{ item.couponName }}</view>
  110. <view>有限期:剩余{{ calcValidity(item.startTime, item.endTime) }}</view>
  111. </view>
  112. </view>
  113. <view class="coupon-popup-list-item-top-right">
  114. <radio color="#FF6D6D" :value="item.id" :checked="item.id === couponPopup.radioCurrent" @click="couponItemClick(item)" />
  115. </view>
  116. </view>
  117. <view class="coupon-popup-list-item-bottom">
  118. 适用停车点:
  119. <template v-if="item.parkList">
  120. <template v-if="item.parkList.length > 1"> 适用多个停车点 </template>
  121. <template v-else> 仅限{{ item.parkList.map((item) => item.parkName).join('、') }} </template>
  122. <template v-if="item.parkList && item.parkList.length > 1">
  123. <view class="cplib-point">
  124. <u-read-more
  125. text-indent="0"
  126. show-height="0"
  127. :toggle="true"
  128. :shadow-style="{ backgroundImage: 'none' }"
  129. fontSize="20rpx"
  130. close-text="展开所有停车点"
  131. >
  132. <view class="cplib-point-content">{{ item.parkList.map((item) => item.parkName).join('、') }}</view>
  133. </u-read-more>
  134. </view>
  135. </template>
  136. </template>
  137. </view>
  138. </view>
  139. </radio-group>
  140. </template>
  141. <template v-else>
  142. <u-empty text="没有适合的优惠券" mode="coupon" margin-top="300"></u-empty>
  143. </template>
  144. </view>
  145. <view class="coupon-popup-btn">
  146. <u-button type="primary" shape="circle" @click="confimCoupon">确 定</u-button>
  147. </view>
  148. </view>
  149. </u-popup>
  150. <u-toast ref="uToast" />
  151. </view>
  152. </template>
  153. <script>
  154. import { getEnvIsWx, getEnvIsAlipay } from '@/utils/judgEnvironment.js';
  155. import $wxPay from '@/utils/wxPay.js';
  156. export default {
  157. props: {
  158. // 订单数组
  159. curOrderList: {
  160. type: Array,
  161. default: null
  162. },
  163. // 设备编号
  164. deviceNo: {
  165. type: String,
  166. default: null
  167. },
  168. // 地磁支付需要字段
  169. payeeId: {
  170. type: String,
  171. default: undefined
  172. },
  173. // 地磁支付需要字段
  174. payeeName: {
  175. type: String,
  176. default: undefined
  177. },
  178. // 扫码支付需要字段
  179. sanPay: {
  180. type: Boolean,
  181. default: false
  182. },
  183. // 追缴类型
  184. pursueType: {
  185. type: String,
  186. default: undefined
  187. },
  188. // 车牌号
  189. vehicleNo: {
  190. type: String,
  191. default: undefined
  192. },
  193. // 跳转页面
  194. jumpUrl: {
  195. type: String,
  196. default: null
  197. },
  198. // 出口扫码 接口不一样
  199. exportFlag: {
  200. type: Boolean,
  201. default: false
  202. },
  203. // 区分包月支付
  204. isMonthPay: {
  205. type: Boolean,
  206. default: false
  207. },
  208. // 包月id
  209. monthId: {
  210. type: String,
  211. default: null
  212. }
  213. },
  214. data() {
  215. return {
  216. // 支付弹框显示
  217. payWayPop: false,
  218. // 是否微信环境
  219. wxEnv: true,
  220. // 支付宝环境
  221. alipayEnv: true,
  222. // 支付方式选择
  223. radioCurrent: '',
  224. // 订单金额
  225. orderMoney: '',
  226. // 显示优惠券选项
  227. isShowCoupon: false,
  228. // 是否取消优惠券标识
  229. isCancelCoupon: false,
  230. // 选择优惠券弹框
  231. couponPopup: {
  232. // 弹框标识
  233. show: false,
  234. // 优惠券列表
  235. couponList: [],
  236. // 优惠券选中项value
  237. radioCurrent: '',
  238. // navbar背景
  239. background: {
  240. backgroundColor: '#008CFF'
  241. },
  242. // 优惠券选中项
  243. currentCoupon: {}
  244. }
  245. };
  246. },
  247. methods: {
  248. /**
  249. * 打开弹框触发
  250. * @date 2023-02-17
  251. * @param {any} details
  252. * @param {any} numType single 单笔订单 multiple 多比订单 用于区分多笔订单不能使用优惠券
  253. * @param {any} orderType road 路段订单 parking 停车场订单 用于区分路段订单不使用优惠券
  254. * @returns {any}
  255. */
  256. openPopup(details, numType = 'single', orderType = 'road') {
  257. this.wxEnv = getEnvIsWx();
  258. this.alipayEnv = getEnvIsAlipay();
  259. this.payWayPop = true;
  260. this.orderMoney = details.payAmount.toFixed(2);
  261. if (numType === 'single' && orderType === 'parking' && !this.isMonthPay) {
  262. this.isShowCoupon = true;
  263. this.isCancelCoupon = true;
  264. this.getCouponList(details.id);
  265. }
  266. },
  267. /**
  268. * 获取优惠券列表
  269. * @date 2023-02-17
  270. * @param {any} orderId
  271. * @returns {any}
  272. */
  273. getCouponList(orderId) {
  274. this.$u.api.getCouponByOrderIdApi({ orderId }).then((res) => {
  275. this.couponPopup.couponList = res?.data ?? [];
  276. });
  277. },
  278. /**
  279. * 选中支付类型
  280. * @date 2023-02-17
  281. * @param {any} {detail}
  282. * @returns {any}
  283. */
  284. payRadioChange({ detail }) {
  285. this.radioCurrent = detail.value;
  286. },
  287. /**
  288. * 选中优惠券
  289. * @date 2023-02-17
  290. * @returns {any}
  291. */
  292. chooseCoupon() {
  293. this.couponPopup.show = true;
  294. },
  295. /**
  296. * 贵阳银行支付
  297. * @param {Array} orderList 需要支付的订单号组成的数组
  298. * @param {String} deviceNo 设备编号(只有车位锁部分有)
  299. * */
  300. async gyBankPay() {
  301. const params = {
  302. orderList: this.curOrderList,
  303. deviceNo: this.deviceNo,
  304. jumpUrl: this.jumpUrl,
  305. payeeId: this.payeeId,
  306. payeeName: this.payeeName,
  307. pursueType: this.pursueType,
  308. vehicleNo: this.vehicleNo,
  309. sanPay: this.sanPay
  310. };
  311. const apiCall = this.exportFlag ? this.$u.api.quickPayExportApi : this.$u.api.payGzbank;
  312. try {
  313. const res = await apiCall({ ...params });
  314. if (res.data.needPay) {
  315. let payUrl = res.data.url;
  316. location.href = payUrl;
  317. } else {
  318. this.showToast('无需支付', 'info');
  319. setTimeout(() => {
  320. uni.hideLoading();
  321. location.reload();
  322. }, 1000);
  323. }
  324. } catch (err) {
  325. // this.showToast(err.msg, 'error');
  326. }
  327. },
  328. /**
  329. * @description: 贵阳银行包月支付
  330. * @return {*}
  331. */
  332. gyBankMonthPay() {
  333. this.$u.api
  334. .monthPay({
  335. monthId: this.monthId,
  336. jumpUrl: this.jumpUrl
  337. })
  338. .then((res) => {
  339. if (res.code === 200) {
  340. location.href = res?.data?.url;
  341. } else {
  342. this.showToast(res?.msg, 'error');
  343. }
  344. })
  345. .catch((err) => {
  346. this.showToast('无法调起支付', 'error');
  347. });
  348. },
  349. /**
  350. * 聚合支付
  351. * */
  352. juhePay() {
  353. this.getWXPayByJava(this.curOrderList, this.deviceNo);
  354. },
  355. /**
  356. * @description: 聚合包月支付
  357. * @return {*}
  358. */
  359. juheMonthPay() {
  360. // 支付成功跳转到包月页面
  361. let params = {
  362. monthId: this.monthId,
  363. jumpUrl: this.jumpUrl
  364. };
  365. this.$u.api
  366. .monthlyWxPay(params)
  367. .then((res) => {
  368. if (res.code === 200) {
  369. localStorage.setItem('jumpUrl', this.jumpUrl);
  370. location.href = res.data.qrCodeUrl;
  371. }
  372. })
  373. .catch((err) => {
  374. this.showToast(`无法调起${this.alipayEnv ? '支付宝' : this.wxEnv ? '微信' : '聚合'}支付!`, 'error');
  375. });
  376. },
  377. /**
  378. * 微信支付
  379. */
  380. wechatPay() {
  381. const params = {
  382. orderList: this.curOrderList,
  383. openid: this.vuex_wxinfo.openId,
  384. deviceNo: this.deviceNo || undefined,
  385. payeeId: this.payeeId || undefined,
  386. payeeName: this.payeeName || undefined,
  387. vehicleNo: this.vehicleNo,
  388. sanPay: this.sanPay
  389. };
  390. if (this.couponPopup.radioCurrent) {
  391. params.couponMemberId = this.couponPopup.radioCurrent;
  392. }
  393. if (this.exportFlag) {
  394. this.$u.api.parkingWechatPayApi(params).then((res) => {
  395. if (res.code === 200) {
  396. if (res.data.needPay) {
  397. $wxPay.wexinPay(res.data.wx).then((r) => {
  398. switch (Number(r.code)) {
  399. case 0: // 成功
  400. //#ifdef H5
  401. window.location.reload();
  402. //#endif
  403. break;
  404. case 1: // 取消
  405. this.$u.api
  406. .updateCouponStatusApi({
  407. orderList: this.curOrderList
  408. })
  409. .then((res) => {
  410. if (res.code === 200) {
  411. this.showToast('已取消支付', 'info');
  412. window.location.reload();
  413. }
  414. });
  415. break;
  416. case 2: // 支付失败
  417. this.showToast('支付失败,请检查!', 'error');
  418. break;
  419. }
  420. });
  421. } else {
  422. this.showToast('无需支付', 'info');
  423. setTimeout(() => {
  424. uni.hideLoading();
  425. location.reload();
  426. }, 1000);
  427. }
  428. }
  429. });
  430. } else {
  431. this.$u.api.wechatPayApi(params).then((res) => {
  432. if (res.code === 200) {
  433. if (res.data.needPay) {
  434. $wxPay.wexinPay(res.data.wx).then((r) => {
  435. switch (Number(r.code)) {
  436. case 0: // 成功
  437. //#ifdef H5
  438. window.location.reload();
  439. //#endif
  440. break;
  441. case 1: // 取消
  442. this.$u.api
  443. .updateCouponStatusApi({
  444. orderList: this.curOrderList
  445. })
  446. .then((res) => {
  447. if (res.code === 200) {
  448. this.$refs.uToast.show({
  449. title: '已取消支付',
  450. type: 'info'
  451. });
  452. window.location.reload();
  453. }
  454. });
  455. break;
  456. case 2: // 支付失败
  457. this.$refs.uToast.show({
  458. title: '支付失败,请检查!',
  459. type: 'error'
  460. });
  461. break;
  462. }
  463. });
  464. } else {
  465. this.$refs.uToast.show({
  466. title: '无需支付',
  467. type: 'info'
  468. });
  469. setTimeout(() => {
  470. uni.hideLoading();
  471. location.reload();
  472. }, 1000);
  473. }
  474. }
  475. });
  476. }
  477. },
  478. /**
  479. * @description: 微信包月支付
  480. * @return {*}
  481. */
  482. wechatMonthPay() {
  483. this.$u.api
  484. .wechatMonthlyPayapi({
  485. monthId: this.monthId,
  486. openid: this.vuex_wxinfo.openId
  487. })
  488. .then((r) => {
  489. if (r.code === 200) {
  490. $wxPay.wexinPay(r.data.wx).then((res) => {
  491. switch (Number(res.code)) {
  492. case 0: // 成功
  493. //#ifdef H5
  494. location.href = this.jumpUrl;
  495. //#endif
  496. break;
  497. case 1: // 取消
  498. this.showToast('已取消支付', 'info');
  499. break;
  500. case 2: // 支付失败
  501. this.showToast('支付失败,请检查!', 'error');
  502. break;
  503. }
  504. });
  505. }
  506. });
  507. },
  508. /**
  509. * 直接通过后台获取贵阳银行微信支付地址
  510. * @param {Array} list 需要支付的订单组合数组
  511. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  512. * */
  513. getWXPayByJava(orderList, deviceNo) {
  514. let params = {
  515. orderList: orderList,
  516. openid: this.vuex_wxinfo.openId,
  517. jumpUrl: this.jumpUrl,
  518. deviceNo: deviceNo ? deviceNo : null,
  519. payeeId: this.payeeId,
  520. payeeName: this.payeeName,
  521. pursueType: this.pursueType,
  522. vehicleNo: this.vehicleNo,
  523. sanPay: this.sanPay
  524. };
  525. if (this.exportFlag) {
  526. this.$u.api
  527. .polyPayExportApi(params)
  528. .then((res) => {
  529. if (res.code === 200) {
  530. if (res.data.needPay) {
  531. localStorage.setItem('jumpUrl', this.jumpUrl);
  532. location.href = res.data.qrCodeUrl;
  533. } else {
  534. this.showToast('无需支付', 'info');
  535. setTimeout(() => {
  536. uni.hideLoading();
  537. location.href = this.jumpUrl;
  538. }, 1000);
  539. }
  540. } else {
  541. uni.hideLoading();
  542. }
  543. })
  544. .catch((err) => {
  545. this.showToast(`无法调起${this.alipayEnv ? '支付宝' : this.wxEnv ? '微信' : '聚合'}支付!`, 'error');
  546. });
  547. } else {
  548. this.$u.api
  549. .ordinaryWxPay(params)
  550. .then((res) => {
  551. if (res.code === 200) {
  552. if (res.data.needPay) {
  553. localStorage.setItem('jumpUrl', this.jumpUrl);
  554. location.href = res.data.qrCodeUrl;
  555. } else {
  556. this.showToast('无需支付', 'info');
  557. setTimeout(() => {
  558. uni.hideLoading();
  559. location.href = this.jumpUrl;
  560. }, 1000);
  561. }
  562. } else {
  563. uni.hideLoading();
  564. }
  565. })
  566. .catch((err) => {
  567. this.showToast(`无法调起${this.alipayEnv ? '支付宝' : this.wxEnv ? '微信' : '聚合'}支付!`, 'info');
  568. });
  569. }
  570. },
  571. /**
  572. * 支付弹框支付触发
  573. * @date 2023-02-17
  574. * @returns {any}
  575. */
  576. modalClose() {
  577. Object.assign(this, {
  578. payWayPop: false,
  579. wxEnv: true,
  580. alipayEnv: true,
  581. radioCurrent: '',
  582. orderMoney: '',
  583. isShowCoupon: false,
  584. isCancelCoupon: false,
  585. couponPopup: {
  586. show: false,
  587. couponList: [],
  588. radioCurrent: '',
  589. background: {
  590. backgroundColor: '#008CFF'
  591. },
  592. currentCoupon: {}
  593. }
  594. });
  595. this.$emit('closePaymentMethod');
  596. },
  597. /**
  598. * 关闭优惠券弹框
  599. * @date 2023-02-17
  600. * @returns {any}
  601. */
  602. customBack() {
  603. this.couponPopup.show = false;
  604. },
  605. /**
  606. * 优惠券单选触发
  607. * @date 2023-02-17
  608. * @param {any} val
  609. * @returns {any}
  610. */
  611. couponRadioChange(val) {
  612. // this.couponPopup.radioCurrent = val.detail.value;
  613. // this.couponPopup.currentCoupon = this.couponPopup.couponList.find((item) => item.id === this.couponPopup.radioCurrent);
  614. },
  615. couponItemClick(item) {
  616. if (item.id === this.couponPopup.radioCurrent) {
  617. this.couponPopup.radioCurrent = '';
  618. } else {
  619. this.couponPopup.radioCurrent = item.id;
  620. }
  621. },
  622. /**
  623. * 优惠券确认
  624. * @date 2023-02-17
  625. * @returns {any}
  626. */
  627. confimCoupon() {
  628. if (this.couponPopup.radioCurrent) {
  629. this.couponPopup.currentCoupon = this.couponPopup.couponList.find((item) => item.id === this.couponPopup.radioCurrent);
  630. } else {
  631. this.couponPopup.currentCoupon = {};
  632. }
  633. this.couponPopup.show = false;
  634. },
  635. /**
  636. * 立即支付
  637. * @date 2023-02-17
  638. * @returns {any}
  639. */
  640. immediatePayment() {
  641. switch (this.radioCurrent) {
  642. case 'weixin': // 微信支付
  643. this.isMonthPay ? this.wechatMonthPay() : this.wechatPay();
  644. break;
  645. case 'gzyh':
  646. this.isMonthPay ? this.gyBankMonthPay() : this.gyBankPay();
  647. break;
  648. case 'juhe':
  649. this.isMonthPay ? this.juheMonthPay() : this.juhePay();
  650. break;
  651. }
  652. },
  653. /**
  654. * 计算剩余时间
  655. * @date 2022-02-17
  656. * @param {any} datetime
  657. * @returns {any}
  658. */
  659. calcValidity(startTime, endTime) {
  660. let endTimeStr = new Date(endTime).valueOf(),
  661. nowTimeStr = new Date(startTime).valueOf() < Date.now() ? Date.now() : new Date(startTime).valueOf(),
  662. remainTimeStr = endTimeStr - nowTimeStr,
  663. day = Math.floor(remainTimeStr / (1000 * 3600 * 24)),
  664. dayOver = remainTimeStr % (1000 * 3600 * 24),
  665. hours = Math.floor(dayOver / (3600 * 1000)),
  666. hourOver = dayOver % (3600 * 1000),
  667. minutes = Math.floor(hourOver / (60 * 1000));
  668. return `${day}天${hours}小时${minutes}分`;
  669. },
  670. getDifference(a, b) {
  671. return a > b ? a - b : 0;
  672. },
  673. /**
  674. * @description: 显示报错信息
  675. * @param {*} title
  676. * @param {*} type
  677. * @return {*}
  678. */
  679. showToast(title, type = 'error') {
  680. this.$refs.uToast.show({ title, type });
  681. }
  682. }
  683. };
  684. </script>
  685. <style lang="scss" scoped>
  686. @import './choosePayment.scss';
  687. </style>