<template>
  <div class="app-container">
    <el-card style="width: 1100px;">
      <el-row>
        <span class="demonstration">日期:</span>
        <el-date-picker
          v-model="startTime"
          :clearable="false"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 160px;margin-top: 10px"
          type="date"
          placeholder="选择日期"
          @change="pageCurrent=1;total=0;searchTable()"/>
        <span>操作者:</span>
        <el-input v-model="workerName" placeholder="操作者" size="small" clearable style="width:100px; margin-top: 10px;margin-bottom: 10px"/>
        <el-button :disabled="loading" 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 style="width: 1120px;">
      <el-table v-loading="loading" :data="tableData" stripe height="700" size="mini" style="width: 1150px;" border>
        <el-table-column label="序号" type="index" align="center" width="55"/>
        <el-table-column label="操作者" prop="姓名" align="center" width="80px">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" sortable prop="零件图号" align="center" width="150px">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" prop="零件名称" align="center" width="120px">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="完成数量" align="center" width="70px">
          <template slot-scope="scope">
            {{ scope.row.完成数量 }}
          </template>
        </el-table-column>
        <el-table-column label="工艺名称" prop="工艺名称" align="center" width="90px">
          <template slot-scope="scope">
            {{ scope.row.工艺名称 }}
          </template>
        </el-table-column>
        <el-table-column label="实际工时" align="center" width="100px">
          <template slot-scope="scope">
            {{ scope.row.实际加工时间段 || '—' }}
          </template>
        </el-table-column>
        <el-table-column label="计划工时" prop="理论加工时间段" align="center" width="100px">
          <template slot-scope="scope">
            {{ scope.row.理论加工时间段 }}
          </template>
        </el-table-column>
        <el-table-column label="实际开始时间" align="center" width="160px">
          <template slot-scope="scope">
            {{ scope.row.加工开始时间1 }}
          </template>
        </el-table-column>
        <el-table-column label="实际完成时间" align="center" width="160px">
          <template slot-scope="scope">
            {{ scope.row.加工完成时间1 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[100, 500, 1000]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>

  </div>
</template>

<script>
import { searchTable } from '@/api/ManufacturingCenter/ActualWorkQuery'
import { mapGetters } from 'vuex'
import { getNowShotTime } from '@/utils/tool'

export default {
  name: 'ActualTimeSupplement',
  data() {
    return {
      startTime: getNowShotTime(),
      workerName: '',
      loading: false,
      pageCurrent: 1,
      pageSize: 1000,
      total: 0,
      tableData: []
    }
  },
  computed: {
    ...mapGetters([
      'id' // 人员编号
    ])
  },
  mounted() {
    this.searchTable()
  },
  methods: {
    // 查询table
    searchTable() {
      this.loading = true
      let check1, check2
      this.startTime ? check1 = 1 : check1 = 0
      this.workerName ? check2 = 1 : check2 = 0
      searchTable(check1, this.startTime, check2, this.workerName, this.pageCurrent, this.pageSize).then(res => {
        res.data.rows.map(v => {
          v.实际加工时间段 = parseFloat(v.实际加工时间段).toFixed(2)
        })
        this.tableData = res.data.rows
        this.total = res.data.total
        this.loading = false
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}
</script>

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