<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="96px">
      <el-form-item label="销售订单编号" prop="saleorderCode">
        <el-input
          v-model="queryParams.saleorderCode"
          placeholder="请输入销售订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="物料编码" prop="materialCode">
        <el-input
          v-model="queryParams.materialCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="物料规格" prop="materialSpec">
        <el-input
          v-model="queryParams.materialSpec"
          placeholder="请输入物料规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单状态" prop="isRelease">
        <el-select v-model="queryParams.isRelease" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.mes_sale_order_is_release"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!--      <el-form-item label="完成日期" prop="completeDate">-->
      <!--        <el-date-picker clearable-->
      <!--          v-model="queryParams.completeDate"-->
      <!--          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="saleOrderList" @selection-change="handleSelectionChange"
              @row-click="handleRowClick"
              highlight-current-row>
      <el-table-column label="主键标识" align="center" prop="saleOrderId"/>
      <el-table-column label="销售订单编号" align="center" prop="saleorderCode"/>
      <el-table-column label="物料编码" align="center" prop="materialCode"/>
      <el-table-column label="物料名称" align="center" prop="materialName"/>
      <el-table-column label="物料规格" align="center" prop="materialSpec"/>
      <el-table-column label="订单数量" align="center" prop="orderAmount"/>
      <el-table-column label="已发布数量" align="center" prop="releaseQty"/>
      <el-table-column label="完成数量" align="center" prop="completeAmount"/>
      <el-table-column label="订单状态" align="center" prop="isRelease">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_sale_order_is_release" :value="scope.row.isRelease"/>
        </template>
      </el-table-column>

      <el-table-column label="开始日期" align="center" prop="beginDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="结束日期" align="center" prop="endDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划交货日期" align="center" prop="planDeliveryDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planDeliveryDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="审核日期" align="center" prop="approveDate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approveDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="ERP最后修改日期" align="center" prop="erpModifyDate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.erpModifyDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </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 { listSaleOrder } from "@/api/mes/saleOrder";


export default {
  name: "saleOrderInfo",
  dicts: ['document_status', 'is_release','mes_sale_order_is_release'],
  props: {
    defineData: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料类型信息树选项
      baseMaterialTypeOptions: [],
      // 物料信息表格数据
      saleOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      SALE_ORDER_CLASSFICATION:{
        ERP:'1'
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        erpId: null,
        materialCode: null,
        oldMaterialCode: null,
        materialName: null,
        materialCategories: null,
        materialSubclass: null,
        materialTypeId: null,
        batchFlag: null,
        materialUnitId: null,
        materialUnit: null,
        materialMatkl: null,
        materialSpec: null,
        netWeight: null,
        grossWeight: null,
        factoryId: null,
        createOrgId: null,
        useOrgId: null,
        prodlineId: null,
        activeFlag: '1',
        deletedFlag: null,
        approveDate: null,
        erpModifyDate: null,
        saleOrderClassfication:'1'
      },
   };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物料信息列表 */
    getList() {
      this.loading = true;
      listSaleOrder(this.queryParams).then(response => {
        this.saleOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.saleOrderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    //选中列赋值
    handleRowClick(row) {
      this.selectedRow = row
    },
  }

};
</script>
