<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <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>
        <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"
              @row-click="handleRowClick"
              highlight-current-row
    >
      <el-table-column label="销售订单编号" align="center" prop="saleorderCode" v-if="columns[3].visible"/>
      <el-table-column label="物料编码" align="center" prop="materialCode" v-if="columns[9].visible"/>
      <el-table-column label="物料名称" align="center" prop="materialName" v-if="columns[10].visible"/>
      <el-table-column label="物料规格" align="center" prop="materialSpec"/>
      <el-table-column label="订单数量" align="center" prop="orderAmount" v-if="columns[12].visible"/>
      <el-table-column label="完成数量" align="center" prop="completeAmount" v-if="columns[13].visible"/>
      <el-table-column label="已发布数量" align="center" prop="releaseQty" v-if="columns[14].visible"/>


    </el-table>

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

  </div>
</template>

<script>
import {getSaleOrders} from "@/api/mes/purchaseOrder";

export default {
  name: "SaleOrder",
  dicts: ['document_status', 'is_release'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售订单信息表格数据
      saleOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        erpId: null,
        fentryId: null,
        saleorderCode: null,
        saleorderLinenumber: null,
        documentStatus: null,
        factoryId: null,
        prodlineId: null,
        saleOrderClassfication:'1',
        materialId: null,
        materialCode: null,
        materialName: null,
        materialSpec: null,
        matkl: null,
        orderAmount: null,
        completeAmount: null,
        releaseQty: null,
        isRelease: null,
        approveDate: null,
        erpModifyDate: null,
        planDeliveryDate: null,
        beginDate: null,
        endDate: null,
        completeDate: null,
        isFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        isFlag: [
          {required: true, message: "是否标识：1-是；0-否不能为空", trigger: "blur"}
        ],
      },
      columns: [
        {key: 0, label: `主键标识`, visible: true},
        {key: 1, label: `ERP主键`, visible: true},
        {key: 2, label: `ERP订单明细ID`, visible: true},
        {key: 3, label: `销售订单编号`, visible: true},
        {key: 4, label: `销售订单行号`, visible: true},
        {key: 5, label: `单据状态`, visible: true},
        {key: 6, label: `所属工厂`, visible: true},
        {key: 7, label: `所属产线`, visible: true},
        {key: 8, label: `物料ID`, visible: true},
        {key: 9, label: `物料编码`, visible: true},
        {key: 10, label: `物料名称`, visible: true},
        {key: 11, label: `物料组`, visible: true},
        {key: 12, label: `订单计划数量`, visible: true},
        {key: 13, label: `完成数量`, visible: true},
        {key: 14, label: `已发布数量`, visible: true},
        {key: 15, label: `是否已下达计划`, visible: true},
        {key: 16, label: `审核日期`, visible: true},
        {key: 17, label: `ERP最后修改日期`, visible: true},
        {key: 18, label: `计划交货日期`, visible: true},
        {key: 19, label: `计划开始日期`, visible: true},
        {key: 20, label: `计划结束日期`, visible: true},
        {key: 21, label: `完成日期`, visible: true},
        {key: 22, label: `是否标识：1-是；0-否`, visible: true},
        {key: 23, label: `备注`, visible: true},
        {key: 24, label: `创建人`, visible: true},
        {key: 25, label: `创建时间`, visible: true},
        {key: 26, label: `更新人`, visible: true},
        {key: 27, label: `更新时间`, visible: true},
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询销售订单信息列表 */
    getList() {
      this.loading = true;
      getSaleOrders(this.queryParams).then(response => {
        this.saleOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

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

  }
};
</script>
