import { FeeItemQueryParam } from "@/api/feeItem/FeeItemModle";
import { reactive, onMounted } from "vue";
import { getFeeItemListApi } from "@/api/FeeItem/FeeItem"
import { getfeeItemSpecialFlagApi, getfeeItemTypeApi } from "@/api/base/basedata"
import { ListIitem } from "@/api/base/BaseDataModel"
import { useQueryList } from "@/hooks/useQueryList";

export default function userFeeItemTable() {

    //特殊计费标志
    const feeItemSpecialFlagSelectList = reactive({
        list: [] as ListIitem[]
    });

    //费用类型
    const feeItemTypeSelectList = reactive({
        list: [] as ListIitem[]
    });

    //定义表格数据
    const feeItemList = reactive({
        list: [],
        loading: false//加载
    });
    //定义列表查询的参数
    const listParm = reactive<FeeItemQueryParam>({
        itemName: '',
        pageNum: 1,
        pageSize: 10,
        itemType: 0,
        total: 0
    })

    //获取费用信息列表
    const getFeeItemList = async () => {
        feeItemList.loading = true
        let res = await getFeeItemListApi(listParams)
        if (res && res.code == 200) {
            feeItemList.list = res.data.records
            listParm.total = res.data.total;
        }
        feeItemList.loading = false
    }


    //获取费项科目类型下拉框数据
    const getfeeItemSpecialFlagSelectList = async () => {
        let res = await getfeeItemSpecialFlagApi()
        if (res && res.code == 200) {
            // debugger;
            feeItemSpecialFlagSelectList.list = res.data;
        }
    }


    //获取费用类型下拉框数据
    const getfeeItemTypeSelectList = async () => {
        let res = await getfeeItemTypeApi()
        if (res && res.code == 200) {
            debugger;
            feeItemTypeSelectList.list = res.data;
        }
    }

    // 重置
    const resetParams = () => {
        listParm.itemName = '';
        listParm.itemType = 0;
    }
    // 初始化列表、分页数据
    const { sizeChange, currentChange, searchBtn, resetBtn, listParams } = useQueryList<FeeItemQueryParam>(getFeeItemList, resetParams, listParm)

    onMounted(() => {
        getfeeItemSpecialFlagSelectList();
        getfeeItemTypeSelectList();
    })

    return {
        feeItemSpecialFlagSelectList,
        feeItemTypeSelectList,
        feeItemList,
        listParm,
        getFeeItemList,
        sizeChange,
        currentChange,
        searchBtn,
        resetBtn
    }
};