import { reactive, computed, unref } from 'vue';

// TODO 处理重算弹窗
export default function useAddBillMainRecount(onClose: Function, onShow: Function, emit) {
    // 定义基础数据
    const state = reactive({
        form: {
            rateVersionId: '',
            id: 0
        }
    })

    const getRateVersionId = computed(() => {
        return state.form.rateVersionId
    })

    // 显示操作
    const show = (row) => {
        state.form.rateVersionId = String(row.rateVersionId)
        state.form.id = row.id
        onShow()
    }

    // 取消弹窗
    const hanleOnClose = () => {
        state.form.rateVersionId = ''
        state.form.id = 0
        onClose()
    }

    // 获取的数据
    const confirm = () => {
        emit("saveRecount", unref(state.form), hanleOnClose)//数据、事件
        // 取消弹窗
        hanleOnClose()
    }

    // 获取版本号
    const changeRateVersion = (rateVersionId) => {
        state.form.rateVersionId = rateVersionId
    }

    return {
        show,
        confirm,
        hanleOnClose,
        changeRateVersion,
        getRateVersionId,
        state
    }
}