handleMonthly.vue 15 KB

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