管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2024-06-13 5dc54a59184b305a85aaad31dd4cce01b31a8a2d
pages/home/home.js
@@ -12,7 +12,7 @@
  data: {
    sessionId: "",
    showConfirm: false,
    myItem:{},
    myItem: {},
    waterIntakeName: "",
    image: "/images/ic_head_bg.jpg",
    userPhone: "158****0723",
@@ -44,7 +44,7 @@
        isRefreshing: true
      });
      this.getOpenList();
    }
  },
@@ -73,9 +73,15 @@
    });
    //当开阀成功后调用刷新
    console.log("onLoad:" + options.param);
    if(options.param){
      getOpenList() ;
    if (options.param) {
      wx.showToast({
        title: '开阀成功',
        icon: 'success',
        duration: 3000
      })
      this.getOpenList();
    }
    this.getUserDataBySession();
  },
  /**
@@ -131,13 +137,7 @@
    });
    console.log(this.data.isRefreshing);
    // 数据请求完成后,停止下拉刷新的动画
    var self = this;
    setTimeout(function () {
      self.setData({
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
      console.log('下拉刷新已完成');
    }, 3000);
    this.getOpenList();
  },
  /**
@@ -159,14 +159,13 @@
    })
  },
  openValveList() {
    wx.showToast({
      title: '正在开发中',
      icon: 'none'
    wx.navigateTo({
      url: '/pages/valveList/valveList',
    })
  },
  feedBack() {
    wx.showToast({
      title: '正在开发中',
      title: '暂未开放',
      icon: 'none'
    })
  },
@@ -176,7 +175,7 @@
    this.setData({
      showConfirm: true,
      waterIntakeName: item.intakeNum,
      myItem:item
      myItem: item
    });
  },
  closeDialog() {
@@ -191,31 +190,46 @@
   * @param {*} vcNum 虚拟卡编号
   */
  postCloseValaue(orderNo, rtuAddr, vcNum) {
    wx.showLoading({
      title: '正在关阀请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    const app = getApp();
    const data = {
      rtuAddr: rtuAddr,
      rtuAddr: rtuAddr,
      vcNum: vcNum, //虚拟卡ID
      orderNo:orderNo,
      userType: 2, //用户类型1-平台,2-App
      orderNo: orderNo,
      operator: app.globalData.sessionId //操作员
    };
    console.log("postCloseValaue"+data);
    console.log("postCloseValaue" + data);
    post({
      url: "valve/close",
      url: "wx/valve/close_wx",
      data: data,
      isShowLoding:true
      isShowLoding: false
    }).then(response => {
      // 处理成功响应
      console.log('请求成功:', response);
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      //完成后回到首页
      wx.reLaunch({
        url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写
      });
      this.getOpenList();
      wx.showToast({
        title: '关阀成功',
        icon: 'success',
        duration: 3000
      })
    }).catch(error => {
      wx.hideLoading();
      if (error.code === "1002") {
        wx.showToast({
          title: '关阀失败',
          icon: 'error',
          duration: 3000 // 提示的持续时间,单位毫秒
        })
      }
      // 处理错误响应
      console.error('请求失败:', error);
    });
  },
  /**
@@ -224,7 +238,7 @@
  getOpenList() {
    const app = getApp();
    const params = {
      url: 'valve/get',
      url: 'wx/valve/get',
      data: {
        operator: app.globalData.sessionId
      }
@@ -233,10 +247,10 @@
      this.setData({
        listData: data.content,
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
    }).catch(err => {
      // 错误回调
      console.error('Error:', err);
      this.setData({
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
@@ -246,14 +260,39 @@
   * 确认关闭回调
   * @param {} item 
   */
  confirmDialog(){
  confirmDialog() {
    this.setData({
      showConfirm: false
    });
    this.postCloseValaue(this.data.myItem.orderNo,this.data.myItem.rtuAddr,this.data.myItem.vcNum);
    this.postCloseValaue(this.data.myItem.orderNo, this.data.myItem.rtuAddr, this.data.myItem.vcNum);
  },
  //根据session获取农户信息
  getUserDataBySession() {
    const app = getApp();
    const params = {
      url: 'sell/client/simple_info',
      data: {
        sessionId: app.globalData.sessionId
      }
    };
    get(params).then(data => {
      this.setData({
        userName: data.content.clientName,
        userPhone: this.maskPhoneNumber(data.content.phone)
      })
    }).catch(err => {
      // 错误回调
    })
  },
  maskPhoneNumber(phoneNumber) {
    if (phoneNumber.length !== 11) {
      throw new Error("Phone number must be 11 digits");
    }
    // 使用正则表达式替换中间四位数字为星号
    const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
    return maskedPhoneNumber;
  }