沙盘演示系统应用的微信小程序
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// pages/waterIntake/waterIntake.js
//常用取水口列表页
const {
  get,
  post
} = require('../../api/request.js');
Page({
  data: {
    currentTab: 0, // 当前显示的表格,默认为第一个表格
    searchQuery: "",
    commonWaterPoints: [], // 常用取水口数据
    allWaterPoints: [], // 所有取水口数据
    searchData: [{
      intakeNum: "1111111"
    }, {
      intakeNum: "2222222"
    }],
    isRefreshing_all: false,
    isRefreshing_common: false,
    showConfirm: false,
    waterIntakeName: "",
    choseItem: null,
    errorData: '', //错误内容
    showErrorDialog: false,
    confirmBtn: {
      content: '确认'
    },
    showForceConfirm: false,
    forceIntakeId: "", //强制开阀的取水口id
    inputValue:"",
    useTestData: false  // 新增: 是否使用测试数据的标志
  },
 
  // 切换 Tabs
  switchTab: function (e) {
    const tab = parseInt(e.currentTarget.dataset.tab);
    this.setData({
      currentTab: tab
    });
  },
  onInput(e) {
    this.setData({
      searchQuery: e.detail.value // 将输入框的值存储到 inputValue
    });
  },
  onSearch: function () {
    const query = this.data.searchQuery;
    if (query) {
      this.getallWaterPoints(query)
      // 在这里进行搜索操作,更新 allWaterPoints 数据
    } else {
      this.setData({
        allWaterPoints: []
      })
    }
  },
 
  /**
   * 跳转到选择虚拟卡界面
   * @param {} event 
   */
  choseCard(event) {
    this.setData({
      choseItem: event.currentTarget.dataset.item,
      allWaterPoints: []
    })
    this.toOpenCard();
  },
  //开泵通信
  /**
   * 
   * @param {*} intakeId 取水口id
   * @param {*} isforce 是否强制开阀
   */
  postOpenValva(intakeId, isforce) {
    this.setData({
      inputValue:""
    })
    console.log("intakeId:" + intakeId + "   isforce:" + isforce)
    wx.showLoading({
      title: '正在开阀请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    const app = getApp();
    const data = {
      intakeId: intakeId, //取水口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") {
        this.setData({
          forceIntakeId: intakeId,
          showForceConfirm: true
        })
      } else {
        this.setData({
          showErrorDialog: true,
          errorData: error.msg
        })
      }
    });
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getcommonWaterPoints();
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
 
 
 
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  },
  /**
   *在所有取水口搜索
   */
  getallWaterPoints: function (intakeNum) {
    // 如果设置了使用测试数据,则直接使用测试数据
    if (this.data.useTestData) {
      if (intakeNum) {
        // 模拟搜索功能,返回匹配的测试数据
        const testData = this.generateTestSearchData(intakeNum);
        if (testData) {
          this.setData({
            allWaterPoints: [testData]
          });
        } else {
          wx.showToast({
            title: '没有搜索到取水口',
            icon: 'error',
          });
        }
      }
      return;
    }
 
    let params = {
      url: 'wx/intake/all_intakes'
    };
    if (intakeNum) {
      params.data = {
        intakeNum: intakeNum
      };
    }
    get(params)
      .then((data) => {
        this.setData({
          isRefreshing_all: false
        });
        if (data.success && data.code === "0001") {
          if (!data.content) {
            wx.showToast({
              title: '没有搜索到取水口',
              icon: 'error',
            })
          }else{
            this.setData({
              allWaterPoints:[data.content]
            });
          }
        
        } else {
          wx.showToast({
            title: data.msg,
          })
        }
        console.log('Failed to add item:');
      })
      .catch((error) => {
        this.setData({
          isRefreshing_all: false
        });
        wx.showToast({
          title: error.msg,
          icon: 'error',
          duration: 3000 // 提示的持续时间,单位毫秒
        })
        console.error('Failed to add item:', error);
      });
  },
  
  /**
   * 生成模拟的搜索结果数据
   * @param {string} intakeNum 搜索的取水口编号
   * @returns {object|null} 匹配的取水口对象,如果没有匹配则返回null
   */
  generateTestSearchData(intakeNum) {
    // 创建一个测试数据数组
    const testDataArray = [
      { intakeId: "test001", intakeNum: "1001", isOnLine: true },
      { intakeId: "test002", intakeNum: "1002", isOnLine: false },
      { intakeId: "test003", intakeNum: "1003", isOnLine: true },
      { intakeId: "test004", intakeNum: "2001", isOnLine: true },
      { intakeId: "test005", intakeNum: "2002", isOnLine: false }
    ];
    
    // 查找匹配的数据
    return testDataArray.find(item => item.intakeNum.includes(intakeNum));
  },
  
  //获取常用取水口
  getcommonWaterPoints() {
    // 如果设置了使用测试数据,则直接使用测试数据
    if (this.data.useTestData) {
      const testData = this.generateTestCommonWaterPoints();
      this.setData({
        commonWaterPoints: testData,
        isRefreshing_common: false
      });
      return;
    }
    
    get({
        url: 'wx/intake/used_intakes',
        data: {
          operatorId: getApp().globalData.clientId
        }
      })
      .then((data) => {
        this.setData({
          isRefreshing_common: false
        });
        if (data.success && data.code === "0001") {
          this.setData({
            commonWaterPoints: data.content
          });
        } else {
          wx.showToast({
            title: data.msg,
          })
        }
        console.log('Failed to add item:');
      })
      .catch((error) => {
        this.setData({
          isRefreshing_common: false
        });
        wx.showToast({
          title: error.msg,
          icon: 'error',
          duration: 3000 // 提示的持续时间,单位毫秒
        })
        console.error('Failed to add item:', error);
      });
  },
  
  /**
   * 生成测试的常用取水口数据
   * @returns {Array} 常用取水口测试数据数组
   */
  generateTestCommonWaterPoints() {
    return [
      { intakeId: "test001", intakeNum: "取水口A", isOnLine: true },
      { intakeId: "test002", intakeNum: "取水口B", isOnLine: false },
      { intakeId: "test003", intakeNum: "取水口C", isOnLine: true },
      { intakeId: "test004", intakeNum: "取水口D", isOnLine: false },
      { intakeId: "test005", intakeNum: "取水口E", isOnLine: true },
      { intakeId: "test005", intakeNum: "取水口1", isOnLine: true },
      { intakeId: "test005", intakeNum: "取水口2", isOnLine: true },
      { intakeId: "test005", intakeNum: "取水口3", isOnLine: true },
      { intakeId: "test005", intakeNum: "取水口4", isOnLine: true }
 
    ];
  },
  
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh_all() {
    this.getallWaterPoints();
  },
  onPullDownRefresh_common() {
    this.getcommonWaterPoints();
  },
  confirmDialog() {
    this.setData({
      showConfirm: false
    })
    this.toOpenCard();
  },
  closeDialog() {
    this.setData({
      showConfirm: false
    })
  },
  closeErrorDialog() {
    this.setData({
      showErrorDialog: false
    })
  },
  cancelDialog() {
    this.setData({
      showForceConfirm: false
    });
  },
  //强制开阀
  confirmForceDialog() {
    this.postOpenValva(this.data.forceIntakeId, true);
  },
  closeSearch(){
    this.setData({
      allWaterPoints:[],
      inputValue:""
    })
  },
  toOpenCard(){
    wx.navigateTo({
      url: '/pages/openCard/openCard?intakeId='+this.data.choseItem.intakeId,
    })
  }
})