choosePayment.vue 22 KB

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