getout.vue 13 KB

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