| | |
| | | get, |
| | | post |
| | | } = require('../../api/request.js'); |
| | | const app = getApp(); |
| | | Page({ |
| | | |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | sessionId: "", |
| | | showConfirm: false, |
| | | myItem: {}, |
| | | waterIntakeName: "", |
| | | image: "/images/ic_head_bg.jpg", |
| | | userPhone: "158****0723", |
| | | userName: "张三", |
| | | userPhone: "未登录", |
| | | userName: "请登录", |
| | | scrollViewHeight: 0, |
| | | listData: [], |
| | | isRefreshing: false, |
| | | isWXRefreshing: false |
| | | isWXRefreshing: false, |
| | | wxCode: '', |
| | | errorData: '', //错误内容 |
| | | showErrorDialog: false |
| | | }, |
| | | |
| | | openValve: function (e) { |
| | |
| | | isRefreshing: true |
| | | }); |
| | | this.getOpenList(); |
| | | |
| | | } |
| | | |
| | | }, |
| | | //获取用户数据 |
| | | getUserData() { |
| | |
| | | console.error('Failed to fetch data:', error); |
| | | }); |
| | | }, |
| | | |
| | | |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | |
| | | }) |
| | | this.getOpenList(); |
| | | } |
| | | this.getUserDataBySession(); |
| | | }, |
| | | |
| | | /** |
| | |
| | | this.setData({ |
| | | sessionId: data |
| | | }); |
| | | if (sessionId !== "") {} |
| | | }).catch((err) => { |
| | | console.error('Failed to load parameter:', err); |
| | | }); |
| | | if (sessionId) { |
| | | this.getOpenList(); |
| | | } |
| | | }).catch((err) => {}); |
| | | } else { |
| | | console.log('Failed to load parameter:false'); |
| | | this.wxLogin(); |
| | | } |
| | | this.getOpenList(); |
| | | }, |
| | | |
| | | /** |
| | |
| | | |
| | | }, |
| | | recharge() { |
| | | // wx.navigateTo({ |
| | | // url: '/pages/rechargeCard/rechargeCard', |
| | | // }) |
| | | wx.showToast({ |
| | | title: '暂未开放', |
| | | icon: 'none' |
| | | wx.navigateTo({ |
| | | url: '/pages/rechargeCard/rechargeCard', |
| | | }) |
| | | |
| | | }, |
| | | openValveList() { |
| | | // wx.navigateTo({ |
| | | // url: '/pages/valveList/valveList', |
| | | // }) |
| | | wx.showToast({ |
| | | title: '暂未开放', |
| | | icon: 'none' |
| | | wx.navigateTo({ |
| | | url: '/pages/valveList/valveList', |
| | | }) |
| | | |
| | | }, |
| | | feedBack() { |
| | | wx.showToast({ |
| | | title: '暂未开放', |
| | | icon: 'none' |
| | | wx.navigateTo({ |
| | | url: '/pages/feedback/feedback', |
| | | }) |
| | | }, |
| | | handleChange(e) { |
| | |
| | | post({ |
| | | url: "wx/valve/close_wx", |
| | | data: data, |
| | | isShowLoding: false |
| | | isShowLoding: false, |
| | | timeout: 185000 |
| | | }).then(response => { |
| | | |
| | | // 处理成功响应 |
| | |
| | | }) |
| | | }).catch(error => { |
| | | wx.hideLoading(); |
| | | if (error.code === "1002") { |
| | | wx.showToast({ |
| | | title: '关阀失败', |
| | | icon: 'error', |
| | | duration: 3000 // 提示的持续时间,单位毫秒 |
| | | }) |
| | | } |
| | | this.setData({ |
| | | showErrorDialog: true, |
| | | errorData: error.msg |
| | | }) |
| | | // 处理错误响应 |
| | | console.error('请求失败:', error); |
| | | |
| | |
| | | * 获取为关阀记录 |
| | | */ |
| | | getOpenList() { |
| | | const app = getApp(); |
| | | const params = { |
| | | url: 'wx/valve/get', |
| | | data: { |
| | |
| | | // 错误回调 |
| | | this.setData({ |
| | | isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成 |
| | | isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成 |
| | | }) |
| | | wx.showToast({ |
| | | title: err.msg, |
| | | icon: 'error', |
| | | duration: 3000 |
| | | }) |
| | | }); |
| | | }, |
| | |
| | | getUserDataBySession() { |
| | | const app = getApp(); |
| | | const params = { |
| | | url: 'sell/client/simple_info', |
| | | url: 'wx/client/simple_info', |
| | | data: { |
| | | sessionId: app.globalData.sessionId |
| | | } |
| | |
| | | |
| | | }) |
| | | }, |
| | | //将手机号中间四位隐藏 |
| | | maskPhoneNumber(phoneNumber) { |
| | | if (phoneNumber.length !== 11) { |
| | | throw new Error("Phone number must be 11 digits"); |
| | |
| | | // 使用正则表达式替换中间四位数字为星号 |
| | | const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2"); |
| | | return maskedPhoneNumber; |
| | | }, |
| | | //没有sessionID时获取sessionID |
| | | getSessionID(code) { |
| | | const params = { |
| | | url: 'https://44978f7456.imdo.co/wx/client/code_login ', |
| | | data: { |
| | | code: code |
| | | } |
| | | }; |
| | | post(params).then(data => { |
| | | if (data.content.client.sessionId) { |
| | | //当前用户绑定过 |
| | | getApp().globalData.sessionId = data.content.client.sessionId |
| | | storage.setItem("sessionId", data.content.client.sessionId); |
| | | this.getOpenList(); |
| | | this.getUserDataBySession(); |
| | | |
| | | } else { |
| | | //当前用户没绑定过,跳转到绑定界面 |
| | | wx.navigateTo({ |
| | | url: '/pages/wxbind/wxbind?wxCode=' + this.data.wxCode, |
| | | }) |
| | | } |
| | | |
| | | }).catch(err => { |
| | | // 错误回调 |
| | | |
| | | }) |
| | | }, |
| | | wxLogin() { |
| | | // 登录 |
| | | wx.login({ |
| | | success: res => { |
| | | if (res.code) { |
| | | console.log('登录成功,获取到的code:', res.code); |
| | | this.setData({ |
| | | wxCode: res.code |
| | | }) |
| | | // 发送 res.code 到后台服务器换取 openId, sessionKey, unionId |
| | | this.getSessionID(res.code) |
| | | } else { |
| | | console.log('登录失败!' + res.errMsg); |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | closeDialog() { |
| | | this.setData({ |
| | | showErrorDialog:false |
| | | }) |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | }) |