track_addition.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view>
  3. <map :latitude="detailData.originLatitude" :longitude="detailData.originLongitude" :markers="covers" class="map"
  4. :polyline="polyline"></map>
  5. <!-- <cover-view v-if='show'>
  6. <view>确认行程已结束?</view>
  7. </cover-view> -->
  8. <view class='wrap'>
  9. <view class="c-row">
  10. <view class="title">车牌号</view>
  11. <view class="con-list">
  12. <!-- <input :disabled='titleBtn=="申请报销"' v-model='detailData.carNo' placeholder="请输入车牌号" maxlength="7"></input> -->
  13. </view>
  14. <picker :range="carNolist" range-key="carNo" @change='carnopicker($event)' :disabled='titleBtn=="申请报销"'
  15. mode="selector">
  16. <view>{{detailData.carNo?detailData.carNo:'请选择车牌号'}}</view>
  17. </picker>
  18. </view>
  19. <view @click='startTrack' class="button" v-if='titleBtn=="开始轨迹"'>{{titleBtn}}</view>
  20. <view @click='endTrack' class="button1" v-if='titleBtn=="结束轨迹"'>{{titleBtn}}</view>
  21. <view @click='reimbursement' class="button2" v-if='titleBtn=="申请报销"'>{{titleBtn}}</view>
  22. </view>
  23. <u-toast ref="uToast" />
  24. <!-- <u-modal v-model="show" @confirm='submit' content="确认行程已结束?" :show-cancel-button='true' ></u-modal> -->
  25. </view>
  26. </template>
  27. <script>
  28. var that
  29. export default {
  30. data() {
  31. return {
  32. place: {},
  33. fillingId: '',
  34. polyline: [{ //指定一系列坐标点,从数组第一项连线至最后一项
  35. points: [],
  36. color: "#0000AA", //线的颜色
  37. width: 1, //线的宽度
  38. //     dottedLine:true,//是否虚线
  39. }],
  40. carNo: '',
  41. show: false,
  42. show4: false,
  43. carNolist: [],
  44. detailData: {
  45. carNo: '',
  46. travelStatus: '',
  47. originProvince: '',
  48. originCity: '',
  49. originArea: '',
  50. originLongitude: '',
  51. originLatitude: '',
  52. destinationProvince: '',
  53. destinationCity: '',
  54. destinationArea: '',
  55. destinationLongitude: '',
  56. destinationLatitude: '',
  57. trackFlag: '',
  58. compId: '',
  59. commonId: '',
  60. driverName: '',
  61. fillingNo: '',
  62. strokeType: '1',
  63. },
  64. covers: [],
  65. titleBtn: "开始轨迹",
  66. }
  67. },
  68. created() {
  69. // #ifdef APP-PLUS
  70. const subNVue = uni.getSubNVueById('popview') //'popview'就是你在
  71. subNVue.hide('none', 100);
  72. uni.$on('page-popup-submit', (data) => {
  73. console.log(data)
  74. subNVue.hide('none', 100);
  75. this.submit()
  76. })
  77. uni.$on('page-popup-close', (data) => {
  78. console.log(data)
  79. subNVue.hide('none', 100);
  80. })
  81. // #endif
  82. },
  83. destroyed() {
  84. // 移除监听事件
  85. uni.$off("page-popup-submit")
  86. },
  87. onLoad(options) {
  88. //获取车牌号
  89. this.$api.doRequest('get', '/carInfo/selectCars', {
  90. currentPage: 1,
  91. pageSize: 9999,
  92. compId: uni.getStorageSync('pcUserInfo').compId,
  93. })
  94. .then(res1 => {
  95. console.log(111)
  96. console.log(res1)
  97. if (res1.data.code == 200) {
  98. this.carNolist = res1.data.data.records
  99. }
  100. })
  101. .catch(res => {
  102. uni.$u.toast(res.message);
  103. });
  104. this.id = options.id
  105. that = this
  106. },
  107. onShow() {
  108. this.getLngLat('开始轨迹');
  109. // this.$api.doRequest('post', '/CarPostionController/api/getlocation', {
  110. // currentPage: 1,
  111. // pageSize: 9999,
  112. // compId: uni.getStorageSync('pcUserInfo').compId,
  113. // })
  114. // .then(res1 => {
  115. // // if(res1.data.code==200){
  116. // console.log(res1, 11111111)
  117. // // }
  118. // })
  119. // .catch(res => {
  120. // uni.$u.toast(res.message);
  121. // });
  122. var that = this
  123. if (this.id) {
  124. this.seeInfo()
  125. } else {
  126. // #ifdef APP-PLUS
  127. this.getLngLat('开始轨迹');
  128. // #endif
  129. }
  130. },
  131. methods: {
  132. carnopicker(e) {
  133. this.detailData.carNo = this.carNolist[e.target.value].carNo
  134. },
  135. async getLngLat(type) {
  136. let that = this
  137. uni.showLoading({
  138. title: '获取定位中',
  139. mask: true
  140. })
  141. let _location = {}
  142. await that.$api.doRequest('post', '/CarPostionController/api/getlocation')
  143. .then(res => {
  144. this.place = JSON.parse(res.data.data)[0]
  145. console.log(this.place)
  146. })
  147. .catch(res => {
  148. // uni.$u.toast(res.message);
  149. });
  150. await that.$api.changeLocation('post', '/v3/assistant/coordinate/convert', {
  151. key: 'dd701d394d116b50268dc16470ddd615',
  152. locations: this.place.lng + "," + this.place.lat
  153. })
  154. .then(res => {
  155. this.place = JSON.parse(res.data.data)[0]
  156. console.log(this.place)
  157. })
  158. .catch(res => {
  159. // uni.$u.toast(res.message);
  160. });
  161. let _data = {
  162. key: 'dd701d394d116b50268dc16470ddd615',
  163. location: this.place.lng + "," + this.place.lat
  164. }
  165. await that.$api.getPlace('get', '/v3/geocode/regeo', _data).then(res => {
  166. console.log('111')
  167. console.log("定位信息", res)
  168. if (type == '开始轨迹' || type == '已开始') {
  169. console.log(2)
  170. that.detailData.originLongitude = that.place.lng;
  171. that.detailData.originLatitude = that.place.lat;
  172. that.detailData.originProvince = res.data.regeocode.addressComponent.province;
  173. that.detailData.originCity = that.$helper.filterUrban(res.data.regeocode
  174. .addressComponent.city)
  175. that.detailData.originArea = that.$helper.filterUrban(res.data.regeocode
  176. .addressComponent.district)
  177. that.detailData.originAddress = res.data.regeocode.formatted_address
  178. console.log("that.detailData", that.detailData)
  179. } else if (type == '结束轨迹') {
  180. console.log("结束")
  181. // console.log("res",res)
  182. that.detailData.carNo = that.carNo
  183. that.detailData.destinationLongitude = that.place.lng;
  184. that.detailData.destinationLatitude = that.place.lat;
  185. that.detailData.destinationProvince = res.data.regeocode.addressComponent.province;
  186. that.detailData.destinationCity = that.$helper.filterUrban(res.data.regeocode
  187. .addressComponent.city)
  188. that.detailData.destinationArea = that.$helper.filterUrban(res.data.regeocode
  189. .addressComponent.district)
  190. that.detailData.destinationAddress = res.data.regeocode.formatted_address
  191. that.detailData.trackFlag = "1"
  192. console.log("asddfadsad", that.detailData)
  193. that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling', that.detailData)
  194. .then(res1 => {
  195. if (res1.data.code == 200) {
  196. this.titleBtn = "申请报销"
  197. }
  198. })
  199. .catch(res => {
  200. uni.$u.toast(res.message);
  201. });
  202. }
  203. this.covers = [{
  204. id: 0,
  205. latitude: that.place.lat,
  206. longitude: that.place.lng,
  207. iconPath: '../../../static/img/location.png',
  208. }]
  209. })
  210. .catch(res => {
  211. // uni.$u.toast(res.message);
  212. });
  213. that.$forceUpdate()
  214. uni.hideLoading()
  215. },
  216. seeInfo() {
  217. this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
  218. id: this.id
  219. }).then(res => {
  220. console.log(222222, res.data, this.id)
  221. if (res.data.code == 200) {
  222. this.detailData = res.data.data
  223. console.log(this.detailData, 111111)
  224. if (this.detailData.travelStatus == "已开始") {
  225. this.titleBtn = "结束轨迹"
  226. } else if (this.detailData.travelStatus == "已结束") {
  227. this.titleBtn = "申请报销"
  228. }
  229. // #ifdef APP-PLUS
  230. this.getLngLat(this.detailData.travelStatus);
  231. // #endif
  232. }
  233. })
  234. },
  235. async seeInfo1() {
  236. await this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
  237. id: this.id
  238. }).then(res => {
  239. if (res.data.code == 200) {
  240. this.detailData = res.data.data
  241. this.getLngLat('结束轨迹')
  242. }
  243. })
  244. },
  245. // 申请报销
  246. reimbursement() {
  247. uni.navigateTo({
  248. url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
  249. })
  250. },
  251. // 结束轨迹
  252. endTrack() {
  253. this.carNo = this.detailData.carNo
  254. let that = this
  255. uni.showModal({
  256. content: "确定结束轨迹?",
  257. showCancel: true,
  258. confirmText: '确定',
  259. success: function(res) {
  260. if (res.confirm) {
  261. let time = new Date();
  262. let timeInfo = (time.getFullYear() + '-' + time.getMonth() + '-' + time.getDate() +
  263. " " + time
  264. .getHours() +
  265. ':' + time.getMinutes() + ':' + time.getSeconds())
  266. uni.setStorageSync('jyEndTime', timeInfo)
  267. that.seeInfo1()
  268. }
  269. }
  270. })
  271. // // #ifdef APP-PLUS
  272. // const subNVue = uni.getSubNVueById('popview') //'popview'就是你在
  273. // subNVue.show('zoom-fade-out', 300, function() {});
  274. // // #endif
  275. },
  276. submit() {
  277. // if (that.$helper.fUN_AmapLocation) {
  278. // that.$helper.fUN_AmapLocation.stop({}, result => {
  279. // console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  280. // // 更新轨迹结束地点
  281. // // 更新结束地点位置
  282. // this.seeInfo1()
  283. // this.getLngLat('结束轨迹')
  284. // });
  285. // }
  286. },
  287. //开始轨迹
  288. async startTrack() {
  289. var that = this
  290. // if (!this.detailData.carNo) {
  291. // uni.showToast({
  292. // title: "车牌号不能为空!",
  293. // icon: "none"
  294. // })
  295. // return
  296. // }
  297. // if (!this.detailData.originAddress) {
  298. // uni.showToast({
  299. // title: "未获取起始位置,请开启定位在试!",
  300. // icon: "none"
  301. // })
  302. // return
  303. // }
  304. uni.showLoading({
  305. title: '加载中',
  306. mask: true
  307. })
  308. that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  309. that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  310. that.detailData.driverName = uni.getStorageSync('userInfo').userName
  311. that.detailData.trackFlag = "0"
  312. console.log(that.detailData)
  313. //存储开始时间
  314. let time = new Date();
  315. let timeInfo = (time.getFullYear() + '-' + time.getMonth() + '-' + time.getDate() + " " + time
  316. .getHours() +
  317. ':' + time.getMinutes() + ':' + time.getSeconds())
  318. await that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling', that.detailData).then(res1 => {
  319. console.log(res1.data)
  320. if (res1.data.code == 200) {
  321. uni.hideLoading()
  322. // that.$helper.fUN_AmapLocation.start({
  323. // intervalTime: 5000,
  324. // isReport: false
  325. // },
  326. // res => {
  327. // this.covers = [{
  328. // id: 0,
  329. // latitude: res.latitude,
  330. // longitude: res.longitude,
  331. // iconPath: '../../../static/img/location.png',
  332. // }]
  333. this.id = res1.data.data
  334. // this.seeInfo1()
  335. // let _data = {
  336. // fillingId: res1.data.data,
  337. // longitude: res.longitude,
  338. // latitude: res.latitude,
  339. // province: res.province,
  340. // city: res.city,
  341. // area: res.district
  342. // }
  343. // if (this.shippingNoteInfos && this.shippingNoteInfos.length > 0) { //更新持续定位经纬度
  344. // for (let i = 0; i < this.shippingNoteInfos.length; i++) {
  345. // this.shippingNoteInfos[i].startLatitude = _data.latitude //纬度
  346. // this.shippingNoteInfos[i].startLocationText = _data.city //起点
  347. // this.shippingNoteInfos[i].startLongitude = _data.longitude //经度
  348. // }
  349. // }
  350. // this.$helper.gjList.push(_data)
  351. // uni.setStorageSync('mapGJ', this.$helper.gjList);
  352. // console.log('this.$helper.gjList')
  353. // console.log(this.$helper.gjList)
  354. // console.log("条数", uni.getStorageSync('mapGJ').length)
  355. // if (uni.getStorageSync('mapGJ').length > 5) {
  356. // //存储轨迹经纬度list
  357. // that.$api.doRequest('post', '/trackDetailInfo/api/addTrackDetail', {
  358. // fillingId: _data.fillingId,
  359. // carNo: that.detailData.carNo,
  360. // // trackDetailInfos: JSON.stringify(uni.getStorageSync('mapGJ'))
  361. // trackDetailInfos: uni.getStorageSync('mapGJ')
  362. // }).then(res => {
  363. // that.polyline[0].points.push({
  364. // latitude: _data.latitude,
  365. // longitude: _data.longitude
  366. // });
  367. // console.log('上传经纬度list', res)
  368. // uni.hideLoading()
  369. // uni.removeStorageSync('mapGJ');
  370. // this.$helper.gjList = []
  371. // })
  372. // .catch(res => {
  373. // uni.showToast({
  374. // icon: "none",
  375. // title: res.message
  376. // })
  377. // });
  378. // }
  379. // }
  380. // );
  381. // uni.showToast({
  382. // title: "轨迹持续监控中!",
  383. // icon: "none",
  384. // complete() {
  385. // that.titleBtn = '结束轨迹'
  386. // }
  387. // })
  388. }
  389. })
  390. .catch(res => {
  391. uni.$u.toast(res.message);
  392. });
  393. if (this.titleBtn == "开始轨迹") {
  394. var that = this
  395. uni.showModal({
  396. content: "确定开始轨迹?",
  397. showCancel: true,
  398. confirmText: '确定',
  399. success: function(res) {
  400. if (res.confirm) {
  401. uni.setStorageSync('jyStartTime', timeInfo)
  402. // that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  403. // that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  404. // that.detailData.driverName = uni.getStorageSync('userInfo').userName
  405. // that.detailData.trackFlag = "0"
  406. // that.detailData.fillingNo = "202207040001"
  407. // that.detailData.originProvince = "辽宁省"
  408. // that.detailData.originCity = "营口市"
  409. // that.detailData.originArea = "鲅鱼圈区"
  410. // that.detailData.originLongitude = "122.21"
  411. // that.detailData.originLatitude = "40.664"
  412. // that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
  413. // that.detailData
  414. // )
  415. // .then(res => {
  416. // that.id = res.data.data
  417. // if (res.data.code == 200) {
  418. // that.$api.msg('提交成功')
  419. that.titleBtn = "结束轨迹"
  420. // } else {
  421. // that.$api.msg('提交失败')
  422. // }
  423. // })
  424. }
  425. }
  426. })
  427. } else {
  428. uni.navigateTo({
  429. url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
  430. })
  431. }
  432. },
  433. }
  434. }
  435. </script>
  436. <style lang='scss' scoped>
  437. page {
  438. background: #F5F6FA;
  439. }
  440. .title_b {
  441. margin: 20rpx 20rpx 0rpx 20rpx;
  442. padding: 20rpx 10rpx 20rpx 10rpx;
  443. font-size: 18px;
  444. font-weight: 550;
  445. }
  446. .c-row {
  447. display: -webkit-box;
  448. display: -webkit-flex;
  449. display: flex;
  450. -webkit-box-align: center;
  451. -webkit-align-items: center;
  452. align-items: center;
  453. /* padding: 20rpx 30rpx;
  454. margin: 20rpx 0; */
  455. }
  456. .con-list {
  457. -webkit-box-flex: 1;
  458. -webkit-flex: 1;
  459. flex: 1;
  460. display: -webkit-box;
  461. display: -webkit-flex;
  462. display: flex;
  463. -webkit-box-orient: vertical;
  464. -webkit-box-direction: normal;
  465. -webkit-flex-direction: column;
  466. flex-direction: column;
  467. color: #303133;
  468. line-height: 40rpx;
  469. text-align: right;
  470. padding-right: 20rpx;
  471. }
  472. .wrap {
  473. background: #fff;
  474. padding: 40rpx 20rpx;
  475. box-sizing: border-box;
  476. height: 20vh;
  477. }
  478. .button {
  479. background: #22C572;
  480. width: 90%;
  481. margin: 40rpx auto 30rpx;
  482. padding: 10px;
  483. color: #fff;
  484. text-align: center;
  485. border-radius: 30px;
  486. }
  487. .button1 {
  488. background: #ff0000;
  489. width: 90%;
  490. margin: 40rpx auto 30rpx;
  491. padding: 10px;
  492. color: #fff;
  493. text-align: center;
  494. border-radius: 30px;
  495. }
  496. .button2 {
  497. background: #4089ff;
  498. width: 90%;
  499. margin: 40rpx auto 30rpx;
  500. padding: 10px;
  501. color: #fff;
  502. text-align: center;
  503. border-radius: 30px;
  504. }
  505. .buns_item {
  506. display: flex;
  507. padding: 80rpx 0 50rpx 0;
  508. justify-content: space-around;
  509. }
  510. .but_css {
  511. background: #22C572;
  512. width: 40%;
  513. padding: 20rpx;
  514. color: #fff;
  515. text-align: center;
  516. border-radius: 20rpx;
  517. }
  518. /deep/.u-radio-group {
  519. flex-direction: row-reverse;
  520. }
  521. .no-boder {
  522. border: 0;
  523. }
  524. .textarea {
  525. background: #F9F9FA;
  526. border: 1px solid #EEEEEE;
  527. }
  528. .map {
  529. width: 100vw;
  530. height: 80vh;
  531. }
  532. </style>