管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2024-08-12 19804e37592d2250c551fcf5df1d87cdf551f1d1
pages/home/home.js
@@ -26,6 +26,8 @@
    confirmBtn: {
      content: '确认'
    },
    errorDialogTitle: "关阀错误",
    showForceConfirm: false //是否强制开阀
  },
  openValve: function (e) {
@@ -192,7 +194,16 @@
    });
  },
  closeDialog() {
    console.log("closeDialog");
    this.setData({
      showConfirm: false,
      showErrorDialog: false,
      showForceConfirm: false
    });
  },
  cancelDialog(){
    this.setData({
      showForceConfirm: false,
      showConfirm: false
    });
  },
@@ -236,7 +247,8 @@
      wx.hideLoading();
      this.setData({
        showErrorDialog: true,
        errorData: error.msg
        errorData: error.msg,
        errorDialogTitle: "关阀错误"
      })
      // 处理错误响应
      console.error('请求失败:', error);
@@ -314,12 +326,71 @@
    const maskedPhoneNumber = phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
    return maskedPhoneNumber;
  },
  closeDialog() {
    this.setData({
      showErrorDialog:false
      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");
  }
})