<template>
  <el-dialog title="工单选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal= false
    width="1000px"
  >
    <el-row :gutter="20">

      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="105px" align="left">
          <el-form-item label="工单编号">
            <el-input
              v-model="queryParams.workorderCode"
              placeholder="工单编号"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <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-form>
        <el-table v-loading="loading" :data="itemList" @selection-change="handleBomSelectionChange" ref="myTable" >
          <el-table-column width="50" align="center" type="selection"/>
          <el-table-column label="生产日期"  align="left"  prop="productDate" width="100"/>
          <el-table-column label="工单编号"  align="left"  prop="workorderCode" width="180"/>
          <el-table-column label="订单编号"  align="left" prop="orderCode" width="120"/>
          <el-table-column label="产品编码"  align="left" prop="productCode" width="180" />
          <el-table-column label="产品名称"  align="left" prop="productName" width="180"/>
          <el-table-column label="规格型号"  align="left" prop="productSpc" :show-overflow-tooltip="true" />
          <el-table-column label="排产数量"  align="left" prop="quantitySplit" width="100" />
          <el-table-column label="单位"  align="left" prop="unit" :show-overflow-tooltip="true" />
          <el-table-column label="班次ID"  align="left" prop="shiftId" :show-overflow-tooltip="true" v-if="false"/>
          <el-table-column label="班次名称"  align="left" prop="shiftName" :show-overflow-tooltip="true" />
          <el-table-column label="生产线体"  align="left" prop="prodLineCode" :show-overflow-tooltip="true" width="100"/> 
          <el-table-column label="工单编号(子)"  align="left"  prop="workorderCodes" width="150"/>
          <el-table-column label="产品编码(子)"  align="left" prop="productCodes" width="180" />
          <el-table-column label="产品名称(子)"  align="left" prop="productNames" width="180"/>
          <el-table-column label="排产数量(子)"  align="left" prop="quantitySplits" width="100" />
          <el-table-column label="单位(子)"  align="left" prop="units" :show-overflow-tooltip="true" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="submitBomForm">确 定</el-button>
              <el-button @click="showFlag=false">取 消</el-button>
       </div>
  </el-dialog>
</template>
<script>

import { getMesListWorkOrder } from "@/api/mes/reportWork";
export default {
  name: "itemSelectWorkOrder",
  data() {
    return {
      showFlag:false,
      // 选中数组
      selectedRows: {},
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // BOM产品表格数据
      itemList: null,

      //树名称
      bomCode: undefined,
      defaultProps: {
        id: "id",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workorderCode: ''
      },
      selectionRow:{}
    };
  },
  created() {
    this.getList();
  },

  methods: {

    /** 查询表格列表*/
    getList() {
      this.loading = true;
      getMesListWorkOrder(this.queryParams).then(response => {
          this.itemList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    
    // 多选框选中数据
		handleBomSelectionChange(selection) {

      if(selection.length>1){
        this.$modal.msgSuccess("只能选一个");
      }

			this.selectionRow = selection[0]
		},


    submitBomForm() {

      this.$emit('onSelected', this.selectionRow);
      this.showFlag = false;
      this.queryParams.itemCodeGet = "";
    }
  }
};
</script>
