short_track_addition.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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', '/shortFillingInfo/api/addShortFilling', that
  101. .detailData)
  102. .then(res1 => {
  103. console.log(111)
  104. console.log(res1)
  105. if (res1.data.code == 200) {
  106. that.$api.msg('提交成功')
  107. uni.navigateTo({
  108. url: '/pages/shortDistance/short_distance_record'
  109. })
  110. } else {
  111. that.$api.msg('提交失败')
  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', '/shortFillingInfo/getShortFilling', {
  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. console.log('车牌号')
  263. console.log(this.detailData.carNo)
  264. if (!this.detailData.carNo) {
  265. uni.showToast({
  266. title: "车牌号不能为空!",
  267. icon: "none"
  268. })
  269. return
  270. }
  271. that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  272. that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  273. that.detailData.driverName = uni.getStorageSync('userInfo').userName
  274. that.detailData.trackFlag = "0"
  275. console.log(that.detailData)
  276. that.$api.doRequest('post', '/shortFillingInfo/api/addShortFilling', that.detailData).then(res1 => {
  277. console.log(111)
  278. console.log(res1)
  279. if (res1.data.code == 200) {
  280. console.log(222)
  281. uni.hideLoading()
  282. that.$helper.fUN_AmapLocation.start({
  283. intervalTime: 5000,
  284. isReport: false
  285. },
  286. res => {
  287. this.covers = [{
  288. id: 0,
  289. latitude: res.latitude,
  290. longitude: res.longitude,
  291. iconPath: '../../../static/img/location.png',
  292. }]
  293. this.id = res1.data.data
  294. let _data = {
  295. fillingId: res1.data.data,
  296. longitude: res.longitude,
  297. latitude: res.latitude,
  298. province: res.province,
  299. city: res.city,
  300. area: res.district
  301. }
  302. // if (this.shippingNoteInfos && this.shippingNoteInfos.length > 0) { //更新持续定位经纬度
  303. // for (let i = 0; i < this.shippingNoteInfos.length; i++) {
  304. // this.shippingNoteInfos[i].startLatitude = _data.latitude //纬度
  305. // this.shippingNoteInfos[i].startLocationText = _data.city //起点
  306. // this.shippingNoteInfos[i].startLongitude = _data.longitude //经度
  307. // }
  308. // }
  309. this.$helper.dtList.push(_data)
  310. uni.setStorageSync('mapDT', this.$helper.dtList);
  311. console.log('this.$helper.dtList')
  312. console.log(this.$helper.dtList)
  313. console.log("条数", uni.getStorageSync('mapDT').length)
  314. if (uni.getStorageSync('mapDT').length > 5) {
  315. //存储轨迹经纬度list
  316. that.$api.doRequest('post', '/trackDetailInfo/api/addTrackDetail', {
  317. fillingId: _data.fillingId,
  318. carNo: that.detailData.carNo,
  319. // trackDetailInfos: JSON.stringify(uni.getStorageSync('mapGJ'))
  320. trackDetailInfos: uni.getStorageSync('mapDT')
  321. }).then(res => {
  322. that.polyline[0].points.push({
  323. latitude: _data.latitude,
  324. longitude: _data.longitude
  325. });
  326. console.log('上传经纬度list', res)
  327. uni.removeStorageSync('mapDT');
  328. this.$helper.dtList = []
  329. })
  330. .catch(res => {
  331. uni.showToast({
  332. icon: "none",
  333. title: res.message
  334. })
  335. });
  336. }
  337. }
  338. );
  339. uni.showToast({
  340. title: "轨迹持续监控中!",
  341. icon: "none",
  342. complete() {
  343. that.titleBtn = '结束轨迹'
  344. }
  345. })
  346. }
  347. })
  348. .catch(res => {
  349. uni.$u.toast(res.message);
  350. });
  351. },
  352. }
  353. }
  354. </script>
  355. <style lang='scss' scoped>
  356. page {
  357. background: #F5F6FA;
  358. }
  359. .title_b {
  360. margin: 20rpx 20rpx 0rpx 20rpx;
  361. padding: 20rpx 10rpx 20rpx 10rpx;
  362. font-size: 18px;
  363. font-weight: 550;
  364. }
  365. .c-row {
  366. display: -webkit-box;
  367. display: -webkit-flex;
  368. display: flex;
  369. -webkit-box-align: center;
  370. -webkit-align-items: center;
  371. align-items: center;
  372. /* padding: 20rpx 30rpx;
  373. margin: 20rpx 0; */
  374. }
  375. .con-list {
  376. -webkit-box-flex: 1;
  377. -webkit-flex: 1;
  378. flex: 1;
  379. display: -webkit-box;
  380. display: -webkit-flex;
  381. display: flex;
  382. -webkit-box-orient: vertical;
  383. -webkit-box-direction: normal;
  384. -webkit-flex-direction: column;
  385. flex-direction: column;
  386. color: #303133;
  387. line-height: 40rpx;
  388. text-align: right;
  389. padding-right: 20rpx;
  390. }
  391. .wrap {
  392. background: #fff;
  393. padding: 40rpx 20rpx;
  394. box-sizing: border-box;
  395. height: 20vh;
  396. }
  397. .button {
  398. background: #22C572;
  399. width: 90%;
  400. margin: 40rpx auto;
  401. padding: 10px;
  402. color: #fff;
  403. text-align: center;
  404. border-radius: 30px;
  405. }
  406. .button1 {
  407. background: #ff0000;
  408. width: 90%;
  409. margin: 0 auto;
  410. padding: 10px;
  411. color: #fff;
  412. text-align: center;
  413. border-radius: 30px;
  414. }
  415. .button2 {
  416. background: #4089ff;
  417. width: 90%;
  418. margin: 0 auto;
  419. padding: 10px;
  420. color: #fff;
  421. text-align: center;
  422. border-radius: 30px;
  423. }
  424. .buns_item {
  425. display: flex;
  426. padding: 80rpx 0 50rpx 0;
  427. justify-content: space-around;
  428. }
  429. .but_css {
  430. background: #22C572;
  431. width: 40%;
  432. padding: 20rpx;
  433. color: #fff;
  434. text-align: center;
  435. border-radius: 20rpx;
  436. }
  437. /deep/.u-radio-group {
  438. flex-direction: row-reverse;
  439. }
  440. .no-boder {
  441. border: 0;
  442. }
  443. .textarea {
  444. background: #F9F9FA;
  445. border: 1px solid #EEEEEE;
  446. }
  447. .map {
  448. width: 100vw;
  449. height: 80vh;
  450. }
  451. </style>