<template>
    <div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="68px"
      >
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            
            <el-form-item label="编排单号" prop="arrangeCode">
              <el-input
                v-model="queryParams.arrangeCode"
                placeholder="请输入编排单号"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <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="itemList"
      >
        <!-- <el-table-column type="selection" width="55" align="center"/> -->
        <el-table-column label="编排单号" width="180" prop="arrangeCode" />
        <el-table-column label="任务单编码" width="120" prop="taskCode" />
        <el-table-column label="排产任务ID" width="80" prop="taskWorkunitId" />
        <el-table-column
          label="工序名称"
          align="center"
          prop="processName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="工作中心"
          align="center"
          prop="workstationName"
          width="140"
        />
        <el-table-column
          label="作业单元名称"
          align="center"
          prop="workunitName"
          width="200"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="opentask(scope.row)"
              >打开</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" 
      :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import {
  listFinishTaskWorkunits,
  openTaskWorkunit
} from "@/api/mes/pro/scheduleList";

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

  },
  mounted() {
    this.getList();
  },
  methods: {
    opentask(row) {
      openTaskWorkunit(row.taskWorkunitId).then(res => {
        if(res.code === 200) {
          this.getList()
        }
      })
    },
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      listFinishTaskWorkunits(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.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>
