parking.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view>
  3. <u-navbar
  4. title="车辆入场"
  5. title-color="#fff"
  6. :custom-back="customBack"
  7. :border-bottom="false"
  8. back-icon-color="#CCE8FF"
  9. :background="{background: 'linear-gradient(145deg, #41AFF9 0%, #2D8CFB 100%)' }"></u-navbar>
  10. <u-empty class="u-m-t-80" text="暂无车位" mode="data" v-if="roadspaceList.length == 0"></u-empty>
  11. <view class="search"><u-search placeholder="请输入车位名称" v-model="roadspaceList.spaceName" shape="round" @search="spaceSearch()" @custom="spaceSearch()"></u-search></view>
  12. <view class="roadspace-list wrap">
  13. <view class="roadspace-list-item" @click="roadspaceClick(item)" @longpress="longopenPage(item)" v-for="(item,index) in roadspaceList" :key="index + item.id">
  14. <view class="block" :class="{flashing: (item.deviceStatus ==1||item.deviceStatus ==5)||(item.placeStatus==1&&(item.vehicleNo==''))}">
  15. <view class="block-top" v-if="item.placeStatus==1&&(item.vehicleNo=='')"></view>
  16. <view class="block-bottom" v-if="item.placeStatus==1&&(item.vehicleNo=='')">
  17. <u-icon name="clock-fill" size="40" color="#3397FA"></u-icon>
  18. <view class="time">{{ item.inTime | timeago(currentTime)}}</view>
  19. </view>
  20. </view>
  21. <view class="text">{{item.spaceName}}</view>
  22. </view>
  23. </view>
  24. <view class="bottom-btn-wrap">
  25. <u-button class="bt1" @click="last(list.pageNum)"><</u-button>
  26. <view class="pagesInput">
  27. <view class="pagesInput-left">第</view><u-input v-model="pageNum" type="text" :border="true" :clearable="false" /><view class="pagesInput-right">页</view></view>
  28. <view class="num">
  29. <u-button @click="jump(list.pageNum)" size="mini">跳转</u-button>
  30. </view>
  31. <u-button class="bt2" @click="next(list.pageNum)">></u-button>
  32. <!-- <view class="bottom-btn" @click="openPage('pages/index/index')">返回主页</view> -->
  33. <!-- <uni-pagination class="page" v-if="roadspaceList" title="标题文字" :total='total' @change='uni_pagination_change'></uni-pagination> -->
  34. </view>
  35. <!-- <u-action-sheet :list="actionList" @click="actionClick" v-model="actionShow"></u-action-sheet> -->
  36. <u-toast ref="uToast" />
  37. </view>
  38. </template>
  39. <script>
  40. import uniPagination from '../../uni_modules/uni-pagination/components/uni-pagination/uni-pagination.vue'
  41. //#ifdef APP-PLUS
  42. let ocr = uni.requireNativePlugin("OcrPlug");
  43. //#endif
  44. export default {
  45. components: {uniPagination},
  46. data() {
  47. return {
  48. currentTime: new Date(),
  49. roadNo:null,//路段编码 ,示例值(RN000000004)
  50. actionList:[
  51. {text: '停车',},
  52. // {text: '查看'}
  53. ],
  54. actionShow:false,
  55. roadspaceList:[],
  56. spaceId:null,
  57. pageNum:'',
  58. spaceName:'',
  59. total:'',
  60. currentPageNum:'',
  61. list:{
  62. pageNum:''
  63. },
  64. vehicleNo:'',
  65. carImg:'',
  66. pages:'',
  67. vehicleImage:null,
  68. placeStatus:'',
  69. timeOutEvent: '0'
  70. }
  71. },
  72. onLoad() {
  73. this.roadNo = this.$store.state.vuex_user.roadList[0].roadNo || '';
  74. this.handleGetRoadspace(this.roadNo);
  75. },
  76. onShow(){
  77. let that = this;
  78. setInterval( () => {
  79. that.currentTime = new Date()//修改数据让他可以实时更新
  80. }, 1000);
  81. },
  82. methods:{
  83. longopenPage(item){
  84. this.spaceId = item.id;
  85. this.spaceName = item.spaceName;
  86. this.inTime = item.inTime;
  87. this.placeStatus=item.placeStatus;
  88. this.currentVehicleNo=item.vehicleNo;
  89. this.$u.route({
  90. url: 'pages/getin/getin',
  91. params:{
  92. spaceId: this.spaceId,
  93. spaceName:this.spaceName,
  94. roadNo:this.roadNo,
  95. inTime:this.inTime,
  96. placeStatus:this.placeStatus,
  97. currentVehicleNo:this.currentVehicleNo
  98. }
  99. })
  100. },
  101. // uni_pagination_change(e){
  102. // //this.getList(e.current)
  103. // this.handleGetRoadspace(this.roadNo, e.current)
  104. // console.log(e)
  105. // // {type: "next", current: 2}
  106. // },
  107. jump(){
  108. this.$u.api.getRoadspace({roadNo:this.roadNo,placeStatus:0,pageNum:this.pageNum})
  109. .then(res => {
  110. this.pages=res.data.pages;
  111. this.currentPageNum=res.data.page;
  112. this.list.pageNum=res.data.page;
  113. this.roadspaceList = res.data.rows;
  114. })
  115. },
  116. spaceSearch(){
  117. console.log(this.roadspaceList.spaceName)
  118. this.$u.api.getRoadspace({roadNo:this.roadNo,placeStatus:0,spaceName:this.roadspaceList.spaceName})
  119. .then(res => {
  120. this.pages=res.data.pages;
  121. this.currentPageNum=res.data.page;
  122. this.list.pageNum=res.data.page;
  123. this.roadspaceList = res.data.rows;
  124. })
  125. },
  126. last(i){
  127. if(i>1){
  128. setTimeout( this.handleGetRoadspace(this.roadNo,i-1),500)
  129. // this.handleGetRoadspace(this.roadNo,i-1)
  130. }else{
  131. return
  132. }
  133. },
  134. next(n){
  135. if(n < this.pages){
  136. setTimeout(this.handleGetRoadspace(this.roadNo,n+1),500)
  137. // this.handleGetRoadspace(this.roadNo,n+1)
  138. }else{
  139. this.$refs.uToast.show({
  140. title: '已经是最后一页',
  141. type: 'warning',
  142. })
  143. }
  144. },
  145. customBack(){
  146. uni.reLaunch({
  147. url: '/pages/index/index'
  148. });
  149. },
  150. openPage(path) {
  151. console.log('path',path);
  152. this.$u.route({
  153. url: path
  154. })
  155. },
  156. handleGetRoadspace(roadNo, page){
  157. this.$u.api.getRoadspace({roadNo:this.roadNo,placeStatus:0,pageNum:page || ''})
  158. .then(res=>{
  159. // this.$refs.uToast.show({
  160. // title: res.msg,
  161. // type: 'success',
  162. // });
  163. this.pages=res.data.pages;
  164. this.currentPageNum=res.data.page;
  165. this.list.pageNum=res.data.page;
  166. this.total=res.data.total;
  167. this.roadspaceList = res.data.rows;
  168. console.log('handleGetRoadspace',res)
  169. }).catch(err=>{
  170. if(err.errMsg){
  171. this.$refs.uToast.show({
  172. title: '请检查网络',
  173. type: 'error',
  174. });
  175. return false;
  176. };
  177. this.$refs.uToast.show({
  178. title: err.msg,
  179. type: 'error',
  180. });
  181. console.log('handleGetRoadspace ',err)
  182. });
  183. },
  184. roadspaceClick(roadspace){
  185. this.actionShow = true;
  186. this.spaceId = roadspace.id;
  187. this.spaceName = roadspace.spaceName;
  188. this.inTime = roadspace.inTime;
  189. this.placeStatus=roadspace.placeStatus;
  190. this.currentVehicleNo=roadspace.vehicleNo
  191. console.log('roadspace',roadspace);
  192. let that = this;
  193. ocr.ocrVehicleNo((ret) => {
  194. if (ret.success){
  195. that.vehicleNo = ret.vehicleNo;
  196. // this.carImg = 'data:image/png;base64,' + ret.imageBase64;
  197. this.$u.api.tencentBase64Upload({
  198. base64: ret.imageBase64,
  199. suffix: 'png'
  200. })
  201. .then(res=>{
  202. that.carImg = res.data.url;
  203. that.vehicleImage = res.data.url;
  204. this.$u.route({
  205. type: 'redirectTo',
  206. url: 'pages/getin/getin',
  207. params: {
  208. spaceId: this.spaceId,
  209. spaceName:this.spaceName,
  210. roadNo:this.roadNo,
  211. vehicleNo:this.vehicleNo,
  212. carImg:that.carImg,
  213. vehicleImage:that.vehicleImage,
  214. inTime:this.inTime,
  215. placeStatus:this.placeStatus,
  216. currentVehicleNo:this.currentVehicleNo
  217. }
  218. });
  219. }).catch(err=>{});
  220. }else {
  221. plus.nativeUI.toast('识别失败');
  222. }
  223. });
  224. },
  225. confirmIn(){
  226. let files = [];
  227. let that = this;
  228. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  229. files = this.$refs.uUpload.lists.filter(val => {
  230. return val.progress == 100;
  231. });
  232. // 如果不需要进行太多的处理,直接如下即可
  233. // files = this.$refs.uUpload.lists;
  234. that.confirmData.images = [];
  235. this.confirmData.spaceId = that.confirmData.id;
  236. files.forEach(function(element) {
  237. that.confirmData.images.push(element.response.data.url);
  238. });
  239. let param = this.confirmData;
  240. this.$u.api.parkInConfirm(param)//有车但是车牌为空
  241. .then(res=>{
  242. this.$refs.uToast.show({
  243. title: res.msg,
  244. type: 'success',
  245. url:'pages/getout/getout'
  246. });
  247. //#ifdef APP-PLUS
  248. device.print(res.data.print);
  249. speak(res.data.speak);
  250. //#endif
  251. console.log('parkInConfirm',res)
  252. }).catch(err=>{
  253. this.$refs.uToast.show({
  254. title: err.msg,
  255. type: 'error',
  256. // url:'pages/parking/parking'
  257. });
  258. console.log('parkInConfirm ',err)
  259. });
  260. },
  261. // actionClick(e){
  262. // console.log('actionClick',e);
  263. // switch (e){
  264. // case 0:
  265. // this.$u.route({
  266. // url: 'pages/getin/getin',
  267. // params: {
  268. // spaceId: this.spaceId,
  269. // spaceName:this.spaceName,
  270. // roadNo:this.roadNo
  271. // }
  272. // });
  273. // break;
  274. // case 1:
  275. // break;
  276. // default:
  277. // break;
  278. // }
  279. // }
  280. },
  281. filters:{
  282. timeago(inTime,currentTime){
  283. var time_start = '', clock_start = ''
  284. if (inTime) {
  285. time_start = new Date(inTime.replace(/-/g,'/'));
  286. time_start.getTime();
  287. }
  288. // console.log('currentTime',this.currentTime)
  289. const formatNumber = (num) => {
  290. num = num.toString()
  291. return num[1] ? num : '0' + num
  292. };
  293. var i_total_secs = Math.round(currentTime.getTime() - time_start);
  294. //计算出相差天数
  295. var days = Math.floor(i_total_secs / (24 * 3600 * 1000))
  296. //计算出小时数
  297. var leave1 = i_total_secs % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  298. var hours = Math.floor(leave1 / (3600 * 1000))
  299. // var hours = Math.floor(i_total_secs / (3600 * 1000))
  300. //计算相差分钟数
  301. var leave2 = i_total_secs % (3600 * 1000) //计算小时数后剩余的毫秒数
  302. var minutes = Math.floor(leave2 / (60 * 1000))
  303. //计算相差秒数
  304. var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  305. var seconds = Math.round(leave3 / 1000)
  306. days = formatNumber(days)
  307. hours = formatNumber(hours);
  308. minutes = formatNumber(minutes);
  309. seconds = formatNumber(seconds);
  310. // console.log(days + '天' + hours + '个小时' + minutes + '分钟' + seconds + '秒');
  311. return days + '天' + hours + '时' + minutes + '分' + seconds + '秒'
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss">
  317. @import "./parking.scss";
  318. </style>