<template>
  <div class="app-container">
    <el-form :model="queryParams" @submit.native.prevent ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="工作单元编码" prop="workunitCode">
            <el-input
              v-model="queryParams.workunitCode"
              placeholder="请输入工作单元编码"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="班次" prop="shiftName">
            <el-select
              v-model="queryParams.shiftName"
              clearable
              style="width: 240px"
              placeholder="请选择班次"
            >
              <el-option
                v-for="dict in dict.type.SHIFT_TYPE"
                :key="dict.value"
                :label="dict.label"
                :value="dict.label"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="车间名称" label-width="100px" prop="workshopName">
            <el-input
              v-model="queryParams.workshopName"
              placeholder="请输入车间名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工作中心名称" label-width="100px" prop="workstationName">
            <el-input
              v-model="queryParams.workstationName"
              placeholder="请输入工作中心名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="tmToolRequestItemList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工作单元编码" align="center" prop="workunitCode" />
      <el-table-column label="工作单元名称" align="center" prop="workunitName" />
      <el-table-column label="班次" align="center" prop="shiftName" />
      <el-table-column label="工作状态" align="center" prop="isWork" >
        <template slot-scope="scope">
          {{ scope.row.isWork == '1'? '工作': '休息' }}
        </template>
      </el-table-column>
      <el-table-column label="车间名称" align="center" prop="workshopName" />
      <el-table-column label="工作中心名称" align="center" prop="workstationName" />
      <el-table-column label="工作开始时间" align="center" prop="startTime" />
      <el-table-column label="工作结束时间" align="center" prop="endTime" />
      <el-table-column label="工作休息开始时间" align="center" prop="breakStartTime" />
      <el-table-column label="工作休息结束时间" align="center" prop="breakEndTime" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listItem } from "@/api/mes/cal/calholiday";

export default {
  dicts: ['SHIFT_TYPE'],
  name: "TmToolRequestItem",
  components: {},
  props:{
    theDay:{
      type:String,
      default:''
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      selectRow: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 刀模版物料申请单表格数据
      tmToolRequestItemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shiftName: null,
        isWork: 1,
        theDay: this.theDay
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      addList: [],
      detailList: []
    };
  },
  watch: {
    // 根据名称筛选分类树
    theDay: {
      handler (newName, oldName) {
        if (newName) {
          this.getList();
        }
      },
      immediate: true
    }
  },
  created() {
  },
  methods: {
    /** 查询刀模版物料申请单列表 */
    getList() {
      this.loading = true;
      listItem(this.queryParams).then(response => {
        this.tmToolRequestItemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      // this.reset();
    },
    // // 表单重置
    // reset() {
    //   this.form = {
    //     toolRequestItemId: null,        toolRequestId: null,        itemId: null,        allQuantity: null,        nextMaintenPeriod: null,        createBy: null,        createTime: null,        updateBy: null,        updateTime: null      };
    //   this.resetForm("form");
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.toolRequestItemId)
      this.selectRow = selection
    }
  }
};
</script>
