track_addition.vue 16 KB

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