map.nvue 16 KB

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