choosePayment.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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.wxEnv = getEnvIsWx();
  234. this.payWayPop = true;
  235. this.orderMoney = details.payAmount.toFixed(2);
  236. if (numType === 'single' && orderType === 'parking') {
  237. this.isShowCoupon = true;
  238. this.getCouponList(details.id);
  239. }
  240. },
  241. /**
  242. * 描述
  243. * @date 2023-02-17
  244. * @param {any} orderId
  245. * @returns {any}
  246. */
  247. getCouponList(orderId) {
  248. this.$u.api.getCouponByOrderIdApi({ orderId }).then((res) => {
  249. this.couponPopup.couponList = res?.data ?? [];
  250. // if (this.couponPopup.couponList.length) {
  251. // this.couponPopup.currentCoupon = this.couponPopup.couponList[0];
  252. // this.couponPopup.radioCurrent = this.couponPopup.couponList[0].id;
  253. // }
  254. });
  255. },
  256. /**
  257. * 选中支付类型
  258. * @date 2023-02-17
  259. * @param {any} {detail}
  260. * @returns {any}
  261. */
  262. payRadioChange({ detail }) {
  263. this.radioCurrent = detail.value;
  264. },
  265. /**
  266. * 选中优惠券
  267. * @date 2023-02-17
  268. * @returns {any}
  269. */
  270. chooseCoupon() {
  271. this.couponPopup.show = true;
  272. },
  273. /**
  274. * 贵阳银行支付
  275. * @param {Array} orderList 需要支付的订单号组成的数组
  276. * @param {String} deviceNo 设备编号(只有车位锁部分有)
  277. * */
  278. gyBankPay() {
  279. const params = {
  280. orderList: this.curOrderList,
  281. deviceNo: this.deviceNo,
  282. jumpUrl: this.jumpUrl,
  283. payeeId: this.payeeId,
  284. payeeName: this.payeeName,
  285. pursueType: this.pursueType,
  286. vehicleNo: this.vehicleNo,
  287. sanPay: this.sanPay
  288. };
  289. if (this.exportFlag == true) {
  290. this.$u.api
  291. .quickPayExportApi(params)
  292. .then((res) => {
  293. if (res.data.needPay) {
  294. let payUrl = res.data.url;
  295. location.href = payUrl;
  296. } else {
  297. this.$refs.uToast.show({
  298. title: '无需支付',
  299. type: 'info'
  300. });
  301. setTimeout(() => {
  302. uni.hideLoading();
  303. location.reload();
  304. }, 1000);
  305. }
  306. })
  307. .catch((err) => {
  308. this.$refs.uToast.show({
  309. title: err.msg,
  310. type: 'error'
  311. });
  312. });
  313. } else {
  314. this.$u.api
  315. .payGzbank(params)
  316. .then((res) => {
  317. if (res.data.needPay) {
  318. let payUrl = res.data.url;
  319. location.href = payUrl;
  320. } else {
  321. this.$refs.uToast.show({
  322. title: '无需支付',
  323. type: 'info'
  324. });
  325. setTimeout(() => {
  326. uni.hideLoading();
  327. location.reload();
  328. }, 1000);
  329. }
  330. })
  331. .catch((err) => {
  332. this.$refs.uToast.show({
  333. title: err.msg,
  334. type: 'error'
  335. });
  336. });
  337. }
  338. },
  339. /**
  340. * 聚合支付
  341. * */
  342. juhePay() {
  343. this.getWXPayByJava(this.curOrderList, this.deviceNo);
  344. },
  345. /**
  346. * 微信支付
  347. */
  348. wechatPay() {
  349. const params = {
  350. orderList: this.curOrderList,
  351. openid: this.vuex_wxinfo.openId,
  352. deviceNo: this.deviceNo || undefined,
  353. payeeId: this.payeeId || undefined,
  354. payeeName: this.payeeName || undefined,
  355. vehicleNo: this.vehicleNo,
  356. sanPay: this.sanPay
  357. };
  358. if (this.couponPopup.radioCurrent) {
  359. params.couponMemberId = this.couponPopup.radioCurrent;
  360. }
  361. if (this.exportFlag) {
  362. this.$u.api.parkingWechatPayApi(params).then((res) => {
  363. if (res.code === 200) {
  364. if (res.data.needPay) {
  365. $wxPay.wexinPay(res.data.wx).then((r) => {
  366. switch (Number(r.code)) {
  367. case 0: // 成功
  368. //#ifdef H5
  369. window.location.reload();
  370. //#endif
  371. break;
  372. case 1: // 取消
  373. this.$u.api
  374. .updateCouponStatusApi({
  375. orderList: this.curOrderList
  376. })
  377. .then((res) => {
  378. if (res.code === 200) {
  379. this.$refs.uToast.show({
  380. title: '已取消支付',
  381. type: 'info'
  382. });
  383. window.location.reload();
  384. }
  385. });
  386. break;
  387. case 2: // 支付失败
  388. this.$refs.uToast.show({
  389. title: '支付失败,请检查!',
  390. type: 'error'
  391. });
  392. break;
  393. }
  394. });
  395. } else {
  396. this.$refs.uToast.show({
  397. title: '无需支付',
  398. type: 'info'
  399. });
  400. setTimeout(() => {
  401. uni.hideLoading();
  402. location.reload();
  403. }, 1000);
  404. }
  405. }
  406. });
  407. } else {
  408. this.$u.api.wechatPayApi(params).then((res) => {
  409. if (res.code === 200) {
  410. if (res.data.needPay) {
  411. $wxPay.wexinPay(res.data.wx).then((r) => {
  412. switch (Number(r.code)) {
  413. case 0: // 成功
  414. //#ifdef H5
  415. window.location.reload();
  416. //#endif
  417. break;
  418. case 1: // 取消
  419. this.$u.api
  420. .updateCouponStatusApi({
  421. orderList: this.curOrderList
  422. })
  423. .then((res) => {
  424. if (res.code === 200) {
  425. this.$refs.uToast.show({
  426. title: '已取消支付',
  427. type: 'info'
  428. });
  429. window.location.reload();
  430. }
  431. });
  432. break;
  433. case 2: // 支付失败
  434. this.$refs.uToast.show({
  435. title: '支付失败,请检查!',
  436. type: 'error'
  437. });
  438. break;
  439. }
  440. });
  441. } else {
  442. this.$refs.uToast.show({
  443. title: '无需支付',
  444. type: 'info'
  445. });
  446. setTimeout(() => {
  447. uni.hideLoading();
  448. location.reload();
  449. }, 1000);
  450. }
  451. }
  452. });
  453. }
  454. },
  455. /**
  456. * 直接通过后台获取贵阳银行微信支付地址
  457. * @param {Array} list 需要支付的订单组合数组
  458. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  459. * */
  460. getWXPayByJava(orderList, deviceNo) {
  461. let params = {
  462. orderList: orderList,
  463. openid: this.vuex_wxinfo.openId,
  464. jumpUrl: this.jumpUrl,
  465. deviceNo: deviceNo ? deviceNo : null,
  466. payeeId: this.payeeId,
  467. payeeName: this.payeeName,
  468. pursueType: this.pursueType,
  469. vehicleNo: this.vehicleNo,
  470. sanPay: this.sanPay
  471. };
  472. if (this.exportFlag) {
  473. this.$u.api
  474. .polyPayExportApi(params)
  475. .then((res) => {
  476. if (res.code === 200) {
  477. if (res.data.needPay) {
  478. localStorage.setItem('jumpUrl', this.jumpUrl);
  479. location.href = res.data.qrCodeUrl;
  480. } else {
  481. this.$refs.uToast.show({
  482. title: '无需支付',
  483. type: 'info'
  484. });
  485. setTimeout(() => {
  486. uni.hideLoading();
  487. location.href = this.jumpUrl;
  488. }, 1000);
  489. }
  490. } else {
  491. uni.hideLoading();
  492. }
  493. })
  494. .catch((err) => {
  495. this.$refs.uToast.show({
  496. title: '无法调起微信支付!',
  497. type: 'error'
  498. });
  499. });
  500. } else {
  501. this.$u.api
  502. .ordinaryWxPay(params)
  503. .then((res) => {
  504. if (res.code === 200) {
  505. if (res.data.needPay) {
  506. localStorage.setItem('jumpUrl', this.jumpUrl);
  507. location.href = res.data.qrCodeUrl;
  508. } else {
  509. this.$refs.uToast.show({
  510. title: '无需支付',
  511. type: 'info'
  512. });
  513. setTimeout(() => {
  514. uni.hideLoading();
  515. location.href = this.jumpUrl;
  516. }, 1000);
  517. }
  518. } else {
  519. uni.hideLoading();
  520. }
  521. })
  522. .catch((err) => {
  523. this.$refs.uToast.show({
  524. title: '无法调起微信支付!',
  525. type: 'error'
  526. });
  527. });
  528. }
  529. },
  530. /**
  531. * 关闭弹框
  532. * */
  533. closePaymentMethod() {
  534. this.modalClose();
  535. this.$emit('closePaymentMethod');
  536. },
  537. /**
  538. * 支付弹框支付触发
  539. * @date 2023-02-17
  540. * @returns {any}
  541. */
  542. modalClose() {
  543. (this.wxEnv = true),
  544. (this.radioCurrent = ''),
  545. (this.orderMoney = ''),
  546. (this.isShowCoupon = false),
  547. (this.couponPopup = {
  548. show: false,
  549. couponList: [],
  550. radioCurrent: '',
  551. background: {
  552. backgroundColor: '#008CFF'
  553. },
  554. currentCoupon: {}
  555. });
  556. },
  557. /**
  558. * 关闭优惠券弹框
  559. * @date 2023-02-17
  560. * @returns {any}
  561. */
  562. customBack() {
  563. this.couponPopup.show = false;
  564. },
  565. /**
  566. * 优惠券单选触发
  567. * @date 2023-02-17
  568. * @param {any} val
  569. * @returns {any}
  570. */
  571. couponRadioChange(val) {
  572. // this.couponPopup.radioCurrent = val.detail.value;
  573. // this.couponPopup.currentCoupon = this.couponPopup.couponList.find((item) => item.id === this.couponPopup.radioCurrent);
  574. },
  575. couponItemClick(item) {
  576. if (item.id === this.couponPopup.radioCurrent) {
  577. this.couponPopup.radioCurrent = '';
  578. } else {
  579. this.couponPopup.radioCurrent = item.id;
  580. }
  581. },
  582. /**
  583. * 优惠券确认
  584. * @date 2023-02-17
  585. * @returns {any}
  586. */
  587. confimCoupon() {
  588. if (this.couponPopup.radioCurrent) {
  589. this.couponPopup.currentCoupon = this.couponPopup.couponList.find((item) => item.id === this.couponPopup.radioCurrent);
  590. } else {
  591. this.couponPopup.currentCoupon = {};
  592. }
  593. this.couponPopup.show = false;
  594. },
  595. /**
  596. * 立即支付
  597. * @date 2023-02-17
  598. * @returns {any}
  599. */
  600. immediatePayment() {
  601. switch (this.radioCurrent) {
  602. case 'weixin': // 微信支付
  603. this.wechatPay();
  604. break;
  605. case 'gzyh':
  606. this.gyBankPay();
  607. break;
  608. case 'juhe':
  609. this.juhePay();
  610. break;
  611. }
  612. },
  613. /**
  614. * 计算剩余时间
  615. * @date 2022-02-17
  616. * @param {any} datetime
  617. * @returns {any}
  618. */
  619. calcValidity(startTime, endTime) {
  620. let endTimeStr = new Date(endTime).valueOf(),
  621. nowTimeStr = new Date(startTime).valueOf() < Date.now() ? Date.now() : new Date(startTime).valueOf(),
  622. remainTimeStr = endTimeStr - nowTimeStr,
  623. day = Math.floor(remainTimeStr / (1000 * 3600 * 24)),
  624. dayOver = remainTimeStr % (1000 * 3600 * 24),
  625. hours = Math.floor(dayOver / (3600 * 1000)),
  626. hourOver = dayOver % (3600 * 1000),
  627. minutes = Math.floor(hourOver / (60 * 1000));
  628. return `${day}天${hours}小时${minutes}分`;
  629. },
  630. getDifference(a, b) {
  631. return a > b ? a - b : 0;
  632. }
  633. }
  634. };
  635. </script>
  636. <style lang="scss" scoped>
  637. @import './choosePayment.scss';
  638. </style>