getout.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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="roadspace-list wrap">
  12. <view class="roadspace-list-item" :class="{used:item.placeStatus==1}" @click="roadspaceClick(item)" v-for="item in roadspaceList" :key="item.id">
  13. <view class="block">
  14. <view class="block-top">
  15. <u-icon name="car-fill" size="40" color="#fff"></u-icon>
  16. <view class="car-no">{{ item.vehicleNo }}</view>
  17. </view>
  18. <view class="block-bottom">
  19. <u-icon name="clock-fill" size="40" color="#3397FA"></u-icon>
  20. <view class="time">{{ item.inTime | timeago(currentTime)}}</view>
  21. </view>
  22. </view>
  23. <view class="text">{{item.spaceName}}</view>
  24. </view>
  25. <view class="bottom-btn-wrap">
  26. <!-- <view class="bottom-btn" @click="jumpToMain()">返回主页</view> -->
  27. <u-button class="bt1" v-if="list.pageNum==0" @click="last(list.pageNum)"><</u-button>
  28. <u-button class="bt2" v-if="list.pageNum==0"@click="next(list.pageNum)">></u-button>
  29. </view>
  30. </view>
  31. <u-action-sheet :list="actionList" @click="actionClick" v-model="actionShow"></u-action-sheet>
  32. <u-popup class="confirm-pop" v-model="confirmPop" mode="center" border-radius="20" width="90%">
  33. <view class="confirm-pop-til">入场确认</view>
  34. <view class="confirm-pop-con car-info u-flex">
  35. <view class="car-info-img" @click="getPic">
  36. <u-image :src="confirmData.carImg" mode="aspectFit" width="100%" height="100%"></u-image>
  37. </view>
  38. <view class="car-info-text u-flex-1">
  39. <view class="text-item position-wrap">
  40. <view class="position">车位:{{confirmData.spaceName}}</view>
  41. </view>
  42. <view class="text-item u-flex u-flex u-row-between">
  43. <view>车牌号</view>
  44. <view class="u-flex-1 u-m-l-40">
  45. <u-input v-model="confirmData.vehicleNo" height="80" width="100" type="text" @focus="messageInputClick" placeholder="输入车牌号" />
  46. <!-- <u-button type="primary" size="s" @click="handleParkInInfo">确认</u-button> -->
  47. </view>
  48. </view>
  49. <view class="text-item u-flex u-flex u-row-between">
  50. <view class="">车辆类型</view>
  51. <view class="" @click="carTypeShow = true">
  52. {{confirmData.vehicleType|filterCarType}}
  53. <u-icon class="u-m-l-10" name="arrow-down-fill" color="#C2C2C2" size="15"></u-icon>
  54. </view>
  55. </view>
  56. <view class="text-item u-flex u-flex u-row-between">
  57. <view>车辆颜色</view>
  58. <view @click="carColorShow = true">
  59. {{confirmData.vehicleColor|filterCarColor}}
  60. <u-icon class="u-m-l-10" name="arrow-down-fill" color="#C2C2C2" size="15"></u-icon>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="upload-wrap">
  66. <u-upload
  67. ref="uUpload"
  68. :action="uploadAction"
  69. :show-progress="false"
  70. upload-text="拍照取证" ></u-upload>
  71. </view>
  72. <view class="btn-wrap">
  73. <view class="btn" @click="confirmIn">确认</view>
  74. </view>
  75. </u-popup>
  76. <u-toast ref="uToast" />
  77. <u-keyboard ref="uKeyboard" mode="car" @change="keyboardChange" @backspace="backspace" v-model="keyboardshow"></u-keyboard>
  78. <u-select v-model="carTypeShow" :default-value="[2]" :list="carTypeList" @confirm="carTypeConfirm"></u-select>
  79. <u-select v-model="carColorShow" :default-value="[2]" :list="carColorList" @confirm="carColorConfirm"></u-select>
  80. </view>
  81. </template>
  82. <script>
  83. import { config } from '@/common/config.js';
  84. import { mydata } from '@/common/data.js';
  85. //#ifdef APP-PLUS
  86. import speak from '@/utils/speaks.js';
  87. let ALog = uni.requireNativePlugin("AndroidLog");
  88. let device = uni.requireNativePlugin("DeviceInfo");
  89. let ocr = uni.requireNativePlugin("OcrPlug");
  90. //#endif
  91. export default {
  92. data() {
  93. return {
  94. roadNo:null,//路段编码 ,示例值(RN000000004)
  95. actionList:[
  96. {text: '出场'},
  97. {text: '入场确认'},
  98. ],
  99. actionShow:false,
  100. roadspaceList:[],
  101. orderInfo:null,
  102. spaceId:null,
  103. currentTime: new Date(), // 获取当前时间
  104. confirmPop:false,
  105. confirmData:{
  106. carImg:'/static/img/default-car.png',
  107. spaceName:null,
  108. vehicleType:null,
  109. vehicleColor:null,
  110. },
  111. keyboardshow:false,
  112. carTypeShow:false,
  113. carColorShow:false,
  114. carTypeList:mydata.carTypeList,
  115. carColorList:mydata.carColorList,
  116. uploadAction:config.baseUrl+'/file/tencent/upload',
  117. list:{
  118. pageNum:''
  119. },
  120. pages:''
  121. }
  122. },
  123. onShow() {
  124. let that = this;
  125. this.roadNo = this.$store.state.vuex_user?.roadList?.[0].roadNo || '';
  126. this.handleGetRoadspace(this.roadNo);
  127. setInterval(function () {
  128. that.currentTime = new Date()//修改数据让他可以实时更新
  129. }, 1000);
  130. },
  131. methods:{
  132. last(i){
  133. if(i>1){
  134. setTimeout( this.handleGetRoadspace(this.roadNo,i-1),500)
  135. // this.handleGetRoadspace(this.roadNo,i-1)
  136. }else{
  137. return
  138. }
  139. },
  140. next(n){
  141. if(n < this.pages){
  142. setTimeout(this.handleGetRoadspace(this.roadNo,n+1),500)
  143. // this.handleGetRoadspace(this.roadNo,n+1)
  144. }else{
  145. this.$refs.uToast.show({
  146. title: '已经是最后一页',
  147. type: 'warning',
  148. })
  149. }
  150. },
  151. jumpToMain(){
  152. this.$u.route({
  153. type: 'redirectTo',
  154. url: '/pages/index/index'
  155. })
  156. },
  157. customBack(){
  158. this.$u.route({
  159. type: 'redirectTo',
  160. url: 'pages/index/index'
  161. });
  162. },
  163. handleGetRoadspace(roadNo){
  164. this.$u.api.getRoadspace({roadNo:this.roadNo,placeStatus:1})
  165. .then(res=>{
  166. // this.$refs.uToast.show({
  167. // title: res.msg,
  168. // type: 'success',
  169. // });
  170. console.log(res.data.rows)
  171. this.pages=res.data.pages;
  172. this.list.pageNum=res.data.page;
  173. this.roadspaceList = res.data.rows;
  174. console.log('handleGetRoadspace',res)
  175. }).catch(err=>{
  176. if(err.errMsg){
  177. this.$refs.uToast.show({
  178. title: '请检查网络',
  179. type: 'error',
  180. });
  181. return false;
  182. };
  183. err.msg&&this.$refs.uToast.show({
  184. title: err.msg,
  185. type: 'error',
  186. });
  187. console.log('handleGetRoadspace ',err)
  188. });
  189. },
  190. roadspaceClick(item){
  191. this.confirmData = item;
  192. this.confirmData.vehicleColor = 0;
  193. this.confirmData.vehicleType = 0;
  194. this.orderInfo = item;
  195. this.spaceId = item.id;
  196. if(!item.vehicleNo){
  197. //无车牌打开补全车牌信息
  198. let that = this;
  199. ocr.ocrVehicleNo((ret) => {
  200. if (ret.success){
  201. that.confirmData.vehicleNo = ret.vehicleNo;
  202. that.confirmData.carImg = 'data:image/png;base64,' + ret.imageBase64;
  203. this.$u.api.tencentBase64Upload({
  204. base64: ret.imageBase64,
  205. suffix: 'png'
  206. })
  207. .then(res=>{
  208. this.confirmPop = true;
  209. that.confirmData.vehicleImage = res.data.url;
  210. }).catch(err=>{});
  211. }else {
  212. plus.nativeUI.toast('识别失败');
  213. }
  214. });
  215. }else {
  216. //信息完整打开出场页面
  217. const d = new Date();
  218. this.$u.route({
  219. url: 'pages/getout/getoutpage/getoutpage',
  220. params: {
  221. orderID:item.id,
  222. orderInTime:item.inTime,
  223. 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()}`,
  224. orderSpaceName:item.spaceName,
  225. orderVehicleNo:item.vehicleNo
  226. }
  227. });
  228. }
  229. },
  230. actionClick(e){
  231. console.log('actionClick',e);
  232. switch (e){
  233. case 0:
  234. const d = new Date();
  235. this.$u.route({
  236. url: 'pages/getout/getoutpage/getoutpage',
  237. params: {
  238. orderID:this.orderInfo.id,
  239. orderInTime:this.orderInfo.inTime,
  240. 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()}`,
  241. orderSpaceName:this.orderInfo.spaceName,
  242. orderVehicleNo:this.orderInfo.vehicleNo
  243. }
  244. });
  245. break;
  246. case 1:{
  247. this.confirmPop = true;
  248. break;
  249. }
  250. default:
  251. break;
  252. }
  253. },
  254. messageInputClick(){
  255. this.keyboardshow = true;
  256. },
  257. // 按键被点击(点击退格键不会触发此事件)
  258. keyboardChange(val) {
  259. // 将每次按键的值拼接到value变量中,注意+=写法
  260. this.confirmData.vehicleNo += val;
  261. console.log(this.confirmData.vehicleNo);
  262. },
  263. // 退格键被点击
  264. backspace() {
  265. // 删除value的最后一个字符
  266. if(this.confirmData.vehicleNo.length) this.confirmData.vehicleNo = this.confirmData.vehicleNo.substr(0, this.confirmData.vehicleNo.length - 1);
  267. console.log(this.confirmData.vehicleNo);
  268. },
  269. carTypeConfirm(e){
  270. this.confirmData.vehicleType = e[0].value;
  271. },
  272. carColorConfirm(e){
  273. console.log('e',e)
  274. this.confirmData.vehicleColor = e[0].value;
  275. console.log('this.confirmData',this.confirmData)
  276. },
  277. getPic(){
  278. let that = this;
  279. ocr.ocrVehicleNo((ret) => {
  280. if (ret.success){
  281. that.confirmData.vehicleNo = ret.vehicleNo;
  282. that.confirmData.carImg = 'data:image/png;base64,' + ret.imageBase64;
  283. this.$u.api.tencentBase64Upload({
  284. base64: ret.imageBase64,
  285. suffix: 'png'
  286. })
  287. .then(res=>{
  288. that.confirmData.vehicleImage = res.data.url;
  289. }).catch(err=>{});
  290. }else {
  291. plus.nativeUI.toast('识别失败');
  292. }
  293. });
  294. // uni.chooseImage({
  295. // count: 1, //默认9
  296. // sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  297. // sourceType: ['camera'], //
  298. // success: function (res) {
  299. // console.log('img',res)
  300. // that.confirmData.carImg = res.tempFilePaths[0];
  301. // uni.showLoading({});
  302. // const tempFilePaths = res.tempFilePaths;
  303. // // 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
  304. // uni.uploadFile({
  305. // url: `${that.config.fileUrl}/baidu/ocr`,
  306. // filePath: tempFilePaths[0],
  307. // name: 'file',
  308. // formData: {
  309. // 'isUpload': '1' // 上传附带参数
  310. // },
  311. // success: (res) => {
  312. // // 根据接口具体返回格式 赋值具体对应url
  313. // // alert(uploadFileRes.data);
  314. // let resobj=eval("("+res.data+")");
  315. // uni.hideLoading();
  316. // if(resobj.code==200){
  317. // console.log(resobj);
  318. // //#ifdef APP-PLUS
  319. // speak(resobj.data.vehicleNo);
  320. // //#endif
  321. // that.confirmData.vehicleNo = resobj.data.vehicleNo;
  322. // that.confirmData.vehicleClor = resobj.data.vehicleClor;
  323. // that.confirmData.vehicleImage = resobj.data.url;
  324. // console.log('that.confirmData',that.confirmData);
  325. // }else{
  326. // that.$refs.uToast.show({
  327. // title: resobj.msg,
  328. // type: 'error'
  329. // });
  330. // };
  331. // console.log('resobj',resobj);
  332. // },
  333. // fail: (err) => {
  334. // that.$refs.uToast.show({
  335. // title:err.msg,
  336. // type: 'error'
  337. // });
  338. // uni.hideLoading();
  339. // }
  340. // });
  341. // }
  342. // });
  343. },
  344. confirmIn(){
  345. let files = [];
  346. let that = this;
  347. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  348. files = this.$refs.uUpload.lists.filter(val => {
  349. return val.progress == 100;
  350. });
  351. // 如果不需要进行太多的处理,直接如下即可
  352. // files = this.$refs.uUpload.lists;
  353. that.confirmData.images = [];
  354. this.confirmData.spaceId = that.confirmData.id;
  355. files.forEach(function(element) {
  356. that.confirmData.images.push(element.response.data.url);
  357. });
  358. let param = this.confirmData;
  359. this.$u.api.parkInConfirm(param)
  360. .then(res=>{
  361. this.$refs.uToast.show({
  362. title: res.msg,
  363. type: 'success',
  364. url:'pages/getout/getout'
  365. });
  366. //#ifdef APP-PLUS
  367. device.print(res.data.print);
  368. speak(res.data.speak);
  369. //#endif
  370. console.log('parkInConfirm',res)
  371. }).catch(err=>{
  372. this.$refs.uToast.show({
  373. title: err.msg,
  374. type: 'error',
  375. // url:'pages/parking/parking'
  376. });
  377. console.log('parkInConfirm ',err)
  378. });
  379. }
  380. },
  381. filters:{
  382. timeago(inTime,currentTime){
  383. var time_start = '', clock_start = ''
  384. if (inTime) {
  385. time_start = new Date(inTime.replace(/-/g,'/'));
  386. time_start.getTime();
  387. }
  388. // console.log('currentTime',this.currentTime)
  389. const formatNumber = (num) => {
  390. num = num.toString()
  391. return num[1] ? num : '0' + num
  392. };
  393. var i_total_secs = Math.round(currentTime.getTime() - clock_start);
  394. //计算出相差天数
  395. var days = Math.floor(i_total_secs / (24 * 3600 * 1000))
  396. //计算出小时数
  397. // var leave1 = i_total_secs % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  398. // var hours = Math.floor(leave1 / (3600 * 1000))
  399. var hours = Math.floor(i_total_secs / (3600 * 1000))
  400. //计算相差分钟数
  401. var leave2 = i_total_secs % (3600 * 1000) //计算小时数后剩余的毫秒数
  402. var minutes = Math.floor(leave2 / (60 * 1000))
  403. //计算相差秒数
  404. var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  405. var seconds = Math.round(leave3 / 1000)
  406. hours = formatNumber(hours);
  407. minutes = formatNumber(minutes);
  408. seconds = formatNumber(seconds);
  409. // console.log(days + '天' + hours + '个小时' + minutes + '分钟' + seconds + '秒');
  410. return hours + ':' + minutes + ':' + seconds
  411. }
  412. }
  413. }
  414. </script>
  415. <style lang="scss">
  416. @import "../parking/parking.scss";
  417. @import "./getout.scss";
  418. </style>