管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2024-05-30 910c37c43eceb27888b90631c868caa08f7eafcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// pages/home/home.js
const storage = require('../../utils/storage.js');
const {
  get,
  post
} = require('../../api/request.js');
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    sessionId: "",
    showConfirm: false,
    myItem:{},
    waterIntakeName: "",
    image: "/images/ic_head_bg.jpg",
    userPhone: "158****0723",
    userName: "张三",
    scrollViewHeight: 0,
    listData: [],
    isRefreshing: false,
    isWXRefreshing: false
  },
 
  openValve: function (e) {
    wx.navigateTo({
      url: '/pages/waterIntake/waterIntake',
    })
  },
  calculateScrollViewHeight: function () {
    wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
      let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0);
      this.setData({
        scrollViewHeight: totalHeight,
      });
    }).exec();
  },
  startPullDownRefresh() {
    if (!this.data.isWXRefreshing) {
      var self = this;
      console.log(this.data.isRefreshing);
      this.setData({
        isRefreshing: true
      });
      this.getOpenList();
 
    }
 
  },
  //获取用户数据
  getUserData() {
    get('/items')
      .then((data) => {
        this.setData({
          items: data
        });
      })
      .catch((error) => {
        console.error('Failed to fetch data:', error);
      });
  },
 
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 使用 wx.nextTick 等待页面渲染完成
    wx.nextTick(() => {
      this.calculateScrollViewHeight();
    });
    //当开阀成功后调用刷新
    console.log("onLoad:" + options.param);
    if(options.param){
      getOpenList() ;
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  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();
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    // 下拉刷新触发的逻辑,可以是请求数据等操作
    // 例如,请求数据后更新页面内容
    console.log(this.data.isRefreshing);
    this.setData({
      isWXRefreshing: true
    });
    console.log(this.data.isRefreshing);
    // 数据请求完成后,停止下拉刷新的动画
    var self = this;
    setTimeout(function () {
      self.setData({
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
      console.log('下拉刷新已完成');
    }, 3000);
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  },
  recharge() {
    wx.navigateTo({
      url: '/pages/rechargeCard/rechargeCard',
    })
  },
  openValveList() {
    wx.showToast({
      title: '正在开发中',
      icon: 'none'
    })
  },
  feedBack() {
    wx.showToast({
      title: '正在开发中',
      icon: 'none'
    })
  },
  handleChange(e) {
    const item = e.currentTarget.dataset.item;
    console.log(item);
    this.setData({
      showConfirm: true,
      waterIntakeName: item.intakeNum,
      myItem:item
    });
  },
  closeDialog() {
    this.setData({
      showConfirm: false
    });
  },
  /**
   * 关闭阀门
   * @param {*} orderNo 订单号
   * @param {*} rtuAddr 阀控器地址
   * @param {*} vcNum 虚拟卡编号
   */
  postCloseValaue(orderNo, rtuAddr, vcNum) {
    const app = getApp();
    const data = {
      rtuAddr: rtuAddr, 
      vcNum: vcNum, //虚拟卡ID
      orderNo:orderNo,
      userType: 2, //用户类型1-平台,2-App
      operator: app.globalData.sessionId //操作员
    };
    console.log("postCloseValaue"+data);
    post({
      url: "valve/close",
      data: data,
      isShowLoding:true
    }).then(response => {
      // 处理成功响应
      console.log('请求成功:', response);
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      //完成后回到首页
      wx.reLaunch({
        url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写
      });
    }).catch(error => {
      // 处理错误响应
      console.error('请求失败:', error);
    });
  },
  /**
   * 获取为关阀记录
   */
  getOpenList() {
    const app = getApp();
    const params = {
      url: 'valve/get',
      data: {
        operator: app.globalData.sessionId
      }
    };
    get(params).then(data => {
      this.setData({
        listData: data.content,
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
    }).catch(err => {
      // 错误回调
      console.error('Error:', err);
      this.setData({
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
    });
  },
  /**
   * 确认关闭回调
   * @param {} item 
   */
  confirmDialog(){
    this.setData({
      showConfirm: false
    });
    this.postCloseValaue(this.data.myItem.orderNo,this.data.myItem.rtuAddr,this.data.myItem.vcNum);
  }
 
 
 
 
 
})