import { queryResultLoadingAndInfo } from "@/common/methods/request/resultInfo";
import { QueryAccMgrTaaccount } from "@/services/go/ermcp/account";
import { ErmcpTaAccountEx } from "@/services/go/ermcp/account/interface";
import { QueryTradeConfigTMP } from "@/services/go/ermcp/business-review";
import { ErmcpTradeConfigTMP } from "@/services/go/ermcp/business-review/interface";
import { ref } from "vue";

export function queryTableList() {
    // 加载状态
    const loading = ref<boolean>(false);
    // 表格数据
    const tableList = ref<ErmcpTaAccountEx[]>([]);
    function queryTable() {
        queryResultLoadingAndInfo(QueryAccMgrTaaccount, loading)
            .then((res: ErmcpTaAccountEx[]) => {
                tableList.value = res.map((e: ErmcpTaAccountEx) => {
                    e.subacclist = e.subacclist.filter(el => el.tradestatus !== 7)
                    return e
                }
                )
            })
    }
    return { loading, tableList, queryTable }
}

/**
 * 处理交易模板
 */
export function handleTradeTemplate() {
    // 保证金
    const marginList = ref<ErmcpTradeConfigTMP[]>([])
    // 手续费
    const feeList = ref<ErmcpTradeConfigTMP[]>([])
    function queryTemplate() {
        return QueryTradeConfigTMP().then(res => {
            marginList.value.length = 0
            feeList.value.length = 0
            res.forEach(el => {
                const { tradeconfigtmptype } = el
                if (tradeconfigtmptype === 1) { // 保证金
                    marginList.value.push(el)
                } else if (tradeconfigtmptype === 2) { // 手续费
                    feeList.value.push(el)
                }
            })
        })
    }
    return { marginList, feeList, queryTemplate }
}