GetMDByCodeFull.js 2.36 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
// 通过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([]);
                });
        });
    }
}