handleMonthly20230315.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <view class="handle-monthly">
  3. <view class="handle-monthly-item">
  4. <view>车牌选择</view>
  5. <view class="choose-license" @click="isShowCarLicense = true">
  6. <view>{{ form.carLicense.label || '未选车牌' }}</view>
  7. <u-icon name="arrow-down" color="#7B7B7B" size="30"></u-icon>
  8. </view>
  9. </view>
  10. <u-select v-model="isShowCarLicense" :list="carLicenseList" :default-value="carLicenseDefaultValue" @confirm="carLicenseListConfirm"></u-select>
  11. <view class="handle-monthly-item">
  12. <view>车辆信息</view>
  13. <view>{{ form.carLicense.value | verifyStatusFilter }}</view>
  14. </view>
  15. <view class="handle-monthly-item">
  16. <view>包月金额</view>
  17. <view class="handle-monthly-money">{{ form.monthAmount || 0 }}元</view>
  18. </view>
  19. <view
  20. class="handle-monthly-item"
  21. v-if="monthlyRuleObj.giveFlag && Number(monthlyRuleObj.giveFlag) === 1"
  22. :class="{ pb20: monthlyRuleObj.minMonth && form.month >= monthlyRuleObj.minMonth && Number(monthlyRuleObj.giveFlag) === 1 }"
  23. >
  24. <view>包月时长</view>
  25. <view class="handle-monthly-time-long">
  26. <button @click="reduceMonthNum()">-</button>
  27. <view>{{ form.month || 0 }}个月</view>
  28. <button @click="addMonthNum()">+</button>
  29. </view>
  30. <view
  31. class="handle-monthly-time-tips"
  32. v-if="monthlyRuleObj.minMonth && form.month >= monthlyRuleObj.minMonth && Number(monthlyRuleObj.giveFlag) === 1"
  33. >
  34. 赠送提示:可获得{{ freeMonthNum }}个月的免费停车时长
  35. </view>
  36. </view>
  37. <view class="handle-monthly-item" v-else>
  38. <view>包月时长</view>
  39. <view class="handle-monthly-time-long">
  40. <button @click="reduceMonthNum()">-</button>
  41. <view>{{ form.month || 0 }}个月</view>
  42. <button @click="addMonthNum()">+</button>
  43. </view>
  44. </view>
  45. <view class="handle-monthly-item">
  46. <view>有效期限</view>
  47. <view>{{ dateRange || '-' }}</view>
  48. </view>
  49. <view class="handle-monthly-explain">
  50. <u-parse :html="monthlyContent"></u-parse>
  51. </view>
  52. <view class="handle-monthly-confirm-button">
  53. <template v-if="carLicenseList.length && form.carLicense && form.carLicense.label">
  54. <u-button type="primary" :loading="loading" @click="submit(roadNo)">确认包月</u-button>
  55. </template>
  56. <template v-else>
  57. <u-button>未选车牌</u-button>
  58. </template>
  59. </view>
  60. <u-modal
  61. ref="uModal"
  62. v-model="payWayPop"
  63. :title-style="{ color: '#1E1E1E', fontSize: '34rpx' }"
  64. title="选择支付方式"
  65. width="550rpx"
  66. :show-cancel-button="true"
  67. :mask-close-able="false"
  68. confirm-text="立即支付"
  69. confirm-color="#fff"
  70. :confirm-style="{ backgroundColor: '#008CFF' }"
  71. :async-close="true"
  72. @confirm="immediatePayment"
  73. @cancel="cancel"
  74. >
  75. <view class="pay-content">
  76. <view class="pay-list">
  77. <radio-group @change="payRadioChange">
  78. <!-- #ifdef H5 || MP-WEIXIN -->
  79. <view class="pay-list-item" v-if="wxEnv">
  80. <view class="pay-list-item-image">
  81. <image class="image" src="/static/img/wechat-icon-new.png" mode="aspectFit" />
  82. <view>微信支付</view>
  83. </view>
  84. <view class="radioBox">
  85. <radio color="#2DCF8C" value="weixin" :checked="'weixin' === radioCurrent" />
  86. </view>
  87. </view>
  88. <!-- #endif -->
  89. <view class="pay-list-item">
  90. <view class="pay-list-item-image">
  91. <image class="image" src="/static/img/gy-icon-new.png" mode="aspectFit" />
  92. <view>贵州银行</view>
  93. </view>
  94. <view class="radioBox">
  95. <radio color="#2DCF8C" value="gzyh" :checked="'gzyh' === radioCurrent" />
  96. </view>
  97. </view>
  98. <view class="pay-list-item">
  99. <view class="pay-list-item-image">
  100. <image class="image" src="/static/img/juhe-icon-new.png" mode="aspectFit" />
  101. <view>聚合支付</view>
  102. </view>
  103. <view class="radioBox">
  104. <radio color="#2DCF8C" value="juhe" :checked="'juhe' === radioCurrent" />
  105. </view>
  106. </view>
  107. </radio-group>
  108. </view>
  109. <view class="pay-money"> 金额:¥{{ orderMoney }} </view>
  110. </view>
  111. </u-modal>
  112. <u-toast ref="uToast" />
  113. </view>
  114. </template>
  115. <script>
  116. import { getEnvIsWx } from '@/utils/judgEnvironment.js';
  117. import $wxPay from '@/utils/wxPay.js';
  118. export default {
  119. data() {
  120. return {
  121. startTime: '',
  122. endTime: '',
  123. payUrl: '',
  124. monthId: '',
  125. vehicleNo: '',
  126. monthEndTime: '',
  127. monthStartTime: '',
  128. lastActiveDate: null,
  129. roadNo: null,
  130. parkNo: null,
  131. carLicenseList: [],
  132. isShowCarLicense: false,
  133. form: {
  134. energyType: [],
  135. monthAmount: 0,
  136. carLicense: {},
  137. month: 1,
  138. dateRange: ''
  139. },
  140. label: '',
  141. payWayPop: false,
  142. jumpUrl: undefined,
  143. monthlyContent: '',
  144. carLicenseDefaultValue: [0],
  145. wxEnv: false,
  146. loading: false,
  147. type: 'road',
  148. monthlyRuleObj: {},
  149. freeMonthNum: 0,
  150. radioCurrent: '',
  151. orderMoney: '',
  152. };
  153. },
  154. watch: {
  155. 'form.month': {
  156. handler(val) {
  157. this.calcFreeMonthNum(val);
  158. },
  159. deep: true,
  160. immediate: false
  161. }
  162. },
  163. onLoad(page) {
  164. this.wxEnv = getEnvIsWx();
  165. this.getSysterms(0);
  166. if (page.vehicleNo && page.roadNo) {
  167. this.roadNo = page.roadNo;
  168. this.vehicleNo = page.vehicleNo;
  169. this.type = 'road';
  170. this.getMonthInfo(this.roadNo, this.vehicleNo);
  171. } else if (page.roadNo) {
  172. this.roadNo = page.roadNo;
  173. this.type = 'road';
  174. this.getMonthInfo(this.roadNo);
  175. } else if (page.vehicleNo && page.parkNo) {
  176. this.parkNo = page.parkNo;
  177. this.vehicleNo = page.vehicleNo;
  178. this.type = 'park';
  179. this.getMonthInfo(this.parkNo, this.vehicleNo);
  180. } else if (page.parkNo) {
  181. this.parkNo = page.parkNo;
  182. this.type = 'park';
  183. this.getMonthInfo(this.parkNo);
  184. }
  185. if (page.monthId) {
  186. this.monthId = page.monthId;
  187. this.payWayPop = true;
  188. }
  189. if (page.roadNo) {
  190. this.monthlyRuleDetails(page.roadNo);
  191. }
  192. const baseUrl = window.location.href.split('#')[0];
  193. let jumpUrl = baseUrl + '#/pages/center/monthly/monthly?type=' + this.type;
  194. this.jumpUrl = jumpUrl;
  195. },
  196. methods: {
  197. /**
  198. * 获取几个月的日期范围
  199. * {date} Date 起始日期,往后推一天
  200. * {monthNum} Number 往后月数
  201. * */
  202. getMonthRange(date, monthNum) {
  203. let Date1 = this.lastActiveDate;
  204. Date1 = new Date(Date1);
  205. const year = Date1.getFullYear();
  206. const month = Date1.getMonth() + 1;
  207. const day = Date1.getDate();
  208. const hours = Date1.getHours();
  209. const minutes = Date1.getMinutes();
  210. const seconds = Date1.getSeconds();
  211. let days = new Date(year, month, 0);
  212. days = days.getDate(); //获取当前日期中的月的天数
  213. let year2 = year;
  214. let month2 = parseInt(month) + parseInt(monthNum);
  215. if (month2 > 12) {
  216. year2 = parseInt(year2) + parseInt(parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12);
  217. month2 = parseInt(month2) % 12;
  218. }
  219. let day2 = day;
  220. let days2 = new Date(year2, month2, 0);
  221. days2 = days2.getDate();
  222. if (day2 > days2) {
  223. day2 = days2;
  224. }
  225. if (month2 < 10) {
  226. month2 = '0' + month2;
  227. }
  228. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day);
  229. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2);
  230. this.startTime = t1;
  231. this.endTime = t2;
  232. this.monthStartTime =
  233. year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' + seconds;
  234. this.monthEndTime = year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' + seconds;
  235. return t1 + '-' + t2;
  236. },
  237. /**
  238. * 月操作 减1
  239. * */
  240. reduceMonthNum() {
  241. if (this.form.month > 1) {
  242. this.form.month -= 1;
  243. this.form.dateRange = this.getMonthRange(new Date(), this.form.month + this.freeMonthNum);
  244. }
  245. },
  246. /**
  247. * 月操作 加1
  248. * */
  249. addMonthNum() {
  250. if (this.form.month >= 24) {
  251. this.$refs.uToast.show({
  252. title: '最多24月',
  253. type: 'warning'
  254. });
  255. return;
  256. }
  257. this.form.month += 1;
  258. this.form.dateRange = this.getMonthRange(new Date(), this.form.month + this.freeMonthNum);
  259. },
  260. carLicenseListConfirm(item) {
  261. this.form.carLicense = item[0];
  262. this.vehicleNo = item[0].label;
  263. this.getMonthInfo(this.roadNo, this.vehicleNo);
  264. },
  265. /**
  266. * 获取包月信息
  267. * @date 2022-10-09
  268. * @param {any} roadNo
  269. * @param {any} vehicleNo
  270. * @returns {any}
  271. */
  272. getMonthInfo(roadNo, vehicleNo) {
  273. const params = {
  274. vehicleNo
  275. };
  276. if (this.type === 'park') {
  277. params.parkNo = roadNo;
  278. } else {
  279. params.roadNo = roadNo;
  280. }
  281. this.$u.api
  282. .monthInfo(params)
  283. .then((res) => {
  284. if (res.code === 200 && res.data.vehicleList && res.data.vehicleList.length) {
  285. this.lastActiveDate = res.data.lastActiveDate;
  286. this.form.monthAmount = res.data.monthAmount;
  287. this.orderMoney = (Number(this.form.monthAmount) * Number(this.form.month)).toFixed(2);
  288. this.carLicenseList = [];
  289. let vehicleNoItem = null;
  290. res.data.vehicleList.forEach((item, index) => {
  291. const obj = {
  292. value: item.energyType,
  293. label: item.vehicleNo,
  294. energyType: item.energyType
  295. };
  296. if (this.vehicleNo == item.vehicleNo) {
  297. vehicleNoItem = obj;
  298. this.carLicenseDefaultValue = [index];
  299. }
  300. this.carLicenseList.push(obj);
  301. });
  302. // 判断是否url存在车牌号,存在则选中项默认选中
  303. if (vehicleNoItem) {
  304. this.form.carLicense = vehicleNoItem;
  305. } else {
  306. this.form.carLicense = this.carLicenseList[0];
  307. }
  308. }
  309. })
  310. .catch((err) => {
  311. console.log(err);
  312. });
  313. },
  314. /**
  315. * 获取包月规则详情
  316. * @date 2022-12-20
  317. * @param {any} roadNo
  318. * @returns {any}
  319. */
  320. monthlyRuleDetails(roadNo) {
  321. this.$u.api
  322. .monthlyRuleDetailsApi({
  323. roadNo
  324. })
  325. .then((res) => {
  326. if (res.code === 200) {
  327. this.monthlyRuleObj = res?.rows[0] ?? {};
  328. this.calcFreeMonthNum(this.form.month);
  329. }
  330. });
  331. },
  332. calcFreeMonthNum(val) {
  333. let freeNum = 0;
  334. if (this.monthlyRuleObj.giveFlag && Number(this.monthlyRuleObj.giveFlag) === 1) {
  335. // let remainNum = Number(val) % Number(this.monthlyRuleObj.minMonth)
  336. let timesNum = parseInt(Number(val) / Number(this.monthlyRuleObj.minMonth));
  337. if (timesNum > 0) {
  338. this.freeMonthNum = Number(timesNum) * Number(this.monthlyRuleObj.giveMonth);
  339. } else {
  340. this.freeMonthNum = 0;
  341. }
  342. }
  343. },
  344. /**
  345. * 提交包月信息
  346. * @date 2022-10-09
  347. * @param {any} roadNo
  348. * @returns {any}
  349. */
  350. submit(roadNo) {
  351. this.loading = true;
  352. const params = {
  353. vehicleNo: this.form.carLicense.label,
  354. energyType: this.form.carLicense.energyType,
  355. monthStartTime: this.monthStartTime,
  356. monthEndTime: this.monthEndTime,
  357. monthCount: this.form.month
  358. };
  359. if (this.type === 'park') {
  360. params.parkNo = this.parkNo;
  361. } else {
  362. params.roadNo = this.roadNo;
  363. }
  364. this.$u.api
  365. .createMonth(params)
  366. .then((res) => {
  367. if (res.code === 200) {
  368. this.monthId = res.data.monthId;
  369. this.orderMoney = (Number(this.form.monthAmount) * Number(this.form.month)).toFixed(2);
  370. this.payWayPop = true;
  371. } else {
  372. this.$refs.uToast.show({
  373. title: res.msg,
  374. type: 'error'
  375. });
  376. }
  377. this.loading = false;
  378. })
  379. .catch((err) => {
  380. this.$refs.uToast.show({
  381. title: '程序错误!',
  382. type: 'error'
  383. });
  384. this.loading = false;
  385. });
  386. },
  387. /**
  388. * 贵州银行包月支付
  389. * @date 2022-10-09
  390. * @returns {any}
  391. */
  392. gyBankPay() {
  393. this.$u.api
  394. .monthPay({
  395. monthId: this.monthId,
  396. jumpUrl: this.jumpUrl
  397. })
  398. .then((res) => {
  399. if (res.code === 200) {
  400. window.location.href = res.data.url;
  401. } else {
  402. this.$refs.uToast.show({
  403. title: res.msg,
  404. type: 'error'
  405. });
  406. this.jumpMonthList();
  407. }
  408. });
  409. },
  410. /**
  411. * 聚合支付直接通过后台获取贵阳银行微信支付地址
  412. * @date 2022-10-09
  413. * @returns {any}
  414. */
  415. juhePay() {
  416. // 支付成功跳转到包月页面
  417. let params = {
  418. monthId: this.monthId,
  419. openid: '',
  420. jumpUrl: this.jumpUrl
  421. };
  422. this.$u.api
  423. .monthlyWxPay(params)
  424. .then((res) => {
  425. if (res.code === 200) {
  426. localStorage.setItem('jumpUrl', this.jumpUrl);
  427. location.href = res.data.qrCodeUrl;
  428. } else {
  429. this.$refs.uToast.show({
  430. title: res.msg,
  431. type: 'error'
  432. });
  433. this.jumpMonthList();
  434. }
  435. })
  436. .catch((err) => {
  437. this.$refs.uToast.show({
  438. title: '无法调起微信支付!',
  439. type: 'error'
  440. });
  441. });
  442. },
  443. /**
  444. * 微信支付
  445. * @date 2022-10-09
  446. * @returns {any}
  447. */
  448. wechatPay() {
  449. this.$u.api
  450. .wechatMonthlyPayapi({
  451. monthId: this.monthId,
  452. openid: this.vuex_wxinfo.openId
  453. })
  454. .then((r) => {
  455. if (r.code === 200) {
  456. $wxPay.weixinPay(r.data.wx).then((res) => {
  457. switch (Number(res.code)) {
  458. case 0: // 成功
  459. //#ifdef H5
  460. location.href = this.jumpUrl;
  461. //#endif
  462. break;
  463. case 1: // 取消
  464. this.$refs.uToast.show({
  465. title: '已取消支付',
  466. type: 'info'
  467. });
  468. this.jumpMonthList();
  469. break;
  470. case 2: // 支付失败
  471. this.$refs.uToast.show({
  472. title: '支付失败,请检查!',
  473. type: 'error'
  474. });
  475. this.jumpMonthList();
  476. break;
  477. }
  478. });
  479. }
  480. });
  481. },
  482. /**
  483. * 获取包月说明
  484. * @date 2022-10-09
  485. * @param {any} termsType
  486. * @returns {any}
  487. */
  488. getSysterms(termsType) {
  489. this.$u.api
  490. .getSysterms({
  491. termsType: termsType
  492. })
  493. .then((res) => {
  494. if (res.code === 200) {
  495. this.monthlyContent = res.data?.content;
  496. } else {
  497. this.$refs.uToast.show({
  498. title: res.msg,
  499. type: 'error'
  500. });
  501. }
  502. })
  503. .catch((err) => {
  504. this.$refs.uToast.show({
  505. title: '系统错误!',
  506. type: 'error'
  507. });
  508. });
  509. },
  510. cancel() {
  511. this.radioCurrent = '';
  512. this.orderMoney = '';
  513. this.payWayPop = false;
  514. this.jumpMonthList();
  515. },
  516. jumpMonthList() {
  517. this.$u.route({
  518. url: '/pages/center/monthly/monthly',
  519. type: 'redirect',
  520. params: {
  521. type: this.type
  522. }
  523. });
  524. },
  525. /**
  526. * 选中支付类型
  527. * @date 2023-02-17
  528. * @param {any} {detail}
  529. * @returns {any}
  530. */
  531. payRadioChange({ detail }) {
  532. this.radioCurrent = detail.value;
  533. },
  534. /**
  535. * 立即支付
  536. * @date 2023-02-17
  537. * @returns {any}
  538. */
  539. immediatePayment() {
  540. if (this.radioCurrent) {
  541. switch (this.radioCurrent) {
  542. case 'weixin': // 微信支付
  543. this.wechatPay();
  544. break;
  545. case 'gzyh':
  546. this.gyBankPay();
  547. break;
  548. case 'juhe':
  549. this.juhePay();
  550. break;
  551. }
  552. } else {
  553. this.$refs.uToast.show({
  554. title: '请选择支付方式!',
  555. type: 'warning'
  556. });
  557. }
  558. this.$refs['uModal'].clearLoading();
  559. }
  560. },
  561. computed: {
  562. dateRange: function () {
  563. return this.getMonthRange(this.lastActiveDate, this.form.month + this.freeMonthNum);
  564. }
  565. },
  566. filters: {
  567. verifyStatusFilter(value) {
  568. if (value === 0) {
  569. return '-';
  570. } else if (value === 1) {
  571. return '汽油车';
  572. } else if (value === 2) {
  573. return '新能源';
  574. } else {
  575. return '-';
  576. }
  577. }
  578. }
  579. };
  580. </script>
  581. <style lang="scss" scoped>
  582. @import './handleMonthly.scss';
  583. @import '../paymentMethod/paymentMethod.scss';
  584. </style>