map.nvue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <template>
  2. <view class="content">
  3. <div class="top_btn">
  4. <div class="returnPage">
  5. <image class="return-icon" src="@/static/images/order/returnPage.png" mode='widthFix'
  6. @click="returnPage">
  7. </image>
  8. </div>
  9. <div class="qiehuan" @click="mapChange">
  10. <image class="qiehuan-icon" src="@/static/images/order/qiehuan.png" mode='widthFix'>
  11. </image>
  12. <text class="tips">{{tips}}</text>
  13. </div>
  14. </div>
  15. <div class="infoBox">
  16. <div class="infoBox_left">
  17. <text class="title">{{infoData.cargoOwnerStatus}}</text>
  18. <text class="address estimate">预计{{infoData.tranEndDate}}送达</text>
  19. </div>
  20. <div class="infoBox_right">
  21. <div class="send">
  22. <text class="title">{{infoData.sendCity}}</text>
  23. <text class="address">{{infoData.sendArea}}</text>
  24. </div>
  25. <image class="jt-icon" src="@/static/images/order/jt.png" mode='widthFix'>
  26. </image>
  27. <div class="end">
  28. <text class="title">{{infoData.unloadCity}}</text>
  29. <text class="address">{{infoData.unloadArea}}</text>
  30. </div>
  31. </div>
  32. </div>
  33. <map v-if="polyline[0].points.length > 0" ref="myMap" id="myMap" :markers="markers" :polyline="polyline"
  34. :latitude="polyline[0].points[0].latitude" :longitude="polyline[0].points[0].longitude"
  35. style="width: 100%; height: 2000rpx" @updated="test" />
  36. <!-- <view v-if="polyline[0].points.length > 0" class="hcp-bottom">
  37. <button v-if="startMove" @click="handleStopMove()">暂停移动</button>
  38. <button v-else @click="handleStartMove()">开始移动</button>
  39. </view> -->
  40. <u-modal :show="show" :title="title" :showCancelButton="true" confirmText="确定支付" @close="show=false"
  41. @cancel="show = false" @confirm="payment" :closeOnClickOverlay="true">
  42. <div class="slot-content" style="align-items: flex-start;">
  43. <text style="width: 270px;">{{content}}</text>
  44. </div>
  45. </u-modal>
  46. </view>
  47. </template>
  48. <script>
  49. const img = '/static/logo.png';
  50. import * as config from '@/config'
  51. let baseUrl = config.def().baseUrlNew
  52. export default {
  53. data() {
  54. return {
  55. scaleNum: 10,
  56. mapContext: null, //地图对象
  57. startMove: false, //是否开始回放
  58. nextPointIndex: 1, //下一个坐标点的索引
  59. durationTime: 1000, //相邻两点动画持续时长默认1秒
  60. //路线信息
  61. polyline: [{
  62. width: 20,
  63. points: [],
  64. arrowLine: true,
  65. color: '#3591FC',
  66. }],
  67. //标记点(即移动标记物)
  68. markers: [{
  69. id: 1,
  70. width: 40,
  71. height: 40,
  72. latitude: 0,
  73. longitude: 0,
  74. iconPath: img,
  75. anchor: {
  76. x: 0.5,
  77. y: 1
  78. }
  79. }],
  80. infoData: {},
  81. tips: "切换北斗轨迹",
  82. title: "支付",
  83. content: "",
  84. show: false,
  85. obj: {}
  86. }
  87. },
  88. onLoad(option) {
  89. this.id = option.id
  90. this.infoData = option
  91. let date = new Date(this.infoData.tranEndDate)
  92. if (!this.infoData.lookBeiDouDate) {
  93. this.infoData.lookBeiDouDate = ""
  94. }
  95. let getMonth = date.getMonth() + 1
  96. let day = date.getDate()
  97. this.infoData.tranEndDate = getMonth + "月" + day + "日"
  98. this.getTrack(0) //获取轨迹信息(只做演示,未进行远程请求)
  99. },
  100. methods: {
  101. returnPage() {
  102. // uni.$u.route('/pages/order/index');
  103. uni.switchTab({
  104. url: '/pages/order/index'
  105. });
  106. },
  107. // isSameDay(date, dateB){
  108. // const {
  109. // getFullYear,
  110. // getMonth,
  111. // getDate] = Date.prototypereturn[getFullYear, getMonth, getDate].every(fn =>
  112. // return fn.call(dateA) === fn.cal1(dateB)
  113. // },
  114. countDay(d1, d2) {
  115. var days = d1 - d2
  116. var time = parseInt(days / (1000 * 60 * 60 * 24))
  117. time = time ==0?time+1:time//为零代表当天
  118. return time
  119. },
  120. mapChange() {
  121. if (this.tips == "切换北斗轨迹") {
  122. if (this.infoData.lookBeiDouDate) { //查看北斗最新时间
  123. let date1 = this.infoData.lookBeiDouDate.split(" ")[0]
  124. let date2 = new Date()
  125. let year = date2.getFullYear();
  126. let month = (date2.getMonth() + 1) < 10 ? "0" + (date2.getMonth() + 1) : date2.getMonth() + 1;
  127. let day = date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate();
  128. let date3 = year + "-" + month + "-" + day
  129. if(this.infoData.cargoOwnerStatus == "已完结"){//如果订单完成 用卸车时间计算天数
  130. date3 = this.infoData.unloadingDate.split(" ")[0]//卸车时间
  131. }
  132. if (date1 != date3) { //查看北斗更新时间 != 今天
  133. // unloadingDate 卸车时间
  134. var k1 = new Date(new Date().toLocaleDateString()).getTime() //当前零点时间蹉
  135. if(this.infoData.cargoOwnerStatus == "已完结"){
  136. k1 = new Date(new Date(this.infoData.unloadingDate).toLocaleDateString()).getTime() //卸车时间
  137. }
  138. var k2 = new Date(new Date(this.infoData.lookBeiDouDate).toLocaleDateString()).getTime()
  139. this.obj.amountMoney = this.countDay(k1, k2)
  140. this.content = "本次查看北斗轨迹将从您的账户余额扣除 " + this.obj.amountMoney + " 元,确认支付查看轨迹?"
  141. this.show = true
  142. } else { ////查看北斗更新时间 == 今天(不需要支付)
  143. this.show = false
  144. this.getTrack(1) //北斗轨迹
  145. }
  146. } else { //没有更新时间证明该订单没有查看过北斗轨迹(需支付)
  147. let date1 = this.infoData.loadingDate.split(" ")[0]
  148. let date2 = new Date()
  149. let year = date2.getFullYear();
  150. let month = (date2.getMonth() + 1) < 10 ? "0" + (date2.getMonth() + 1) : date2.getMonth() + 1;
  151. let day = date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate();
  152. let date3 = year + "-" + month + "-" + day
  153. // if(this.infoData.cargoOwnerStatus == "已完结"){//如果订单完成 用卸车时间计算天数
  154. // date3 = this.infoData.unloadingDate.split(" ")[0]//卸车时间
  155. // }
  156. if (date1 == date3) { //装车时间==当前时间
  157. this.obj.amountMoney = 1
  158. this.content = "本次查看北斗轨迹将从您的账户余额扣除 " + this.obj.amountMoney + " 元,确认支付查看轨迹?"
  159. this.show = true
  160. } else { //装车时间 != 当前时间 且没有查看过北斗轨迹
  161. var k1 = new Date(new Date().toLocaleDateString()).getTime() //当前零点时间蹉
  162. var k2 = new Date(new Date(this.infoData.loadingDate).toLocaleDateString()).getTime()
  163. if(this.infoData.cargoOwnerStatus == "已完结"){//如果订单完成 用卸车时间计算天数
  164. // let date3 = this.infoData.unloadingDate.split(" ")[0]//卸车时间
  165. k1 = new Date(new Date(this.infoData.unloadingDate).toLocaleDateString()).getTime()
  166. }
  167. this.obj.amountMoney = this.countDay(k1, k2)+1//加1算装车当天
  168. this.show = true
  169. this.content = "本次查看北斗轨迹将从您的账户余额扣除" + this.obj.amountMoney + "元,确认支付查看轨迹?"
  170. }
  171. }
  172. } else {
  173. this.tips == "切换北斗轨迹"
  174. this.getTrack(0)
  175. }
  176. },
  177. payment() {
  178. if (this.infoData.compName != "个人货主") { //查看北斗轨迹 标识(1个人2企业)
  179. this.obj.companyId = this.infoData.compId
  180. this.obj.flag = 2
  181. } else {
  182. this.obj.commonId = this.infoData.cargoCommonId
  183. this.obj.flag = 1
  184. }
  185. this.obj.orderId = this.infoData.id
  186. this.obj.orderNo = this.infoData.orderNo
  187. uni.request({
  188. url: baseUrl + '/hyCargoOwnerCapitalInfo/api/lookBeiDou',
  189. data: this.obj,
  190. method: 'post',
  191. header: {
  192. 'content-type': 'application/json' //'application/x-www-form-urlencoded; charset=UTF-8',
  193. },
  194. success: (res) => {
  195. this.show = false
  196. if (res.data.code == 200) {
  197. this.getTrack(1) //调北斗
  198. } else {
  199. uni.showToast({
  200. title: '支付失败',
  201. icon: 'none',
  202. duration: 2000
  203. })
  204. return
  205. }
  206. }
  207. })
  208. },
  209. // /hyOrderTravelPath/orderPath
  210. //模拟获取远程数据
  211. getTrack(num) {
  212. if (num == 0) { //平台轨迹
  213. uni.request({
  214. url: baseUrl + '/hyOrderTravelPath/getInfo',
  215. data: {
  216. orderId: this.id,
  217. currentPage: 1,
  218. pageSize: 9999
  219. },
  220. method: 'get',
  221. header: {
  222. 'content-type': 'application/json' //'application/x-www-form-urlencoded; charset=UTF-8',
  223. },
  224. success: (res) => {
  225. if (res.data.code == 200) {
  226. if (res.data.data.records.length >0) {
  227. var trajectory = []
  228. for (let i = 0; i < res.data.data.records.length; i++) {
  229. let maplist = []
  230. if (res.data.data.records[i].longitudeLatitude) {
  231. maplist = JSON.parse(res.data.data.records[i]
  232. .longitudeLatitude)
  233. for (let j = 0; j < maplist.length; j++) {
  234. trajectory.push({
  235. latitude: maplist[j].latitude,
  236. longitude: maplist[j].longitude
  237. })
  238. }
  239. }
  240. }
  241. this.polyline[0].points = trajectory
  242. } else {
  243. uni.showToast({
  244. title: '暂无运输轨迹',
  245. icon: 'none',
  246. duration: 2000
  247. })
  248. return
  249. }
  250. }
  251. }
  252. })
  253. } else if (num == 1) {
  254. uni.request({
  255. url: baseUrl + '/hyOrderTravelPath/orderPath ',
  256. data: {
  257. orderId: this.id,
  258. },
  259. method: 'post',
  260. header: {
  261. 'content-type': 'application/json' //'application/x-www-form-urlencoded; charset=UTF-8',
  262. },
  263. success: (res) => {
  264. if (res.data.code == 200) {
  265. this.tips = "切换平台轨迹"
  266. if (res.data.data.longitudeLatitude) {
  267. var trajectory = []
  268. var patharr = JSON.parse(res.data.data.longitudeLatitude)
  269. for (let i = 0; i < patharr.length; i++) {
  270. trajectory.push({
  271. latitude: patharr[i].lat,
  272. longitude: patharr[i].lon
  273. });
  274. }
  275. this.polyline[0].points = trajectory
  276. } else {
  277. uni.showToast({
  278. title: '暂无运输轨迹',
  279. icon: 'none',
  280. duration: 2000
  281. })
  282. }
  283. }
  284. }
  285. })
  286. }
  287. // this.$request.baseRequest('post', '/hyOrderTravelPath/getInfo', {
  288. // orderId: this.id,
  289. // }).then(res => {
  290. // console.log("res",res)
  291. // this.polyline[0].points = [
  292. // {latitude: 39.997761, longitude: 116.478935},
  293. // {latitude: 39.997825, longitude: 116.478939},
  294. // {latitude: 39.998549, longitude: 116.478912},
  295. // {latitude: 39.998555, longitude: 116.478998},
  296. // {latitude: 39.998566, longitude: 116.479282},
  297. // {latitude: 39.998528, longitude: 116.479658},
  298. // {latitude: 39.998453, longitude: 116.480151},
  299. // {latitude: 39.998302, longitude: 116.480784},
  300. // {latitude: 39.998184, longitude: 116.481149},
  301. // {latitude: 39.997997, longitude: 116.481573},
  302. // {latitude: 39.997846, longitude: 116.481863},
  303. // {latitude: 39.997718, longitude: 116.482072},
  304. // {latitude: 39.997718, longitude: 116.482362},
  305. // {latitude: 39.998935, longitude: 116.483633},
  306. // {latitude: 39.998968, longitude: 116.48367},
  307. // {latitude: 39.999861, longitude: 116.484648}
  308. // ]
  309. // for(var i =0 ;i<7200;i++){
  310. // var latitude = this.polyline[0].points[this.polyline[0].points.length -1].latitude + 0.0001
  311. // var longitude = this.polyline[0].points[this.polyline[0].points.length -1].longitude + 0.0001
  312. // this.polyline[0].points.push({latitude,longitude})
  313. // }
  314. var that = this
  315. setTimeout(() => {
  316. that.durationTime = Math.ceil(30000 / that.polyline[0].points
  317. .length) //默认播放全程使用30秒,计算相连两点动画时长
  318. that.initMapData()
  319. }, 1000)
  320. },
  321. //设置地图
  322. initMapData() {
  323. this.initMarkers()
  324. this.mapContext = uni.createMapContext('myMap', this)
  325. },
  326. test() {
  327. this.mapContext.includePoints({
  328. points: this.polyline[0].points,
  329. padding: [100, 100, 1000, 100]
  330. })
  331. },
  332. //设置位置(从起点开始)
  333. initMarkers() {
  334. this.markers[0].latitude = this.polyline[0].points[0].latitude
  335. this.markers[0].longitude = this.polyline[0].points[0].longitude
  336. },
  337. //开始移动
  338. handleStartMove() {
  339. this.startMove = true
  340. this.movePoint()
  341. },
  342. //停止移动
  343. handleStopMove() {
  344. this.startMove = false
  345. },
  346. //移动坐标
  347. movePoint() {
  348. /*
  349. //也可以用这个方法
  350. this.mapContext.moveAlong({
  351. duration: 30000,
  352. markerId: this.markers[0].id,
  353. path: this.polyline[0].points
  354. })
  355. return
  356. */
  357. this.mapContext.moveAlong({
  358. duration: 10000,
  359. markerId: this.markers[0].id,
  360. path: this.polyline[0].points
  361. })
  362. console.log("this.nextPointIndex1 ", this.nextPointIndex, this.polyline[0].points.length - 1)
  363. console.log("this.startMove1", this.startMove)
  364. // this.mapContext.translateMarker({
  365. // duration: this.durationTime,
  366. // markerId: this.markers[0].id,
  367. // destination: {
  368. // latitude: this.polyline[0].points[this.nextPointIndex].latitude,
  369. // longitude: this.polyline[0].points[this.nextPointIndex].longitude
  370. // },
  371. // animationEnd: res => {
  372. // console.log("this.nextPointIndex ",this.nextPointIndex ,this.polyline[0].points.length - 1)
  373. // console.log("this.startMove",this.startMove)
  374. // //播放结束,继续移动到下一个点,最后一个点时结束移动
  375. // if (this.nextPointIndex < this.polyline[0].points.length - 1) {
  376. // this.nextPointIndex++
  377. // if (this.startMove) {
  378. // this.movePoint()
  379. // }
  380. // } else {
  381. // this.nextPointIndex = 1
  382. // this.startMove = false
  383. // }
  384. // }
  385. // })
  386. }
  387. }
  388. };
  389. </script>
  390. <style lang="scss" scoped>
  391. .hcp-bottom {
  392. left: 0;
  393. bottom: 0;
  394. width: 750rpx;
  395. // position: fixed;
  396. }
  397. .content {
  398. .top_btn {
  399. // background-color: red;
  400. position: fixed;
  401. top: 30rpx;
  402. left: 10px;
  403. right: 30rpx;
  404. flex-direction: row;
  405. display: flex;
  406. margin-top: 30px;
  407. justify-content: space-between;
  408. .returnPage {
  409. flex-direction: row;
  410. display: flex;
  411. .return-icon {
  412. width: 90rpx;
  413. height: 90rpx;
  414. }
  415. }
  416. .qiehuan {
  417. flex-direction: row;
  418. display: flex;
  419. // width: 240rpx;
  420. height: 90rpx;
  421. background-color: #ffffff;
  422. border-radius: 50rpx;
  423. padding: 0 30rpx;
  424. .tips {
  425. line-height: 90rpx;
  426. }
  427. .qiehuan-icon {
  428. width: 30rpx;
  429. height: 30rpx;
  430. margin-top: 30rpx;
  431. margin-right: 10rpx;
  432. }
  433. }
  434. }
  435. .infoBox {
  436. // width: 90%;
  437. height: 260rpx;
  438. background-color: #FFFFFF;
  439. position: fixed;
  440. top: 30rpx;
  441. left: 10px;
  442. right: 30rpx;
  443. border-radius: 40rpx;
  444. // padding:50rpx;
  445. display: flex;
  446. flex-direction: row;
  447. margin-top: 100px;
  448. .infoBox_left {
  449. padding-top: 50rpx;
  450. width: 250rpx;
  451. padding-top: 80rpx;
  452. // background-color: #18BC37;
  453. }
  454. .infoBox_right {
  455. background-image: linear-gradient(to right, #f9f7f7, #ffffff);
  456. display: flex;
  457. flex-direction: row;
  458. border-bottom-right-radius: 40rpx;
  459. border-top-right-radius: 40rpx;
  460. .jt-icon {
  461. position: relative;
  462. top: 75rpx;
  463. width: 60rpx;
  464. margin: auto 10rpx;
  465. }
  466. .send {
  467. padding-top: 80rpx;
  468. width: 180rpx;
  469. // background-color: #0077AA;
  470. }
  471. .end {
  472. padding-top: 80rpx;
  473. width: 180rpx;
  474. }
  475. }
  476. .title {
  477. font-size: 44rpx;
  478. font-weight: 600;
  479. text-align: center;
  480. }
  481. .address {
  482. text-align: center;
  483. color: #8F8F8F;
  484. font-size: 30rpx;
  485. margin-top: 15rpx;
  486. }
  487. .estimate {
  488. width: 120px;
  489. text-align: center;
  490. }
  491. }
  492. }
  493. </style>