import { Ermcp3SellBuyContract, Querytype } from '@/services/go/ermcp/purchase/interface';
import { QueryWareHouse } from '@/services/go/ermcp/sell';
import { message } from 'ant-design-vue';
import { ref } from 'vue';

/**
 * 获取表格列表数据
 * @param type
 * @returns
 */
export function queryTableList(type: Querytype) {
    // 加载状态
    const loading = ref<boolean>(false);
    // 表格数据
    const tableList = ref<Ermcp3SellBuyContract[]>([]);
    function queryTable() {
        QueryWareHouse({ querytype: type })
            .then((res) => {
                tableList.value = res.map((e, i) => {
                    return { ...e, key: String(i) };
                });
                loading.value = false;
            })
            .catch((err) => {
                message.error(err);
                loading.value = false;
            });
    }
    return { loading, tableList, queryTable }
}

export function handleEnumdic(text: number | string, record: Ermcp3SellBuyContract) {
    return text + record.enumdicname
}