电速宝
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. const api = require('../../api/index.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. // 地图初始中心坐标(北京市中心)
  6. longitude: 116.404,
  7. latitude: 39.915,
  8. scale:10,
  9. markers: [],
  10. polyline: [],
  11. startLocation: {},
  12. endLocation: {},
  13. showTripInfo: true,
  14. showCallButton: true,
  15. showDriverInfo: true,
  16. carsNearby: 0,
  17. // 司机信息
  18. driverAvatar: 'https://esos-iot.com/myminio/project/2a1b32553c3d4ef992bc797d26cf1614.png',
  19. driverName: '王师傅',
  20. carNumber: '京·A88888',
  21. estimatedArrival: 5,
  22. locationTimer: null,
  23. isTracking: false,
  24. userdata:[],
  25. workorderdata:[],
  26. background: ['https://esos-iot.com/myminio/project/8e68e25a4e6042b09e233d496c0aad3b.png', 'https://esos-iot.com/myminio/project/8e68e25a4e6042b09e233d496c0aad3b.png', 'https://esos-iot.com/myminio/project/8e68e25a4e6042b09e233d496c0aad3b.png'],
  27. indicatorDots: true,
  28. vertical: false,
  29. autoplay: true,
  30. interval: 3000,
  31. duration: 500
  32. },
  33. // 收益统计
  34. onLoad() {
  35. // 初始化地图
  36. this.getuser()
  37. this.initMap()
  38. wx.$on('wsMessage', this.handleWsMessage);
  39. },
  40. onHide(){
  41. // 页面卸载时,取消订阅,这是至关重要的一步!
  42. wx.$off('wsMessage', this.handleWsMessage);
  43. },
  44. /**
  45. * 处理接收到的 WebSocket 消息
  46. * @param {Object} message 从 app.js 广播过来的消息对象
  47. */
  48. handleWsMessage(message) {
  49. console.log('Other Page 收到 WebSocket 消息:', message);
  50. // 根据消息类型进行不同的处理
  51. switch (message.api) {
  52. case '/sysworkorder/selectworkorderlist':
  53. // 在这里可以更新地图、刷新UI等
  54. if (message.type==1) {
  55. this.getworkordertype()
  56. }
  57. break;
  58. case 'trajectoryInit':
  59. // 处理初始轨迹数据
  60. break;
  61. case 'heartbeatReply':
  62. // 心跳回复,通常不需要UI处理
  63. break;
  64. default:
  65. // 处理其他类型的消息
  66. break;
  67. }
  68. },
  69. // 获取待执行工单
  70. getworkordertype(){
  71. let data ={
  72. workorderId:'',
  73. workorderName:'',
  74. addressId:'',
  75. driverId:'',
  76. carId:'',
  77. customerId:'',
  78. workorderType:4,
  79. chargedischargeType:'',
  80. pageNum:1,
  81. pageSize:99
  82. }
  83. api.request(`/sysworkorder/selectworkorderlist`, 'post',data ,{ isPublic: false })
  84. .then((data) => {
  85. console.log(data.data);
  86. if (data.code==200) {
  87. this.setData({
  88. workorderdata:data.data.list
  89. })
  90. }
  91. })
  92. .catch((err) => {
  93. console.error('请求失败:', err);
  94. });
  95. },
  96. getuser(){
  97. api.request(`/sysoperation/selectoperationid`, 'post',{ isPublic: false })
  98. .then((data) => {
  99. console.log(data.data);
  100. if (data.code==200) {
  101. this.setData({
  102. userdata:data.data
  103. })
  104. // 设置数据到本地存储
  105. wx.setStorage({
  106. key: 'user', // 存储的key值
  107. data:data.data
  108. });
  109. }
  110. })
  111. .catch((err) => {
  112. console.error('请求失败:', err);
  113. });
  114. },
  115. // 初始化地图,获取用户位置
  116. initMap() {
  117. const that = this;
  118. // 获取用户当前位置
  119. wx.getLocation({
  120. type: 'gcj02', // 国测局坐标系,微信地图使用该坐标系
  121. success(res) {
  122. const longitude = res.longitude;
  123. const latitude = res.latitude;
  124. // 更新地图中心位置
  125. that.setData({
  126. longitude,
  127. latitude,
  128. startLocation: {
  129. longitude,
  130. latitude,
  131. name: '我的位置'
  132. },
  133. // 添加起点标记
  134. markers: [{
  135. id: 0,
  136. longitude,
  137. latitude,
  138. iconPath: 'https://esos-iot.com/myminio/project/a0d245bf00c6493d949c3be82a6d2b98.png',
  139. width: 40,
  140. height: 40,
  141. anchor: {x: 0.5, y: 1}
  142. }],
  143. carsNearby: 0, // 附近车辆数
  144. stationsNearby: 0, // 附近电站数
  145. powerUseNearby: 0, // 附近用电位置数
  146. });
  147. // 加载附近车辆数据
  148. //
  149. // that.getloadNearbyCars();
  150. that.refreshAllNearbyData()
  151. },
  152. fail() {
  153. wx.showToast({
  154. title: '无法获取位置,请检查权限',
  155. icon: 'none'
  156. });
  157. }
  158. });
  159. },
  160. onelectricity(){
  161. wx.navigateTo({
  162. url: `/package-order/pages/createorder/index?order=`,
  163. })
  164. },
  165. onHide() {
  166. // 页面卸载时停止追踪
  167. this.stopTracking();
  168. },
  169. // 停止追踪
  170. stopTracking() {
  171. if (this.data.locationTimer) {
  172. clearInterval(this.data.locationTimer);
  173. this.setData({
  174. locationTimer: null,
  175. isTracking: false
  176. });
  177. }
  178. },
  179. // 加载附近车辆
  180. getloadNearbyCars() {
  181. const that = this;
  182. let data = {};
  183. api.request(`/syscar/selectoperationcar`, 'post', data, { isPublic: false })
  184. .then((data) => {
  185. if (data.code == 200) {
  186. const cars = [];
  187. for (let index = 0; index < data.data.syscarList.length; index++) {
  188. let carPosition = data.data.syscarList[index].carPosition.split(",");
  189. cars.push({
  190. id: 100 + index, // 车辆标记 ID 段:100+
  191. longitude: carPosition[1],
  192. latitude: carPosition[0],
  193. iconPath: 'https://esos-iot.com/myminio/project/e9c0fba9b61448e59458054d335b162b.png',
  194. width: 26,
  195. height: 32,
  196. anchor: { x: 0.5, y: 0.5 },
  197. type: 'car' // 标记类型,用于过滤
  198. });
  199. }
  200. // 更新车辆标记:先移除旧车辆标记,再添加新的
  201. const updatedMarkers = that.updateMarkers('car', cars);
  202. that.setData({
  203. markers: updatedMarkers,
  204. carsNearby: data.data.carcount
  205. });
  206. }
  207. })
  208. .catch((err) => {
  209. console.error('加载附近车辆失败:', err);
  210. });
  211. },
  212. // ========== 新增:加载附近电站 ==========
  213. getloadNearbyStations() {
  214. const that = this;
  215. let data = {}; // 根据接口要求传参,如当前定位、范围等
  216. // 替换为你的电站列表接口
  217. api.request(`/sysaddress/selectpower`, 'post', data, { isPublic: false })
  218. .then((data) => {
  219. if (data.code == 200) {
  220. console.log(data);
  221. const stations = [];
  222. // 假设接口返回的电站列表字段为 syscarList,坐标字段为 carPosition(格式:纬度,经度)
  223. // data.data.syscarList = [{carPosition: "40.155721,116.652896"},{carPosition: "40.105315,116.763173"},{carPosition: "40.108386,116.595002"}]
  224. for (let index = 0; index < data.data.length; index++) {
  225. // let carPosition = data.data[index].carPosition.split(",");
  226. if (data.data[index].addressType==2) {
  227. // console.log('');
  228. // 网点 绿电
  229. stations.push({
  230. id: 200 + index, // 电站标记 ID 段:200+(避免和车辆冲突)
  231. longitude: data.data[index].longitude,
  232. latitude: data.data[index].latitude,
  233. // 替换为你的电站图标地址
  234. iconPath: 'https://esos-iot.com/myminio/project/62a7a9c509f948558436bc56ee9bfe2e.png',
  235. width: 28, // 电站图标尺寸,和车辆区分
  236. height: 32,
  237. anchor: { x: 0.5, y: 0.5 },
  238. type: 'station' // 标记类型
  239. });
  240. }
  241. }
  242. // 更新电站标记
  243. const updatedMarkers = that.updateMarkers('station', stations);
  244. that.setData({
  245. markers: updatedMarkers,
  246. stationsNearby: data.data.length // 电站数量
  247. });
  248. }
  249. })
  250. .catch((err) => {
  251. console.error('加载附近电站失败:', err);
  252. });
  253. },
  254. // ========== 新增:加载附近用电位置 ==========
  255. getloadNearbyPowerUse() {
  256. const that = this;
  257. let data = {}; // 根据接口要求传参
  258. // 替换为你的用电位置列表接口
  259. api.request(`/sysaddress/selectpower`, 'post', data, { isPublic: false })
  260. .then((data) => {
  261. if (data.code == 200) {
  262. const powerUses = [];
  263. // 假设接口返回的用电位置列表字段为 syscarList,坐标字段为 carPosition(格式:纬度,经度)
  264. // data.data.syscarList = [{carPosition: "40.086206,116.850604"},{carPosition: "40.017232,116.61686"},{carPosition: "40.230298,116.739424"}]
  265. for (let index = 0; index < data.data.length; index++) {
  266. // let carPosition = data.data.syscarList[index].carPosition.split(",");
  267. if (data.data[index].addressType==0||data.data[index].addressType==1) {
  268. powerUses.push({
  269. id: 300 + index, // 用电位置 ID 段:300+
  270. longitude: data.data[index].longitude,
  271. latitude: data.data[index].latitude,
  272. // 替换为你的用电位置图标地址
  273. iconPath: 'https://esos-iot.com/myminio/project/42dd004817dd4f268d97dcd1145ca113.png',
  274. width: 26, // 用电位置图标尺寸
  275. height: 30,
  276. anchor: { x: 0.5, y: 0.5 },
  277. type: 'powerUse' // 标记类型
  278. });
  279. }
  280. }
  281. // 更新用电位置标记
  282. const updatedMarkers = that.updateMarkers('powerUse', powerUses);
  283. that.setData({
  284. markers: updatedMarkers,
  285. powerUseNearby: data.data.length // 用电位置数量
  286. });
  287. }
  288. })
  289. .catch((err) => {
  290. console.error('加载附近用电位置失败:', err);
  291. });
  292. },
  293. // ========== 通用方法:更新地图标记(核心复用逻辑) ==========
  294. /**
  295. * 更新地图标记
  296. * @param {String} type 标记类型(car/station/powerUse)
  297. * @param {Array} newMarkers 新的标记列表
  298. * @returns {Array} 更新后的所有标记
  299. */
  300. updateMarkers(type, newMarkers) {
  301. // 1. 过滤掉原有同类型的标记
  302. const filteredMarkers = this.data.markers.filter(marker => marker.type !== type);
  303. // 2. 添加新的同类型标记
  304. filteredMarkers.push(...newMarkers);
  305. // 3. 返回更新后的标记列表
  306. return filteredMarkers;
  307. },
  308. // 可选:刷新所有附近数据
  309. refreshAllNearbyData() {
  310. this.getloadNearbyCars();
  311. if (this.data.userdata.operationRole==6) {
  312. this.getloadNearbyPowerUse(); // 用电
  313. }else if (this.data.userdata.operationRole==5) {
  314. this.getloadNearbyStations(); // 绿电
  315. }else if (this.data.userdata.operationRole==4){
  316. this.getloadNearbyStations();
  317. this.getloadNearbyPowerUse();
  318. }
  319. },
  320. // 取消工单
  321. positioning(){
  322. this.initMap()
  323. },
  324. details(e){
  325. wx.navigateTo({
  326. url: `/package-map/pages/map/index?id=${e.currentTarget.dataset.id}`,
  327. })
  328. },
  329. onShow() {
  330. // this.loadNearbyCars()
  331. this.getworkordertype()
  332. },
  333. });
  334. //