<template>
  <div id="scroll-board">
    <cmpTitle title="房屋异常告警" visitMoreBtn="true" @onMore="clickMore"></cmpTitle>
    <div style="display: inline-block;">
      <div style="display: flex;border: 1px solid #0099FF;font-size: 12px;color: #fff;margin: 5px 0;">
        <div @click="switchData(0)" :style="current==0?'background:#0099FF;':''" style="padding:2px 5px;cursor: pointer;">基础数据</div>
        <div @click="switchData(1)" :style="current==1?'background:#0099FF;':''" style="padding:2px 5px;cursor: pointer;">异常数据</div>
      </div>
    </div>
    <dv-scroll-board v-if="current==0" :config="config2" style="flex:1;cursor: pointer;" @click="jump"/>
    <dv-scroll-board v-if="current==1" :config="config" style="flex:1;cursor: pointer;" @click="jump"/>
  </div>
</template>
<script>
import {getList} from "@/api/order/deviceorder.js"
import {getSmartdevice} from "@/api/grid/index.js"//社区维度（基础数据）
import {getList as smartdevice  } from "@/api/device/iotdevice" //小区维度（基础数据）
import cmpTitle from "../common/cmpTitle.vue"
export default {
  components:{
    cmpTitle
  },
  data () {
    return {
      config: {
        header: ['告警时间', '告警设备', '告警位置', '管理员-电话'],
        data: [],
        index: false,
        align: ['center'],
        rowNum: 4,
        headerBGC: 'rgba(6, 30, 93, 0.1)',
        headerHeight: 30,
        oddRowBGC: 'rgba(0, 44, 81, 0.8)',
        evenRowBGC: 'rgba(10, 29, 50, 0.8)',
        // path:'/jobs/personjob'
        path:''
      },
      config2: {
        header: ['设备名称', '设备编号', '设备厂商', '告警时间'],
        data: [],
        index: false,
        align: ['center'],
        rowNum: 4,
        headerBGC: 'rgba(6, 30, 93, 0.1)',
        headerHeight: 30,
        oddRowBGC: 'rgba(0, 44, 81, 0.8)',
        evenRowBGC: 'rgba(10, 29, 50, 0.8)',
        // path:'/jobs/personjob'
        path:''
      },
      xiaofangtype:'100004',
      yangantype:'960417',
      dataList:[],
      current:0,
      agencies:'',
      dataList2:[]
    }
  },
  props:{
    listRowNum:{
      type:Number,
      default:4
    },
    type:{
      type:'String'
    },
     showType:{
          type:String,
          default:"2"
        }
  },
  mounted() {
    this.getDataList2()
    this.getDataList()
  },
  methods:{
    switchData(current){
      this.current = current
    },
    clickMore(){
      this.$router.push({path:'/jobs/devicejob'})
    },
    requireSmartDeviceAll(params){
      var _this  = this
      getSmartdevice(params).then((res)=>{
        let list = []
        _this.dataList2 = res.data.data.records
        res.data.data.records.map((item)=>{
          let arr = [];
          arr.push(item.deviceName)
          arr.push(item.deviceId)
          arr.push(item.manufacturers)
          arr.push(item.lastUpdateTime)
          // if(item.jobStatus==1){
          //   item.jobStatus = "已处理"
          // }else{
          //   item.jobStatus = "未处理"
          // }
          // arr.push(item.jobStatus)
          list.push(arr)
        })
        _this.config2.data = list;
        _this.config2.rowNum = _this.listRowNum
        _this.$set(_this.config2)
      })
    },
    requireReDeviceAll(params){
      var _this  = this
      smartdevice("1","20",params).then((res)=>{
        let list = []
        _this.dataList2 = res.data.data.records
        res.data.data.records.map((item)=>{
          let arr = [];
          arr.push(item.deviceName)
          arr.push(item.deviceId)
          arr.push(item.manufacturers)
          arr.push(item.lastUpdateTime)
          // if(item.jobStatus==1){
          //   item.jobStatus = "已处理"
          // }else{
          //   item.jobStatus = "未处理"
          // }
          // arr.push(item.jobStatus)
          list.push(arr)
        })
        _this.config2.data = list;
        _this.config2.rowNum = _this.listRowNum
        _this.$set(_this.config2)
      })
    },
    getDataList2(){
      let params = {};
      params['deviceUsage'] = "20"
      if(this.showType=="1"){
        this.agencies = JSON.parse(localStorage.getItem('agencies1'))
        params['agencyId'] = this.agencies.id
        this.requireSmartDeviceAll(params)
      }else{
        this.agencies = JSON.parse(localStorage.getItem('agencies2'))
        params['residentialId'] = this.agencies.id
        this.requireReDeviceAll(params)
      }
    },
    getDataList(){
      var _this = this;
      let current = 1;
      let size = 20;
      let params = {};
      if(this.showType=="1"){
        this.agencies = JSON.parse(localStorage.getItem('agencies1'))
        params['agencyId'] = this.agencies.id
      }else{
        this.agencies = JSON.parse(localStorage.getItem('agencies2'))
        params['residentialId'] = this.agencies.id
      }
      return getList(current,size,params).then((res)=>{
        let list = []
        _this.dataList = res.data.data.records
        res.data.data.records.map((item)=>{
          if(_this.type=='fireCmp'){
            if(item.deviceType==_this.xiaofangType||item.deviceType==_this.yangantype){
              let arr = [];
              arr.push(item.alarmTime)
              arr.push(item.deviceName)
              arr.push(item.alarmPosition)
              arr.push(item.handler)
              // if(item.jobStatus==1){
              //   item.jobStatus = "已处理"
              // }else{
              //   item.jobStatus = "未处理"
              // }
              // arr.push(item.jobStatus)
              list.push(arr)
            }
          }else{
              let arr = [];
              arr.push(item.alarmTime)
              arr.push(item.deviceName)
              arr.push(item.alarmPosition)
              arr.push(item.handler)
              // if(item.jobStatus==1){
              //   item.jobStatus = "已处理"
              // }else{
              //   item.jobStatus = "未处理"
              // }
              list.push(arr)
          }

        })
        _this.config.data = list;
        _this.config.rowNum = _this.listRowNum
        _this.$set(_this.config)
      }).catch((err)=>{
        console.log(err)
      })
    },
    jump(row){
      if(this.config.path!==''){
        this.$router.push({path:this.config.path})
      }else{
        let data
        let params
        if(this.current==0){
          data = this.dataList2[row.rowIndex]
          params = {
            title:'设备告警信息',
            type:'alarmInfo2'
          }
        }else{
          data = this.dataList[row.rowIndex]
          params = {
            title:'设备告警信息',
            type:'alarmInfo'
          }
        }
        this.$emit("onEmit",data,params)
      }
    },

  }
}
</script>

<style lang="less">
  #scroll-board{
    box-sizing: border-box;
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
</style>
