// pages/basics/MakingRounds/process/process.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    RoomNumber:"",
    HotelName:"",
    deviceList:[
      {id:1, name:'取电面板通讯',   status:'在线',note:'在线',isnote:"0"},
      {id:2, name:'温控面板通讯',   status:'在线',note:'在线',isnote:0},
      {id:3, name:'红外转发通讯',   status:'离线',note:'在线',isnote:0},
      {id:4, name:'485窗帘电机通讯',status:'在线',note:'在线',isnote:0},
      {id:5, name:'门口传感器测试', status:'显示',note:'在线',isnote:0},
      {id:6, name:'卫生间传感器测试',status:'显示',note:'在线',isnote:0},
      {id:7, name:'淋浴间传感器测试',status:'不显示',note:'在线',isnote:0},
      {id:8, name:'床尾传感器测试',  status:'不显示',note:'在线',isnote:0},
      {id:9, name:'镜前传感器测试',  status:'不显示',note:'在线',isnote:0},
      {id:10,name:'休闲区传感器测试',status:'不显示',note:'在线',isnote:0},
      {id:11,name:'客厅传感器测试',  status:'不显示',note:'在线',isnote:0},
      {id:12,name:'厅卫传感器测试',  status:'不显示',note:'在线',isnote:0},
      {id:13,name:'浴缸传感器测试',  status:'不显示',note:'在线',isnote:0},
      {id:14,name:'门磁测试',        status:'不显示',note:'在线',isnote:0},
      {id:15,name:'干接点窗帘测试',  status:'正常',note:'在线',isnote:0}   // 最后一条你自行改状态
    ],
    deviceListindex:0,
    inputValue:"",
    toView:"",  
    scrollHeight: 0 ,
    modalName: "",
    note:"",
    noteok:"",
    errorsNumber:0,
    HotelId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  
    if (!options.RoomNumber  || !options.HotelName ||!options.HotelId) { 
      app.toast(2, "无酒店信息~") 
      return; 
    }
    console.log(options.RoomNumber)
    this.setData ({
      RoomNumber:options.RoomNumber,
      HotelName:options.HotelName,
      HotelId:options.HotelId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.calcScrollHeight();
  },
  calcScrollHeight() {
    // 1. 拿到屏幕可用高度（px）
    const sys = wx.getSystemInfoSync();
    const screenHeight = sys.windowHeight;   // px

    // 2. 拿到 scroll-view 的 top（px）
    wx.createSelectorQuery()
      .in(this)
      .select('#myScroll')
      .boundingClientRect(rect => {
        if (rect) {
          const topPx = rect.top;                    // px
          const bottomPx = 10 / 2;                   // 10rpx → 5px（2倍屏）
          const heightPx = screenHeight - topPx - bottomPx;

          // 3. 转 rpx 并写入
          this.setData({
            scrollHeight: heightPx * 2   // px→rpx
          });
        }
      })
      .exec();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target,
      deviceListindex:e.currentTarget.dataset.id-1
    })
  },
  DialogModal1(e){
    let deviceList = this.data.deviceList
    let deviceListindex=this.data.deviceListindex
    deviceList[deviceListindex].equipmentstatus=e.currentTarget.dataset.id
    
    this.setData({
      modalName: null,
      deviceList:deviceList
    })
    console.log(this.data.deviceList)
  },
  DialogModal2(e){    
    let deviceList = this.data.deviceList
    let deviceListindex=this.data.deviceListindex
    if (e.currentTarget.dataset.id==="hideModal_1") {
      deviceList[deviceListindex].isnote=1      
    }else{
      deviceList[deviceListindex].isnote=0
    }
  
    
    this.setData({    
      deviceList:deviceList
    })
    console.log(this.data.deviceList)
  },
  inputSearchForHotels(e){
    this.setData({
      note: e.detail.value
    })
    console.log(this.data.note)
  },
  checkWardRoundRecords(e){
   
    wx.navigateTo({
      url: `/pages/basics/MakingRoundsAbnormal/MakingRoundsAbnormal?HotelId=${this.data.HotelId}&RoomNumber=${this.data.RoomNumber}`
    });
  },
  saveTheText(e){
    let deviceList = this.data.deviceList
    let deviceListindex=this.data.deviceListindex
    let note=this.data.note
    let noteok=e.currentTarget.dataset.id
    deviceList[deviceListindex].isnote= 0
    if (noteok==="ok") {
      deviceList[deviceListindex].note= note
    }
    this.setData({    
      deviceList:deviceList
    })
  },
})