<template>
  <div class="app-container">

    <el-card>
      <el-row>
        <span>操作者:</span>
        <el-input v-model="workerName" placeholder="操作者" size="small" clearable style="width:200px"/>
        <span class="demonstration">完成加工时间:</span>
        <el-date-picker
          v-model="startTime"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 160px"
          type="date"
          placeholder="选择日期"/>
        <span class="demonstration">~</span>
        <el-date-picker
          v-model="endTime"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 160px"
          type="date"
          placeholder="选择日期"/>
        <el-button type="success" class="el-icon-search" size="small" style="margin: 10px 0 0 10px" @click="pageCurrent=1;total = 0;searchTable();">查询</el-button>
      </el-row>
    </el-card>
    <el-card>
      <el-col :span="7">
        <el-table v-loading="loading" :data="tableData" highlight-current-row height="580" style="width: 100%;" border element-loading-text="拼命加载中" @row-click="searchTable2">
          <el-table-column
            label=" "
            type="index"
            align="center"
            width="50"/>
          <el-table-column label="操作者" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.姓名 }}
            </template>
          </el-table-column>
          <el-table-column label="实际工时" align="center">
            <template slot-scope="scope">
              {{ scope.row.实际加工时间段 }}
            </template>
          </el-table-column>
        </el-table>
        <div style="margin: 10px">
          <el-pagination
            v-if="!loading"
            :current-page="pageCurrent"
            :page-size="pageSize"
            :total="total"
            layout="total, prev, pager, next"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </el-col>
      <el-col :span="16" style="margin-left: 30px;">
        <el-table v-loading="loading2" :data="tableData2" height="580" style="width: 100%;" border element-loading-text="拼命加载中">
          <el-table-column
            label=" "
            type="index"
            align="center"
            width="50"/>
          <el-table-column label="零件图号" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.零件图号 }}
            </template>
          </el-table-column>
          <el-table-column label="零件名称" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.零件名称 }}
            </template>
          </el-table-column>
          <el-table-column label="工艺名称" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.工艺名称 }}
            </template>
          </el-table-column>
          <el-table-column label="理论工时" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.理论加工时间段 }}
            </template>
          </el-table-column>
          <el-table-column label="实际工时" align="center" width="150px">
            <template slot-scope="scope">
              {{ scope.row.实际加工时间段 }}
            </template>
          </el-table-column>
          <el-table-column label="完成日期" align="center">
            <template slot-scope="scope">
              {{ scope.row.加工完成时间 }}
            </template>
          </el-table-column>
        </el-table>
        <div style="margin: 10px">
          <el-pagination
            v-if="!loading2"
            :current-page="pageCurrent2"
            :page-size="pageSize2"
            :total="total2"
            layout="total, prev, pager, next, jumper"
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"/>
        </div>
      </el-col>
    </el-card>
  </div>
</template>
<script>
import { searchtable, searchtable2 } from '@/api/ManufacturingCenter/machiningHoursStatistics'

export default {
  data() {
    return {
      workerName: '',
      startTime: '',
      endTime: '',
      loading: false,
      tableData: [], // 表格数据
      total: null, // 总条数
      pageSize: 20, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      gongzuozhebianhao: '',
      loading2: false,
      tableData2: [], // 表格数据
      total2: null, // 总条数
      pageSize2: 20, // 每页显示条数
      pageCurrent2: 1 // 后台获取页
    }
  },
  created() {
    this.searchTable()
  },
  methods: {
    // 查询表格数据
    searchTable() {
      this.loading = true
      this.tableData = []
      this.tableData2 = []
      this.total2 = 0
      if (this.startTime !== '' && this.startTime !== null && this.endTime !== null && this.endTime !== null) {
        this.timeCheck = 1
      } else {
        this.startTime = ''
        this.endTime = ''
        this.timeCheck = 0
      }
      if (this.workerName !== '' && this.workerName !== null) {
        this.workerName_ckeck = 1
      } else {
        this.workerName_ckeck = 0
      }
      searchtable(this.workerName_ckeck, this.workerName, this.timeCheck, this.startTime, this.endTime, this.pageCurrent, this.pageSize).then(response => {
        if (response.data.total === 0) {
          this.loading = false
        } else {
          this.total = response.data.total
          this.tableData = response.data.rows
        }
      }).then(() => {
        this.loading = false
      })
    },
    searchTable2(row) {
      this.loading2 = true
      this.tableData2 = []
      this.pageCurrent2 = 1
      this.gongzuozhebianhao = row.人员编号
      searchtable2(row.人员编号, this.timeCheck, this.startTime, this.endTime, this.pageCurrent2, this.pageSize2).then(response => {
        if (response.data.total === 0) {
          this.loading2 = false
        } else {
          this.total2 = response.data.total
          this.tableData2 = response.data.rows
        }
      }).then(() => {
        this.loading2 = false
      })
    },
    searchTable3(row) {
      this.loading2 = true
      this.tableData2 = []
      searchtable2(this.gongzuozhebianhao, this.timeCheck, this.startTime, this.endTime, this.pageCurrent2, this.pageSize2).then(response => {
        if (response.data.total === 0) {
          this.loading2 = false
        } else {
          this.total2 = response.data.total
          this.tableData2 = response.data.rows
        }
      }).then(() => {
        this.loading2 = false
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    handleSizeChange2(val) {
      this.pageCurrent2 = 1
      this.pageSize2 = val
      this.searchTable3()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.searchTable3()
    }
  }
}
</script>

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