| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | /** * 组成物相关数据 * * @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;};
 |