import { QueryAreaStockApply } from '@/services/go/ermcp/inventory-review';
import { Ermcp3AreaStockApply, QueryAreaStockApplyReq } from '@/services/go/ermcp/inventory-review/interface';
import { message } from 'ant-design-vue';
import { ref } from 'vue';
/**
 * 获取表格列表数据
 * @param type
 * @returns
 */
export function queryTableList(type: QueryAreaStockApplyReq) {
    // 加载状态
    const loading = ref<boolean>(false);
    // 表格数据
    const tableList = ref<Ermcp3AreaStockApply[]>([]);
    function queryTable() {
        return QueryAreaStockApply(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 function handleName(record: Ermcp3AreaStockApply) {
    const { contracttype, buyusername, sellusername } = record;
    if (contracttype === 1) {
        // 采购
        return sellusername ? sellusername : '--'
    } else {
        return buyusername ? buyusername : '--'
    }
}

export type { Ermcp3AreaStockApply };
