var Api = require("../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: {},   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id){
      this.setData({
        code: options.code,
        id: options.id
      })
    }
    this.getDetail()   
  },
  //详情
  getDetail(){
    var that = this
    wx.showLoading({
      title: '加载中...',
    }) 
    Api.req('nh/device/detail', {
      id: this.data.id
    }, 'get')
      .then(res => {
        wx.hideLoading()
        if(res.code == 200){
          that.setData({
            detail: res.data
          })
          this.formatePVData(res.data.monitorInverter)
        }else{
          wx.showToast({
            title: res.msg,
            icon: 'none'
          })
        }  
      })
  },
  //设备信息提取
  formatePVData(data) {
    var that = this
    if (!data || !data.pvModules || !data.acModules) {
      return;
    }
    let pvStr = data.pvModules;
    let pvList = [];//直流
    if (pvStr != null && pvStr.trim().length > 0) {
      pvStr.split("|").forEach((e, i) => {
        let eArr = e.split(":");
        let pvItem = {};
        pvItem.name = 'PV' + (i + 1);
        pvItem.dy = eArr[0];
        pvItem.dl = eArr[1];
        pvList.push(pvItem);
      })
      that.setData({
        pvList
      })
      console.log('pvList',pvList);
    }

    let uvwStr = data.acModules;
    let uvwList = [];//交流
    if (uvwStr != null && uvwStr.trim().length > 0) {
      uvwStr.split("|").forEach((e, i) => {
        let eArr = e.split(":");
        let uvwItem = {};
        if(data.sysType=='0'){
          uvwItem.name = i == 0 ? 'U' : (i == 1 ? 'V' : 'W');
          uvwItem.hz = data.fac+"Hz";
        }else{
          uvwItem.name = i == 0 ? 'R' : (i == 1 ? 'S' : 'T');
        }        
        uvwItem.dy = eArr[0];
        uvwItem.dl = eArr[1];
        uvwList.push(uvwItem);
      })
      that.setData({
        uvwList
      })
      console.log('uvwList',uvwList);
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },   
  
})