choosePayment.vue 28 KB

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