drivingDetails.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view>
  3. <map
  4. v-if="order.status == 2 || order.status == 1 || order.status == 4"
  5. class="map"
  6. :latitude="map.latitude"
  7. :longitude="map.longitude"
  8. :scale="map.scale"
  9. :polyline="map.polyline"
  10. :markers="map.covers"
  11. ></map>
  12. <view class="new" v-if="order.status == 1">
  13. <view class="user">
  14. <image :src="order.user.avatar" mode=""></image>
  15. <view class="name">
  16. <text class="item1">{{ order.user.nickname }}</text>
  17. </view>
  18. <view class="phone" @tap="call(order.user.mobile)">
  19. <text class="icon">&#xe657;</text>
  20. {{ order.user.mobile }}
  21. </view>
  22. </view>
  23. <view class="money">
  24. <text>预计费用{{ order.estimated_price }}元</text>
  25. </view>
  26. <button class="start" type="primary" @tap="reach">我已到达,等待客户</button>
  27. </view>
  28. <view class="new" v-if="order.status == 4">
  29. <view class="user">
  30. <image :src="order.user.avatar" mode=""></image>
  31. <view class="name">
  32. <text class="item1">{{ order.user.nickname }}</text>
  33. </view>
  34. <view class="phone" @tap="call(order.user.mobile)">
  35. <text class="icon">&#xe657;</text>
  36. {{ order.user.mobile }}
  37. </view>
  38. </view>
  39. <view class="money">
  40. <text>预计费用{{ order.estimated_price }}元</text>
  41. </view>
  42. <button class="start" type="primary" @tap="start">立即出发</button>
  43. </view>
  44. <view class="processing" v-if="order.status == 2">
  45. <view class="user">
  46. <view class="item">实时费用{{ actual.price }}元</view>
  47. <view class="item1">已行驶{{ actual.distance | kilometer }} km,预计还需要{{ route.duration }}分钟到达</view>
  48. </view>
  49. <button type="primary" @tap="done">已到达终点</button>
  50. </view>
  51. <view class="done" v-if="order.status == -1 || order.status == 3 || order.status == 99">
  52. <!--待支付或已完成-->
  53. <view class="index">
  54. <view class="top">
  55. <view class="user">
  56. <image :src="order.user.avatar" mode=""></image>
  57. <text>{{ order.user.nickname }}</text>
  58. </view>
  59. <text>{{ order.end_datetime }}</text>
  60. </view>
  61. <view class="center">
  62. <view class="left">
  63. <view class="input">
  64. <text class="icon green">&#xe608;</text>
  65. <text class="gray">从</text>
  66. {{ order.start_address }}
  67. </view>
  68. <view class="input">
  69. <text class="icon orange">&#xe608;</text>
  70. <text class="gray">到</text>
  71. {{ order.end_address }}
  72. </view>
  73. </view>
  74. <!-- <text class="right icon gray">&#xe60f;</text> -->
  75. </view>
  76. <view class="money" v-if="order.status != -1">
  77. <view class="t1">
  78. {{ order.price }}
  79. <text class="yuan">元</text>
  80. </view>
  81. <text class="t2">{{ order.distance | kilometer }}公里 {{ order.duration | duration }}</text>
  82. <text class="t3">{{ order.status_text }}</text>
  83. </view>
  84. <view class="qrimg"><tki-qrcode ref="qrcode" :onval="true" :size="400" :val="paystr" /></view>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import QQMapWX from '../../libs/qqmap-wx-jssdk/qqmap-wx-jssdk.js';
  91. import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
  92. import helper from '../../common/helper.js';
  93. import api from '../../common/api.js';
  94. export default {
  95. components: { tkiQrcode },
  96. data() {
  97. return {
  98. map: {
  99. latitude: '',
  100. longitude: '',
  101. covers: [],
  102. scale: 16,
  103. polyline: []
  104. },
  105. focus: false,
  106. price: '',
  107. order: {},
  108. orderId: '',
  109. timer: '',
  110. isDirection: false,
  111. actual: {
  112. price: 0,
  113. distance: 0
  114. },
  115. route: {
  116. duration: '--'
  117. },
  118. paystr: ''
  119. };
  120. },
  121. filters: {
  122. kilometer: value => {
  123. let distance = parseFloat(value / 1000);
  124. return distance.toFixed(2);
  125. },
  126. duration: value => {
  127. if (value > 3600) {
  128. let h = parseInt(value / 3600);
  129. let s = value % 3600;
  130. if (s > 0) {
  131. return h + '小时' + parseInt(s / 60) + '分钟';
  132. } else {
  133. return h + '小时';
  134. }
  135. } else {
  136. return parseInt(value / 60) + '分钟';
  137. }
  138. }
  139. },
  140. onLoad(option) {
  141. this.initSdk();
  142. this.orderId = option.order_id;
  143. this.getOrderInfo();
  144. },
  145. onShow() {
  146. // 如果存在订单则更新订单信息
  147. if (this.orderId) {
  148. this.getOrderInfo();
  149. }
  150. },
  151. onHide() {
  152. // 隐藏时关闭定时器
  153. if (this.timer) {
  154. console.log('清除定时器');
  155. clearInterval(this.timer);
  156. this.timer = '';
  157. }
  158. },
  159. methods: {
  160. call(mobile) {
  161. uni.makePhoneCall({
  162. phoneNumber: mobile
  163. });
  164. },
  165. reach() {
  166. uni.showModal({
  167. title: '操作提示',
  168. content: '请确认已到达出发地点等待用户',
  169. success: async e => {
  170. if (e.confirm) {
  171. let res = await api.orderReach(this.orderId);
  172. if (res.code == 1) {
  173. this.getOrderInfo();
  174. } else {
  175. helper.toast(res.msg);
  176. }
  177. }
  178. }
  179. });
  180. },
  181. done() {
  182. uni.showModal({
  183. title: '操作提示',
  184. content: '请确认已经达到目的地',
  185. success: async e => {
  186. if (e.confirm) {
  187. uni.getLocation({
  188. type: 'gcj02',
  189. success: async ret => {
  190. console.log(2);
  191. // 更新一次结束位置
  192. await this.updateOrderInfo();
  193. // 结束订单
  194. let res = await api.doneOrder({
  195. order_id: this.orderId,
  196. latitude: ret.latitude,
  197. longitude: ret.longitude
  198. });
  199. // 更新订单信息
  200. this.getOrderInfo();
  201. },
  202. fail: e => {
  203. helper.toast('获取位置失败');
  204. }
  205. });
  206. }
  207. }
  208. });
  209. },
  210. start() {
  211. uni.showModal({
  212. title: '操作提示',
  213. content: '请确认已接到用户并马上出发吗?',
  214. success: async e => {
  215. if (e.confirm) {
  216. console.log(1);
  217. uni.getLocation({
  218. type: 'gcj02',
  219. success: async ret => {
  220. console.log(2);
  221. // 当前地址
  222. let res = await api.startOrder({
  223. order_id: this.orderId,
  224. latitude: ret.latitude,
  225. longitude: ret.longitude
  226. });
  227. this.getOrderInfo();
  228. },
  229. fail: e => {
  230. helper.toast('获取位置失败');
  231. }
  232. });
  233. }
  234. }
  235. });
  236. },
  237. initSdk() {
  238. this.qqmapsdk = new QQMapWX({
  239. key: helper.config.qqmapsdk.key
  240. });
  241. },
  242. async getOrderPayScanInfo() {
  243. let res = await api.getOrderPayScanInfo(this.orderId);
  244. this.paystr = res;
  245. console.log(this.paystr);
  246. },
  247. async getOrderInfo() {
  248. console.log('获取订单信息');
  249. let res = await api.getOrderInfo(this.orderId);
  250. this.order = res.data;
  251. // 如果订单未开始,以用户位置未起始点
  252. if (this.order.status == 1 || this.order.status == 4) {
  253. this.map.latitude = res.data.start_latitude;
  254. this.map.longitude = res.data.start_longitude;
  255. // 设置用户坐标点
  256. this.map.covers.push({
  257. latitude: res.data.start_latitude,
  258. longitude: res.data.start_longitude,
  259. iconPath: '../../static/marker.png'
  260. });
  261. }
  262. // 如果订单为进行中,则实时更新费用及到达时间
  263. if (this.order.status == 2) {
  264. this.updateOrderInfo();
  265. }
  266. // 获取支付订单信息
  267. if (this.order.status == 3 && !this.paystr) {
  268. this.getOrderPayScanInfo();
  269. }
  270. // 如果订单为未完成状态,则定时更新
  271. if (this.order.status != 99 && !this.timer) {
  272. console.log('注册定时器');
  273. this.timer = setInterval(() => {
  274. this.getOrderInfo();
  275. }, 10 * 1000);
  276. }
  277. // 如果订单状态为已完成,切存在定时器,则关闭
  278. if (this.order.status == 99 && this.timer) {
  279. console.log('清除定时器');
  280. clearInterval(this.timer);
  281. this.timer = '';
  282. }
  283. },
  284. updateOrderInfo() {
  285. // 更新坐标信息
  286. uni.getLocation({
  287. type: 'gcj02',
  288. success: async res => {
  289. // 当前地址
  290. this.currLocation = res;
  291. this.map.latitude = res.latitude;
  292. this.map.longitude = res.longitude;
  293. // 设置当前坐标点
  294. this.map.covers = [
  295. {
  296. latitude: res.latitude,
  297. longitude: res.longitude,
  298. iconPath: '../../static/marker.png'
  299. }
  300. ];
  301. // 更新用户位置
  302. res.order_id = this.orderId;
  303. let data = await api.updateOrderLocation(res);
  304. this.actual = data.data;
  305. this.direction();
  306. }
  307. });
  308. },
  309. // 路径规划
  310. direction() {
  311. this.qqmapsdk.direction({
  312. mode: 'driving',
  313. from: this.currLocation.latitude + ',' + this.currLocation.longitude,
  314. to: this.order.end_latitude + ',' + this.order.end_longitude,
  315. complete: res => {
  316. if (!res.result || !res.result.routes || res.result.routes.length == 0) {
  317. helper.toast('未获取到有效路线');
  318. return false;
  319. }
  320. let coors = res.result.routes[0].polyline,
  321. pl = []; //坐标解压(返回的点串坐标,通过前向差分进行压缩)
  322. this.route = res.result.routes[0];
  323. let kr = 1000000;
  324. // 处理坐标
  325. for (let i = 2; i < coors.length; i++) {
  326. coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
  327. }
  328. for (let i = 0; i < coors.length; i += 2) {
  329. pl.push({ latitude: coors[i], longitude: coors[i + 1] });
  330. }
  331. this.map.latitude = pl[0].latitude;
  332. this.map.longitude = pl[0].longitude;
  333. this.map.polyline = [
  334. {
  335. points: pl,
  336. color: '#227AFF',
  337. width: 4
  338. }
  339. ];
  340. this.isDirection = true;
  341. }
  342. });
  343. }
  344. }
  345. };
  346. </script>
  347. <style lang="scss" scoped>
  348. .map {
  349. width: 100%;
  350. height: calc(100vh - 400upx);
  351. }
  352. .processing {
  353. position: absolute;
  354. width: 100%;
  355. bottom: 0;
  356. text-align: center;
  357. .user {
  358. margin-bottom: 10%;
  359. .item {
  360. margin-bottom: 10upx;
  361. font-size: 28upx;
  362. font-weight: 800;
  363. }
  364. .item1 {
  365. font-size: 24upx;
  366. color: #d2d2d2;
  367. }
  368. }
  369. button {
  370. border-radius: 0;
  371. background-color: #32c45e;
  372. font-size: 28upx;
  373. }
  374. }
  375. .new {
  376. width: 100%;
  377. height: 100%;
  378. .start {
  379. width: 100%;
  380. border-radius: 0px;
  381. background-color: #32c45e;
  382. border: none;
  383. position: absolute;
  384. bottom: 0;
  385. }
  386. .start:after {
  387. border: none;
  388. }
  389. .user {
  390. width: 100%;
  391. display: flex;
  392. justify-content: center;
  393. align-items: center;
  394. font-size: 28upx;
  395. image {
  396. width: 80upx;
  397. height: 80upx;
  398. border-radius: 50%;
  399. }
  400. .name {
  401. width: 40%;
  402. margin-left: 20upx;
  403. .item2 {
  404. font-size: 20upx;
  405. }
  406. }
  407. .phone {
  408. width: 40%;
  409. text-align: right;
  410. }
  411. }
  412. .money {
  413. display: flex;
  414. flex-direction: column;
  415. align-items: center;
  416. justify-content: center;
  417. font-size: 22upx;
  418. height: 200upx;
  419. color: #d2d2d2;
  420. text {
  421. margin-bottom: 10upx;
  422. color: #101010;
  423. font-size: 30upx;
  424. }
  425. }
  426. }
  427. .done {
  428. height: 100%;
  429. padding: 40upx;
  430. .top {
  431. display: flex;
  432. justify-content: space-between;
  433. align-items: center;
  434. border-bottom: 1px solid #dfdfdf;
  435. font-size: 26upx;
  436. padding: 20upx;
  437. .user {
  438. display: flex;
  439. align-items: center;
  440. image {
  441. width: 100upx;
  442. height: 100upx;
  443. border-radius: 50%;
  444. margin-right: 20upx;
  445. }
  446. }
  447. }
  448. .center {
  449. padding: 30upx 20upx;
  450. border-bottom: 1px solid #dfdfdf;
  451. display: flex;
  452. align-items: center;
  453. justify-content: space-between;
  454. .input {
  455. font-size: 28upx;
  456. display: flex;
  457. align-items: center;
  458. .gray {
  459. margin: 20upx;
  460. }
  461. }
  462. }
  463. .money {
  464. display: flex;
  465. margin-top: 10%;
  466. width: 100%;
  467. flex-direction: column;
  468. align-items: center;
  469. justify-content: center;
  470. .t1 {
  471. font-size: 60upx;
  472. .yuan {
  473. font-size: 28upx;
  474. }
  475. }
  476. .t2 {
  477. font-size: 24upx;
  478. margin-top: 20upx;
  479. }
  480. .t3 {
  481. font-size: 28upx;
  482. margin-top: 5%;
  483. }
  484. }
  485. }
  486. .qrimg {
  487. text-align: center;
  488. padding: 40upx;
  489. height: 400upx;
  490. }
  491. </style>