choosePayment.vue 21 KB

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