map.nvue 17 KB

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