choosePayment.vue 26 KB

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