const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    worningList:[],
    newsNavIndex:20,
    modalHidden:true,
    modalVal:'',// 解除预警信息
    deviceCode:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {chainId} = options;
    this.setData({
      chainId,
    })
    this.getWorningList(chainId,20);
  },
  getWorningList(chainId,deviceType){
    var that = this;
    app.requestP({
      url:'/chainBound/warningDevices',
      method:'post',
      contentType:'application/json',
      data:{
        chainId,
        deviceType
      }
    }).then(res=>{
      that.setData({
        worningList:res.data.data
      })
    }).catch(err=>{
      app.showToptip(that,'error',err.data.msg)
    })
  },
  toInfo(e){
    var deviceCode = e.currentTarget.dataset.devicecode;
    var chainId = this.data.chainId;
    wx.navigateTo({
      url: '/pages/query/clearWarning/warningInfo/warningInfo?deviceCode='+deviceCode+'&chainId='+chainId,
    })
  },
  setTab(e){
    var val =e.currentTarget.dataset.val;
    var chainId = this.data.chainId;
    this.setData({newsNavIndex:val});
    this.getWorningList(chainId,val);
  },
  clearWorning(e){
    var deviceCode = e.currentTarget.dataset.devicecode;
    this.setData({
      modalHidden:!this.data.modalHidden,
      deviceCode
    })
  },
  modalBindaconfirm:function(){
    var that = this;
    const {chainId,modalVal,deviceCode} = that.data;
    app.requestP({
      url:'/chain/cleanWarning',
      method:'post',
      contentType:'application/json',
      data:{
        chainId,
        cause:modalVal,
        deviceCode
      }
    }).then(res=>{
      app.showToptip(that,'success',res.data.msg);
      wx.navigateBack({
        delta: 1,
      });
      that.setData({
        modalHidden:!that.data.modalHidden,
      })
    }).catch(err=>{
      app.showToptip(that,'error',err.data.msg);
    })
  },
  //取消按钮点击事件
  modalBindcancel:function(){
    this.setData({
      modalHidden:!this.data.modalHidden,
      deviceCode:''
    })
  },
  setModalVal(e){
    this.setData({
      modalVal:e.detail.value
    })
  },
})