handleMonthly.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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" @confirm="carLicenseListConfirm"></u-select>
  11. <view class="handle-monthly-item">
  12. <view>车辆信息</view>
  13. <view>{{form.carLicense.value | verifyStatusFilter}}</view>
  14. </view>
  15. <view class="handle-monthly-item">
  16. <view>包月金额</view>
  17. <view class="handle-monthly-money">{{form.monthAmount}}元</view>
  18. </view>
  19. <view class="handle-monthly-item">
  20. <view>包月时长</view>
  21. <view class="handle-monthly-time-long">
  22. <button @click="reduceMonthNum()">-</button>
  23. <view>{{form.month}}个月</view>
  24. <button @click="addMonthNum()">+</button>
  25. </view>
  26. </view>
  27. <view class="handle-monthly-item">
  28. <view>有效期限</view>
  29. <view>{{dateRange}}</view>
  30. </view>
  31. <view class="handle-monthly-explain">
  32. <!-- <view>包月说明</view>
  33. <view>1、停车不足30分钟,免费;</view>
  34. <view>2、停车 超过20分钟,按2元/小时收费;</view>
  35. <view>3、月卡会员在有效期内停车免费</view> -->
  36. <u-parse :html="monthlyContent"></u-parse>
  37. </view>
  38. <view class="handle-monthly-confirm-button">
  39. <button type="default"@click="submit(roadNo)">确认包月</button>
  40. </view>
  41. <u-modal
  42. v-model="payWayPop"
  43. :title-style="{color: '#404040'}"
  44. title="缴费方式"
  45. :show-confirm-button="false"
  46. :show-cancel-button="false">
  47. <view class="slot-content">
  48. <!-- <view class="pay-way">
  49. <view class="pay-way-item" @click="gyBankPay">
  50. <image src="../../static/img/gy-bank-pay-icon.png" mode=""></image>
  51. <view>贵州银行</view>
  52. </view>
  53. <view class="pay-way-item" @click="wechatPay">
  54. <image src="../../static/img/wechat-pay-icon.png" mode=""></image>
  55. <view>微信支付</view>
  56. </view>
  57. </view> -->
  58. <view class="pay-way-new">
  59. <view class="pay-way-item pay-way-item-hy" @click="gyBankPay">
  60. <image src="../../static/img/guiyang-bank-icon.png" mode=""></image>
  61. <view class="title">贵州银行</view>
  62. <view class="subtitle">前三个月每天首次一分钱<br/>长期八折优惠</view>
  63. </view>
  64. <view class="pay-way-item pay-way-item-jh" @click="wechatPay">
  65. <image src="../../static/img/juhe-icon.png" mode=""></image>
  66. <view class="title">聚合支付</view>
  67. </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) + ' ' + hours + ':' + minutes + ':' +seconds
  170. this.monthEndTime=year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' +seconds
  171. return t1 + '-' + t2
  172. },
  173. /**
  174. * 月操作 减1
  175. * */
  176. reduceMonthNum () {
  177. if (this.form.month > 1) {
  178. this.form.month -= 1
  179. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  180. }
  181. },
  182. /**
  183. * 月操作 加1
  184. * */
  185. addMonthNum () {
  186. if(this.form.month >=24){
  187. this.$refs.uToast.show({
  188. title: '最多24月',
  189. type: 'warning',
  190. })
  191. return
  192. }
  193. this.form.month += 1
  194. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  195. },
  196. carLicenseListConfirm (item) {
  197. this.form.carLicense = item[0]
  198. this.vehicleNo = item[0].label
  199. this.getMonthInfo(this.roadNo, this.vehicleNo)
  200. },
  201. getMonthInfo(roadNo, vehicleNo){
  202. this.$u.api.monthInfo({roadNo: roadNo, vehicleNo: vehicleNo})
  203. .then(res => {
  204. if (res.code === 200){
  205. this.lastActiveDate = res.data.lastActiveDate;
  206. this.form.monthAmount=res.data.monthAmount;
  207. this.carLicenseList = [];
  208. let vehicleNoItem = null
  209. res.data.vehicleList.forEach((item, index) => {
  210. const obj = {
  211. value: item.energyType,
  212. label: item.vehicleNo,
  213. energyType:item.energyType
  214. }
  215. if (this.vehicleNo == item.vehicleNo) {
  216. vehicleNoItem = obj
  217. this.carLicenseDefaultValue = [index]
  218. }
  219. this.carLicenseList.push(obj)
  220. });
  221. // 判断是否url存在车牌号,存在则选中项默认选中
  222. if (vehicleNoItem) {
  223. this.form.carLicense = vehicleNoItem
  224. } else {
  225. this.form.carLicense = this.carLicenseList[0]
  226. }
  227. }
  228. })
  229. },
  230. submit(roadNo){
  231. this.$u.api.createMonth({
  232. roadNo:this.roadNo,
  233. vehicleNo:this.form.carLicense.label,
  234. energyType:this.form.carLicense.energyType,
  235. monthStartTime:this.monthStartTime,
  236. monthEndTime:this.monthEndTime,
  237. monthCount:this.form.month})
  238. .then(res => {
  239. console.log("createMonth",res)
  240. if(res.code === 200){
  241. this.monthId = res.data.monthId
  242. console.log(this.monthId)
  243. this.payWayPop = true
  244. }else{
  245. this.$refs.uToast.show({
  246. title: res.msg,
  247. type: 'error',
  248. });
  249. }
  250. }).catch(err=>{
  251. this.$refs.uToast.show({
  252. title: '程序错误!',
  253. type: 'error',
  254. });
  255. });
  256. },
  257. gyBankPay() {
  258. console.log(this.jumpUrl)
  259. this.$u.api.monthPay({
  260. monthId: this.monthId,
  261. jumpUrl: this.jumpUrl
  262. }).then(res => {
  263. if(res.code === 200){
  264. window.location.href = res.data.url
  265. } else {
  266. this.$refs.uToast.show({
  267. title: res.msg,
  268. type: 'error',
  269. });
  270. }
  271. })
  272. },
  273. /**
  274. * 微信支付
  275. * 判断vuex中是否存在openId
  276. * 存在直接调起微信支付
  277. * 不存在则通过微信登录去获取用户的code
  278. * 完成后通过code去获取用户的openId等信息
  279. * 最后再调起微信支付
  280. * */
  281. wechatPay() {
  282. // const openId = this.$store.state.vuex_wxinfo.openId
  283. // if (openId) {
  284. // this.getWXPay()
  285. // } else {
  286. // this.getCode()
  287. // }
  288. this.getWXPayByJava()
  289. },
  290. /**
  291. * 微信支付
  292. */
  293. wechatPay() {
  294. this.$u.api.wechatPayApi({
  295. orderList: this.curOrderList,
  296. openid: this.vuex_wxinfo.openId
  297. }).then(res => {
  298. if (res.code === 200) {
  299. $wxPay.wexinPay(res.data.wx).then(res1 => {
  300. switch (Number(res1.code)) {
  301. case 0: // 成功
  302. //#ifdef H5
  303. window.location.reload();
  304. //#endif
  305. break;
  306. case 1: // 取消
  307. this.$refs.uToast.show({
  308. title: '已取消支付',
  309. type: 'info'
  310. });
  311. break;
  312. case 2: // 支付失败
  313. this.$refs.uToast.show({
  314. title: '支付失败,请检查!',
  315. type: 'error'
  316. });
  317. break;
  318. }
  319. })
  320. }
  321. })
  322. },
  323. /**
  324. * 调起微信支付接口
  325. * @param {Array} list 需要支付的订单组合数组
  326. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  327. * */
  328. async getWXPay(){
  329. // 支付成功跳转到包月页面
  330. let params = {
  331. monthId: this.monthId,
  332. openid: this.$store.state.vuex_wxinfo.openId
  333. };
  334. await this.$wxApi.config();
  335. this.$pay.wechatPay(params, '/client/monthpay/wechat', this.jumpUrl).then(res =>{
  336. switch (Number(res.code)) {
  337. case 0: // 成功
  338. //#ifdef H5
  339. window.location.reload();
  340. //#endif
  341. break;
  342. case 1: // 取消
  343. this.$refs.uToast.show({
  344. title: '已取消支付',
  345. type: 'info',
  346. });
  347. break;
  348. case 2: // 支付失败
  349. this.$refs.uToast.show({
  350. title: '支付失败,请检查!',
  351. type: 'error',
  352. });
  353. break;
  354. }
  355. });
  356. },
  357. /**
  358. * 直接通过后台获取贵阳银行微信支付地址
  359. * @param {Array} list 需要支付的订单组合数组
  360. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  361. * */
  362. getWXPayByJava(orderList, deviceNo) {
  363. // 支付成功跳转到包月页面
  364. let params = {
  365. monthId: this.monthId,
  366. openid: '',
  367. jumpUrl: this.jumpUrl
  368. };
  369. this.$u.api.monthlyWxPay(params)
  370. .then(res => {
  371. if (res.code === 200) {
  372. // if (getEnvIsWx()) {
  373. // location.href = res.data.qrCodeUrl + '&jump_url=' + encodeURIComponent(this.jumpUrl)
  374. // } else {
  375. // location.href = res.data.qrCodeUrl
  376. // }
  377. localStorage.setItem('jumpUrl', this.jumpUrl)
  378. location.href = res.data.qrCodeUrl
  379. } else {
  380. this.$refs.uToast.show({
  381. title: res.msg,
  382. type: 'error',
  383. });
  384. }
  385. })
  386. .catch(err => {
  387. this.$refs.uToast.show({
  388. title: '无法调起微信支付!',
  389. type: 'error',
  390. });
  391. })
  392. },
  393. /**
  394. * 获取code
  395. * 1 微信登录获取code
  396. * 2 url中截取
  397. * */
  398. getCode () {
  399. // 获取页面完整url
  400. const local = window.location.href
  401. // 获取url后面的参数
  402. const locationLocaturl = window.location.search;
  403. // 截取url中的code
  404. this.code = getUrlParams(locationLocaturl, "code");
  405. // 如果没有code,则去请求
  406. if (this.code == null || this.code === '') {
  407. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wxAppid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`
  408. } else {
  409. // 把code传给后台获取用户信息
  410. this.handleGetWXInfo(this.code)
  411. }
  412. },
  413. /**
  414. * 通过code获取openId等用户信息
  415. * 拿到用户信息后再调起微信支付
  416. * */
  417. handleGetWXInfo (code) {
  418. let _this = this
  419. this.$u.api.getWXInfo(code).then((res) => {
  420. if (res.code === 200 ) {
  421. this.$u.vuex('vuex_wxinfo', res.data);
  422. this.getWXPay(this.currentItem)
  423. }
  424. }).catch((err) => {
  425. this.$refs.uToast.show({
  426. title: err.msg,
  427. type: 'error',
  428. });
  429. })
  430. },
  431. /**
  432. * 获取包月说明
  433. * */
  434. getSysterms(termsType) {
  435. this.$u.api.getSysterms({
  436. termsType: termsType
  437. })
  438. .then(res => {
  439. if (res.code === 200) {
  440. this.monthlyContent = res.data?.content
  441. } else {
  442. this.$refs.uToast.show({
  443. title: res.msg,
  444. type: 'error',
  445. })
  446. }
  447. })
  448. .catch(err => {
  449. this.$refs.uToast.show({
  450. title: '系统错误!',
  451. type: 'error',
  452. })
  453. })
  454. }
  455. },
  456. computed:{
  457. dateRange:function(){
  458. return this.getMonthRange(this.lastActiveDate,this.form.month)
  459. },
  460. },
  461. filters:{
  462. verifyStatusFilter(value) {
  463. if (value === 0) {
  464. return '';
  465. } else if(value === 1){
  466. return '汽油车';
  467. } else if(value === 2){
  468. return '新能源';
  469. } else {
  470. return '';
  471. }
  472. },
  473. }
  474. }
  475. </script>
  476. <style lang="scss" scoped>
  477. @import './handleMonthly.scss';
  478. @import '../paymentMethod/paymentMethod.scss'
  479. </style>