沙盘演示系统应用的微信小程序
zuoxiao
2024-08-28 eb3dbfdcb126beeb1d08f3306ac8f5bbc466e133
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
// 开卡选择虚拟卡
const {
  get,
  post
} = require('../../api/request.js');
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    intakeId: 0,
    showDialog: true,
    vcId: "",
    activeIndex: -1,
    datetimeVisible: false,
    datetime: new Date().getTime(),
    datetimeText: '',
    allCardPoints: [], // 所有虚拟卡
    irrigateProfile: [], //获取所选灌溉方式的详细数据
    dialog_mode: true,
    dialog_time: false,
    dialog_water: false,
    group_time: false,
    openTime: "",
    isShowOpenTime: "false"
  },
  openValva(event) {
    const {
      item
    } = event.currentTarget.dataset; // 获取当前点击的 item
    if (item.isAlarmValue === true) {
      //金额报警
      wx.navigateTo({
        url: '/pages/rechargeMoney/rechargMoney?vcId=' + item.vcId,
      })
    } else if (item.inUse === false) {
      // 选择虚拟卡后
      this.setData({
        vcId: item.vcId,
        showDialog: true,
        dialog_mode: true,
        dialog_time: false,
        dialog_water: false
      })
    }
  },
  handleAutoIrrigation() {},
  //立即开泵
  postOpenValva() {
    const app = getApp();
    const data = {
      intakeId: this.data.intakeId, //取水口ID
      vcId: this.data.vcId, //虚拟卡ID
      operator: app.globalData.sessionId //操作员
    };
    post({
      url: "wx/valve/open_wx",
      data: data
    }).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 === "1002") {
        wx.showToast({
          title: '开泵失败',
          icon: 'error',
          duration: 3000 // 提示的持续时间,单位毫秒
        })
      }
    });
  },
  postTimeOpen() {},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const {
      intakeId
    } = options;
    this.setData({
      intakeId
    })
    console.log('intakeId:' + this.data.intakeId);
    this.getCardList();
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  },
  //获取虚拟卡列表
  getCardList() {
    get({
        url: 'wx/virtual_card/get',
        data: {
          clientId: getApp().globalData.clientId
        }
      })
      .then((data) => {
        if (data.success && data.code === "0001") {
          this.setData({
            allCardPoints: data.content
          });
          this.updateDisplayText();
        } else {
          wx.showToast({
            title: data.msg,
          })
        }
        console.log('Failed to add item:');
      })
      .catch((error) => {
        console.error('Failed to add item:', error);
      });
  },
  updateDisplayText() {
    const updatedList = this.data.allCardPoints.map(item => {
      let displayText = '';
      if (item.inUse) {
        displayText = '使用中';
      } else {
        if (item.isAlarmValue) {
          displayText = '充值';
        } else {
          displayText = '选择';
        }
      }
      return {
        ...item,
        displayText
      }; // 保留所有其他字段,并添加 displayText 字段
    });
    // 更新列表数据
    this.setData({
      allCardPoints: updatedList
    });
  },
  handleClost() {
    this.setData({
      showDialog: false
    })
  },
  handleMoneyWrapperTap: function (e) {
    const index = e.currentTarget.dataset.index;
    console.log(index)
    if (index !== undefined) {
      this.setData({
        activeIndex: parseInt(index),
      });
    }
  },
  //获取常用用水时长及用水量
  getIrrigateProfileData(type) {
    get({
        url: 'wx/valve/irrigate_profile',
        data: {
          type: type
        }
      })
      .then((data) => {
        if (data.success && data.code === "0001") {
          const items = data.content.obj.map(item => {
            return {
              defaultValue: item.defaultValue,
              unit: item.unit,
              unitText: item.unit === "1" ? "小时" : item.unit === "2" ? "分钟" : "立方米"
            };
          });
          this.setData({
            dialog_mode: false,
            dialog_time: type === 1,
            dialog_water: type === 2,
            irrigateProfile: items
          });
        } else {
          wx.showToast({
            title: data.msg,
          })
        }
        console.log('Failed to add item:');
      })
      .catch((error) => {
        console.error('Failed to add item:', error);
      });
  },
  handleSetDuration() {
    this.getIrrigateProfileData(1);
  },
  onGroupChange(event) {
    const {
      value
    } = event.detail;
    console.log('Failed to add item:' + value);
    if (value == 1) {
      this.showPicker();
    } else {
      this.setData({
        isShowOpenTime: false
      })
    }
  },
  showPicker(e) {
    this.setData({
      datetimeVisible: true,
      isShowOpenTime: true
    });
  },
  onTimeInputChange() {
    this.setData({
      group_time: true
    })
  },
  onConfirm(e) {
    const {
      value
    } = e?.detail;
    this.setData({
      openTime: "开阀时间:" + value
    })
  },
  handleSetWaterVolume() {
    this.getIrrigateProfileData(2);
  },
  dialogBack() {
    this.setData({
      dialog_time: false,
      dialog_water: false,
      dialog_mode: true,
      group_time: false
    })
  }
})