|  |  | 
 |  |  |       content: '确认' | 
 |  |  |     }, | 
 |  |  |     errorDialogTitle: "关阀错误", | 
 |  |  |     showForceConfirm: false //是否强制开阀 | 
 |  |  |     showForceConfirm: false, //是否强制开阀 | 
 |  |  |     lastIntakeName: "" | 
 |  |  |   }, | 
 |  |  |  | 
 |  |  |   openValve: function (e) { | 
 |  |  | 
 |  |  |    * 生命周期函数--监听页面加载 | 
 |  |  |    */ | 
 |  |  |   onLoad(options) { | 
 |  |  |     //判断本地是否保存sessionId | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     // 使用 wx.nextTick 等待页面渲染完成 | 
 |  |  |     wx.nextTick(() => { | 
 |  |  |       this.calculateScrollViewHeight(); | 
 |  |  | 
 |  |  |       }) | 
 |  |  |       this.getOpenList(); | 
 |  |  |     } | 
 |  |  |     this.getUserDataBySession(); | 
 |  |  |     this.initData(); | 
 |  |  |   }, | 
 |  |  |  | 
 |  |  |   /** | 
 |  |  |    * 生命周期函数--监听页面初次渲染完成 | 
 |  |  |    */ | 
 |  |  |   onReady() { | 
 |  |  |     //判断本地是否保存sessionId | 
 |  |  |     if (storage.isHasKeySync("sessionId")) { | 
 |  |  |       storage.getItem('sessionId').then((data) => { | 
 |  |  |         this.setData({ | 
 |  |  |           sessionId: data | 
 |  |  |         }); | 
 |  |  |         if (sessionId !== "") {} | 
 |  |  |       }).catch((err) => { | 
 |  |  |         console.error('Failed to load parameter:', err); | 
 |  |  |       }); | 
 |  |  |     } else { | 
 |  |  |       console.log('Failed to load parameter:false'); | 
 |  |  |     } | 
 |  |  |     this.getOpenList(); | 
 |  |  |  | 
 |  |  |   }, | 
 |  |  |  | 
 |  |  |   /** | 
 |  |  | 
 |  |  |       showForceConfirm: false | 
 |  |  |     }); | 
 |  |  |   }, | 
 |  |  |   cancelDialog(){ | 
 |  |  |   cancelDialog() { | 
 |  |  |     this.setData({ | 
 |  |  |       showForceConfirm: false, | 
 |  |  |       showConfirm: false | 
 |  |  | 
 |  |  |     wx.scanCode({ | 
 |  |  |       success(res) { | 
 |  |  |         console.log(res.result); // 当且仅当扫码为非微信二维码时,会返回result   | 
 |  |  |         wx.showLoading({ | 
 |  |  |           title: '正在开阀请稍候...', // 加载提示文字 | 
 |  |  |           mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false | 
 |  |  |         }); | 
 |  |  |         const app = getApp(); | 
 |  |  |         const data = { | 
 |  |  |           intakeName: res.result, //取水口ID | 
 |  |  |           // vcId: vcId, //虚拟卡ID | 
 |  |  |           operator: app.globalData.sessionId //操作员 | 
 |  |  |         }; | 
 |  |  |         post({ | 
 |  |  |           url: "wx/valve/open_wx", | 
 |  |  |           data: data, | 
 |  |  |           timeout: 180000 | 
 |  |  |         }).then(response => { | 
 |  |  |         if (res.result.startsWith("content://")) { | 
 |  |  |           let jsonStr = res.result.replace("content://", "") | 
 |  |  |           try { | 
 |  |  |  | 
 |  |  |           // 处理成功响应 | 
 |  |  |           console.log('请求成功:', response); | 
 |  |  |           // 加载完成后隐藏加载动画 | 
 |  |  |           wx.hideLoading(); | 
 |  |  |           //完成后回到首页 | 
 |  |  |           wx.reLaunch({ | 
 |  |  |             url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写 | 
 |  |  |           }); | 
 |  |  |         }).catch(error => { | 
 |  |  |           // 加载完成后隐藏加载动画 | 
 |  |  |           wx.hideLoading(); | 
 |  |  |           // 处理错误响应 | 
 |  |  |           console.error('请求失败:', error); | 
 |  |  |           if (error.code==="1003") { | 
 |  |  |             that.setData({ | 
 |  |  |               showForceConfirm:true | 
 |  |  |             }) | 
 |  |  |           } else { | 
 |  |  |             that.setData({ | 
 |  |  |               showErrorDialog: true, | 
 |  |  |               errorData: error.msg, | 
 |  |  |               errorDialogTitle: "开阀错误" | 
 |  |  |             }) | 
 |  |  |             that.saveData(jsonStr) | 
 |  |  |           } catch (error) { | 
 |  |  |             console.error('Error parsing JSON:', error); | 
 |  |  |           } | 
 |  |  |      | 
 |  |  |  | 
 |  |  |         }); | 
 |  |  |         } else { | 
 |  |  |           that.postOppenValva(res.result) | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |       }, | 
 |  |  |       fail(err) { | 
 |  |  |         console.error(err); | 
 |  |  |       } | 
 |  |  |  | 
 |  |  |     }) | 
 |  |  |   }, | 
 |  |  |   confirmForceDialog(){ | 
 |  |  |   confirmForceDialog() { | 
 |  |  |     console.log("confirmForceDialog"); | 
 |  |  |     this.setData({ | 
 |  |  |       showForceConfirm: false | 
 |  |  |     }) | 
 |  |  |     this.postOppenValva(this.data.lastIntakeName, true) | 
 |  |  |   }, | 
 |  |  |   /** | 
 |  |  |    *  | 
 |  |  |    * @param {*} intakeName  | 
 |  |  |    */ | 
 |  |  |   postOppenValva(intakeName, isforce) { | 
 |  |  |     const that = this; | 
 |  |  |     wx.showLoading({ | 
 |  |  |       title: '正在开阀请稍候...', // 加载提示文字 | 
 |  |  |       mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false | 
 |  |  |     }); | 
 |  |  |     const app = getApp(); | 
 |  |  |     that.setData({ | 
 |  |  |       lastIntakeName: intakeName | 
 |  |  |     }) | 
 |  |  |     const data = { | 
 |  |  |       intakeName: intakeName, //取水口ID | 
 |  |  |       // vcId: vcId, //虚拟卡ID | 
 |  |  |       operator: app.globalData.sessionId, //操作员 | 
 |  |  |       forceOpen: !!isforce // 使用逻辑非操作符 !! 来确保 isForce 是布尔值   | 
 |  |  |     }; | 
 |  |  |     post({ | 
 |  |  |       url: "wx/valve/open_wx", | 
 |  |  |       data: data, | 
 |  |  |       timeout: 180000 | 
 |  |  |     }).then(response => { | 
 |  |  |  | 
 |  |  |       // 处理成功响应 | 
 |  |  |       console.log('请求成功:', response); | 
 |  |  |       // 加载完成后隐藏加载动画 | 
 |  |  |       wx.hideLoading(); | 
 |  |  |       //完成后回到首页 | 
 |  |  |       wx.reLaunch({ | 
 |  |  |         url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写 | 
 |  |  |       }); | 
 |  |  |     }).catch(error => { | 
 |  |  |       // 加载完成后隐藏加载动画 | 
 |  |  |       wx.hideLoading(); | 
 |  |  |       // 处理错误响应 | 
 |  |  |       console.error('请求失败:', error); | 
 |  |  |       if (error.code === "10005") { | 
 |  |  |         that.setData({ | 
 |  |  |           showForceConfirm: true | 
 |  |  |         }) | 
 |  |  |       } else { | 
 |  |  |         that.setData({ | 
 |  |  |           showErrorDialog: true, | 
 |  |  |           errorData: error.msg, | 
 |  |  |           errorDialogTitle: "开阀错误" | 
 |  |  |         }) | 
 |  |  |       } | 
 |  |  |     }); | 
 |  |  |   }, | 
 |  |  |   /** | 
 |  |  |    * 扫描后保存用户id和tag | 
 |  |  |    */ | 
 |  |  |   saveData(userData) { | 
 |  |  |     storage.setItem("userData", userData).then(() => { | 
 |  |  |       this.initData(); | 
 |  |  |     }).catch((error) => {}); | 
 |  |  |  | 
 |  |  |   }, | 
 |  |  |   //进入界面获取界面数据 | 
 |  |  |   initData() { | 
 |  |  |     const app = getApp(); | 
 |  |  |     console.log("tag>>>>:" +app.globalData.tag) | 
 |  |  |   | 
 |  |  |     if (storage.isHasKeySync("userData")) { | 
 |  |  |       storage.getItem('userData').then((data) => { | 
 |  |  |         let jsonObj = JSON.parse(data); | 
 |  |  |         app.globalData.sessionId = jsonObj.sessionId; | 
 |  |  |         app.globalData.tag = jsonObj.tag; | 
 |  |  |         this.getUserDataBySession(); | 
 |  |  |         this.getOpenList(); | 
 |  |  |         console.log("userData>>>>>>>" + data) | 
 |  |  |       }).catch((err) => { | 
 |  |  |         console.error('Failed to load parameter:', err); | 
 |  |  |       }); | 
 |  |  |     } else { | 
 |  |  |       this.getUserDataBySession(); | 
 |  |  |       this.getOpenList(); | 
 |  |  |       console.log('Failed to load parameter:false'); | 
 |  |  |     } | 
 |  |  |    | 
 |  |  |   } | 
 |  |  | }) |