import { api_UserDetailListFeeItem } from '@/api/usermoneysum/apiUserMoneySum';
import { DetailListFeeItemParam } from '@/api/usermoneysum/apiUserMoneySumModel';
import { reactive, nextTick } from 'vue';
/**
 * 费用费项明细
 */
function useQueryExpenseItemDetail(onClose: Function, onShow: Function) {
    // 表单数据
    const queryExpenseItemDetailForm = reactive<DetailListFeeItemParam>({
        moneyId: undefined,
        feeType: undefined,
        recountByLastFee: undefined,
        // validData: true
    })
    // 列表数据
    const dealData = reactive({
        mainList: [],
        // validData: [
        //     {
        //         value: true,
        //         label: '有效数据'
        //     },
        //     {
        //         value: false,
        //         label: '全部数据'
        //     }
        // ]
    })
    // 初始化列表数据
    const initList = async () => {
        const res = await api_UserDetailListFeeItem(queryExpenseItemDetailForm)
        if (res.code === 200) {
            dealData.mainList = res.data
        }
    }

    // 隐藏
    const onclose = () => {
        onClose()
    }
    // 显示
    const show = (data: Recordable) => {
        // console.log(data,":data");
        // 标题
        onShow()
        queryExpenseItemDetailForm.moneyId = data.moneyId
        queryExpenseItemDetailForm.feeType = data.feeType
        data.recountByLastFee ? 
        queryExpenseItemDetailForm.recountByLastFee = data.recountByLastFee :
        queryExpenseItemDetailForm.recountByLastFee = undefined
        nextTick(() => {
            initList()
        })
    }
    // 下拉框change事件
    const hanleChangeValidData = (val) => {
        initList()
    }

    return {
        dealData,
        queryExpenseItemDetailForm,
        show,
        onclose,
        hanleChangeValidData
    }
}

export {
    useQueryExpenseItemDetail
}
