管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2025-03-06 91751b1b9b16c0044e16ad80c237b7275a409046
pages/waterIntake/waterIntake.js
@@ -6,9 +6,27 @@
Page({
  data: {
    currentTab: 0, // 当前显示的表格,默认为第一个表格
    searchQuery:"",
    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:""
  },
  // 切换 Tabs
@@ -18,7 +36,7 @@
      currentTab: tab
    });
  },
  onInput(e){
  onInput(e) {
    this.setData({
      searchQuery: e.detail.value // 将输入框的值存储到 inputValue
    });
@@ -26,10 +44,12 @@
  onSearch: function () {
    const query = this.data.searchQuery;
    if (query) {
     this.getallWaterPoints(query)
      this.getallWaterPoints(query)
      // 在这里进行搜索操作,更新 allWaterPoints 数据
    } else {
      this.getallWaterPoints(query)
      this.setData({
        allWaterPoints: []
      })
    }
  },
@@ -38,13 +58,73 @@
   * @param {} event 
   */
  choseCard(event) {
   const intakeId= event.currentTarget.dataset.item.intakeId;
   console.log(intakeId);
    wx.navigateTo({
      url: '/pages/openCard/openCard?intakeId='+intakeId,
    //显示二次确认弹窗
    this.setData({
      showConfirm: true,
      choseItem: event.currentTarget.dataset.item,
      allWaterPoints: []
    })
  },
    //  console.log(intakeId);
    //   wx.navigateTo({
    //     url: '/pages/openCard/openCard?intakeId='+intakeId,
    //   })
  },
  //开泵通信
  /**
   *
   * @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.operator, //操作员
      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
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
@@ -57,7 +137,6 @@
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getallWaterPoints();
    this.getcommonWaterPoints();
  },
@@ -82,12 +161,8 @@
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
@@ -101,24 +176,37 @@
   */
  onShareAppMessage() {
  }
  ,
  },
  /**
   * 获取所有取水口
   *在所有取水口搜索
   */
  getallWaterPoints: function (intakeNum) {
    let params = { url: 'rtu/get_online_intakes' };
    let params = {
      url: 'wx/intake/all_intakes'
    };
    if (intakeNum) {
      params.data = { intakeNum: intakeNum };
      params.data = {
        intakeNum: intakeNum
      };
    }
    get(params)
      .then((data) => {
        if(data.success&&data.code==="0001"){
          this.setData({
            allWaterPoints:  data.content.obj
          });
        }else{
        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,
          })
@@ -126,28 +214,90 @@
        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);
      });
  },
  getcommonWaterPoints(){
    get({url:'rtu/used_intakes', data: {
      operator: getApp().globalData.sessionId
    }})
    .then((data) => {
      if(data.success&&data.code==="0001"){
  //获取常用取水口
  getcommonWaterPoints() {
    get({
        url: 'wx/intake/used_intakes',
        data: {
          operatorId: getApp().globalData.operator
        }
      })
      .then((data) => {
        this.setData({
          commonWaterPoints:  data.content
          isRefreshing_common: false
        });
      }else{
        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: data.msg,
          title: error.msg,
          icon: 'error',
          duration: 3000 // 提示的持续时间,单位毫秒
        })
      }
      console.log('Failed to add item:');
        console.error('Failed to add item:', error);
      });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh_all() {
    this.getallWaterPoints();
  },
  onPullDownRefresh_common() {
    this.getcommonWaterPoints();
  },
  confirmDialog() {
    this.setData({
      showConfirm: false
    })
    .catch((error) => {
      console.error('Failed to add item:', error);
    this.postOpenValva(this.data.choseItem.intakeId);
  },
  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:""
    })
  }
})