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

    // 获取基础数据
    getMDObject(name, code, num) {
        let param = {}
        if (num == 1) {
            param = {
                "limit": 1,
                "offset": 0,
                "pagination": true,
                "tableName": name,
                "objectcode": code,
                "queryDataStructure": "ALL"//返回的接口类型
            }
        } else {
            param = {
                "limit": 1,
                "offset": 0,
                "pagination": true,
                "tableName": name,
                "code": code,
                "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([]);
                });
        });
    }
}