<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="波次号" prop="orderWave">
        <el-input
          v-model="queryParams.orderWave"
          placeholder="请输入波次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料号" prop="goodsId">
        <el-input
          v-model="queryParams.goodsId"
          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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:waveConstitute:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="waveConstituteList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="波次号" align="center" prop="orderWave" />
      <!--<el-table-column label="记录号" align="center" prop="recordId" />-->
      <el-table-column label="wms订单号" align="center" prop="orderId" />
      <el-table-column label="物料编码" align="center" prop="goodsId" />
      <el-table-column label="出库单号" align="center" prop="listId" />
      <el-table-column label="出库单类型" align="center" prop="orderType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.out_order_type" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column label="客户名称" align="center" prop="customerId" />
      <el-table-column label="订单出库数量" align="center" prop="goodsNum" />
      <el-table-column label="总出库数量" align="center" prop="pickNum" />
      <el-table-column label="确认出库数量" align="center" prop="trNum" />
      <el-table-column label="确认出库数量" align="center" prop="shelvesNum" />
      <el-table-column label="库存数量" align="center" prop="stockNum" />
      <el-table-column label="物料描述" align="center" prop="goodsDesc" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.out_order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否锁定" align="center" prop="isLock" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_or_order_status" :value="scope.row.isLock"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="0：未生成 1：生成波次" align="center" prop="generateWave" />-->
    </el-table>

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

<script>
import { listWaveConstitute} from "@/api/system/waveConstitute";

export default {
  name: "WaveConstitute",
  dicts: ["out_order_type", "out_order_status","stock_or_order_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 波次构成表格数据
      waveConstituteList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        generateWave: 1,
        goodsId: null,
        orderWave: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        listId: [
          { required: true, message: "出库单号不能为空", trigger: "blur" }
        ],
        orderType: [
          { required: true, message: "出库单类型不能为空", trigger: "change" }
        ],
        goodsId: [
          { required: true, message: "物料号不能为空", trigger: "blur" }
        ],
        goodsNum: [
          { required: true, message: "订单出库数量不能为空", trigger: "blur" }
        ],
        goodsDesc: [
          { required: true, message: "物料描述不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询波次构成列表 */
    getList() {
      this.loading = true;
      listWaveConstitute(this.queryParams).then(response => {
        this.waveConstituteList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordId: null,
        orderId: null,
        listId: null,
        orderType: null,
        customerId: null,
        goodsId: null,
        goodsNum: null,
        pickNum: null,
        trNum: null,
        shelvesNum: null,
        stockNum: null,
        goodsDesc: null,
        spare1: null,
        spare2: null,
        orderStatus: null,
        isLock: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        generateWave: 1,
        orderWave: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/waveConstitute/export', {
        ...this.queryParams
      }, `waveConstitute_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
