track_addition.vue 16 KB

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