track_addition.vue 18 KB

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