handleMonthly.vue 14 KB

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