<template>
  <div class="container">
    <el-row type="flex" justify="space-between">
      <div class="handle-box" style="margin-bottom:10px">
        <el-button
          type="primary"
          icon="el-icon-refresh"
          class="handle-refresh"
          @click="OnPullNodes"
        >刷新</el-button>
        <span>
          共[
          <span class="handle-waring" style="margin:0 10px">{{pagination.total}}</span> ]条数据
        </span>
      </div>
      <div style="display:flex;flex-direction:row;margin-bottom:10px;">
        <el-input
          placeholder="关键词"
          v-model="pagination.name"
          class="wdiv searchParamsstyle"
          clearable
        ></el-input>

        <div class="block">
          <span class="demonstration">默认时间段</span>
          <el-date-picker
            v-model="pagination.datetime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </div>

        <el-button
          icon="el-icon-search"
          type="primary"
          size="mini"
          width="100"
          @click="OnSerch"
          class="searchParamsstyle"
        >查询</el-button>
      </div>
    </el-row>

    <el-table
      :data="alertTable"
      border
      class="table"
      :highlight-current-row="true"
      :default-sort="{prop: 'name', order: 'descending'}"
    >
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="id" label="报警ID" sortable width="400"></el-table-column>
      <el-table-column prop="alertText" label="报警规则" sortable width="180"></el-table-column>
      <el-table-column
        prop="lastUpdateTime"
        label="最近更新时间"
        sortable
        width="180"
      ><template slot-scope="scope">{{ scope.row.lastUpdateTime | datetimeString }}</template></el-table-column>
      <el-table-column prop="opened" label="报警状态" sortable width="180"><template slot-scope="scope">{{ scope.row.opened | isOpend }}</template></el-table-column>
      <el-table-column prop="part" label="工艺环节" sortable width="180">
      <!-- 
          <template slot-scope="scope">{{ scope.row.part | getPartZhName }}</template>
          -->
          </el-table-column>
      <el-table-column prop="rank" label="级别" sortable width="180"></el-table-column>
      <el-table-column prop="ruleId" label="关联规则ID" sortable width="180"></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, prev, pager, next"
        :current-page="pagination.pagenum"
        :page-size="pagination.pagesize"
        :total="pagination.total"
        @current-change="OnPageChange"
      ></el-pagination>
    </div>
  </div>
</template>

<style lang="less" scoped>
.wdiv {
  width: 200px;
}
.searchParamsstyle {
  width: 150px;
  margin-left: 10px;
}
</style>


<script>
import { nodes } from "@/network/network"
import { projectconfig } from '@/static/projectconfig'
import { alert } from '../../network/network'
import { dateFormat } from '../../assets/js/common'



var dayjs = require('dayjs');
//dayjs().format(projectconfig.date.dayjsFomart);


export default {
  data()
  {
    return {
      alertTable: [],
      pagination: {
        pagenum: 1,
        pagesize: 30,
        name: "",
        datetime: [dayjs().add(-1, 'day'), dayjs()],
        total: 0,
      }
    }
  },
  mounted()
  {

    // 1596441296000
    var dtjs = dayjs(1596441296000).format(projectconfig.date.dayjsFomart);
    console.log(dtjs)

    //   var c=dateFormat('yyyy-MM-dd HH:mm:ss',dayjs(1596441296000));
    //   console.log(c)
    // console.log(this.pagination.datetime)

  },
  methods: {
    OnPageChange(nextPageIndex)
    {
      console.log(nextPageIndex)
      this.pagination.pagenum = nextPageIndex;

    },
    OnSerch()
    {
      this.pagination.pagenum = 1;
      // 网络请求数据
      alert.searchAlert(this.pagination, this.dataBinding)
    },
    OnPullNodes()
    {
      this.pagination.total = 0;
      console.log(this.pagination);
      nodes.pull(this.pagination, res =>
      {
        console.log(res.data);
        this.alertTable = res.data.data.dataList;
        this.pagination.total = res.data.data.total;
      });
    },
    dataBinding(res)
    {
      console.log(res)
      this.alertTable = res.data.data.dataList;
      console.log(res.data.data.dataList)

    }
    ,
    formatter(row, column) 
    {
      return row.address;
    }
  },
  filters: {
      datetimeString(longTimeStamp)
      {
          return dayjs(longTimeStamp).format(projectconfig.date.dayjsFomart)
      },
      isOpend(openState)
      {
        return  openState == true ? '是':'否';
      },
      getPartZhName(partName)
      {
          return $store.state.bindingsetting.TechnologicalProcess[partName];
      }
  },

}
</script>

