import { CustomerFeeSetQueryParam } from "@/api/customerfee/CustomerFeeSetModel";
import { reactive,onMounted } from "vue";
import {getCustomerFeeSetListApi} from "@/api/customerfee/customerfeeset"
import{ListIitem} from "@/api/base/BaseDataModel"
import{getproductApi,getCustomertApi,getFeeSetTypeApi,getBranchCompanyCustomersApi} from "@/api/base/basedata"

export default function userCustomerFeeSetTable(){

       //产品
       const productSelectList = reactive({
        list:[] as ListIitem[]
             });
        //分组
        const groupSelectList = reactive({
                list:[] as ListIitem[]
                     });
        //分公司机构
        const orgSelectList = reactive({
                    list:[] as ListIitem[]
                    });
        //客户
        const customerSelectList = reactive({
                list:[] as ListIitem[]
            });
        //费用类型
        const feeSetTypeSelectList = reactive({
                list:[] as ListIitem[]
            }); 
   
           
       
        
        //获取产品下拉框数据
     const getproductSelectList =async () => {
            let res = await getproductApi()
            if(res && res.code == 200)
            {              
                productSelectList.list = res.data;
            }
        };
        //获取客户数据
        const getCustomertSelectList =async () => {
            let res = await getCustomertApi()
            if(res && res.code == 200)
            {     
                customerSelectList.list = res.data;         
               
            }
        };

            //获取费用类型数据
            const getFeeSetTypeSelectList  =async () => {
            let res = await getFeeSetTypeApi()
            if(res && res.code == 200)
            {              
                feeSetTypeSelectList.list = res.data;
            }
        };

            //获取分公司数据
            const getbranchCompanyCustomersList  =async () => {
                let res = await getBranchCompanyCustomersApi()
                if(res && res.code == 200)
                {              
                    orgSelectList.list = res.data;
                }
            };
        
        




    //定义表格数据
    const customerFeeSetList = reactive({
         list:[]
    });
        //定义列表查询的参数
        const listParm = reactive<CustomerFeeSetQueryParam>({
            productId:'',           
            feeSetName:'',
            feeSetType:null,
            createUserId:null,
            activeFlag:false,
            pageNum:0,
            pageSize:10,          
            total:0
        })

         //获取客户费用设置信息列表
    const getCustomerFeeSetList = async() =>{
        let res = await getCustomerFeeSetListApi(listParm)
        if(res && res.code == 200){           
            customerFeeSetList.list = res.data.records
            listParm.total = res.data.total;
        }
    }
    //页容量改变时触发
    const sizeChange = (size:number) =>{
        listParm.pageSize = size;
        getCustomerFeeSetList();
    }
    //页数改变时触发
    const currentChange = (page:number) =>{
        listParm.pageNum = page;
        getCustomerFeeSetList();
    }
    //搜索
    const searchBtn = () =>{
        getCustomerFeeSetList();
    }
    //重置
    const resetBtn = () =>{
        listParm.productId='';
        listParm.feeSetName='';
        listParm.feeSetType =0;
        listParm.createUserId =0;
        getCustomerFeeSetList();
    }
    onMounted(() =>{
        getCustomerFeeSetList();
        getproductSelectList();
        getCustomertSelectList();
        getFeeSetTypeSelectList();
        getbranchCompanyCustomersList();
    })

    return{
        productSelectList,
        groupSelectList,
        orgSelectList,
        customerSelectList,
        feeSetTypeSelectList,
        customerFeeSetList,     
        listParm,
        getCustomerFeeSetList,
        sizeChange,
        currentChange,
        searchBtn,
        resetBtn
    }
};