| | |
| | | lastIntakeName: "", |
| | | isLogin: false, //是否已经登录 |
| | | showInfoDialog: false, |
| | | |
| | | showTipDialog: false, |
| | | options: '', |
| | | showUnBind: false |
| | | }, |
| | | |
| | | openValve: function (e) { |
| | |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | // 使用 wx.nextTick 等待页面渲染完成 |
| | | wx.nextTick(() => { |
| | | this.calculateScrollViewHeight(); |
| | | }); |
| | | //当开阀成功后调用刷新 |
| | | console.log("onLoad:" + options.param); |
| | | if (options.param) { |
| | | wx.showToast({ |
| | | title: '开阀成功', |
| | | icon: 'success', |
| | | duration: 3000 |
| | | if (options.param === "1" || options.param === "2") { |
| | | this.setData({ |
| | | options: options, |
| | | isLogin: true, |
| | | }) |
| | | this.getOpenList(); |
| | | } |
| | | |
| | | }, |
| | |
| | | isLogin: true |
| | | }) |
| | | if (app.globalData.sessionId) { |
| | | this.getOpenList(); |
| | | this.getUserDataBySession(); |
| | | } |
| | | }).catch((err) => {}); |
| | | storage.getItem('clientId').then((data) => { |
| | | app.globalData.clientId = data; |
| | | this.getOpenList(); |
| | | }).catch((err) => {}); |
| | | } else { |
| | | //本地没有缓存微信登录 |
| | | this.wxLogin(); |
| | | } |
| | | if (this.data.options.param === "1") { |
| | | this.setData({ |
| | | showTipDialog: true, |
| | | tipData: "开阀命令下发成功,因开阀需要时间,约20-60秒后可刷新快速关阀列表查看执行结果。" |
| | | }) |
| | | setTimeout(() => { |
| | | this.getOpenList(); |
| | | }, 20000) |
| | | |
| | | } else if (this.data.options.param === "2") { |
| | | this.setData({ |
| | | showTipDialog: true, |
| | | tipData: "预约开阀命令下发成功,当到达预约时间并且成功开阀后快速关阀列表会显示未关阀记录" |
| | | }) |
| | | this.getOpenList(); |
| | | } |
| | | }, |
| | | wxLogin() { |
| | | const that = this; |
| | | wx.login({ |
| | | success: function (res) { |
| | | if (res.code) { |
| | | var code = res.code; |
| | | console.log(code); |
| | | // 将code发送到服务器获取openid |
| | | that.codeLogin(code); |
| | | } else { |
| | | console.log('登录失败!' + res.errMsg); |
| | | // if (!this.data.isLogin) { |
| | | const that = this; |
| | | wx.login({ |
| | | success: function (res) { |
| | | if (res.code) { |
| | | var code = res.code; |
| | | console.log(code); |
| | | // 将code发送到服务器获取openid |
| | | that.codeLogin(code); |
| | | } else { |
| | | console.log('登录失败!' + res.errMsg); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | // } |
| | | |
| | | }, |
| | | //微信code登录 |
| | | codeLogin(codeData) { |
| | |
| | | this.setData({ |
| | | showConfirm: false, |
| | | showErrorDialog: false, |
| | | showForceConfirm: false |
| | | showForceConfirm: false, |
| | | showTipDialog: false |
| | | }); |
| | | }, |
| | | cancelDialog() { |
| | | this.setData({ |
| | | showForceConfirm: false, |
| | | showConfirm: false |
| | | showConfirm: false, |
| | | showTipDialog: false, |
| | | showUnBind: false |
| | | }); |
| | | }, |
| | | /** |
| | |
| | | wx.hideLoading(); |
| | | this.getOpenList(); |
| | | if (response.content.data.success) { |
| | | wx.showToast({ |
| | | title: '关阀成功', |
| | | icon: 'success', |
| | | duration: 3000 |
| | | this.setData({ |
| | | isLogin: true, |
| | | showTipDialog: true, |
| | | tipData: "关阀命令下发成功,约20-60秒后可刷新快速关阀列表查看执行结果。" |
| | | }) |
| | | setTimeout(() => { |
| | | this.getOpenList(); |
| | | }, 40000) |
| | | } else { |
| | | wx.showToast({ |
| | | title: '关阀失败', |
| | | title: '命令执行失败', |
| | | icon: 'error', |
| | | duration: 3000 |
| | | }) |
| | |
| | | const params = { |
| | | url: 'wx/valve/get', |
| | | data: { |
| | | operator: app.globalData.sessionId |
| | | operator: app.globalData.clientId |
| | | } |
| | | }; |
| | | get(params).then(data => { |
| | |
| | | title: '正在强制删除请稍候...', // 加载提示文字 |
| | | mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false |
| | | }); |
| | | that.setData({ |
| | | lastIntakeName: intakeName |
| | | }) |
| | | const data = { |
| | | vcNum: item.vcNum, //取水口ID |
| | | rtuAddr: item.rtuAddr, //阀控器地址 |
| | |
| | | } else { |
| | | displayText = "关阀" |
| | | } |
| | | let deleteText = "删除" |
| | | let time; |
| | | if (!item.dt) { |
| | | time = "暂无" |
| | | } else { |
| | | time = this.extractTime(item.dt) |
| | | } |
| | | if (item.waterInstant===null) { |
| | | item.waterInstant = "暂无" |
| | | } |
| | | |
| | | return { |
| | | ...item, |
| | | displayText |
| | | displayText, |
| | | deleteText, |
| | | time |
| | | }; // 保留所有其他字段,并添加 displayText 字段 |
| | | }); |
| | | // 更新列表数据 |
| | |
| | | }, |
| | | //解绑 |
| | | unbind() { |
| | | //清空数据 |
| | | this.setData({ |
| | | userPhone: "请登录", |
| | | userName: "未登录", |
| | | listData: [] |
| | | showUnBind: true |
| | | }) |
| | | }, |
| | | //确认解绑 |
| | | unBindPost() { |
| | | this.setData({ |
| | | showUnBind: false |
| | | }) |
| | | wx.showLoading({ |
| | | title: '正在解绑请稍候...', // 加载提示文字 |
| | |
| | | wx.hideLoading(); |
| | | // 处理错误响应 |
| | | console.error('请求失败:', error); |
| | | wx.showToast({ |
| | | title: '解绑失败', |
| | | icon: 'error', |
| | | duration: 3000 |
| | | }) |
| | | }); |
| | | }, |
| | | //点击提示按钮 |
| | |
| | | this.setData({ |
| | | showInfoDialog: false |
| | | }) |
| | | }, |
| | | //处理时间去掉年月日 |
| | | extractTime(datetimeString) { |
| | | const formattedDate = datetimeString.replace(" ", "T"); |
| | | const date = new Date(formattedDate); |
| | | // 获取小时、分钟和秒 |
| | | const hours = date.getHours().toString().padStart(2, '0'); |
| | | const minutes = date.getMinutes().toString().padStart(2, '0'); |
| | | const seconds = date.getSeconds().toString().padStart(2, '0'); |
| | | return `${hours}:${minutes}:${seconds}`; |
| | | }, |
| | | onShareAppMessage: function (options) { |
| | | // 设置分享内容 |
| | | return { |
| | | title: '大禹灌溉助手', // 分享标题 |
| | | path: '/pages/home/home', // 分享路径,该路径需要是当前小程序存在的页面路径 |
| | | imageUrl: '/images/logo2.jpg', // 分享图标,可以是网络图片路径或本地图片路径 |
| | | success: function (res) { |
| | | // 分享成功的回调函数 |
| | | }, |
| | | fail: function (res) { |
| | | // 分享失败的回调函数 |
| | | } |
| | | }; |
| | | } |
| | | }) |