handleMonthly.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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'(val) {
  140. let freeNum = 0;
  141. if (this.monthlyRuleObj.giveFlag && Number(this.monthlyRuleObj.giveFlag) === 1) {
  142. let remainNum = Number(val) % Number(this.monthlyRuleObj.minMonth),
  143. timesNum = Number(val) / Number(this.monthlyRuleObj.minMonth);
  144. if (remainNum === 0) {
  145. this.freeMonthNum = Number(timesNum) * Number(this.monthlyRuleObj.giveMonth);
  146. }
  147. }
  148. }
  149. },
  150. onLoad(page) {
  151. this.wxEnv = getEnvIsWx();
  152. this.getSysterms(0);
  153. if (page.vehicleNo && page.roadNo) {
  154. this.roadNo = page.roadNo;
  155. this.vehicleNo = page.vehicleNo;
  156. this.type = 'road'
  157. this.getMonthInfo(this.roadNo, this.vehicleNo);
  158. } else if (page.roadNo) {
  159. this.roadNo = page.roadNo;
  160. this.type = 'road'
  161. this.getMonthInfo(this.roadNo);
  162. } else if (page.vehicleNo && page.parkNo) {
  163. this.parkNo = page.parkNo;
  164. this.vehicleNo = page.vehicleNo;
  165. this.type = 'park'
  166. this.getMonthInfo(this.parkNo, this.vehicleNo);
  167. } else if (page.parkNo) {
  168. this.parkNo = page.parkNo;
  169. this.type = 'park'
  170. this.getMonthInfo(this.parkNo);
  171. }
  172. if (page.monthId) {
  173. this.monthId = page.monthId
  174. this.payWayPop = true
  175. }
  176. if (page.roadNo) {
  177. this.monthlyRuleDetails(page.roadNo);
  178. }
  179. const baseUrl = window.location.href.split('#')[0];
  180. let jumpUrl = baseUrl + '#/pages/center/monthly/monthly?type=' + this.type;
  181. this.jumpUrl = jumpUrl;
  182. },
  183. methods: {
  184. /**
  185. * 获取几个月的日期范围
  186. * {date} Date 起始日期,往后推一天
  187. * {monthNum} Number 往后月数
  188. * */
  189. getMonthRange(date, monthNum) {
  190. let Date1 = this.lastActiveDate;
  191. Date1 = new Date(Date1);
  192. const year = Date1.getFullYear();
  193. const month = Date1.getMonth() + 1;
  194. const day = Date1.getDate();
  195. const hours = Date1.getHours();
  196. const minutes = Date1.getMinutes();
  197. const seconds = Date1.getSeconds();
  198. let days = new Date(year, month, 0);
  199. days = days.getDate(); //获取当前日期中的月的天数
  200. let year2 = year;
  201. let month2 = parseInt(month) + parseInt(monthNum);
  202. if (month2 > 12) {
  203. year2 = parseInt(year2) + parseInt(parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12);
  204. month2 = parseInt(month2) % 12;
  205. }
  206. let day2 = day;
  207. let days2 = new Date(year2, month2, 0);
  208. days2 = days2.getDate();
  209. if (day2 > days2) {
  210. day2 = days2;
  211. }
  212. if (month2 < 10) {
  213. month2 = '0' + month2;
  214. }
  215. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day);
  216. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2);
  217. this.startTime = t1;
  218. this.endTime = t2;
  219. this.monthStartTime =
  220. year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours +
  221. ':' + minutes + ':' + seconds;
  222. this.monthEndTime = year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' + seconds;
  223. return t1 + '-' + t2;
  224. },
  225. /**
  226. * 月操作 减1
  227. * */
  228. reduceMonthNum() {
  229. if (this.form.month > 1) {
  230. this.form.month -= 1;
  231. this.form.dateRange = this.getMonthRange(new Date(), this.form.month);
  232. }
  233. },
  234. /**
  235. * 月操作 加1
  236. * */
  237. addMonthNum() {
  238. if (this.form.month >= 24) {
  239. this.$refs.uToast.show({
  240. title: '最多24月',
  241. type: 'warning'
  242. });
  243. return;
  244. }
  245. this.form.month += 1;
  246. this.form.dateRange = this.getMonthRange(new Date(), this.form.month);
  247. },
  248. carLicenseListConfirm(item) {
  249. this.form.carLicense = item[0];
  250. this.vehicleNo = item[0].label;
  251. this.getMonthInfo(this.roadNo, this.vehicleNo);
  252. },
  253. /**
  254. * 获取包月信息
  255. * @date 2022-10-09
  256. * @param {any} roadNo
  257. * @param {any} vehicleNo
  258. * @returns {any}
  259. */
  260. getMonthInfo(roadNo, vehicleNo) {
  261. const params = {
  262. vehicleNo
  263. }
  264. if (this.type === 'park') {
  265. params.parkNo = roadNo
  266. } else {
  267. params.roadNo = roadNo
  268. }
  269. this.$u.api
  270. .monthInfo(params)
  271. .then((res) => {
  272. if (res.code === 200 && res.data.vehicleList && res.data.vehicleList.length) {
  273. this.lastActiveDate = res.data.lastActiveDate;
  274. this.form.monthAmount = res.data.monthAmount;
  275. this.carLicenseList = [];
  276. let vehicleNoItem = null;
  277. res.data.vehicleList.forEach((item, index) => {
  278. const obj = {
  279. value: item.energyType,
  280. label: item.vehicleNo,
  281. energyType: item.energyType
  282. };
  283. if (this.vehicleNo == item.vehicleNo) {
  284. vehicleNoItem = obj;
  285. this.carLicenseDefaultValue = [index];
  286. }
  287. this.carLicenseList.push(obj);
  288. });
  289. // 判断是否url存在车牌号,存在则选中项默认选中
  290. if (vehicleNoItem) {
  291. this.form.carLicense = vehicleNoItem;
  292. } else {
  293. this.form.carLicense = this.carLicenseList[0];
  294. }
  295. }
  296. }).catch((err) => {
  297. console.log(err);
  298. })
  299. },
  300. /**
  301. * 获取包月规则详情
  302. * @date 2022-12-20
  303. * @param {any} roadNo
  304. * @returns {any}
  305. */
  306. monthlyRuleDetails(roadNo) {
  307. this.$u.api.monthlyRuleDetailsApi({
  308. roadNo
  309. }).then(res => {
  310. if (res.code === 200) {
  311. this.monthlyRuleObj = res?.rows[0] ?? {}
  312. }
  313. })
  314. },
  315. /**
  316. * 提交包月信息
  317. * @date 2022-10-09
  318. * @param {any} roadNo
  319. * @returns {any}
  320. */
  321. submit(roadNo) {
  322. this.loading = true;
  323. const params = {
  324. vehicleNo: this.form.carLicense.label,
  325. energyType: this.form.carLicense.energyType,
  326. monthStartTime: this.monthStartTime,
  327. monthEndTime: this.monthEndTime,
  328. monthCount: this.form.month
  329. }
  330. if (this.type === 'park') {
  331. params.parkNo = this.parkNo
  332. } else {
  333. params.roadNo = this.roadNo
  334. }
  335. this.$u.api
  336. .createMonth(params)
  337. .then((res) => {
  338. if (res.code === 200) {
  339. this.monthId = res.data.monthId;
  340. this.payWayPop = true;
  341. } else {
  342. this.$refs.uToast.show({
  343. title: res.msg,
  344. type: 'error'
  345. });
  346. }
  347. this.loading = false;
  348. })
  349. .catch((err) => {
  350. this.$refs.uToast.show({
  351. title: '程序错误!',
  352. type: 'error'
  353. });
  354. this.loading = false;
  355. });
  356. },
  357. /**
  358. * 贵州银行包月支付
  359. * @date 2022-10-09
  360. * @returns {any}
  361. */
  362. gyBankPay() {
  363. this.$u.api
  364. .monthPay({
  365. monthId: this.monthId,
  366. jumpUrl: this.jumpUrl
  367. })
  368. .then((res) => {
  369. if (res.code === 200) {
  370. window.location.href = res.data.url;
  371. } else {
  372. this.$refs.uToast.show({
  373. title: res.msg,
  374. type: 'error'
  375. });
  376. this.jumpMonthList()
  377. }
  378. });
  379. },
  380. /**
  381. * 聚合支付直接通过后台获取贵阳银行微信支付地址
  382. * @date 2022-10-09
  383. * @returns {any}
  384. */
  385. juhePay() {
  386. // 支付成功跳转到包月页面
  387. let params = {
  388. monthId: this.monthId,
  389. openid: '',
  390. jumpUrl: this.jumpUrl
  391. };
  392. this.$u.api
  393. .monthlyWxPay(params)
  394. .then((res) => {
  395. if (res.code === 200) {
  396. localStorage.setItem('jumpUrl', this.jumpUrl);
  397. location.href = res.data.qrCodeUrl;
  398. } else {
  399. this.$refs.uToast.show({
  400. title: res.msg,
  401. type: 'error'
  402. });
  403. this.jumpMonthList()
  404. }
  405. })
  406. .catch((err) => {
  407. this.$refs.uToast.show({
  408. title: '无法调起微信支付!',
  409. type: 'error'
  410. });
  411. });
  412. },
  413. /**
  414. * 微信支付
  415. * @date 2022-10-09
  416. * @returns {any}
  417. */
  418. wechatPay() {
  419. this.$u.api
  420. .wechatMonthlyPayapi({
  421. monthId: this.monthId,
  422. openid: this.vuex_wxinfo.openId
  423. })
  424. .then((r) => {
  425. if (r.code === 200) {
  426. $wxPay.wexinPay(r.data.wx).then((res) => {
  427. switch (Number(res.code)) {
  428. case 0: // 成功
  429. //#ifdef H5
  430. // this.jumpMonthList()
  431. location.href = this.jumpUrl
  432. //#endif
  433. break;
  434. case 1: // 取消
  435. this.$refs.uToast.show({
  436. title: '已取消支付',
  437. type: 'info'
  438. });
  439. this.jumpMonthList()
  440. break;
  441. case 2: // 支付失败
  442. this.$refs.uToast.show({
  443. title: '支付失败,请检查!',
  444. type: 'error'
  445. });
  446. this.jumpMonthList()
  447. break;
  448. }
  449. });
  450. }
  451. });
  452. },
  453. /**
  454. * 获取包月说明
  455. * @date 2022-10-09
  456. * @param {any} termsType
  457. * @returns {any}
  458. */
  459. getSysterms(termsType) {
  460. this.$u.api
  461. .getSysterms({
  462. termsType: termsType
  463. })
  464. .then((res) => {
  465. if (res.code === 200) {
  466. this.monthlyContent = res.data?.content;
  467. } else {
  468. this.$refs.uToast.show({
  469. title: res.msg,
  470. type: 'error'
  471. });
  472. }
  473. })
  474. .catch((err) => {
  475. this.$refs.uToast.show({
  476. title: '系统错误!',
  477. type: 'error'
  478. });
  479. });
  480. },
  481. cancel() {
  482. this.payWayPop = false
  483. this.jumpMonthList()
  484. },
  485. jumpMonthList() {
  486. this.$u.route({
  487. url: '/pages/center/monthly/monthly',
  488. type: 'redirect',
  489. params: {
  490. type: this.type
  491. }
  492. })
  493. }
  494. },
  495. computed: {
  496. dateRange: function() {
  497. return this.getMonthRange(this.lastActiveDate, this.form.month);
  498. }
  499. },
  500. filters: {
  501. verifyStatusFilter(value) {
  502. if (value === 0) {
  503. return '-';
  504. } else if (value === 1) {
  505. return '汽油车';
  506. } else if (value === 2) {
  507. return '新能源';
  508. } else {
  509. return '-';
  510. }
  511. }
  512. }
  513. };
  514. </script>
  515. <style lang="scss" scoped>
  516. @import './handleMonthly.scss';
  517. @import '../paymentMethod/paymentMethod.scss';
  518. </style>