<template>
    <div>
      <el-form :model="queryParams" @submit.native.prevent ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="编排单号" prop="arrangeCodes">
        <el-input
          v-model="queryParams.arrangeCodes"
          placeholder="请输入编排单号"
          clearable type="textarea" :rows="2" resize="none"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产工单" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入生产工单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类别名称" prop="itemTypeName" label-width="100px">
        <el-input
          v-model="queryParams.itemTypeName"
          placeholder="请输入产品类别名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编排人员" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入编排人员"
          clearable
          @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"
      height="40vh"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编排单号" align="center" prop="arrangeCode">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="$emit('clickTask', scope.row.arrangeCode)"
            >{{ scope.row.arrangeCode }}</el-button
          >
        </template>
      </el-table-column>
      <!-- <el-table-column label="生产工单" align="center" prop="workorderCode"/> -->
      <el-table-column label="编排时间" align="center" prop="createTime"/>
      <el-table-column label="产品类别名称" align="center" prop="itemTypeName"/>
      <el-table-column label="编排人员" align="center" prop="createBy"/>

    </el-table>

    <pagination
      v-show="total > 0"
      :page-sizes="[50, 100, 500, 1000, 2000, 3000, 4000]"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>
</template>

<script>
import {
  distinctList
} from "@/api/mes/pro/scheduleList";

export default {
  name: "orderList",
  components: { },
  data() {
    return {
      showFlag: false,
      // 选中数组
      ids: [],
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料产品表格数据
      itemList: null,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        itemTypeName: "",
        arrangeCodes: '',
        workorderCode: '',
        createBy: ''
      },
    };
  },
  created() {

  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      const formdata = new FormData()
      formdata.append('pageNum', this.queryParams.pageNum)
      formdata.append('pageSize', this.queryParams.pageSize)
      if (this.queryParams.arrangeCodes) {
        const arr = this.queryParams.arrangeCodes.split(/[\n,;，、；。]/).filter(item => item)
        arr.forEach((value, index) => {
          formdata.append(`arrangeCodes[${index}]`, value)
        })
      }

      formdata.append('itemTypeName', this.queryParams.itemTypeName)
      formdata.append('workorderCode', this.queryParams.workorderCode)
      formdata.append('createBy', this.queryParams.createBy)
      formdata.append('workorderStatus', ['ORCHESTRATED'])
      distinctList(formdata).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.queryParams.statusArr = ["ORCHESTRATED"]
      this.handleQuery();
    },
     // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workorderId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.selectedRows = selection;
    },
  },
};
</script>
