import { QueryBusinessJs } from '@/services/go/ermcp/business-review';
import { QryBussinessJsRsp, QueryBusinessJsReq } from '@/services/go/ermcp/business-review/interface';
import { message } from 'ant-design-vue';
import { ref } from 'vue';

/**
 * 获取表格列表数据
 * @param type
 * @returns
 */
export function queryTableList(type: QueryBusinessJsReq) {
    // 加载状态
    const loading = ref<boolean>(false);
    // 表格数据
    const tableList = ref<QryBussinessJsRsp[]>([]);
    function queryTable() {
        return QueryBusinessJs(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 { QryBussinessJsRsp };
