<!-- 仓位找货优先级 -->
<template>
    <div class="table-box">
        <div style="padding-bottom: 16px">
            <PermissionButton
                :buttons="dataStore.buttons"
                @handleButtonClickCallback="handleButtonClickCallback"
            ></PermissionButton>
        </div>

        <ProTable
            ref="proTableRef"
            :columns="dataStore.columns"
            :request-api="getMaterialListApi"
            :init-param="dataStore.initParam"
            @selectionChange="selectionChange"
        >
            <template v-slot:search>
                <SearchForm
                    @search="handleSearch"
                    @reset="handleReset"
                    :searchParams="dataStore.initParam"
                    :formData="dataStore.formData"
                />
            </template>
        </ProTable>
    </div>
</template>

<script setup lang="ts" name="foundationSetWarehouse">
import ProTable from "@/components/ProTable/index.vue";
import SearchForm from "@/components/SearchForm/index.vue";
import PermissionButton from "@/components/PermissionButton/index.vue";
import { getMaterialListApi } from "@/api/modules/foundationMaterial";
// import { useMsg } from "@/hooks/useMsg";
import { RULE_FORM, FORM_DATA, COLUMNS, BUTTON } from "./constant/list/index";

//表格TS
import { ProTableInstance } from "@/components/ProTable/interface";

//深拷贝方法
import { cloneDeep } from "lodash-es";
// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTableRef = ref<ProTableInstance>();

// 数据源
const dataStore = reactive<any>({
    columns: COLUMNS, //列表配置项
    initParam: cloneDeep(RULE_FORM), // 初始化搜索条件|重置搜索条件
    formData: FORM_DATA, //搜索配置项
    buttons: cloneDeep(BUTTON),
    labelWidth: "120px",
    dialogVisible: false, //弹窗
    selectionList: [] //选中表格的行
});

// 表格选择事件
const selectionChange = (selection: any) => {
    dataStore.selectionList = selection;
};

//顶部按钮点击事件
const handleButtonClickCallback = (item: any) => {
    console.log(item);
};

//搜索
const handleSearch = async (params: any) => {
    dataStore.initParam = cloneDeep(params);
    //这里需要等到表格刷新以后才去请求
    nextTick(() => {
        proTableRef?.value!.getTableList();
    });
};
//重置
const handleReset = () => {
    dataStore.initParam = cloneDeep(RULE_FORM);
    //这里需要等到表格刷新以后才去请求
    nextTick(() => {
        proTableRef?.value!.getTableList();
    });
};
</script>

<style scope lang="scss">
.down-dialog-box {
    .el-dialog__body {
        padding: 0 16px 40px;
    }
}
.el-dialog .el-dialog__header {
    padding: 8px 0;
    font-weight: bold;
}
</style>
