import {show_message} from "../utils/tdesign";

/**
 * 撤销(返回选中项的id列表)
 */
export const getSelectedIds = (list: any[], condition: any = {status: 'NEW'}, key: string = 'is_checked') => {
    const ids: any[] = [];
    for (let i = 0; i < list.length; i++) {
        const item = list[i];
        if (item[key]) {
            // 循环条件列表
            const keys = Object.keys(condition);
            for (let j = 0; j < keys.length; j++) {
                const conditionKey = keys[j];
                if (item[conditionKey]) {
                    // 存在这个字段,值是否相等
                    if (item[conditionKey] !== condition[conditionKey]) {
                        show_message('所选撤销行不满足条件', 'error');
                        return;
                    } else {
                        // 等于
                        ids.push(item.id);
                    }
                }
            }
        }
    }
    if (!ids.length) {
        show_message('未选择行');
        return;
    }
    return ids;
}
