<template> <view> <u-navbar title="车辆出场" title-color="#fff" :custom-back="customBack" :border-bottom="false" back-icon-color="#CCE8FF" :background="{background: '#008CFF' }"></u-navbar> <u-empty class="u-m-t-80" text="暂无停车" mode="data" v-if="roadspaceList.length == 0"></u-empty> <view class="roadspace-list wrap"> <view class="roadspace-list-item" :class="{used:item.placeStatus==1}" @click="roadspaceClick(item)" v-for="item in roadspaceList" :key="item.id"> <view class="block"> <view class="block-top"> <u-icon name="car-fill" size="40" color="#fff"></u-icon> <view class="car-no">{{ item.vehicleNo }}</view> </view> <view class="block-bottom"> <u-icon name="clock-fill" size="40" color="#3397FA"></u-icon> <view class="time">{{ item.inTime | timeago(currentTime)}}</view> </view> </view> <view class="text">{{item.spaceName}}</view> </view> <view class="bottom-btn-wrap"> <view class="bottom-btn" @click="openPage('pages/index/index')">返回主页</view> </view> </view> <u-action-sheet :list="actionList" @click="actionClick" v-model="actionShow"></u-action-sheet> <u-toast ref="uToast" /> </view> </template> <script> export default { data() { return { roadNo:null,//路段编码 ,示例值(RN000000004) actionList:[ {text: '出场'}, ], actionShow:false, roadspaceList:[], orderInfo:null, spaceId:null, currentTime: new Date(), // 获取当前时间 } }, onShow() { let that = this; this.roadNo = this.$store.state.vuex_user?.roadList?.[0].roadNo || ''; this.handleGetRoadspace(this.roadNo); setInterval(function () { that.currentTime = new Date()//修改数据让他可以实时更新 }, 1000); }, methods:{ openPage(path) { console.log('path',path); this.$u.route({ url: path }) }, customBack(){ this.$u.route({ // type:'switchTab', url: 'pages/index/index' }); }, handleGetRoadspace(roadNo){ this.$u.api.getRoadspace({roadNo:this.roadNo,placeStatus:1}) .then(res=>{ // this.$refs.uToast.show({ // title: res.msg, // type: 'success', // }); this.roadspaceList = res.data; console.log('handleGetRoadspace',res) }).catch(err=>{ if(err.errMsg){ this.$refs.uToast.show({ title: '请检查网络', type: 'error', }); return false; }; err.msg&&this.$refs.uToast.show({ title: err.msg, type: 'error', }); console.log('handleGetRoadspace ',err) }); }, roadspaceClick(orderInfo){ this.actionShow = true; this.orderInfo = orderInfo; this.spaceId = orderInfo.id; console.log('orderInfo',orderInfo); }, actionClick(e){ console.log('actionClick',e); switch (e){ case 0: const d = new Date(); this.$u.route({ url: 'pages/getout/getoutpage/getoutpage', params: { orderID:this.orderInfo.id, orderInTime:this.orderInfo.inTime, orderOutTime:`${d.getFullYear()}-${((d.getMonth()+1)>=10?+(d.getMonth()+1):"0"+(d.getMonth()+1))}-${((d.getDate())>=10?d.getDate():'0'+d.getDate())} ${d.getHours()>=10?d.getHours():'0'+d.getHours()}:${d.getMinutes()>=10?d.getMinutes():'0'+d.getMinutes()}:${d.getSeconds()>=10?d.getSeconds():'0'+d.getSeconds()}`, orderSpaceName:this.orderInfo.spaceName, orderVehicleNo:this.orderInfo.vehicleNo } }); break; default: break; } }, }, filters:{ timeago(inTime,currentTime){ var time_start = new Date(inTime.replace(/-/g,'/')); var clock_start = time_start.getTime(); // console.log('currentTime',this.currentTime) const formatNumber = (num) => { num = num.toString() return num[1] ? num : '0' + num }; var i_total_secs = Math.round(currentTime.getTime() - clock_start); //计算出相差天数 var days = Math.floor(i_total_secs / (24 * 3600 * 1000)) //计算出小时数 // var leave1 = i_total_secs % (24 * 3600 * 1000) //计算天数后剩余的毫秒数 // var hours = Math.floor(leave1 / (3600 * 1000)) var hours = Math.floor(i_total_secs / (3600 * 1000)) //计算相差分钟数 var leave2 = i_total_secs % (3600 * 1000) //计算小时数后剩余的毫秒数 var minutes = Math.floor(leave2 / (60 * 1000)) //计算相差秒数 var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数 var seconds = Math.round(leave3 / 1000) hours = formatNumber(hours); minutes = formatNumber(minutes); seconds = formatNumber(seconds); // console.log(days + '天' + hours + '个小时' + minutes + '分钟' + seconds + '秒'); return hours + ':' + minutes + ':' + seconds } } } </script> <style lang="scss"> @import "../parking/parking.scss"; </style>