<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="taskCode">
        <el-input
          v-model="queryParams.taskCode"
          placeholder="请输入任务编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库" prop="warehouseId">
        <el-select v-model="queryParams.warehouseId" placeholder="请选择仓库" clearable>
          <el-option
            v-for="(category, index) in warehouseOptions"
            :key="index"
            :label="category.warehouseName"
            :value="category.warehouseId"
          ></el-option>
        </el-select>

      </el-form-item>
      <el-form-item label="库位编码" prop="locationCode">
        <el-input
          v-model="queryParams.locationCode"
          placeholder="请输入库位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购订单" prop="poNo">
        <el-input
          v-model="queryParams.poNo"
          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="materialBarcode">
        <el-input
          v-model="queryParams.materialBarcode"
          placeholder="请输入物料条码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="托盘编码" prop="palletInfoCode">
        <el-input
          v-model="queryParams.palletInfoCode"
          placeholder="请输入托盘编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库人" prop="applyBy">
        <el-input
          v-model="queryParams.applyBy"
          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">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="rawinstockList">
      <el-table-column label="任务编号" align="center" prop="taskCode" />
      <el-table-column label="仓库" align="center" prop="warehouseId" >
        <template slot-scope="scope">
            <span
              v-for="(item, index) in warehouseOptions"
              :key="index"
              :value="item.warehouseOptions"
              v-if="scope.row.warehouseId == item.warehouseId"
            >
              {{ item.warehouseName }}
            </span>
        </template>
      </el-table-column>
      <el-table-column label="库位编码" align="center" prop="locationCode" />
      <el-table-column label="采购订单号" align="center" prop="poNo" />
      <el-table-column label="操作类型" align="center" prop="operationType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_operation_type" :value="scope.row.operationType"/>
        </template>
      </el-table-column>
      <el-table-column label="入库类型" align="center" prop="instockType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_instock_type" :value="scope.row.instockType"/>
        </template>
      </el-table-column>
      <el-table-column label="物料编码" align="center" prop="materialCode" />
      <el-table-column label="物料名称" align="center" prop="materialName" />
      <el-table-column label="物料条码" align="center" prop="materialBarcode" />
      <el-table-column label="批次条码" align="center" prop="materialBatchCode" />
      <el-table-column label="托盘编码" align="center" prop="palletInfoCode" />
      <el-table-column label="入库数量" align="center" prop="instockAmount" />
      <el-table-column label="执行状态" align="center" prop="executeStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_execute_status" :value="scope.row.executeStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="同步ERP状态" align="center" prop="erpStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_erp_status" :value="scope.row.erpStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="同步ERP数量" align="center" prop="erpAmount" />
      <el-table-column label="入库人" align="center" prop="applyBy" />
      <el-table-column label="入库时间" align="center" prop="applyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!--el-table-column label="质检状态(0:待质检,1:合格,2:NG)" align="center" prop="qualityStatus" /-->

    </el-table>

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

  </div>
</template>

<script>
import { listRawinstock, getRawWarehouses } from "@/api/wms/rawinstock";

export default {
  name: "Rawinstock",
  dicts: ["wms_operation_type","wms_instock_type","wms_execute_status","wms_erp_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原材料入库记录表格数据
      rawinstockList: [],
      // 仓库类别
      warehouseOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskCode: null,
        warehouseId: null,
        locationCode: null,
        poNo: null,
        operationType: null,
        instockType: null,
        materialCode: null,
        materialName: null,
        materialBarcode: null,
        materialBatchCode: null,
        palletInfoCode: null,
        instockAmount: null,
        executeStatus: null,
        erpStatus: null,
        erpAmount: null,
        applyBy: null,
        applyDate: null,
        machineName: null,
        qualityStatus: null,
        updateDate: null,
        beginTime: null,
        endTime: null,
        rawReturnId: null
      },
    };
  },
  created() {
    this.getList();
    this.getRawWarehouses();
  },
  methods: {
    /** 查询原材料入库记录列表 */
    getList() {
      this.loading = true;
      listRawinstock(this.queryParams).then(response => {
        this.rawinstockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

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

    /** 导出按钮操作 */
    handleExport() {
      this.download('wms/rawinstock/export', {
        ...this.queryParams
      }, `rawinstock_${new Date().getTime()}.xlsx`)
    },


    /** 查询仓库类别 */
    getRawWarehouses() {
      getRawWarehouses().then(response => {
        this.warehouseOptions = response.data;
      });
    },
  }
};
</script>
