<template>
    <div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <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="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          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="workorderCode">
        <!-- <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="$emit('clickTask', scope.row.workorderCode)"
            >{{ scope.row.workorderCode }}</el-button
          >
        </template> -->
      </el-table-column>
      <el-table-column label="产品编码" align="center" prop="productCode"/>
      <el-table-column label="产品名称" align="center" prop="productName"/>
      <el-table-column label="未排数量" align="center" prop="disQuantity"/>
      <el-table-column label="本次数量" align="center" prop="scheduleQuantity">
        <template slot-scope="scope">
          <el-input-number style="width: 140px;"
            v-model="scope.row.scheduleQuantity"
            placeholder=""
            clearable
          />
        </template>
      </el-table-column>

    </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 {
  scheduleList
} 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,
        workorderCode: '',
        productCode: '',
        productName: ''
      },
    };
  },
  created() {

  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;

      scheduleList(this.queryParams).then((response) => {
        response.rows = response.rows.map(v=>{
          return {
            ...v,
            disQuantity : v.quantity - v.quantityScheduled,
            scheduleQuantity: v.quantity - v.quantityScheduled
          }
        })
        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>
