<template>
  <div class="status-table">
      <div class="my-box">
           <i-Table stripe  :columns="columns1" :data="tableData" size="large" :no-data-text="noData"  @on-sort-change="onSortChange"></i-Table>
      </div>
      <div class="mask-bg"></div>
     <div id="messageBox" v-if="itemsData">
        <pomp-box :itemsData="itemsData" :detailData='detailData' :messageName='messageName' :emailName='emailName' @onClose="close"></pomp-box>
    </div>
  </div>
</template>

<script>
import pompBox from './PompBox'
// import { formatTime, toHourMinute} from '../../tools/formatTime.js'
import axios from 'axios'
export default {
  components: {
    pompBox
  },

  mixins: [],

  props: ['tableData'],

  data () {
    return {
      itemsData: {},
      messageName: [],
      detailData: {},
      emailName: [],
      noData:
        '<div style="padding-top:204px;height:868px;"><img src="/static/img/handleicon.png">' +
        '<p style="font-size: 16px;margin-top:48px;color: #6D747C;">报警已全部帮您自动处理</p> <p style="font-size:16px;color:#6D747C">您可前往<button style="width:101px;height:30px;margin-left:10px;border: 1px solid #728DEE;border-radius: 2px;color:#728DEE;background: #fff;">查找历史报警</button></p></div>',
      columns1: [
        {
          title: "重要级别",
          key: "level",
          sortable: 'custom',
          render: (h, params) => {
            const text = params.row.level + '级'
            if (params.row.level == 'S') {
              return h('div', [
                h('img', {
                  attrs: {
                    src: '/static/img/ernomal.png'
                  },
                  style: {
                    marginRight: '5px',
                    verticalAlign: 'middle',
                    marginTop: '-3px'
                  }
                }),
                h('span', {
                  style: {
                    color: '#F08378'
                  }
                }, '' + text)
              ])
            } else if (params.row.level == 'A') {
              return h('div', [
                h('span', {
                  style: {
                    color: '#F08378',
                    marginLeft: '10px'
                  }
                }, '' + text)
              ])
            } else if (params.row.level == 'B') {
              return h('div', [
                h('span', {
                  style: {
                    color: '#F3B767',
                    marginLeft: '10px'
                  }
                }, '' + text)
              ])
            } else {
              return h('div', [
                h('span', {
                  style: {
                    marginLeft: '10px'
                  }
                }, '' + text)
              ])
            }
          }
        },
        {
          title: "报警类型",
          key: "type"
        },
        {
          title: "报警内容",
          key: "content",
          width: 400,
          className: "description-td",
          render: (h, params) => {
            const content = params.row.content ? params.row.content : ""
            if (content) {
              const text1 = content.split("/")[0]
              const text2 = content.split("/")[1]
              return h('div', [
                h('span', {
                  style: {
                    marginRight: '18px'

                  }
                }, text1),
                h('span', {
                  style: {
                    color: "#A6ADB5"
                  }
                }, text2)
              ])
            }
          }
        },
        {
          title: "报警开始时间",
          key: "cTime",
          sortable: 'custom'
        },
        {
          title: "报警持续时间",
          key: "durationT",
          sortable: 'custom',
          align: 'right'
        },
        {
          title: "报警状态",
          key: "status",
          align: 'center',
          render: (h, params) => {
            const status = params.row.status
            if (status == 'alarm') {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'text',
                    size: 'small'
                  },
                  style: {
                    color: '#F08378'
                  }
                }, '未恢复')
              ])
            } else {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'text',
                    size: 'small'
                  },
                  style: {
                    color: '#3BC6A1'
                  }
                }, '已恢复')
              ])
            }
          }
        },
        {
          title: "处理情况",
          key: "deal",
          align: 'center',
          render: (h, params) => {
            const deal = params.row.deal
            const status = params.row.event ? params.row.event.status : ""
            const id = params.row.event ? params.row.event.id : ""
            if (deal == 0) {
              return h('div', [
                h('Button', {
                  props: {
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px',
                    color: '#728DEE',
                    border: '1px solid #728DEE'
                  },
                  on: {
                    click: () => {
                      this.handleClick(params.row)
                    }
                  }
                }, '需手动处理')
              ])
            }
            if (deal == 1) {
              const text = '工单状态：' + status + '工单编号：DGFJKALJNLPPPK782200' + id
              return h('div', [
                h('img', {
                  attrs: {
                    src: '/static/img/bills.png'
                  },
                  style: {
                    marginRight: '5px',
                    verticalAlign: 'middle'
                  }
                }),
                h('span', {
                  style: {
                    marginRight: '5px',
                    color: '#6D747C',
                    cursor: 'pointer'
                  },
                  on: {
                    click: () => {
                      this.handleClick(params.row)
                    }
                  }
                }, text)
              ])
            }
            if (deal == 2) {
              const text = '事件状态：' + status + '事件编号：' + id
              return h('div', [
                h('img', {
                  attrs: {
                    src: '/static/img/event.png'
                  },
                  style: {
                    marginRight: '5px',
                    verticalAlign: 'middle'
                  }
                }),
                h('span', {
                  style: {
                    marginRight: '5px',
                    color: '#6D747C',
                    cursor: 'pointer'
                  },
                  on: {
                    click: () => {
                      this.handleClick(params.row)
                    }
                  }
                }, text)
              ])
            }
          }
        }
      ]
    }
  },

  computed: {

  },

  mounted () {

  },

  methods: {
    // iview的排序
    onSortChange (col) {
      this.$emit('setSort', col)
    },
    handleClick (row) {
      document.querySelector('.mask-bg').style.display = 'block'
      document.querySelector('#messageBox').style.display = 'block'
      this.itemsData = row
      this.getEamilInfo(row)
    },
    getEamilInfo (row) {
      let params = {
        id: row.id
      }
      axios.post(`/dp-auxiliary/alarm-system/alarm/detail/query?projectId=${this.$store.state.projId}&secret=${this.$store.state.secret}`, params).then(res => {
        let data = res.data
        if (data.Result == 'success') {
          this.detailData = data.Content
          if (data.Content && data.Content.notification) {
            let emailName = data.Content.notification.mail ? data.Content.notification.mail : []
            let messageName = data.Content.notification.message ? data.Content.notification.message : []
            this.emailName = []
            if (emailName.length > 0) {
              emailName.forEach(el => {
                this.emailName.push(el.name)
              })
            }

            this.messageName = []
            if (messageName.length > 0) {
              messageName.forEach(el => {
                this.messageName.push(el.name)
              })
            }
          } else {
            this.messageName = []
            this.emailName = []
          }
        }
      })
    },
    close () {
      document.querySelector('.mask-bg').style.display = 'none'
      document.querySelector('#messageBox').style.display = 'none'
    }
  }

}
</script>

<style scoped lang="less" >
.status-table {
    .my-box{
       padding: 0 20px 20px 24px;
       background: #fff;
    }
    .mask-bg {
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 99;
      background:rgba(0, 0, 0, .6);
      display: none;
    }
    #messageBox{
      width: 747px;
      height: 630px;
      background: #fff;
      box-shadow: 0 2px 8px 0 rgba(0,0,0,0.12);
      border-radius: 4px;
      z-index: 999;
      position: fixed;
      top: 70px;
      left: 50%;
      margin-left: -360px;
      display: none;
    }
}
</style>
<style lang="less">
.status-table{
    .ivu-table-wrapper {
    border: none;
  }
  .ivu-table td,
  .ivu-table th {
    border: none;
  }
  .ivu-table:before{
      height: 0;
  }
  .ivu-table:after{
      width:0;
  }
  .ivu-table-row .description-td>.ivu-table-cell>span{
        // overflow: hidden;
        // text-overflow: ellipsis;
        // white-space: nowrap;
        max-height: 100px;
        display: inline-block;
    }
}

</style>
