管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2024-08-12 19804e37592d2250c551fcf5df1d87cdf551f1d1
pages/home/home.js
@@ -20,7 +20,14 @@
    scrollViewHeight: 0,
    listData: [],
    isRefreshing: false,
    isWXRefreshing: false
    isWXRefreshing: false,
    errorData: '', //错误内容
    showErrorDialog: false,
    confirmBtn: {
      content: '确认'
    },
    errorDialogTitle: "关阀错误",
    showForceConfirm: false //是否强制开阀
  },
  openValve: function (e) {
@@ -187,7 +194,16 @@
    });
  },
  closeDialog() {
    console.log("closeDialog");
    this.setData({
      showConfirm: false,
      showErrorDialog: false,
      showForceConfirm: false
    });
  },
  cancelDialog(){
    this.setData({
      showForceConfirm: false,
      showConfirm: false
    });
  },
@@ -213,7 +229,8 @@
    post({
      url: "wx/valve/close_wx",
      data: data,
      isShowLoding: false
      isShowLoding: false,
      timeout: 185000
    }).then(response => {
      // 处理成功响应
@@ -228,13 +245,11 @@
      })
    }).catch(error => {
      wx.hideLoading();
      if (error.code === "1002") {
        wx.showToast({
          title: '关阀失败',
          icon: 'error',
          duration: 3000 // 提示的持续时间,单位毫秒
        })
      }
      this.setData({
        showErrorDialog: true,
        errorData: error.msg,
        errorDialogTitle: "关阀错误"
      })
      // 处理错误响应
      console.error('请求失败:', error);
@@ -261,6 +276,12 @@
      // 错误回调
      this.setData({
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
      })
      wx.showToast({
        title: err.msg,
        icon: 'error',
        duration: 3000
      })
    });
  },
@@ -278,7 +299,7 @@
  getUserDataBySession() {
    const app = getApp();
    const params = {
      url: 'sell/client/simple_info',
      url: 'wx/client/simple_info',
      data: {
        sessionId: app.globalData.sessionId
      }
@@ -290,7 +311,11 @@
      })
    }).catch(err => {
      // 错误回调
      wx.showToast({
        title: err.msg,
        icon: 'error',
        duration: 3000
      })
    })
  },
  maskPhoneNumber(phoneNumber) {
@@ -300,8 +325,72 @@
    // 使用正则表达式替换中间四位数字为星号
    const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
    return maskedPhoneNumber;
  },
  closeDialog() {
    this.setData({
      showErrorDialog: false
    })
  },
  /**
   * 扫码开阀
   */
  scenCode() {
    const that = this;
    wx.scanCode({
      success(res) {
        console.log(res.result); // 当且仅当扫码为非微信二维码时,会返回result
        wx.showLoading({
          title: '正在开阀请稍候...', // 加载提示文字
          mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
        });
        const app = getApp();
        const data = {
          intakeName: res.result, //取水口ID
          // vcId: vcId, //虚拟卡ID
          operator: app.globalData.sessionId //操作员
        };
        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==="1003") {
            that.setData({
              showForceConfirm:true
            })
          } else {
            that.setData({
              showErrorDialog: true,
              errorData: error.msg,
              errorDialogTitle: "开阀错误"
            })
          }
        });
      },
      fail(err) {
        console.error(err);
      }
    })
  },
  confirmForceDialog(){
    console.log("confirmForceDialog");
  }
})