getout.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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="openPage('pages/index/index')">返回主页</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. openPage(path) {
  127. console.log('path',path);
  128. this.$u.route({
  129. url: path
  130. })
  131. },
  132. customBack(){
  133. this.$u.route({
  134. // type:'switchTab',
  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. this.roadspaceList = res.data.rows;
  146. console.log('handleGetRoadspace',res)
  147. }).catch(err=>{
  148. if(err.errMsg){
  149. this.$refs.uToast.show({
  150. title: '请检查网络',
  151. type: 'error',
  152. });
  153. return false;
  154. };
  155. err.msg&&this.$refs.uToast.show({
  156. title: err.msg,
  157. type: 'error',
  158. });
  159. console.log('handleGetRoadspace ',err)
  160. });
  161. },
  162. roadspaceClick(item){
  163. this.confirmData = item;
  164. this.confirmData.vehicleColor = 0;
  165. this.confirmData.vehicleType = 0;
  166. this.orderInfo = item;
  167. this.spaceId = item.id;
  168. if(!item.vehicleNo){
  169. //无车牌打开补全车牌信息
  170. let that = this;
  171. ocr.ocrVehicleNo((ret) => {
  172. if (ret.success){
  173. that.confirmData.vehicleNo = ret.vehicleNo;
  174. that.confirmData.carImg = 'data:image/png;base64,' + ret.imageBase64;
  175. this.$u.api.tencentBase64Upload({
  176. base64: ret.imageBase64,
  177. suffix: 'png'
  178. })
  179. .then(res=>{
  180. this.confirmPop = true;
  181. that.confirmData.vehicleImage = res.data.url;
  182. }).catch(err=>{});
  183. }else {
  184. plus.nativeUI.toast('识别失败');
  185. }
  186. });
  187. }else {
  188. //信息完整打开出场页面
  189. const d = new Date();
  190. this.$u.route({
  191. url: 'pages/getout/getoutpage/getoutpage',
  192. params: {
  193. orderID:item.id,
  194. orderInTime:item.inTime,
  195. 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()}`,
  196. orderSpaceName:item.spaceName,
  197. orderVehicleNo:item.vehicleNo
  198. }
  199. });
  200. }
  201. },
  202. actionClick(e){
  203. console.log('actionClick',e);
  204. switch (e){
  205. case 0:
  206. const d = new Date();
  207. this.$u.route({
  208. url: 'pages/getout/getoutpage/getoutpage',
  209. params: {
  210. orderID:this.orderInfo.id,
  211. orderInTime:this.orderInfo.inTime,
  212. 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()}`,
  213. orderSpaceName:this.orderInfo.spaceName,
  214. orderVehicleNo:this.orderInfo.vehicleNo
  215. }
  216. });
  217. break;
  218. case 1:{
  219. this.confirmPop = true;
  220. break;
  221. }
  222. default:
  223. break;
  224. }
  225. },
  226. messageInputClick(){
  227. this.keyboardshow = true;
  228. },
  229. // 按键被点击(点击退格键不会触发此事件)
  230. keyboardChange(val) {
  231. // 将每次按键的值拼接到value变量中,注意+=写法
  232. this.confirmData.vehicleNo += val;
  233. console.log(this.confirmData.vehicleNo);
  234. },
  235. // 退格键被点击
  236. backspace() {
  237. // 删除value的最后一个字符
  238. if(this.confirmData.vehicleNo.length) this.confirmData.vehicleNo = this.confirmData.vehicleNo.substr(0, this.confirmData.vehicleNo.length - 1);
  239. console.log(this.confirmData.vehicleNo);
  240. },
  241. carTypeConfirm(e){
  242. this.confirmData.vehicleType = e[0].value;
  243. },
  244. carColorConfirm(e){
  245. console.log('e',e)
  246. this.confirmData.vehicleColor = e[0].value;
  247. console.log('this.confirmData',this.confirmData)
  248. },
  249. getPic(){
  250. let that = this;
  251. ocr.ocrVehicleNo((ret) => {
  252. if (ret.success){
  253. that.confirmData.vehicleNo = ret.vehicleNo;
  254. that.confirmData.carImg = 'data:image/png;base64,' + ret.imageBase64;
  255. this.$u.api.tencentBase64Upload({
  256. base64: ret.imageBase64,
  257. suffix: 'png'
  258. })
  259. .then(res=>{
  260. that.confirmData.vehicleImage = res.data.url;
  261. }).catch(err=>{});
  262. }else {
  263. plus.nativeUI.toast('识别失败');
  264. }
  265. });
  266. // uni.chooseImage({
  267. // count: 1, //默认9
  268. // sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  269. // sourceType: ['camera'], //
  270. // success: function (res) {
  271. // console.log('img',res)
  272. // that.confirmData.carImg = res.tempFilePaths[0];
  273. // uni.showLoading({});
  274. // const tempFilePaths = res.tempFilePaths;
  275. // // 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
  276. // uni.uploadFile({
  277. // url: `${that.config.fileUrl}/baidu/ocr`,
  278. // filePath: tempFilePaths[0],
  279. // name: 'file',
  280. // formData: {
  281. // 'isUpload': '1' // 上传附带参数
  282. // },
  283. // success: (res) => {
  284. // // 根据接口具体返回格式 赋值具体对应url
  285. // // alert(uploadFileRes.data);
  286. // let resobj=eval("("+res.data+")");
  287. // uni.hideLoading();
  288. // if(resobj.code==200){
  289. // console.log(resobj);
  290. // //#ifdef APP-PLUS
  291. // speak(resobj.data.vehicleNo);
  292. // //#endif
  293. // that.confirmData.vehicleNo = resobj.data.vehicleNo;
  294. // that.confirmData.vehicleClor = resobj.data.vehicleClor;
  295. // that.confirmData.vehicleImage = resobj.data.url;
  296. // console.log('that.confirmData',that.confirmData);
  297. // }else{
  298. // that.$refs.uToast.show({
  299. // title: resobj.msg,
  300. // type: 'error'
  301. // });
  302. // };
  303. // console.log('resobj',resobj);
  304. // },
  305. // fail: (err) => {
  306. // that.$refs.uToast.show({
  307. // title:err.msg,
  308. // type: 'error'
  309. // });
  310. // uni.hideLoading();
  311. // }
  312. // });
  313. // }
  314. // });
  315. },
  316. confirmIn(){
  317. let files = [];
  318. let that = this;
  319. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  320. files = this.$refs.uUpload.lists.filter(val => {
  321. return val.progress == 100;
  322. });
  323. // 如果不需要进行太多的处理,直接如下即可
  324. // files = this.$refs.uUpload.lists;
  325. that.confirmData.images = [];
  326. this.confirmData.spaceId = that.confirmData.id;
  327. files.forEach(function(element) {
  328. that.confirmData.images.push(element.response.data.url);
  329. });
  330. let param = this.confirmData;
  331. this.$u.api.parkInConfirm(param)
  332. .then(res=>{
  333. this.$refs.uToast.show({
  334. title: res.msg,
  335. type: 'success',
  336. url:'pages/getout/getout'
  337. });
  338. //#ifdef APP-PLUS
  339. device.print(res.data.print);
  340. speak(res.data.speak);
  341. //#endif
  342. console.log('parkInConfirm',res)
  343. }).catch(err=>{
  344. this.$refs.uToast.show({
  345. title: err.msg,
  346. type: 'error',
  347. // url:'pages/parking/parking'
  348. });
  349. console.log('parkInConfirm ',err)
  350. });
  351. }
  352. },
  353. filters:{
  354. timeago(inTime,currentTime){
  355. var time_start = new Date(inTime.replace(/-/g,'/'));
  356. var clock_start = time_start.getTime();
  357. // console.log('currentTime',this.currentTime)
  358. const formatNumber = (num) => {
  359. num = num.toString()
  360. return num[1] ? num : '0' + num
  361. };
  362. var i_total_secs = Math.round(currentTime.getTime() - clock_start);
  363. //计算出相差天数
  364. var days = Math.floor(i_total_secs / (24 * 3600 * 1000))
  365. //计算出小时数
  366. // var leave1 = i_total_secs % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  367. // var hours = Math.floor(leave1 / (3600 * 1000))
  368. var hours = Math.floor(i_total_secs / (3600 * 1000))
  369. //计算相差分钟数
  370. var leave2 = i_total_secs % (3600 * 1000) //计算小时数后剩余的毫秒数
  371. var minutes = Math.floor(leave2 / (60 * 1000))
  372. //计算相差秒数
  373. var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  374. var seconds = Math.round(leave3 / 1000)
  375. hours = formatNumber(hours);
  376. minutes = formatNumber(minutes);
  377. seconds = formatNumber(seconds);
  378. // console.log(days + '天' + hours + '个小时' + minutes + '分钟' + seconds + '秒');
  379. return hours + ':' + minutes + ':' + seconds
  380. }
  381. }
  382. }
  383. </script>
  384. <style lang="scss">
  385. @import "../parking/parking.scss";
  386. @import "./getout.scss";
  387. </style>