choosePayment.vue 22 KB

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