/** * 组成物相关数据 * * @author CaiAoLin * @date 2017/10/27 * @version */ function Composition() { this.datas = null; this.isLoading = false; } /** * 加载数据 * * @param {function} callback * @return {boolean} */ Composition.prototype.loadData = function (callback = null) { let self = this; if (self.isLoading) { return false; } // 加载组成物数据 $.ajax({ url: '/glj/get-composition', type: 'post', dataType: 'json', data: {project_id: scUrlUtil.GetQueryString('project')}, error: function() { // alert('数据传输错误'); }, beforeSend: function() { self.isLoading = true; }, success: function(response) { self.isLoading = false; if (response.err === 1) { let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取组成物数据失败!'; alert(msg); return false; } self.datas = response.data; // 回调函数 if (callback !== null) { callback(response.data); } // 存入缓存 projectObj.project.composition = self; } }); }; /** * 获取对应code的组成物数据 * * @param {String} code * @param {Number} gljType * @return {Array} */ Composition.prototype.getCompositionByCode = function(code, gljType = 0) { let result = []; if (code === '') { return result; } if (gljType === 0) { return this.datas[code] !== undefined ? this.datas[code] : result; } for(let composition of this.datas[code]) { if (composition.glj_type === gljType) { result.push(composition); } } return result; }; Composition.prototype.getCompositionByGLJ = function (glj) { let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap; let projectGljs = projectObj.project.projectGLJ.datas.gljList; let connect_index = gljOprObj.getIndex(glj,gljKeyArray); let gljList=[]; if(mixRatioMap[connect_index]){ //说明是有组成物的类型 gljList = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs); } return gljList; }