choosePayment.vue 20 KB

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