| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- const api = require('../../api/index.js');
- const app = getApp();
- Page({
- data: {
- // 地图初始中心坐标(北京市中心)
- longitude: 116.404,
- latitude: 39.915,
- scale:10,
- markers: [],
- polyline: [],
- startLocation: {},
- endLocation: {},
- showTripInfo: true,
- showCallButton: true,
- showDriverInfo: true,
- carsNearby: 0,
- // 司机信息
- driverAvatar: 'https://esos-iot.bjdexn.cn/myminio/project/2a1b32553c3d4ef992bc797d26cf1614.png',
- driverName: '王师傅',
- carNumber: '京A88888',
- estimatedArrival: 5,
- locationTimer: null,
- isTracking: false,
- userdata:[],
- workorderdata:[]
- },
- // 收益统计
- onLoad() {
- // 初始化地图
- this.getuser()
- this.initMap()
- wx.$on('wsMessage', this.handleWsMessage);
- },
- onHide(){
- // 页面卸载时,取消订阅,这是至关重要的一步!
- wx.$off('wsMessage', this.handleWsMessage);
- },
- /**
- * 处理接收到的 WebSocket 消息
- * @param {Object} message 从 app.js 广播过来的消息对象
- */
- handleWsMessage(message) {
- console.log('Other Page 收到 WebSocket 消息:', message);
-
- // 根据消息类型进行不同的处理
- switch (message.api) {
- case '/sysworkorder/selectworkorderlist':
-
- // 在这里可以更新地图、刷新UI等
- if (message.type==1) {
- this.getworkordertype()
- }
-
- break;
-
- case 'trajectoryInit':
- // 处理初始轨迹数据
- break;
-
- case 'heartbeatReply':
- // 心跳回复,通常不需要UI处理
- break;
-
- default:
- // 处理其他类型的消息
- break;
- }
- },
- // 获取待执行工单
- getworkordertype(){
- let data ={
- workorderId:'',
- workorderName:'',
- addressId:'',
- driverId:'',
- carId:'',
- customerId:'',
- workorderType:4,
- chargedischargeType:'',
- }
- api.request(`/sysworkorder/selectworkorderlist`, 'post',data ,{ isPublic: false })
- .then((data) => {
- console.log(data.data);
- if (data.code==200) {
- this.setData({
- workorderdata:data.data
- })
-
- }
- })
- .catch((err) => {
- console.error('请求失败:', err);
- });
- },
- getuser(){
-
- api.request(`/sysoperation/selectoperationid`, 'post',{ isPublic: false })
- .then((data) => {
- console.log(data.data);
- if (data.code==200) {
- this.setData({
- userdata:data.data
- })
- // 设置数据到本地存储
- wx.setStorage({
- key: 'user', // 存储的key值
- data:data.data
- });
-
- }
- })
- .catch((err) => {
- console.error('请求失败:', err);
- });
- },
- // 初始化地图,获取用户位置
- initMap() {
- const that = this;
-
- // 获取用户当前位置
- wx.getLocation({
- type: 'gcj02', // 国测局坐标系,微信地图使用该坐标系
- success(res) {
- const longitude = res.longitude;
- const latitude = res.latitude;
-
- // 更新地图中心位置
- that.setData({
- longitude,
- latitude,
- startLocation: {
- longitude,
- latitude,
- name: '我的位置'
- },
- // 添加起点标记
- markers: [{
- id: 0,
- longitude,
- latitude,
- iconPath: 'https://esos-iot.bjdexn.cn/myminio/project/a0d245bf00c6493d949c3be82a6d2b98.png',
- width: 40,
- height: 40,
- anchor: {x: 0.5, y: 1}
- }]
- });
- // 加载附近车辆数据
- that.getloadNearbyCars();
-
- },
- fail() {
- wx.showToast({
- title: '无法获取位置,请检查权限',
- icon: 'none'
- });
- }
- });
- },
-
-
- // 预约叫车
- onelectricity(){
-
- wx.navigateTo({
- url: `/package-order/pages/createorder/index?order=`,
- })
- },
-
- onHide() {
- // 页面卸载时停止追踪
- this.stopTracking();
- },
-
- // 停止追踪
- stopTracking() {
- if (this.data.locationTimer) {
- clearInterval(this.data.locationTimer);
- this.setData({
- locationTimer: null,
- isTracking: false
- });
- }
-
- },
- // 加载附近车辆
- getloadNearbyCars() {
- const that = this;
-
- let data ={
- carId:'',
- carType:'',
- carMondel:'',
- }
- api.request(`/syscar/selectcarall`, 'post',data,{ isPublic: false })
- .then((data) => {
- if (data.code==200) {
- const cars = [];
- for (let index = 0; index < data.data.length; index++) {
- let carPosition = data.data[index].carPosition.split(",");
- cars.push({
- id: 100+index,
- longitude: carPosition[1],
- latitude: carPosition[0],
- iconPath: 'https://esos-iot.bjdexn.cn/myminio/project/f6fba6c83b2d4864a73f5f1d83cda416.png',
- width: 30,
- height: 40,
- anchor: {x: 0.5, y: 0.5}
- });
- }
- // 将车辆标记添加到现有标记中
- const updatedMarkers = [...that.data.markers];
- // 先移除之前的车辆标记
- const filteredMarkers = updatedMarkers.filter(marker => marker.id);
- // 添加新的车辆标记
- filteredMarkers.push(...cars);
-
- that.setData({
- markers: filteredMarkers,
- carsNearby: data.data.length
- });
- // this.loadNearbyCars()
- }
-
- })
- .catch((err) => {
-
- console.error('请求失败:', err);
- });
-
-
- },
- // 加载附近车辆
- loadNearbyCars() {
- const { longitude, latitude } = this.data;
-
- if (this.data.isTracking) return;
-
- const that = this;
- this.setData({ isTracking: true });
- this.setData({
- locationTimer:setInterval(() => {
- let data ={
- carId:'',
- carType:'',
- carMondel:'',
- }
- api.request(`/syscar/selectcarall`, 'post',data,{ isPublic: false })
- .then((data) => {
- if (data.code==200) {
- const cars = [];
- for (let index = 0; index < data.data.length; index++) {
- let carPosition = data.data[index].carPosition.split(",");
- cars.push({
- id: 100+index,
- longitude: carPosition[1],
- latitude: carPosition[0],
- iconPath: 'https://esos-iot.bjdexn.cn/myminio/project/f6fba6c83b2d4864a73f5f1d83cda416.png',
- width: 30,
- height: 40,
- anchor: {x: 0.5, y: 0.5}
- });
- }
- // 将车辆标记添加到现有标记中
- const updatedMarkers = [...that.data.markers];
- // 先移除之前的车辆标记
- const filteredMarkers = updatedMarkers.filter(marker => marker.id);
- // 添加新的车辆标记
- filteredMarkers.push(...cars);
-
- that.setData({
- markers: filteredMarkers,
- carsNearby: data.data.length
- });
- }
-
- })
- .catch((err) => {
-
- console.error('请求失败:', err);
- });
- }, 10000) // 每10秒更新一次位置
- })
-
-
- },
-
- // 取消订单
- positioning(){
- this.initMap()
-
- },
-
- details(e){
-
- wx.navigateTo({
- url: `/package-map/pages/map/index?id=${e.currentTarget.dataset.id}`,
- })
- },
-
-
- onShow() {
- // this.loadNearbyCars()
- this.getworkordertype()
-
- },
- });
- //
|