// 通过code前几位获取指定基础数据项（当前版本）
export default {
    execute:async function(){
        console.log("通过code前几位获取指定基础数据项");
        if(arguments&&arguments[0]&&arguments[0][0]&&arguments[0][1]&&arguments[0][2]&&arguments[1]){
            let
            tablename = arguments[0][0].StaticValue//基础数据表名
            ,mdcodeArg = arguments[0][1]//基础数据code
            ,num =arguments[0][2].StaticValue
            ,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 lastCode = mdcode.substring(0,Number(num))
            let mdObject = await this.getMDObject(tablename,lastCode);
            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([]);
                });
        });
    }
}