管灌系统农户端微信小程序(嘉峪关应用)
pages/waterIntake/waterIntake.js
@@ -26,7 +26,20 @@
    },
    showForceConfirm: false,
    forceIntakeId: "", //强制开阀的取水口id
    inputValue:""
    inputValue: "",
    //以下为开阀弹窗相关
    isShowOpenTime: "false",
    isOpenTiming: false, //是否是计划开阀时间样式的开阀
    postMinutes: 0, //定灌溉时长的时间
    showForceConfirm: false,
    showErrorDialog: false, //错误提示
    showDialog: false,
    dialog_mode: false,
    dialog_time: false,
    dialog_water: false,
    openTimeText: "",
    openTime: "",
    irrigateProfile: [], //获取所选灌溉方式的详细数据
  },
  // 切换 Tabs
@@ -78,7 +91,7 @@
   */
  postOpenValva(intakeId, isforce) {
    this.setData({
      inputValue:""
      inputValue: ""
    })
    console.log("intakeId:" + intakeId + "   isforce:" + isforce)
    wx.showLoading({
@@ -200,12 +213,12 @@
              title: '没有搜索到取水口',
              icon: 'error',
            })
          }else{
          } else {
            this.setData({
              allWaterPoints:[data.content]
              allWaterPoints: [data.content]
            });
          }
        } else {
          wx.showToast({
            title: data.msg,
@@ -294,10 +307,238 @@
  confirmForceDialog() {
    this.postOpenValva(this.data.forceIntakeId, true);
  },
  closeSearch(){
  closeSearch() {
    this.setData({
      allWaterPoints:[],
      inputValue:""
      allWaterPoints: [],
      inputValue: ""
    })
  }
  },
  //以下为定时定量相关代码
  //初始化所有开泵的参数
  initDialogData() {
    this.setData({
      isShowOpenTime: "false",
      isOpenTiming: false, //是否是计划开阀时间样式的开阀
      postMinutes: 0, //定灌溉时长的时间
      showForceConfirm: false,
      showErrorDialog: false, //错误提示
      showDialog: true,
      dialog_mode: true,
      dialog_time: false,
      dialog_water: false,
      openTimeText: "",
      openTime: ""
    })
  },
  handleClost() {
    this.setData({
      showDialog: false
    })
  },
  handleSetDuration() {
    this.getIrrigateProfileData(1);
  },
  //获取常用用水时长及用水量
  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);
      });
  },
  handleSetWaterVolume() {
    this.getIrrigateProfileData(2);
  },
  dialogBack() {
    this.setData({
      dialog_time: false,
      dialog_water: false,
      dialog_mode: true,
      group_time: false,
      activeIndex: -1
    })
  },
  //选择时间后的处理
  handleTimeWrapperTap(e) {
    const index = e.currentTarget.dataset.index;
    console.log(index)
    if (index !== undefined) {
      let minutes;
      if (this.data.irrigateProfile[index].unit === "1") {
        minutes = this.hourToMinutes(this.data.irrigateProfile[index].defaultValue)
      } else {
        minutes = this.data.irrigateProfile[index].defaultValue;
      }
      this.setData({
        activeIndex: parseInt(index),
        postMinutes: minutes,
        costiomTime: "",
        group_time: false,
      });
    }
  },
  onTimeInputChange(data) {
    console.log(data.detail.value)
    if (data.detail.value !== "") {
      this.setData({
        group_time: true,
        activeIndex: -1,
        postMinutes: parseInt(data.detail.value)
      })
    } else {
      this.setData({
        group_time: false,
        postMinutes: 0,
      })
    }
  },
  //定灌溉时长自定义输入时间时修改时间单位0:分钟,1:小时
  onGroupOpenTimeTypeChange(event) {
    let value = event.detail.value;
    if (value === "1") {
      this.setData({
        postMinutes: this.hourToMinutes(this.data.postMinutes)
      })
    } else {
      this.setData({
        postMinutes: this.minutesToHours(this.data.postMinutes)
      })
    }
  },
  onGroupOpenTimeChange(event) {
    const {
      value
    } = event.detail;
    console.log('onGroupOpenTimeChange:' + value);
    if (value == 1) {
      this.showPicker();
      this.setData({
        isOpenTiming: true,
        radioValue: value,
        dateStartTime: new Date().getTime()
      })
    } else {
      this.setData({
        isShowOpenTime: false,
        isOpenTiming: false,
        radioValue: value,
      })
    }
  },
  //定时开泵按钮
  btnOpenOnTime() {
    if (this.data.postMinutes > 0) {
      if (this.data.isOpenTiming) {
        this.timeClosePlaned();
      } else {
        this.timeClose();
      }
    } else {
      wx.showToast({
        icon: 'error',
        title: '请选择或输入灌溉时间!',
      })
    }
  },
  //定时关阀式计划开阀
  timeClosePlaned() {
    const app = getApp();
    wx.showLoading({
      title: '正在通信请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    const data = {
      intakeId: this.data.intakeId, //取水口ID
      // vcId: this.data.vcId, //虚拟卡ID
      minutes: this.data.postMinutes, //分钟
      operator: app.globalData.clientId, //操作员
      plannedOpenTime: this.data.openTime
    };
    post({
      url: "wx/valve/planed_open_timed_close",
      data: data
    }).then(response => {
      // 处理成功响应
      console.log('请求成功:', response);
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      //完成后回到首页
      wx.reLaunch({
        url: '/pages/home/home?param=2' // 首页的路径,根据实际情况填写
      });
    }).catch(error => {
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      // 处理错误响应
      console.error('请求失败:', error);
      this.setData({
        showErrorDialog: true,
        errorData: error.msg
      })
    });
  },
  //定时关阀式开阀
  timeClose() {
    const app = getApp();
    wx.showLoading({
      title: '正在开阀请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    const data = {
      intakeId: this.data.intakeId, //取水口ID
      // vcId: this.data.vcId, //虚拟卡ID
      minutes: this.data.postMinutes, //分钟
      operator: app.globalData.clientId //操作员
    };
    post({
      url: "wx/valve/timed_close",
      data: data
    }).then(response => {
      // 处理成功响应
      console.log('请求成功:', response);
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      //完成后回到首页
      wx.reLaunch({
        url: '/pages/home/home?param=1' // 首页的路径,根据实际情况填写
      });
    }).catch(error => {
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      // 处理错误响应
      console.error('请求失败:', error);
      this.setData({
        showErrorDialog: true,
        errorData: error.msg
      })
    });
  },
})