// 通过code获取指定基础数据项（当前版本）
export default {
    execute:async function(){
        console.log("进入到GetMDByCode前端公式");
        if(arguments&&arguments[0]&&arguments[0][0]&&arguments[0][1]&&arguments[1]){
            let
            tablename = arguments[0][0].StaticValue//基础数据表名
            ,mdcodeArg = arguments[0][1]//基础数据code
            ,context = arguments[1];
            let mdcode = ""
            if(mdcodeArg instanceof BillDataNode){
                mdcode  = arguments[0][1].getResult().Value
            }else if(mdcodeArg  instanceof StaticDataNode ){
                mdcode = arguments[0][1].StaticValue
            }
            let mdObject = await this.getMDObject(tablename,mdcode);
            return mdObject;
            
        }else{
            GAMS.Common.messagePrompt('GetMDByCode公式：参数配置有误');
            return '';
        }
    },
    getResultType:function(){
        return FMR.ConstDataTypes.General;
    },

    // 获取基础数据
    getMDObject(name, code) {
        let param = {
            "limit": 1,
            "offset": 0,
            "pagination": true,
            "tableName": name,
            "code": code,//按code和name过滤
            "queryDataStructure": "ALL"//返回的接口类型
        }
        return new Promise((resolve, reject) => {
            let promise = GMS.$http.post("/baseData/data/list", param);
            promise
                .then((data) => {
                    if (data.data && data.data.rows && data.data.rows.length > 0) {
                        resolve(data.data.rows[0]);
                    } else {
                        resolve([]);
                    }
                })
                .catch((error) => {
                    resolve([]);
                });
        });
    }
}