choosePayment.vue 19 KB

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