handleMonthly.vue 13 KB

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