track_addition.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <view>
  3. <map :latitude="detailData.originLatitude" :longitude="detailData.originLongitude" :markers="covers"
  4. class="map"></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. </view>
  17. </template>
  18. <script>
  19. var that
  20. export default {
  21. data() {
  22. return {
  23. detailData: {
  24. carNo: '',
  25. travelStatus: '',
  26. originProvince: '',
  27. originCity: '',
  28. originArea: '',
  29. originLongitude: '',
  30. originLatitude: '',
  31. destinationProvince: '',
  32. destinationCity: '',
  33. destinationArea: '',
  34. destinationLongitude: '',
  35. destinationLatitude: '',
  36. trackFlag: '',
  37. compId: '',
  38. commonId: '',
  39. driverName: '',
  40. fillingNo: '',
  41. strokeType: '1',
  42. },
  43. covers: [],
  44. titleBtn: "开始轨迹",
  45. }
  46. },
  47. onLoad(options) {
  48. this.id = options.id
  49. // #ifdef APP-PLUS
  50. this.getLngLat();
  51. // #endif
  52. that = this
  53. },
  54. onShow() {
  55. var that = this
  56. if (this.id) {
  57. this.seeInfo()
  58. }
  59. },
  60. methods: {
  61. getLngLat() {
  62. this.checkOpenGPSServiceByAndroidIOS()
  63. var that = this
  64. uni.showLoading({
  65. title: '获取定位中',
  66. mask: true
  67. })
  68. uni.getLocation({
  69. type: 'gcj02',
  70. geocode: true,
  71. success: res => {
  72. if (res.latitude) {
  73. console.log(res)
  74. that.detailData.originLongitude = res.longitude;
  75. that.detailData.originLatitude = res.latitude;
  76. that.detailData.destinationCity = that.$helper.filterUrban(res.address.city)
  77. that.detailData.originArea = that.$helper.filterUrban(res.address.district)
  78. this.covers = [{
  79. id: 0,
  80. latitude: res.latitude,
  81. longitude: res.longitude,
  82. iconPath: '../../../static/img/location.png',
  83. }]
  84. that.$forceUpdate()
  85. uni.hideLoading()
  86. } else {
  87. if (uni.getSystemInfoSync().platform == 'android') {
  88. var context = plus.android.importClass("android.content.Context");
  89. var locationManager = plus.android.importClass(
  90. "android.location.LocationManager");
  91. var main = plus.android.runtimeMainActivity();
  92. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  93. that.bool = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)
  94. }
  95. if (that.bool === false) {
  96. uni.showModal({
  97. title: '提示',
  98. content: '请打开定位服务',
  99. success: ({
  100. confirm,
  101. cancel
  102. }) => {
  103. if (confirm) {
  104. if (uni.getSystemInfoSync().platform == 'android') {
  105. var Intent = plus.android.importClass(
  106. 'android.content.Intent');
  107. var Settings = plus.android.importClass(
  108. 'android.provider.Settings');
  109. var intent = new Intent(Settings
  110. .ACTION_LOCATION_SOURCE_SETTINGS);
  111. var main = plus.android.runtimeMainActivity();
  112. main.startActivity(intent); // 打开系统设置GPS服务页面
  113. }
  114. }
  115. }
  116. });
  117. uni.hideLoading()
  118. }
  119. }
  120. },
  121. fail: res => {
  122. console.log('定位失败')
  123. console.log(res)
  124. uni.hideLoading()
  125. }
  126. });
  127. },
  128. checkOpenGPSServiceByAndroidIOS() {
  129. let system = uni.getSystemInfoSync(); // 获取系统信息
  130. if (system.platform === 'android') { // 判断平台
  131. var context = plus.android.importClass("android.content.Context");
  132. var locationManager = plus.android.importClass("android.location.LocationManager");
  133. var main = plus.android.runtimeMainActivity();
  134. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  135. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  136. uni.showModal({
  137. title: '提示',
  138. content: '请打开定位服务功能',
  139. // showCancel: false, // 不显示取消按钮
  140. success(res) {
  141. if (res.confirm) {
  142. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  143. var Intent = plus.android.importClass('android.content.Intent');
  144. var Settings = plus.android.importClass('android.provider.Settings');
  145. var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  146. main.startActivity(intent); // 打开系统设置GPS服务页面
  147. }
  148. }
  149. }
  150. });
  151. }
  152. } else if (system.platform === 'ios') {
  153. // console.log("苹果");
  154. var cllocationManger = plus.ios.import("CLLocationManager");
  155. var enable = cllocationManger.locationServicesEnabled();
  156. var status = cllocationManger.authorizationStatus();
  157. plus.ios.deleteObject(cllocationManger);
  158. if (enable && status != 2) {
  159. console.log("手机系统的定位已经打开");
  160. } else {
  161. console.log("手机系统的定位没有打开");
  162. uni.showModal({
  163. title: '提示',
  164. content: '请前往设置-隐私-定位服务打开定位服务功能',
  165. // showCancel: false, // 不显示取消按钮
  166. success(res) {
  167. if (res.confirm) {
  168. var UIApplication = plus.ios.import("UIApplication");
  169. var application2 = UIApplication.sharedApplication();
  170. var NSURL2 = plus.ios.import("NSURL");
  171. // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
  172. // var setting2 = NSURL2.URLWithString("App-Prefs:root=LOCATION_SERVICES");
  173. // var setting2 = NSURL2.URLWithString("app-settings");
  174. var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION");
  175. // var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION_SERVICES");
  176. application2.openURL(setting2);
  177. plus.ios.deleteObject(setting2);
  178. plus.ios.deleteObject(NSURL2);
  179. plus.ios.deleteObject(application2);
  180. }
  181. }
  182. });
  183. }
  184. }
  185. },
  186. seeInfo() {
  187. this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
  188. id: this.id
  189. }).then(res => {
  190. if (res.data.code == 200) {
  191. this.detailData = res.data.data
  192. if (this.detailData.travelStatus == "已开始") {
  193. this.titleBtn = "结束轨迹"
  194. } else if (this.detailData.travelStatus == "已结束") {
  195. this.titleBtn = "申请报销"
  196. }
  197. }
  198. })
  199. },
  200. // 申请报销
  201. reimbursement() {
  202. uni.navigateTo({
  203. url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
  204. })
  205. },
  206. // 结束轨迹
  207. endTrack() {
  208. if (that.$helper.fUN_AmapLocation) {
  209. that.$helper.fUN_AmapLocation.stop({}, result => {
  210. console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  211. // 更新轨迹结束地点
  212. this.titleBtn = "申请报销"
  213. });
  214. }
  215. },
  216. //开始轨迹
  217. startTrack() {
  218. that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  219. that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  220. that.detailData.driverName = uni.getStorageSync('userInfo').userName
  221. that.detailData.trackFlag = "1"
  222. that.detailData.destinationProvince = ""
  223. that.detailData.destinationCity = ""
  224. that.detailData.destinationArea = ""
  225. that.detailData.destinationLongitude = ""
  226. that.detailData.destinationLatitude = ""
  227. that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling', that.detailData).then(res => {
  228. if (res.code == 200) {
  229. uni.hideLoading()
  230. that.$helper.fUN_AmapLocation.start({
  231. intervalTime: 5000,
  232. isReport: false
  233. },
  234. res => {
  235. let _data = {
  236. orderId: that.id,
  237. longitude: res.longitude,
  238. latitude: res.latitude,
  239. province: res.province,
  240. city: res.city,
  241. area: res.district
  242. }
  243. // if (this.shippingNoteInfos && this.shippingNoteInfos.length > 0) { //更新持续定位经纬度
  244. // for (let i = 0; i < this.shippingNoteInfos.length; i++) {
  245. // this.shippingNoteInfos[i].startLatitude = _data.latitude //纬度
  246. // this.shippingNoteInfos[i].startLocationText = _data.city //起点
  247. // this.shippingNoteInfos[i].startLongitude = _data.longitude //经度
  248. // }
  249. // }
  250. this.$helper.gjList.push(_data)
  251. uni.setStorageSync('mapGJ', this.$helper.gjList);
  252. // console.log('this.$helper.gjList')
  253. // console.log(this.$helper.gjList)
  254. // console.log("条数", uni.getStorageSync('mapGJ').length)
  255. if (uni.getStorageSync('mapGJ').length > 100) {
  256. //存储轨迹经纬度list
  257. this.$request.baseRequest('post', 'xx', {
  258. orderId: that.id,
  259. longitudeLatitude: JSON.stringify(uni.getStorageSync('mapGJ'))
  260. }).then(res => {
  261. uni.removeStorageSync('mapGJ');
  262. this.$helper.gjList = []
  263. })
  264. .catch(res => {
  265. uni.$u.toast(res.message);
  266. });
  267. }
  268. }
  269. );
  270. this.$refs.uToast.show({
  271. type: 'success',
  272. message: "轨迹持续监控中!",
  273. complete() {
  274. this.titleBtn = '结束轨迹'
  275. }
  276. })
  277. }
  278. })
  279. .catch(res => {
  280. uni.$u.toast(res.message);
  281. });
  282. // if (this.titleBtn == "开始轨迹") {
  283. // var that = this
  284. // uni.showModal({
  285. // content: "确定开始轨迹?",
  286. // showCancel: true,
  287. // confirmText: '确定',
  288. // success: function(res) {
  289. // if (res.confirm) {
  290. // that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  291. // that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  292. // that.detailData.driverName = uni.getStorageSync('userInfo').userName
  293. // that.detailData.trackFlag = "0"
  294. // that.detailData.fillingNo = "202207040001"
  295. // that.detailData.originProvince = "辽宁省"
  296. // that.detailData.originCity = "营口市"
  297. // that.detailData.originArea = "鲅鱼圈区"
  298. // that.detailData.originLongitude = "122.21"
  299. // that.detailData.originLatitude = "40.664"
  300. // that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
  301. // that.detailData
  302. // )
  303. // .then(res => {
  304. // that.id = res.data.data
  305. // if (res.data.code == 200) {
  306. // that.$api.msg('提交成功')
  307. // that.titleBtn = "结束轨迹"
  308. // } else {
  309. // that.$api.msg('提交失败')
  310. // }
  311. // })
  312. // }
  313. // }
  314. // })
  315. // } else if (this.titleBtn == "结束轨迹") {
  316. // var that = this
  317. // uni.showModal({
  318. // content: "确定结束轨迹?",
  319. // showCancel: true,
  320. // confirmText: '确定',
  321. // success: function(res) {
  322. // if (res.confirm) {
  323. // that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  324. // that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  325. // that.detailData.driverName = uni.getStorageSync('userInfo').userName
  326. // that.detailData.trackFlag = "1"
  327. // that.detailData.destinationProvince = "江苏省"
  328. // that.detailData.destinationCity = "宿迁市"
  329. // that.detailData.destinationArea = "宿城区"
  330. // that.detailData.destinationLongitude = "118.291"
  331. // that.detailData.destinationLatitude = "33.942"
  332. // that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
  333. // that.detailData
  334. // )
  335. // .then(res => {
  336. // if (res.data.code == 200) {
  337. // that.$api.msg('提交成功')
  338. // that.titleBtn = "申请报销"
  339. // } else {
  340. // that.$api.msg('提交失败')
  341. // }
  342. // })
  343. // }
  344. // }
  345. // })
  346. // } else {
  347. // uni.navigateTo({
  348. // url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
  349. // })
  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>