<template>
    <div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="工单名称" prop="workorderName">
        <el-input
          v-model="queryParams.workorderName"
          placeholder="请输入工单名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源单据" prop="sourceCode">
        <el-input
          v-model="queryParams.sourceCode"
          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 label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需求日期" prop="requestDate">
        <el-date-picker
          clearable
          v-model="queryParams.requestDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择需求日期"
        >
        </el-date-picker>
      </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="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="工单编码" width="180" prop="workorderCode"/>

      <el-table-column label="单据状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.mes_workorder_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column label="工单类型" align="center" prop="workorderType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.mes_workorder_type"
            :value="scope.row.workorderType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="组合单号"
        width="180"
        align="center"
        prop="combinationCode"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="编排单号"
        width="130px"
        align="center"
        prop="arrangeCode"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="订单编号"
        width="140"
        align="center"
        prop="sourceCode"
      />
      <el-table-column
        label="产品编号"
        width="120"
        align="center"
        prop="productCode"
      />
      <el-table-column
        label="产品名称"
        width="200"
        align="center"
        prop="productName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="规格型号"
        align="center"
        prop="productSpc"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="需求日期"
        align="center"
        prop="requestDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requestDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单位" align="center" prop="unitOfMeasure"/>
      <el-table-column label="工单数量" align="center" prop="quantity"/>
      <el-table-column label="调整数量" align="center" prop="quantityChanged"/>
      <el-table-column
        label="已生产数量"
        align="center"
        width="100px"
        prop="quantityProduced"
      />
      <el-table-column
        label="批次号"
        align="center"
        width="100px"
        prop="batchCode"
      />
      <el-table-column label="客户编码" align="center" prop="clientCode"/>
      <el-table-column
        label="客户名称"
        align="center"
        prop="clientName"
        :show-overflow-tooltip="true"
      />
    </el-table>

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

<script>
import {
  listWorkorder
} from "@/api/mes/pro/workorder";

export default {
  name: "orderList",
  dicts: ["mes_workorder_status","mes_workorder_type",],
  components: { },
  data() {
    return {
      showFlag: false,
      // 选中数组
      ids: [],
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料产品表格数据
      itemList: null,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workorderCode: null,
        workorderName: null,
        orderSource: null,
        sourceCode: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpc: null,
        routeName: null,
        unitOfMeasure: null,
        quantity: null,
        quantityProduced: null,
        quantityChanged: null,
        quantityScheduled: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        requestDate: null,
        parentId: null,
        ancestors: null,
        statusArr: ["ORCHESTRATED"],
      },
    };
  },
  created() {

  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      listWorkorder(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>
