<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">工位号：</span>
        <el-select v-model="dataTypeValue" placeholder="工位号" clearable size="small" style="width:150px">
          <el-option
            v-for="item in dataType"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <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="pageSize=50;pageCurrent=1;searchTable()">查询</el-button>
        <!--        <el-button type="success" plain icon="el-icon-document-copy" size="small" @click="copyData('form4')">复制</el-button>-->
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        size="mini"
        height="740"
        center
        style="width: 100%">
        <el-table-column width="60" label="序号" type="index" align="center"/>
        <el-table-column label="工位号" width="200px" align="center">
          <template slot-scope="scope">
            {{ scope.row.StationNumber }}
          </template>
        </el-table-column>
        <el-table-column label="报警类型" width="200px" align="center">
          <template slot-scope="scope">
            {{ scope.row.ErrType }}
          </template>
        </el-table-column>
        <el-table-column label="报警状态" width="200px" align="center">
          <template slot-scope="scope">
            <el-tag v-if="Number(scope.row.Status) == 1" size="mini" type="warning">报警出现</el-tag>
            <el-tag v-if="Number(scope.row.Status) == 0" size="mini" type="success">报警结束</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="报警文本" align="center">
          <template slot-scope="scope">
            {{ scope.row.Text}}
          </template>
        </el-table-column>
        <el-table-column label="报警时间" width="200px" align="center">
          <template slot-scope="scope">
            {{ scope.row.CreateTime }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-sizes="[50, 100, 200]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      dataType: [], // 日志类型数组
      dataTypeValue: '', // 日志类型
      valueType: [],
      valueTypeValue: '',
      alarmType: [],
      alarmTypeValue: '',
      dateTime: '', // 时间
      dialogFormVisible: false,
      dialogFormVisible4: false,
      form4: {
        engineTypeValue: ''
      },
      rules4: { // 订单下发验证
        engineTypeValue: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      title: '',
      form: {
        tagID: '',
        stationNo: '',
        measurementItems: '',
        valueName: ''
      },
      rules: { // 表单验证规则
      },
      total: 0, // 总条数
      pageList: 50, // 每页显示条数
      pageSize: 50, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new Date() // 修改数据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
    console.log(audiTime, 'audiTime')
    this.dateTime = [audiTime, audiTime]
    this.getDataType()
    this.getValueType()
    this.searchTable()
  },
  methods: {
    // 初始化获取日志类型
    getDataType() {
      this.dataType = []
      var param = []
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (const item of response.data) {
          console.log(item)
          this.dataType.push({
            lable: item.工位号,
            value: item.工位号
          })
        }
      })
    }, // 初始化日志描述
    getValueType() {
      this.valueType = []
      var param = []
      var Data = this.CreateData('11', '_日志_描述表_查询模块描述', param)
      this.ExecDatabase(Data).then(response => {
        for (const item of response.data) {
          this.valueType.push({
            lable: item.描述,
            value: item.描述
          })
        }
      })
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      let stationNumberValue_check, valueType_check
      // this.engineTypeValue ? engineTypeValue_check = 1 : (engineTypeValue_check = 0, this.engineTypeValue = '')
      this.dataTypeValue ? stationNumberValue_check = 1 : (stationNumberValue_check = 0, this.dataTypeValue = '')
      // this.valueTypeValue ? valueType_check = 1 : (valueType_check = 0, this.valueTypeValue = '')
      var param = []
      param[0] = ['工位号_ischeck', stationNumberValue_check]
      param[1] = ['工位号', this.dataTypeValue]
      param[2] = ['PageCurrent', this.pageCurrent]
      param[3] = ['PageSize', this.pageSize]
      param[4] = ['PageCount', '1111', 'int', '1']
      param[5] = ['ItemCount', '1111', 'int', '1']
      param[6] = ['开始时间', this.dateTime[0] + ' ' + '00:00:00']
      param[7] = ['结束时间', this.dateTime[1] + ' ' + '23:59:59']
      var Data = this.CreateData('11', '报警工位记录表_查询', param)
      this.ExecDatabase(Data).then(response => {
        console.log(response, 66)
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    callOff() {
      this.dialogFormVisible = false
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}
</script>

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