<template>
  <div class="app-container">
    <el-card>
      <el-date-picker
        v-model="startTime"
        value-format="yyyy-MM-dd"
        size="small"
        style="width: 170px;margin:0px 10px"
        type="date"
        placeholder="选择开始加工日期"/>
      <span class="demonstration">~</span>
      <el-date-picker
        v-model="endTime"
        value-format="yyyy-MM-dd"
        size="small"
        style="width: 170px;margin:0px 10px"
        type="date"
        placeholder="选择加工完成日期"/>
      <el-button type="primary" class="el-icon-search" size="small" plain style="margin:0px 10px" @click="pageCurrent=1;total = 0;searchTable();">查询</el-button>
    </el-card>
    <el-row>
      <el-col :span="9">
        <el-card>
          <el-table v-loading="loading" :data="tableData" highlight-current-row size="mini" stripe style="width: 100%;" height="700px" border element-loading-text="拼命加载中" @row-click="searchTable2">
            <el-table-column label="操作者" align="center" show-overflow-tooltip>
              <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="完成工时(分)" align="center" width="70px">
              <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="完成数量" align="center" width="70px">
              <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>
          <div>
            <el-pagination
              v-if="!loading"
              :current-page="pageCurrent"
              :page-size="pageSize"
              :total="total"
              layout="total"/>
          </div>
        </el-card>
      </el-col>
      <el-col :span="15">
        <el-card>
          <el-table v-loading="loading2" :data="tableData2" size="mini" style="width: 100%;" height="700px" border element-loading-text="拼命加载中">
            <el-table-column label="零件图号" align="center" width="135px" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.零件图号 }}
              </template>
            </el-table-column>
            <el-table-column label="零件名称" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.零件名称 }}
              </template>
            </el-table-column>
            <el-table-column label="工艺名称" align="center" width="70px" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.工艺名称 }}
              </template>
            </el-table-column>
            <el-table-column label="完成数" align="center" width="60px">
              <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="完成工时(分)" align="center" width="70px">
              <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="加工时间" align="center" width="115px">
              <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>
          <div>
            <el-pagination
              v-if="!loading2"
              :current-page="pageCurrent2"
              :page-size="pageSize2"
              :total="total2"
              layout="total"
              @size-change="handleSizeChange2"
              @current-change="handleCurrentChange2"/>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { searchtable, searchtable2 } from '@/api/ManufacturingCenter/ScheduleCompletionDetails'
import { getNowShotTime } from '@/utils/tool'
export default {
  data() {
    return {
      startTime: getNowShotTime(), // 开始时间
      endTime: getNowShotTime(), // 结束时间
      tableData: [], // 操作者工时统计
      loading: '',
      tableData2: [], // 工序统计表
      loading2: '',
      pageCurrent: 1,
      pageSize: 10000,
      total: 0,
      pageCurrent2: 1,
      pageSize2: 10000,
      total2: 0,
      timeCheck: '',
      operater: ''
    }
  },
  created() {
    this.searchTable()
  },
  methods: {
    // 查询表格数据
    searchTable() {
      this.loading = true
      this.tableData = []
      this.tableData2 = []
      this.total2 = 0
      var STime = ''
      var ETime = ''
      STime = this.startTime + ' 00:00:00'
      ETime = this.endTime + ' 23:59:59'
      searchtable(STime, ETime, 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
      var STime = ''
      var ETime = ''
      STime = this.startTime + ' 00:00:00'
      ETime = this.endTime + ' 23:59:59'
      searchtable2(row.人员编号, STime, ETime, this.pageCurrent2, this.pageSize2).then(response => {
        console.log(response.data, 222)
        if (response.data.rows.length !== 0) {
          this.tableData2 = response.data.rows
        }
        this.loading2 = false
        this.total2 = response.data.total
      })
    },
    handleSizeChange2(val) {
      this.pageCurrent2 = 1
      this.pageSize2 = val
      this.searchTable2()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.searchTable2()
    }
  }
}
</script>

<style scoped>

</style>
