123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <template>
- <view>
- <map
- v-if="order.status == 2 || order.status == 1 || order.status == 4"
- class="map"
- :latitude="map.latitude"
- :longitude="map.longitude"
- :scale="map.scale"
- :polyline="map.polyline"
- :markers="map.covers"
- ></map>
- <view class="new" v-if="order.status == 1">
- <view class="user">
- <image :src="order.user.avatar" mode=""></image>
- <view class="name">
- <text class="item1">{{ order.user.nickname }}</text>
- </view>
- <view class="phone" @tap="call(order.user.mobile)">
- <text class="icon"></text>
- {{ order.user.mobile }}
- </view>
- </view>
- <view class="money">
- <text>预计费用{{ order.estimated_price }}元</text>
- </view>
- <button class="start" type="primary" @tap="reach">我已到达,等待客户</button>
- </view>
- <view class="new" v-if="order.status == 4">
- <view class="user">
- <image :src="order.user.avatar" mode=""></image>
- <view class="name">
- <text class="item1">{{ order.user.nickname }}</text>
- </view>
- <view class="phone" @tap="call(order.user.mobile)">
- <text class="icon"></text>
- {{ order.user.mobile }}
- </view>
- </view>
- <view class="money">
- <text>预计费用{{ order.estimated_price }}元</text>
- </view>
- <button class="start" type="primary" @tap="start">立即出发</button>
- </view>
- <view class="processing" v-if="order.status == 2">
- <view class="user">
- <view class="item">实时费用{{ actual.price }}元</view>
- <view class="item1">已行驶{{ actual.distance | kilometer }} km,预计还需要{{ route.duration }}分钟到达</view>
- </view>
- <button type="primary" @tap="done">已到达终点</button>
- </view>
- <view class="done" v-if="order.status == -1 || order.status == 3 || order.status == 99">
- <!--待支付或已完成-->
- <view class="index">
- <view class="top">
- <view class="user">
- <image :src="order.user.avatar" mode=""></image>
- <text>{{ order.user.nickname }}</text>
- </view>
- <text>{{ order.end_datetime }}</text>
- </view>
- <view class="center">
- <view class="left">
- <view class="input">
- <text class="icon green"></text>
- <text class="gray">从</text>
- {{ order.start_address }}
- </view>
- <view class="input">
- <text class="icon orange"></text>
- <text class="gray">到</text>
- {{ order.end_address }}
- </view>
- </view>
- <!-- <text class="right icon gray"></text> -->
- </view>
- <view class="money" v-if="order.status != -1">
- <view class="t1">
- {{ order.price }}
- <text class="yuan">元</text>
- </view>
- <text class="t2">{{ order.distance | kilometer }}公里 {{ order.duration | duration }}</text>
- <text class="t3">{{ order.status_text }}</text>
- </view>
- <view class="qrimg"><tki-qrcode ref="qrcode" :onval="true" :size="400" :val="paystr" /></view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import QQMapWX from '../../libs/qqmap-wx-jssdk/qqmap-wx-jssdk.js';
- import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
- import helper from '../../common/helper.js';
- import api from '../../common/api.js';
- export default {
- components: { tkiQrcode },
- data() {
- return {
- map: {
- latitude: '',
- longitude: '',
- covers: [],
- scale: 16,
- polyline: []
- },
- focus: false,
- price: '',
- order: {},
- orderId: '',
- timer: '',
- isDirection: false,
- actual: {
- price: 0,
- distance: 0
- },
- route: {
- duration: '--'
- },
- paystr: ''
- };
- },
- filters: {
- kilometer: value => {
- let distance = parseFloat(value / 1000);
- return distance.toFixed(2);
- },
- duration: value => {
- if (value > 3600) {
- let h = parseInt(value / 3600);
- let s = value % 3600;
- if (s > 0) {
- return h + '小时' + parseInt(s / 60) + '分钟';
- } else {
- return h + '小时';
- }
- } else {
- return parseInt(value / 60) + '分钟';
- }
- }
- },
- onLoad(option) {
- this.initSdk();
- this.orderId = option.order_id;
- this.getOrderInfo();
- },
- onShow() {
- // 如果存在订单则更新订单信息
- if (this.orderId) {
- this.getOrderInfo();
- }
- },
- onHide() {
- // 隐藏时关闭定时器
- if (this.timer) {
- console.log('清除定时器');
- clearInterval(this.timer);
- this.timer = '';
- }
- },
- methods: {
- call(mobile) {
- uni.makePhoneCall({
- phoneNumber: mobile
- });
- },
- reach() {
- uni.showModal({
- title: '操作提示',
- content: '请确认已到达出发地点等待用户',
- success: async e => {
- if (e.confirm) {
- let res = await api.orderReach(this.orderId);
- if (res.code == 1) {
- this.getOrderInfo();
- } else {
- helper.toast(res.msg);
- }
- }
- }
- });
- },
- done() {
- uni.showModal({
- title: '操作提示',
- content: '请确认已经达到目的地',
- success: async e => {
- if (e.confirm) {
- uni.getLocation({
- type: 'gcj02',
- success: async ret => {
- console.log(2);
- // 更新一次结束位置
- await this.updateOrderInfo();
- // 结束订单
- let res = await api.doneOrder({
- order_id: this.orderId,
- latitude: ret.latitude,
- longitude: ret.longitude
- });
- // 更新订单信息
- this.getOrderInfo();
- },
- fail: e => {
- helper.toast('获取位置失败');
- }
- });
- }
- }
- });
- },
- start() {
- uni.showModal({
- title: '操作提示',
- content: '请确认已接到用户并马上出发吗?',
- success: async e => {
- if (e.confirm) {
- console.log(1);
- uni.getLocation({
- type: 'gcj02',
- success: async ret => {
- console.log(2);
- // 当前地址
- let res = await api.startOrder({
- order_id: this.orderId,
- latitude: ret.latitude,
- longitude: ret.longitude
- });
- this.getOrderInfo();
- },
- fail: e => {
- helper.toast('获取位置失败');
- }
- });
- }
- }
- });
- },
- initSdk() {
- this.qqmapsdk = new QQMapWX({
- key: helper.config.qqmapsdk.key
- });
- },
- async getOrderPayScanInfo() {
- let res = await api.getOrderPayScanInfo(this.orderId);
- this.paystr = res;
- console.log(this.paystr);
- },
- async getOrderInfo() {
- console.log('获取订单信息');
- let res = await api.getOrderInfo(this.orderId);
- this.order = res.data;
- // 如果订单未开始,以用户位置未起始点
- if (this.order.status == 1 || this.order.status == 4) {
- this.map.latitude = res.data.start_latitude;
- this.map.longitude = res.data.start_longitude;
- // 设置用户坐标点
- this.map.covers.push({
- latitude: res.data.start_latitude,
- longitude: res.data.start_longitude,
- iconPath: '../../static/marker.png'
- });
- }
- // 如果订单为进行中,则实时更新费用及到达时间
- if (this.order.status == 2) {
- this.updateOrderInfo();
- }
- // 获取支付订单信息
- if (this.order.status == 3 && !this.paystr) {
- this.getOrderPayScanInfo();
- }
- // 如果订单为未完成状态,则定时更新
- if (this.order.status != 99 && !this.timer) {
- console.log('注册定时器');
- this.timer = setInterval(() => {
- this.getOrderInfo();
- }, 10 * 1000);
- }
- // 如果订单状态为已完成,切存在定时器,则关闭
- if (this.order.status == 99 && this.timer) {
- console.log('清除定时器');
- clearInterval(this.timer);
- this.timer = '';
- }
- },
- updateOrderInfo() {
- // 更新坐标信息
- uni.getLocation({
- type: 'gcj02',
- success: async res => {
- // 当前地址
- this.currLocation = res;
- this.map.latitude = res.latitude;
- this.map.longitude = res.longitude;
- // 设置当前坐标点
- this.map.covers = [
- {
- latitude: res.latitude,
- longitude: res.longitude,
- iconPath: '../../static/marker.png'
- }
- ];
- // 更新用户位置
- res.order_id = this.orderId;
- let data = await api.updateOrderLocation(res);
- this.actual = data.data;
- this.direction();
- }
- });
- },
- // 路径规划
- direction() {
- this.qqmapsdk.direction({
- mode: 'driving',
- from: this.currLocation.latitude + ',' + this.currLocation.longitude,
- to: this.order.end_latitude + ',' + this.order.end_longitude,
- complete: res => {
- if (!res.result || !res.result.routes || res.result.routes.length == 0) {
- helper.toast('未获取到有效路线');
- return false;
- }
- let coors = res.result.routes[0].polyline,
- pl = []; //坐标解压(返回的点串坐标,通过前向差分进行压缩)
- this.route = res.result.routes[0];
- let kr = 1000000;
- // 处理坐标
- for (let i = 2; i < coors.length; i++) {
- coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
- }
- for (let i = 0; i < coors.length; i += 2) {
- pl.push({ latitude: coors[i], longitude: coors[i + 1] });
- }
- this.map.latitude = pl[0].latitude;
- this.map.longitude = pl[0].longitude;
- this.map.polyline = [
- {
- points: pl,
- color: '#227AFF',
- width: 4
- }
- ];
- this.isDirection = true;
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .map {
- width: 100%;
- height: calc(100vh - 400upx);
- }
- .processing {
- position: absolute;
- width: 100%;
- bottom: 0;
- text-align: center;
- .user {
- margin-bottom: 10%;
- .item {
- margin-bottom: 10upx;
- font-size: 28upx;
- font-weight: 800;
- }
- .item1 {
- font-size: 24upx;
- color: #d2d2d2;
- }
- }
- button {
- border-radius: 0;
- background-color: #32c45e;
- font-size: 28upx;
- }
- }
- .new {
- width: 100%;
- height: 100%;
- .start {
- width: 100%;
- border-radius: 0px;
- background-color: #32c45e;
- border: none;
- position: absolute;
- bottom: 0;
- }
- .start:after {
- border: none;
- }
- .user {
- width: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 28upx;
- image {
- width: 80upx;
- height: 80upx;
- border-radius: 50%;
- }
- .name {
- width: 40%;
- margin-left: 20upx;
- .item2 {
- font-size: 20upx;
- }
- }
- .phone {
- width: 40%;
- text-align: right;
- }
- }
- .money {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- font-size: 22upx;
- height: 200upx;
- color: #d2d2d2;
- text {
- margin-bottom: 10upx;
- color: #101010;
- font-size: 30upx;
- }
- }
- }
- .done {
- height: 100%;
- padding: 40upx;
- .top {
- display: flex;
- justify-content: space-between;
- align-items: center;
- border-bottom: 1px solid #dfdfdf;
- font-size: 26upx;
- padding: 20upx;
- .user {
- display: flex;
- align-items: center;
- image {
- width: 100upx;
- height: 100upx;
- border-radius: 50%;
- margin-right: 20upx;
- }
- }
- }
- .center {
- padding: 30upx 20upx;
- border-bottom: 1px solid #dfdfdf;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .input {
- font-size: 28upx;
- display: flex;
- align-items: center;
- .gray {
- margin: 20upx;
- }
- }
- }
- .money {
- display: flex;
- margin-top: 10%;
- width: 100%;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- .t1 {
- font-size: 60upx;
- .yuan {
- font-size: 28upx;
- }
- }
- .t2 {
- font-size: 24upx;
- margin-top: 20upx;
- }
- .t3 {
- font-size: 28upx;
- margin-top: 5%;
- }
- }
- }
- .qrimg {
- text-align: center;
- padding: 40upx;
- height: 400upx;
- }
- </style>
|