short_track_addition.vue 14 KB

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