2025-04-05 23:47:00 +08:00
|
|
|
|
// pages/wangdian/wangdian.js
|
2025-04-10 19:01:02 +08:00
|
|
|
|
var t = require("../../utils/login.js");
|
|
|
|
|
|
2025-04-05 23:47:00 +08:00
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
2025-04-09 23:29:51 +08:00
|
|
|
|
banner: [],
|
|
|
|
|
info: {},
|
|
|
|
|
jiqilist: [],
|
|
|
|
|
number: '',
|
|
|
|
|
machineCount: 0,
|
|
|
|
|
freeMachineCount: 0,
|
|
|
|
|
timer: null,
|
2025-04-05 23:47:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
|
2025-04-09 23:29:51 +08:00
|
|
|
|
// 如果没有wx.getStorageSync('latitude') 或者 wx.getStorageSync('longitude') 则获取当前位置
|
|
|
|
|
if (!wx.getStorageSync('latitude') || !wx.getStorageSync('longitude')) {
|
|
|
|
|
wx.getLocation({
|
|
|
|
|
type: 'wgs84',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
wx.setStorageSync('latitude', res.latitude);
|
|
|
|
|
wx.setStorageSync('longitude', res.longitude);
|
|
|
|
|
this.getBranchDetail();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
number: options.number || ''
|
|
|
|
|
});
|
|
|
|
|
this.getBranchDetail();
|
|
|
|
|
this.getMachineList();
|
|
|
|
|
// 设置定时器,每10秒刷新一次机器状态
|
|
|
|
|
this.data.timer = setInterval(() => {
|
|
|
|
|
this.getMachineList();
|
|
|
|
|
}, 10000);
|
2025-04-05 23:47:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide() {
|
|
|
|
|
|
2025-04-09 23:29:51 +08:00
|
|
|
|
// 页面卸载时清除定时器
|
|
|
|
|
if (this.data.timer) {
|
|
|
|
|
clearInterval(this.data.timer);
|
|
|
|
|
this.data.timer = null;
|
|
|
|
|
}
|
2025-04-05 23:47:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload() {
|
2025-04-09 23:29:51 +08:00
|
|
|
|
// 页面卸载时清除定时器
|
|
|
|
|
if (this.data.timer) {
|
|
|
|
|
clearInterval(this.data.timer);
|
|
|
|
|
this.data.timer = null;
|
|
|
|
|
}
|
2025-04-05 23:47:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
2025-04-09 23:29:51 +08:00
|
|
|
|
},
|
|
|
|
|
// 获取网点详情信息
|
|
|
|
|
getBranchDetail() {
|
2025-04-10 19:01:02 +08:00
|
|
|
|
t.request('/miniprogram/branch/detail', {
|
|
|
|
|
number: this.data.number,
|
|
|
|
|
latitude: wx.getStorageSync('latitude'),
|
|
|
|
|
longitude: wx.getStorageSync('longitude'),
|
2025-04-09 23:29:51 +08:00
|
|
|
|
method: 'GET',
|
2025-04-10 19:01:02 +08:00
|
|
|
|
}, !0).then((res) => {
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
this.setData({
|
|
|
|
|
banner: res.data.banner || [],
|
|
|
|
|
info: res.data.info || {},
|
|
|
|
|
});
|
2025-04-09 23:29:51 +08:00
|
|
|
|
}
|
2025-04-10 19:01:02 +08:00
|
|
|
|
})
|
2025-04-09 23:29:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取机器列表
|
|
|
|
|
getMachineList() {
|
|
|
|
|
|
2025-04-10 19:01:02 +08:00
|
|
|
|
t.request('/miniprogram/branch/machine', {
|
|
|
|
|
number: this.data.number,
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
this.setData({
|
|
|
|
|
jiqilist: res.data || [],
|
|
|
|
|
});
|
|
|
|
|
// 计算机器数量, 与空闲机器数量 free machine
|
|
|
|
|
let machineCount = this.data.jiqilist.length;
|
|
|
|
|
let freeMachineCount = 0;
|
|
|
|
|
for (let i = 0; i < this.data.jiqilist.length; i++) {
|
|
|
|
|
if (this.data.jiqilist[i].devicestatus == 0) {
|
|
|
|
|
freeMachineCount++;
|
|
|
|
|
}
|
2025-04-09 23:29:51 +08:00
|
|
|
|
}
|
2025-04-10 19:01:02 +08:00
|
|
|
|
// 更新数据
|
|
|
|
|
this.setData({
|
|
|
|
|
machineCount,
|
|
|
|
|
freeMachineCount
|
|
|
|
|
});
|
2025-04-09 23:29:51 +08:00
|
|
|
|
}
|
2025-04-10 19:01:02 +08:00
|
|
|
|
})
|
2025-04-09 23:29:51 +08:00
|
|
|
|
},
|
2025-04-10 22:36:01 +08:00
|
|
|
|
|
|
|
|
|
// 打开地图导航
|
|
|
|
|
openLocation() {
|
|
|
|
|
if (this.data.info.latitude && this.data.info.longitude) {
|
|
|
|
|
wx.openLocation({
|
|
|
|
|
latitude: Number(this.data.info.latitude),
|
|
|
|
|
longitude: Number(this.data.info.longitude),
|
|
|
|
|
name: this.data.info.name,
|
|
|
|
|
address: this.data.info.address,
|
|
|
|
|
scale: 18
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '暂无位置信息',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-04-05 23:47:00 +08:00
|
|
|
|
})
|