choosePayment.vue 26 KB

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