<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <div>
          <span style="margin-left: 10px">关键字：</span>
          <el-input v-model="keyword" placeholder="请输入日志关键字" clearable size="small" style="width: 200px; margin-left: 13px" />
          <span style="margin-left: 10px">时间：</span>
          <el-date-picker
            :clearable="false"
            v-model="dateTime"
            size="small"
            type="daterange"
            align="center"
            style="width: 240px;"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            range-separator="～"
            start-placeholder="开始日期"
            end-placeholder="结束日期" />
          <el-button
            type="primary"
            plain
            size="small"
            icon="el-icon-search"
            style="margin-left: 5px"
            @click="pageCurrent = 1; selectDate()">查询</el-button>
        </div>
        <el-table
          v-loading="loading"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          class="main"
          tooltip-effect="dark"
          height="660px"
          style="width: 70%;max-height: 700px"
          border
          size="mini">
          <el-table-column type="index" width="60" label="序号" align="center" />
          <el-table-column align="center" label="日志文本">
            <template slot-scope="scope">
              {{ scope.row.日志文本 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作时间" width="150">
            <template slot-scope="scope">
              {{ scope.row.操作时间 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" width="150">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="recoverOnline(scope.row.订单号)">恢复上线状态</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            v-if="!loading"
            :current-page="pageCurrent"
            :page-sizes="[15, 30, 40]"
            :page-size="pageSize"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange" />
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      loading: false,
      total: 0,
      pageSize: 30,
      pageCurrent: 1,
      dateTime: '',
      keyword: '',
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new Date()
    year = new Date().getFullYear()
    month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
    day = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
    audiTime = year + '-' + month + '-' + day
    this.dateTime = [audiTime, audiTime]
    this.selectDate()
  },
  methods: {
    selectDate() {
      this.loading = true
      let param = []
      param[0] = ['关键字', this.keyword]
      param[1] = ['开始时间', this.dateTime[0]]
      param[2] = ['结束时间', this.dateTime[1]]
      param[3] = ['PageCurrent', this.pageCurrent]
      param[4] = ['PageSize', this.pageSize]
      param[5] = ['PageCount', '1111', 'int', '1']
      param[6] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', 'MES_重要系统异常日志_分页_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result && response.data.result.length !== 0) {
          this.tableData = response.data.result
        } else {
          this.tableData = []
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.selectDate()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.selectDate()
    },
    recoverOnline(orderNo) {
      let param = []
      param[0] = ['订单号', orderNo]
      let Data = this.CreateData('11', 'MES_重要系统异常日志_重新上线', param)
      this.ExecDatabase(Data).then(res => {
        if (res.data && res.data[0]) {
          this.$message({
            message: res.data[0].msg,
            type: res.data[0].result == 1 ? 'success' : 'warning'
          })
          if (res.data[0].result == 1) {
            this.selectDate()
          }
        }
      })
    }
  }
}
</script>

<style scoped>
.topCard {
  margin: 5px;
}

.topDiv {
  margin-bottom: 10px;
}
</style>
