track_addition.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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)'
  15. :disabled='titleBtn=="申请报销"' 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. fillingId: '',
  33. polyline: [{ //指定一系列坐标点,从数组第一项连线至最后一项
  34. points: [],
  35. color: "#0000AA", //线的颜色
  36. width: 1, //线的宽度
  37. //     dottedLine:true,//是否虚线
  38. }],
  39. carNo:'',
  40. show:false,
  41. show4:false,
  42. carNolist:[],
  43. detailData: {
  44. carNo: '',
  45. travelStatus: '',
  46. originProvince: '',
  47. originCity: '',
  48. originArea: '',
  49. originLongitude: '',
  50. originLatitude: '',
  51. destinationProvince: '',
  52. destinationCity: '',
  53. destinationArea: '',
  54. destinationLongitude: '',
  55. destinationLatitude: '',
  56. trackFlag: '',
  57. compId: '',
  58. commonId: '',
  59. driverName: '',
  60. fillingNo: '',
  61. strokeType: '1',
  62. },
  63. covers: [],
  64. titleBtn: "开始轨迹",
  65. }
  66. },
  67. created() {
  68. // #ifdef APP-PLUS
  69. const subNVue = uni.getSubNVueById('popview') //'popview'就是你在
  70. subNVue.hide('none', 100);
  71. uni.$on('page-popup-submit', (data) => {
  72. console.log(data)
  73. subNVue.hide('none', 100);
  74. this.submit()
  75. })
  76. uni.$on('page-popup-close', (data) => {
  77. console.log(data)
  78. subNVue.hide('none', 100);
  79. })
  80. // #endif
  81. },
  82. destroyed() {
  83. // 移除监听事件
  84. uni.$off("page-popup-submit")
  85. },
  86. onLoad(options) {
  87. // this.$api.doRequest('get', '/carInfo/selectCars', { currentPage:1,
  88. // pageSize:9999,
  89. // compId: uni.getStorageSync('pcUserInfo').compId,})
  90. // .then(res1 => {
  91. // if(res1.data.code==200){
  92. // this.carNolist=res1.data.data.records
  93. // }
  94. // })
  95. // .catch(res => {
  96. // uni.$u.toast(res.message);
  97. // });
  98. this.id = options.id
  99. that = this
  100. },
  101. onShow() {
  102. // this.$api.doRequest('post', '/CarPostionController/api/getlocation', {currentPage:1,
  103. // pageSize:9999,compId: uni.getStorageSync('pcUserInfo').compId,})
  104. // .then(res1 => {
  105. // // if(res1.data.code==200){
  106. // console.log(res1,11111111)
  107. // // }
  108. // })
  109. // .catch(res => {
  110. // uni.$u.toast(res.message);
  111. // });
  112. var that = this
  113. if (this.id) {
  114. console.log(1111111)
  115. this.seeInfo()
  116. } else {
  117. // #ifdef APP-PLUS
  118. this.getLngLat('开始轨迹');
  119. // #endif
  120. }
  121. },
  122. methods: {
  123. carnopicker(e){
  124. this.detailData.carNo=this.carNolist[e.target.value].carNo
  125. },
  126. getLngLat(type) {
  127. this.checkOpenGPSServiceByAndroidIOS()
  128. var that = this
  129. uni.showLoading({
  130. title: '获取定位中',
  131. mask: true
  132. })
  133. var num=0
  134. uni.getLocation({
  135. type: 'gcj02',
  136. geocode: true,
  137. success: res => {
  138. if (res.latitude) {
  139. console.log("定位信息", res)
  140. if (type == '开始轨迹' || type == '已开始') {
  141. that.detailData.originLongitude = res.longitude;
  142. that.detailData.originLatitude = res.latitude;
  143. that.detailData.originProvince = res.address.province;
  144. that.detailData.originCity = that.$helper.filterUrban(res.address.city)
  145. that.detailData.originArea = that.$helper.filterUrban(res.address.district)
  146. that.detailData.originAddress = res.address.street + res.address.streetNum
  147. } else if (type == '结束轨迹') {
  148. // console.log("res",res)
  149. that.detailData.carNo=that.carNo
  150. that.detailData.destinationLongitude = res.longitude;
  151. that.detailData.destinationLatitude = res.latitude;
  152. that.detailData.destinationProvince = res.address.province;
  153. that.detailData.destinationCity = that.$helper.filterUrban(res.address.city)
  154. that.detailData.destinationArea = that.$helper.filterUrban(res.address
  155. .district)
  156. that.detailData.destinationAddress = res.address.street + res.address.streetNum
  157. that.detailData.trackFlag = "1"
  158. num++
  159. console.log("asddfadsad",that.detailData,num)
  160. if (!that.detailData.destinationAddress) {
  161. uni.showToast({
  162. title: "未获取结束位置,请开启定位在试!",
  163. icon: "none"
  164. })
  165. return
  166. }
  167. that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling', that.detailData)
  168. .then(res1 => {
  169. if (res1.data.code == 200) {
  170. this.titleBtn = "申请报销"
  171. }
  172. })
  173. .catch(res => {
  174. uni.$u.toast(res.message);
  175. });
  176. }
  177. this.covers = [{
  178. id: 0,
  179. latitude: res.latitude,
  180. longitude: res.longitude,
  181. iconPath: '../../../static/img/location.png',
  182. }]
  183. that.$forceUpdate()
  184. uni.hideLoading()
  185. } else {
  186. if (uni.getSystemInfoSync().platform == 'android') {
  187. var context = plus.android.importClass("android.content.Context");
  188. var locationManager = plus.android.importClass(
  189. "android.location.LocationManager");
  190. var main = plus.android.runtimeMainActivity();
  191. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  192. that.bool = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)
  193. }
  194. if (that.bool === false) {
  195. uni.showModal({
  196. title: '提示',
  197. content: '请打开定位服务',
  198. success: ({
  199. confirm,
  200. cancel
  201. }) => {
  202. if (confirm) {
  203. if (uni.getSystemInfoSync().platform == 'android') {
  204. var Intent = plus.android.importClass(
  205. 'android.content.Intent');
  206. var Settings = plus.android.importClass(
  207. 'android.provider.Settings');
  208. var intent = new Intent(Settings
  209. .ACTION_LOCATION_SOURCE_SETTINGS);
  210. var main = plus.android.runtimeMainActivity();
  211. main.startActivity(intent); // 打开系统设置GPS服务页面
  212. }
  213. }
  214. }
  215. });
  216. uni.hideLoading()
  217. }
  218. }
  219. },
  220. fail: res => {
  221. console.log('定位失败')
  222. console.log(res)
  223. uni.hideLoading()
  224. }
  225. });
  226. },
  227. checkOpenGPSServiceByAndroidIOS() {
  228. let system = uni.getSystemInfoSync(); // 获取系统信息
  229. if (system.platform === 'android') { // 判断平台
  230. var context = plus.android.importClass("android.content.Context");
  231. var locationManager = plus.android.importClass("android.location.LocationManager");
  232. var main = plus.android.runtimeMainActivity();
  233. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  234. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  235. uni.showModal({
  236. title: '提示',
  237. content: '请打开定位服务功能',
  238. // showCancel: false, // 不显示取消按钮
  239. success(res) {
  240. if (res.confirm) {
  241. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  242. var Intent = plus.android.importClass('android.content.Intent');
  243. var Settings = plus.android.importClass('android.provider.Settings');
  244. var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  245. main.startActivity(intent); // 打开系统设置GPS服务页面
  246. }
  247. }
  248. }
  249. });
  250. }
  251. } else if (system.platform === 'ios') {
  252. // console.log("苹果");
  253. var cllocationManger = plus.ios.import("CLLocationManager");
  254. var enable = cllocationManger.locationServicesEnabled();
  255. var status = cllocationManger.authorizationStatus();
  256. plus.ios.deleteObject(cllocationManger);
  257. if (enable && status != 2) {
  258. console.log("手机系统的定位已经打开");
  259. } else {
  260. console.log("手机系统的定位没有打开");
  261. uni.showModal({
  262. title: '提示',
  263. content: '请前往设置-隐私-定位服务打开定位服务功能',
  264. // showCancel: false, // 不显示取消按钮
  265. success(res) {
  266. if (res.confirm) {
  267. var UIApplication = plus.ios.import("UIApplication");
  268. var application2 = UIApplication.sharedApplication();
  269. var NSURL2 = plus.ios.import("NSURL");
  270. // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
  271. // var setting2 = NSURL2.URLWithString("App-Prefs:root=LOCATION_SERVICES");
  272. // var setting2 = NSURL2.URLWithString("app-settings");
  273. var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION");
  274. // var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION_SERVICES");
  275. application2.openURL(setting2);
  276. plus.ios.deleteObject(setting2);
  277. plus.ios.deleteObject(NSURL2);
  278. plus.ios.deleteObject(application2);
  279. }
  280. }
  281. });
  282. }
  283. }
  284. },
  285. seeInfo() {
  286. this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
  287. id: this.id
  288. }).then(res => {
  289. console.log(222222,res.data,this.id)
  290. if (res.data.code == 200) {
  291. this.detailData = res.data.data
  292. console.log(this.detailData,111111)
  293. if (this.detailData.travelStatus == "已开始") {
  294. this.titleBtn = "结束轨迹"
  295. } else if (this.detailData.travelStatus == "已结束") {
  296. this.titleBtn = "申请报销"
  297. }
  298. // #ifdef APP-PLUS
  299. this.getLngLat(this.detailData.travelStatus);
  300. // #endif
  301. }
  302. })
  303. },
  304. async seeInfo1() {
  305. await this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
  306. id: this.id
  307. }).then(res => {
  308. if (res.data.code == 200) {
  309. this.detailData = res.data.data
  310. }
  311. })
  312. },
  313. // 申请报销
  314. reimbursement() {
  315. uni.navigateTo({
  316. url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
  317. })
  318. },
  319. // 结束轨迹
  320. endTrack() {
  321. this.carNo=this.detailData.carNo
  322. // #ifdef APP-PLUS
  323. const subNVue = uni.getSubNVueById('popview') //'popview'就是你在
  324. subNVue.show('zoom-fade-out', 300, function(){ });
  325. // #endif
  326. },
  327. submit(){
  328. if (that.$helper.fUN_AmapLocation) {
  329. that.$helper.fUN_AmapLocation.stop({}, result => {
  330. console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  331. // 更新轨迹结束地点
  332. // 更新结束地点位置
  333. this.seeInfo1()
  334. this.getLngLat('结束轨迹')
  335. });
  336. }
  337. },
  338. //开始轨迹
  339. startTrack() {
  340. var that=this
  341. if (!this.detailData.carNo) {
  342. uni.showToast({
  343. title: "车牌号不能为空!",
  344. icon: "none"
  345. })
  346. return
  347. }
  348. if (!this.detailData.originAddress) {
  349. uni.showToast({
  350. title: "未获取起始位置,请开启定位在试!",
  351. icon: "none"
  352. })
  353. return
  354. }
  355. uni.showLoading({
  356. title:'加载中',
  357. mask:true
  358. })
  359. that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  360. that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  361. that.detailData.driverName = uni.getStorageSync('userInfo').userName
  362. that.detailData.trackFlag = "0"
  363. console.log(that.detailData)
  364. that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling', that.detailData).then(res1 => {
  365. console.log(res1.data)
  366. if (res1.data.code == 200) {
  367. that.$helper.fUN_AmapLocation.start({
  368. intervalTime: 5000,
  369. isReport: false
  370. },
  371. res => {
  372. this.covers = [{
  373. id: 0,
  374. latitude: res.latitude,
  375. longitude: res.longitude,
  376. iconPath: '../../../static/img/location.png',
  377. }]
  378. this.id = res1.data.data
  379. this.seeInfo1()
  380. let _data = {
  381. fillingId: res1.data.data,
  382. longitude: res.longitude,
  383. latitude: res.latitude,
  384. province: res.province,
  385. city: res.city,
  386. area: res.district
  387. }
  388. // if (this.shippingNoteInfos && this.shippingNoteInfos.length > 0) { //更新持续定位经纬度
  389. // for (let i = 0; i < this.shippingNoteInfos.length; i++) {
  390. // this.shippingNoteInfos[i].startLatitude = _data.latitude //纬度
  391. // this.shippingNoteInfos[i].startLocationText = _data.city //起点
  392. // this.shippingNoteInfos[i].startLongitude = _data.longitude //经度
  393. // }
  394. // }
  395. this.$helper.gjList.push(_data)
  396. uni.setStorageSync('mapGJ', this.$helper.gjList);
  397. console.log('this.$helper.gjList')
  398. console.log(this.$helper.gjList)
  399. console.log("条数", uni.getStorageSync('mapGJ').length)
  400. if (uni.getStorageSync('mapGJ').length > 5) {
  401. //存储轨迹经纬度list
  402. that.$api.doRequest('post', '/trackDetailInfo/api/addTrackDetail', {
  403. fillingId: _data.fillingId,
  404. carNo: that.detailData.carNo,
  405. // trackDetailInfos: JSON.stringify(uni.getStorageSync('mapGJ'))
  406. trackDetailInfos: uni.getStorageSync('mapGJ')
  407. }).then(res => {
  408. that.polyline[0].points.push({
  409. latitude: _data.latitude,
  410. longitude: _data.longitude
  411. });
  412. console.log('上传经纬度list', res)
  413. uni.hideLoading()
  414. uni.removeStorageSync('mapGJ');
  415. this.$helper.gjList = []
  416. })
  417. .catch(res => {
  418. uni.showToast({
  419. icon: "none",
  420. title: res.message
  421. })
  422. });
  423. }
  424. }
  425. );
  426. uni.showToast({
  427. title: "轨迹持续监控中!",
  428. icon: "none",
  429. complete() {
  430. that.titleBtn = '结束轨迹'
  431. }
  432. })
  433. }
  434. })
  435. .catch(res => {
  436. uni.$u.toast(res.message);
  437. });
  438. // if (this.titleBtn == "开始轨迹") {
  439. // var that = this
  440. // uni.showModal({
  441. // content: "确定开始轨迹?",
  442. // showCancel: true,
  443. // confirmText: '确定',
  444. // success: function(res) {
  445. // if (res.confirm) {
  446. // that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  447. // that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  448. // that.detailData.driverName = uni.getStorageSync('userInfo').userName
  449. // that.detailData.trackFlag = "0"
  450. // that.detailData.fillingNo = "202207040001"
  451. // that.detailData.originProvince = "辽宁省"
  452. // that.detailData.originCity = "营口市"
  453. // that.detailData.originArea = "鲅鱼圈区"
  454. // that.detailData.originLongitude = "122.21"
  455. // that.detailData.originLatitude = "40.664"
  456. // that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
  457. // that.detailData
  458. // )
  459. // .then(res => {
  460. // that.id = res.data.data
  461. // if (res.data.code == 200) {
  462. // that.$api.msg('提交成功')
  463. // that.titleBtn = "结束轨迹"
  464. // } else {
  465. // that.$api.msg('提交失败')
  466. // }
  467. // })
  468. // }
  469. // }
  470. // })
  471. // } else if (this.titleBtn == "结束轨迹") {
  472. // var that = this
  473. // uni.showModal({
  474. // content: "确定结束轨迹?",
  475. // showCancel: true,
  476. // confirmText: '确定',
  477. // success: function(res) {
  478. // if (res.confirm) {
  479. // that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  480. // that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  481. // that.detailData.driverName = uni.getStorageSync('userInfo').userName
  482. // that.detailData.trackFlag = "1"
  483. // that.detailData.destinationProvince = "江苏省"
  484. // that.detailData.destinationCity = "宿迁市"
  485. // that.detailData.destinationArea = "宿城区"
  486. // that.detailData.destinationLongitude = "118.291"
  487. // that.detailData.destinationLatitude = "33.942"
  488. // that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
  489. // that.detailData
  490. // )
  491. // .then(res => {
  492. // if (res.data.code == 200) {
  493. // that.$api.msg('提交成功')
  494. // that.titleBtn = "申请报销"
  495. // } else {
  496. // that.$api.msg('提交失败')
  497. // }
  498. // })
  499. // }
  500. // }
  501. // })
  502. // } else {
  503. // uni.navigateTo({
  504. // url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
  505. // })
  506. // }
  507. },
  508. }
  509. }
  510. </script>
  511. <style lang='scss' scoped>
  512. page {
  513. background: #F5F6FA;
  514. }
  515. .title_b {
  516. margin: 20rpx 20rpx 0rpx 20rpx;
  517. padding: 20rpx 10rpx 20rpx 10rpx;
  518. font-size: 18px;
  519. font-weight: 550;
  520. }
  521. .c-row {
  522. display: -webkit-box;
  523. display: -webkit-flex;
  524. display: flex;
  525. -webkit-box-align: center;
  526. -webkit-align-items: center;
  527. align-items: center;
  528. /* padding: 20rpx 30rpx;
  529. margin: 20rpx 0; */
  530. }
  531. .con-list {
  532. -webkit-box-flex: 1;
  533. -webkit-flex: 1;
  534. flex: 1;
  535. display: -webkit-box;
  536. display: -webkit-flex;
  537. display: flex;
  538. -webkit-box-orient: vertical;
  539. -webkit-box-direction: normal;
  540. -webkit-flex-direction: column;
  541. flex-direction: column;
  542. color: #303133;
  543. line-height: 40rpx;
  544. text-align: right;
  545. padding-right: 20rpx;
  546. }
  547. .wrap {
  548. background: #fff;
  549. padding: 40rpx 20rpx;
  550. box-sizing: border-box;
  551. height: 20vh;
  552. }
  553. .button {
  554. background: #22C572;
  555. width: 90%;
  556. margin: 40rpx auto 30rpx;
  557. padding: 10px;
  558. color: #fff;
  559. text-align: center;
  560. border-radius: 30px;
  561. }
  562. .button1 {
  563. background: #ff0000;
  564. width: 90%;
  565. margin: 40rpx auto 30rpx;
  566. padding: 10px;
  567. color: #fff;
  568. text-align: center;
  569. border-radius: 30px;
  570. }
  571. .button2 {
  572. background: #4089ff;
  573. width: 90%;
  574. margin: 40rpx auto 30rpx;
  575. padding: 10px;
  576. color: #fff;
  577. text-align: center;
  578. border-radius: 30px;
  579. }
  580. .buns_item {
  581. display: flex;
  582. padding: 80rpx 0 50rpx 0;
  583. justify-content: space-around;
  584. }
  585. .but_css {
  586. background: #22C572;
  587. width: 40%;
  588. padding: 20rpx;
  589. color: #fff;
  590. text-align: center;
  591. border-radius: 20rpx;
  592. }
  593. /deep/.u-radio-group {
  594. flex-direction: row-reverse;
  595. }
  596. .no-boder {
  597. border: 0;
  598. }
  599. .textarea {
  600. background: #F9F9FA;
  601. border: 1px solid #EEEEEE;
  602. }
  603. .map {
  604. width: 100vw;
  605. height: 80vh;
  606. }
  607. </style>