track_addition.vue 18 KB

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