import { QueryBusinessFp } from '@/services/go/ermcp/finance-review';
import { QryBussinessFpRsp, QueryBusinessFpReq } from '@/services/go/ermcp/finance-review/interface';
import { message } from 'ant-design-vue';
import { ref } from 'vue';


/**
 * 获取表格列表数据
 * @param type
 * @returns
 */
export function queryTableList(type: QueryBusinessFpReq) {
    // 加载状态
    const loading = ref<boolean>(false);
    // 表格数据
    const tableList = ref<QryBussinessFpRsp[]>([]);
    function queryTable() {
        return QueryBusinessFp(type)
            .then((res) => {
                tableList.value = res.map((e, i) => {
                    return { ...e, key: String(i) };
                }).sort((a, b) => {
                    if (a.applystatus === 1) {
                        return b.applystatus === 1 ? 0 : -1
                    } else {
                        return b.applystatus === 1 ? 1 : 0
                    }
                });
                loading.value = false;
                console.log('查询列表', tableList);
            })
            .catch((err) => {
                message.error(err);
                loading.value = false;
            });
    }
    return { loading, tableList, queryTable }
}



export type { QryBussinessFpRsp };
