car_position.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template style="height: 100%;">
  2. <view class="carPosition">
  3. <view class="position-top">
  4. <view class="child">
  5. <view class="children1" style="width: 60%;">
  6. <picker mode="date" :value="startTime" @change="start" style="font-size: 28upx;">
  7. 开始时间:{{startTime}}
  8. </picker>
  9. <picker mode="date" :value="endTime" @change="end" style="font-size: 28upx;">
  10. 结束时间:{{endTime}}
  11. </picker>
  12. </view>
  13. <view class="children1" style="width: 30%;">
  14. <view class="btn" @click="show">显示轨迹</view>
  15. <view class="btn" @click="hidn">清除轨迹</view>
  16. </view>
  17. </view>
  18. <view class="hint">
  19. <text class="color"></text>
  20. <text>用户骑行</text>
  21. <text class="color color1"></text>
  22. <text>运维骑行</text>
  23. <text class="color color2"></text>
  24. <text>未骑行</text>
  25. </view>
  26. </view>
  27. <map id="map" :longitude="longitude" :latitude="latitude" scale="14" :controls="controls" :markers="markers"
  28. :polyline="polyline" style="width: 100%; position: absolute;bottom: 0;left: 0;" :style="{height:mapHeight-117 + 'px'}"></map>
  29. </view>
  30. </template>
  31. <script>
  32. var app = getApp()
  33. export default {
  34. data() {
  35. return {
  36. markers: [],
  37. polyline: [],
  38. controls: [],
  39. hasEmptyGrid: false,
  40. bikeId: '',
  41. bike_no: '',
  42. longitude: '',
  43. latitude: '',
  44. mapHeight: "", //地图高度
  45. startTime: "12", //开始时间 默认昨天
  46. endTime: "12", //结束时间 默认今天
  47. }
  48. },
  49. onLoad: function(options) {
  50. console.log(options)
  51. this.bikeId = options.id,
  52. this.bike_no = options.bike_no,
  53. this.getPosition();
  54. this.timeInit();
  55. uni.getSystemInfo({
  56. success: (res) => {
  57. console.log(res.windowHeight, "999")
  58. this.mapHeight = res.windowHeight
  59. }
  60. })
  61. },
  62. methods: {
  63. getPosition: function() {
  64. uni.showLoading({
  65. title: '获取位置中...',
  66. })
  67. let data = {
  68. bike_no: this.bike_no
  69. }
  70. app.request('bike/position', data, 'GET').then(res => {
  71. uni.hideLoading();
  72. console.log(res);
  73. if (res.statusCode == 200) {
  74. if (res.data[0] == 0) {
  75. uni.showToast({
  76. title: '暂无车辆最后位置信息~',
  77. icon: 'none'
  78. })
  79. uni.getLocation({
  80. type: 'gcj02',
  81. success: function(res) {
  82. var latitude = res.latitude
  83. var longitude = res.longitude
  84. this.longitude = longitude;
  85. this.latitude = latitude;
  86. console.log(res, 'jingwei')
  87. },
  88. })
  89. } else {
  90. let position = [];
  91. position[0] = {
  92. width: 32,
  93. height: 32,
  94. zIndex: 1111,
  95. iconPath: 'http://resource.weilaibike.com/common/start-location-mark-old.png',
  96. longitude: res.data[0],
  97. latitude: res.data[1]
  98. }
  99. this.markers = position;
  100. this.longitude = res.data[0];
  101. this.latitude = res.data[1];
  102. }
  103. }
  104. })
  105. },
  106. //初始化日期
  107. timeInit: function() {
  108. let that = this;
  109. let start = new Date();
  110. start.setTime(start.getTime() - 24 * 60 * 60 * 1000)
  111. let startTime = that.getTime(start)
  112. let tom = new Date();
  113. // tom.setTime(tom.getTime() + 24 * 60 * 60 * 1000);
  114. let end = that.getTime(tom);
  115. this.startTime = startTime;
  116. this.endTime = end;
  117. console.log(start)
  118. console.log(end)
  119. },
  120. //获取年月日 时分秒
  121. getTime: function(date) {
  122. var year = date.getFullYear();
  123. var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  124. var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
  125. // var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
  126. // var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
  127. // var today = year + "-" + month + "-" + day + ' ' + hours + ":" + minute;
  128. var today = year + "-" + month + "-" + day;
  129. console.log(today)
  130. return today;
  131. },
  132. start(e) {
  133. console.log(e)
  134. this.startTime = e.detail.value;
  135. console.log(this.startTime)
  136. },
  137. end(e) {
  138. console.log(e)
  139. this.endTime = e.detail.value;
  140. },
  141. //显示轨迹
  142. show: function() {
  143. uni.showLoading({
  144. title: '加载中...',
  145. })
  146. let start = new Date(this.startTime).getTime();
  147. let end = new Date(this.endTime).getTime();
  148. if (start > end) {
  149. uni.showToast({
  150. title: '开始日期不能大于结束日期',
  151. icon: 'none'
  152. })
  153. } else {
  154. this.markers = []
  155. var data = {
  156. 'bike_no': this.bike_no,
  157. 'time_between[0]': this.startTime,
  158. 'time_between[1]': this.endTime,
  159. }
  160. app.request('bike/bikeLocation', data, 'POST').then(res => {
  161. uni.hideLoading();
  162. if (res.statusCode == 200) {
  163. // console.log(res, '车辆位置')
  164. if (res.data == '') {
  165. uni.showToast({
  166. title: '暂无骑行轨迹~',
  167. icon: 'none'
  168. })
  169. } else {
  170. this.polyline = res.data.all_locations;
  171. this.markers = res.data.points;
  172. console.log(this.markers)
  173. }
  174. }
  175. })
  176. }
  177. },
  178. //清除轨迹
  179. hidn() {
  180. let that = this;
  181. this.timeInit();
  182. this.polyline = [];
  183. this.markers = '';
  184. },
  185. }
  186. }
  187. </script>
  188. <style>
  189. uni-page-body,
  190. uni-page-refresh {
  191. height: 100vh;
  192. width: 100%;
  193. background: white !important;
  194. }
  195. .carPosition {
  196. background: #EDEDED;
  197. width: 100%;
  198. height: 100vh;
  199. position: relative;
  200. }
  201. .position-top {
  202. /* margin-bottom: 10upx; */
  203. /* margin-top:10upx; */
  204. padding: 30upx 0rpx;
  205. border-top: 5upx solid #EDEDED;
  206. height: 200upx;
  207. background-color: #FFFFFF;
  208. position: absolute;
  209. top: 0upx;
  210. left: 0upx;
  211. width: 100%;
  212. /* box-sizing: border-box; */
  213. /* border-top: solid 1upx #8A8A8A; */
  214. /* background-color: #007AFF; */
  215. }
  216. .child {
  217. height: 90upx;
  218. display: flex;
  219. margin-bottom: 20upx !important;
  220. display: flex;
  221. align-items: center;
  222. justify-content: space-around;
  223. width: 90%;
  224. margin: 0 auto;
  225. }
  226. .children1 {
  227. height: 70upx;
  228. line-height: 65upx;
  229. margin: 0 !important;
  230. padding: 0 !important;
  231. }
  232. .children1 picker {
  233. font: 24upx !important;
  234. }
  235. /* .date {
  236. width: 576upx;
  237. height: 224upx;
  238. background: #fff;
  239. border-radius: 20upx;
  240. padding: 20upx 60upx;
  241. box-sizing: border-box;
  242. margin: 0 auto;
  243. margin-top: 50upx !important;
  244. }
  245. .date view {
  246. font-size: 28upx;
  247. display: flex;
  248. align-items: center;
  249. justify-content: space-between;
  250. } */
  251. .btn {
  252. width: 200upx;
  253. font-size: 26upx;
  254. height: 60upx;
  255. line-height: 60upx;
  256. text-align: center;
  257. /* padding: 8upx 50upx; */
  258. background: #18d5b9;
  259. color: #fff;
  260. border-radius: 8upx;
  261. margin-left: 50upx;
  262. }
  263. .btn:first-child {
  264. margin-bottom: 10upx;
  265. }
  266. .van-icon-underway-o {
  267. font-size: 40upx !important;
  268. }
  269. .canlendarBgView {
  270. flex-grow: 1;
  271. display: flex;
  272. flex-direction: column;
  273. align-items: center;
  274. }
  275. .canlendarView {
  276. color: #66c;
  277. display: flex;
  278. flex-direction: column;
  279. z-index: 999;
  280. margin-top: 320upx;
  281. background: white;
  282. }
  283. .canlendarTopView {
  284. height: 80upx;
  285. font-size: 28upx;
  286. display: flex;
  287. flex-direction: row;
  288. align-items: center;
  289. justify-content: center;
  290. }
  291. .leftBgView {
  292. text-align: right;
  293. height: 80upx;
  294. display: flex;
  295. flex-direction: row-reverse;
  296. }
  297. .leftView {
  298. width: 80upx;
  299. height: 100%;
  300. display: flex;
  301. flex-direction: row;
  302. align-items: center;
  303. justify-content: center;
  304. }
  305. .centerView {
  306. width: 50%;
  307. height: 80upx;
  308. text-align: center;
  309. display: flex;
  310. flex-direction: row;
  311. align-items: center;
  312. justify-content: center;
  313. }
  314. .rightBgView {
  315. height: 80upx;
  316. display: flex;
  317. flex-direction: row;
  318. }
  319. .rightView {
  320. width: 80upx;
  321. height: 100%;
  322. display: flex;
  323. flex-direction: row;
  324. align-items: center;
  325. justify-content: center;
  326. }
  327. .weekBgView {
  328. height: 50upx;
  329. line-height: 50upx;
  330. opacity: 0.5;
  331. display: flex;
  332. flex-direction: row;
  333. justify-content: center;
  334. align-items: center;
  335. }
  336. .weekView {
  337. flex-grow: 1;
  338. text-align: center;
  339. font-size: 28upx;
  340. }
  341. .dateBgView {
  342. height: 500upx;
  343. display: flex;
  344. flex-direction: row;
  345. flex-wrap: wrap;
  346. }
  347. .dateEmptyView {
  348. width: 107.1428571429upx;
  349. color: #fff;
  350. display: flex;
  351. align-items: center;
  352. justify-content: center;
  353. }
  354. .dateView {
  355. width: 107.1428571429upx;
  356. color: #fff;
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. }
  361. .datesView {
  362. width: 60upx;
  363. height: 60upx;
  364. color: #66c;
  365. font-size: 26upx;
  366. font-weight: 200;
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. }
  371. .dateSelectView {
  372. border-radius: 50%;
  373. position: relative;
  374. left: 0;
  375. top: 0;
  376. color: #fff;
  377. background-color: #66c;
  378. }
  379. .hint {
  380. width: 500upx;
  381. background: #fff;
  382. height: 60upx;
  383. padding: 20upx 30upx 0 20upx;
  384. display: flex;
  385. align-items: center;
  386. border-radius: 10upx;
  387. margin: 0 auto;
  388. }
  389. .hint text {
  390. font-size: 26upx;
  391. }
  392. .color {
  393. display: inline-block;
  394. width: 30upx;
  395. height: 30upx;
  396. background: #18d3b8;
  397. margin: 0 10upx;
  398. border-radius: 50%;
  399. }
  400. .color1 {
  401. background: #ff6477;
  402. }
  403. .color2 {
  404. background: #d684dd;
  405. }
  406. </style>