<template>
  <div class="app-container">
    <el-card class="topCard">
      <el-table
        ref="multipleTable"
        :data="tableData"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        :cell-class-name="tableRowClassName"
        :cell-style="cellStyle"
        element-loading-background="rgba(0, 0, 0, 0.2)"
        class="main"
        tooltip-effect="dark"
        height="830px"
        style="width: 100%;max-height: 860px"
        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="On">
          <template slot-scope="scope">
            {{ scope.row.On }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="Start">
          <template slot-scope="scope">
            {{ scope.row.Start }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="Fault">
          <template slot-scope="scope">
            {{ scope.row.Fault }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="NoPart">
          <template slot-scope="scope">
            {{ scope.row.NoPart }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="Block">
          <template slot-scope="scope">
            {{ scope.row.Block }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="Time">
          <template slot-scope="scope">
            {{ scope.row.时间 }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      tableData: []
    }
  },
  created() {
    this.searchTable()
  },
  methods: {
    // 表格颜色变化
    tableRowClassName({ row, rowIndex }) {
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 2 && Number(row.机床上电) === 1) {
        return 'background-color: red'
      }
      if (columnIndex === 3 && Number(row.循环开始) === 1) {
        return 'background-color: red'
      }
      if (columnIndex === 4 && Number(row.机床故障) === 1) {
        return 'background-color: red'
      }
      if (columnIndex === 5 && Number(row.上料无件) === 1) {
        return 'background-color: yellow'
      }
      if (columnIndex === 5 && Number(row.下料堵塞) === 1) {
        return 'background-color: red'
      }
    },
    // 获取工位名称
    searchTable() {
      this.tableData = []
      request({
        url: '',
        method: 'post',
        data: {
          type: '3',
          name: `select 工位号,机床上电 ,循环开始 ,机床故障 ,上料无件 , 下料堵塞 , lastupdatetime as 时间 from 测量数据工位机床状态 order by 工位号`
        }
      }).then(response => {
        console.log(response.data)
        this.tableData = response.data
      })
    }
  }
}
</script>

<style scoped>
  .topCard{
    margin: 5px;
  }
  .topDiv{
    margin-bottom: 10px;
  }
  .el-select{
    width:200px
  }
  .el-input{
    width:200px
  }
  .text {
    font-size: 14px;
  }

  .item {
    padding: 18px 0;
  }

  .box-card {
    position: absolute;
    right: 6px;
    top: 80px;
    width: 300px;
  }
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  /deep/.el-input.is-disabled .el-input__inner{
    color: #606266!important;
  }
  /deep/.el-input.is-disabled .el-input__inner{
    background-color: white!important;
  }
</style>
