handleMonthly.vue 14 KB

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