<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="$t('生产工单')" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"

          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('产品编码')" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('产品名称')" prop="productName">
        <el-input
          v-model="queryParams.productName"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('产品图号')" prop="customerDrawingNo">
        <el-input
          v-model="queryParams.customerDrawingNo"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('项目号')" prop="customerProjectNo">
        <el-input
          v-model="queryParams.customerProjectNo"

          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('订单号')" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('订单项次')" prop="orderSerial">
        <el-input
          v-model="queryParams.orderSerial"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('common.search') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('common.reset') }}</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="$t('生产工单')" align="center" prop="workorderCode">
        <template slot-scope="scope">
          <el-tooltip :content="scope.row.productName" placement="right">
            <span>{{scope.row.workorderCode}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column :label="$t('产品编码')" align="center" prop="productCode"/>
      <el-table-column :label="$t('产品名称')" align="center" prop="productName"/>
      <el-table-column :label="$t('产品图号')" align="center" prop="customerDrawingNo"/>
      <el-table-column :label="$t('首工序名称')" align="center" prop="firstProcessName" min-width="120" show-overflow-tooltip/>
      <el-table-column :label="$t('预交日期')" align="center" prop="requestDate"/>
      <el-table-column :label="$t('未排数量')" align="center" prop="disQuantity"/>
      <el-table-column :label="$t('本次数量')" align="center" prop="scheduleQuantity" width="160">
        <template slot-scope="scope">
          <el-input-number style="width: 140px;"
                           v-model="scope.row.scheduleQuantity"

                           clearable
          />
        </template>
      </el-table-column>
      <el-table-column
          :label="$t('排程日期')"
          align="center"
          prop="scheduleDate"
          width="200"
          :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <el-date-picker
              v-model="scope.row.scheduleDate"
              type="datetime"
              style="width: 100%;"
              value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm">
          >
          </el-date-picker>
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目号')" align="center" prop="customerProjectNo"/>
      <el-table-column :label="$t('订单号')" align="center" prop="orderCode"/>
      <el-table-column :label="$t('订单项次')" align="center" prop="orderSerial"/>
    </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: '',
        customerDrawingNo: '',
        productName: '',
        customerProjectNo: '',
        orderCode: '',
        orderSerial: ''
      },
    };
  },
  created() {

  },
  mounted() {
    this.getList();
  },
  methods: {
    
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      var defDate = new Date();
      defDate.setHours(8);
      defDate.setMinutes(0);
      defDate.setSeconds(0)
      scheduleList(this.queryParams).then((response) => {
        response.rows = response.rows.map(v=>{
          return {
            ...v,
            disQuantity : v.quantity - v.quantityScheduled,
            scheduleQuantity: v.quantity - v.quantityScheduled,
            scheduleDate:defDate
          }
        })
        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>
