<!-- 库存预占查询 -->
<template>
  <div>
    <p-card title="库存预占查询">
      <!-- <template slot="extra">
			<p-button type="primary" icon="check" @click="showModal">确认</p-button>
			<p-button type="primary" icon="redo" @click="hanlderRest">重置</p-button>
		</template> -->
      <div class="plg-inner-form-mb">
        <p-grid-form ref="search" :span="8" :label-col="{ span: 6 }" :items="items" @submit="hanlderSubmit" />
      </div>
      <!-- @checkRow="checkRow" -->
      <p-table
        :columns="columns"
        :data-source="data"
        rowKey="id"
        dragle
        auto-width
        :scroll="{ x: true }"
        :selectedRowKeys.sync="selectedRowKeys"
        hasRowSelectCheck
        @selectChange="selectChange"
        :loading="loading"
        bordered
      >
        <!-- @change='changePagination'
			:pagination="pagination" -->
        <template slot="locatorType" slot-scope="text, record, index">
          {{ return_locatorType(text) }}
        </template>
        <template slot="warehouseId" slot-scope="text, record, index">
          {{ return_warehouseId(text) }}
        </template>
        <template slot="locatorId" slot-scope="text, record, index">
          {{ return_locatorId(text) }}
        </template>
        <!-- <span slot="action"
		         slot-scope="text, record,index">
		 
		     <a @click="showModal(record)">编辑</a>
		     <a-divider type="vertical"
		                style="" />
		     <a @click="del(record)">删除</a>
		 
		   </span> -->
      </p-table>
    </p-card>
  </div>
</template>

<script>
// 设置默认仓库
import { sorter } from "@/views/kzyWMS/utils/sort.js";
import { setwarehouse } from "@/views/kzyWMS/SearchModal/mixins_warehouse.js";
import { items, columns } from "./api/inventoryPre.js";
import { wave_bill_itemLocator, wave_bill_workstage } from "./api/api.js";
import { dict_listbytype, warehouse_page } from "../../basedata/warehouse/api/api_warehouse.js";
// 货位
import { freightPage } from "../../basedata/warehouse/api/api.js";
export default {
  mixins: [setwarehouse],
  data() {
    return {
      items,
      columns: sorter(columns),
      data: [],
      selectedRowKeys: [],
      loading: false,
      wms_loctype: [], //货位类型
      arr_warehouse_page: [], //仓库列表
      arr_locator: [], //货位
      pagination: {
        total: 0,
        pageSize: 10, //每页中显示10条数据
        current: 1,
        showSizeChanger: true,
        pageSizeOptions: ["10", "15", "20"], //每页中显示的数据
        showTotal: (total) => `共有 ${total} 条数据`, //分页中显示总的数据
      },
    };
  },
  methods: {
    getData(params) {
      (params = {
        pageNum: this.pagination.current,
        pageSize: this.pagination.pageSize,
        ...params,
      }),
        (this.loading = true);
      // /波次/波次库存预占查询
      wave_bill_itemLocator(params)
        .then((res) => {
          if (res.success) {
            this.data = res.data.list;
            this.pagination.total = Number(res.data.totalCount);
            this.selectedRowKeys.length = 0;
            this.loading = false;
          } else {
            this.loading = false;
            this.$exception(res);
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    selectChange(selectedRowKeys, selectedRows) {
      console.log(selectedRowKeys, selectedRows);
    },
    hanlderSubmit(event, form) {
      event.preventDefault();
      // console.log("getFieldsValue:",form.getFieldsValue());
      // this.getData(form.getFieldsValue())
      this.$refs.search.form.validateFields((err, values) => {
        if (!err) {
          console.log("验证通过: ", values);
          this.getData(values);
        }
      });
    },
    // 重置
    hanlderRest(event, form) {
      this.$refs.search.form.resetFields();
    },
    changePagination(pagination, filters, sorter) {
      // 分页变化
      console.log(pagination, filters, sorter, "分页变化分页变化");
      this.pagination = pagination;
      this.getData({ ...this.$refs.search.form.getFieldsValue() });
    },
    // 过滤货位类型
    return_locatorType(text) {
      let temp = this.wms_loctype.find((v) => v.dictCode == text);
      return temp ? temp.dictName : "";
    },
    // 过滤仓库
    return_warehouseId(text) {
      let temp = this.arr_warehouse_page.find((v) => v.warehouseId == text);
      return temp ? temp.warehouseName : text;
    },
    // 过滤货位
    return_locatorId(text) {
      let temp = this.arr_locator.find((v) => v.warehouseLocatorId == text);
      return temp ? temp.warehouseLocatorName : text;
    },
  }, // methods
  mounted() {
    this.getData({ ...this.$refs.search.form.getFieldsValue() });
    // 数据字典：货位类型
    dict_listbytype({ dicttypeCodes: "wms_loctype" }).then((res) => {
      if (res.success) {
        this.wms_loctype = res.data;
        console.log("货位类型：", res.data);
      }
    });
    //  仓库
    warehouse_page({ pageNum: 1, pageSize: 9999 }).then((res) => {
      if (res.success) {
        this.arr_warehouse_page = res.data.list;
        console.log("仓库：", res.data.list);
      }
    });
    //  货位
    freightPage({ pageNum: 1, pageSize: 9999 }).then((res) => {
      if (res.success) {
        this.arr_locator = res.data.list;
        console.log("货位：", res.data.list);
      }
    });
  },
};
</script>

<style></style>
