| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 | /** * 工料机汇总相关 * * @author CaiAoLin * @date 2017/6/15 * @version */let projectGLJSpread = null;let projectGLJSheet = null;// websocket所需let host = '';let socket = null;let roomId = 0;// 判定常量let materialIdList = [];let canNotChangeTypeId = [];let GLJTypeConst = [];// spreadjs载入数据所需let jsonData = [];let mixRatioConnectData = [];let mixRatioMap={};// 单价文件相关let usedUnitPriceInfo = {};let usedTenderList = [];let otherFileData = {};let currentTag = '';let isChanging = false;$(document).ready(function () {    $('#tab_gongliaoji').on('show.bs.tab', function (e) {        $(e.relatedTarget.hash).removeClass('active');        init();    });    slideResize($("#glj-main"), function() {        projectGLJSpread.sheetObj.spread.refresh();    });    // 单价文件切换弹框    $('#change-dj').on('shown.bs.modal', function () {        // 获取当前建设项数据        let projectName = projectInfoObj.projectInfo.fullFolder !== undefined &&            projectInfoObj.projectInfo.fullFolder.length > 0 ? projectInfoObj.projectInfo.fullFolder[0] : '';        $("#current-project-name").text(projectName);        // 获取切换单价文件相关数据        $.ajax({            url: '/glj/get-project-info',            type: 'post',            data: {project_id: scUrlUtil.GetQueryString('project')},            dataType: 'json',            success: function(response) {                if (response.err === 1) {                    alert('数据传输错误!');                    return false;                }                let data = response.data;                // 本项目中的单价文件                if (data.self.length > 0) {                    let selfFileHtml = '';                    for(let tmp of data.self) {                        let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';                        selfFileHtml += '<option'+ select +' value="'+ tmp.id +'">'+ tmp.name +'</option>';                    }                    $("#self-file").html(selfFileHtml);                }                // 其他建设项目数据                if (data.other.length > 0) {                    let otherProjectHtml = '';                    let otherFileHtml = '';                    for(let tmp of data.other) {                        otherProjectHtml += '<option value="'+ tmp.ID +'">'+ tmp.name +'</option>';                        otherFileData[tmp.ID] = tmp.unitPriceList;                        if (otherFileHtml !== '') {                            continue;                        }                        for(let unitPrice of tmp.unitPriceList) {                            otherFileHtml += '<option value="'+ unitPrice.id +'">'+ unitPrice.name +'</option>';                        }                    }                    $("#other-project").html(otherProjectHtml);                    $("#other-file").html(otherFileHtml);                }            }        });    });    // 单价文件另存为弹框    $("#file-save-as-dialog").on('shown.bs.modal', function() {        // 获取当前建设项数据        $("#save-as-name").val(usedUnitPriceInfo.name + '(复件)');    });    // 单价文件另存为操作    $("#save-as-confirm").click(function() {        let name = $("#save-as-name").val();        if (name === '') {            $("#save-as-tips").text('请填写单价文件名称').show();            return false;        }        if (isChanging) {            return false;        }        $.ajax({            url: '/glj/save-as',            type: 'post',            data: {name: name, project_id: scUrlUtil.GetQueryString('project')},            dataType: 'json',            error: function() {                isChanging = false;            },            beforeSend: function() {                isChanging = true;            },            success: function(response) {                isChanging = false;                if (response.err === 1) {                    let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';                    $("#save-as-tips").text(msg).show();                    return false;                }                $("#file-save-as-dialog").modal("hide");            }        });    });    // 从其他建设项目中复制 选择建设项目    $("#other-project").change(function() {        let projectId = $(this).val();        if (otherFileData[projectId] === undefined) {            return false;        }        let otherFileHtml = '';        for(let unitPrice of otherFileData[projectId]) {            otherFileHtml += '<option value="'+ unitPrice.id +'">'+ unitPrice.name +'</option>';        }        $("#other-file").html(otherFileHtml);    });    // 单价文件选项切换    $("input[name='change-type']").change(function() {        let type = $(this).val();        type = parseInt(type);        $("#change-dj .option").hide();        if (type === 0) {            $(".option.select").show();        } else {            $(".option.copy").show();        }    });    // 单价文件切换确认    $("#change-file-confirm").click(function() {        if (isChanging) {            return false;        }        let type = $("input[name='change-type']:checked").val();        type = parseInt(type);        let changeUnitPriceId = 0;        if (type === 0) {            // 从本项目中选择            changeUnitPriceId = $("#self-file").val();        } else {            // 从其他项目中复制            changeUnitPriceId = $("#other-file").val();        }        $('#change-dj').modal("hide");        $.bootstrapLoading.start();        $.ajax({            url: '/glj/change-file',            type: 'post',            data: {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId, type: type},            error: function() {                isChanging = false;                $.bootstrapLoading.end();            },            beforeSend: function() {                isChanging = true;            },            success: function(response) {                isChanging = false;                if (response.err === 1) {                    let msg = response.msg !== undefined ? response.msg : '未知错误';                    alert(msg);                    $.bootstrapLoading.end();                    return false;                }                projectObj.project.projectGLJ.loadData(function () {                    let projectGLJ = projectObj.project.projectGLJ;                    projectGLJ.loadCacheData();                    unitPriceFileInit();                    gljOprObj.refreshView();                    $.bootstrapLoading.end();                });            }        });    });    // 是否主动更改数据    $("#message").on('click', '#load-data', function() {        $("#message").html('正在加载...');        // 重新加载数据到缓存        projectObj.project.projectGLJ.loadData(function() {            projectObj.project.projectGLJ.loadCacheData();            $("#notify").slideUp('fast');        });    });    $('#pop-dj').popover({            placement:"bottom",            html:true,            trigger:"hover | focus",            content: getUsedTenderInfo        }    );});/** * 初始化数据 * * @return {void|boolean} */function init() {    projectObj.project.projectGLJ.loadData(function(data) {        if (jsonData.length <= 0) {            // 赋值            jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];            jsonData= filterProjectGLJ(jsonData);            jsonData = sortProjectGLJ(jsonData);            mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;            mixRatioMap = data.mixRatioMap !== undefined ? data.mixRatioMap : mixRatioMap;            host = data.constData.hostname !== undefined ? data.constData.hostname : '';            materialIdList = data.constData.materialIdList !== undefined ? data.constData.materialIdList : materialIdList;            roomId = data.constData.roomId !== undefined ? data.constData.roomId : roomId;            canNotChangeTypeId = data.constData.ownCompositionTypes !== undefined ?                data.constData.ownCompositionTypes : canNotChangeTypeId;            GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;            // 连接socket服务器            socketInit();            unitPriceFileInit();            setTimeout(spreadInit, 1);        } else {            projectObj.project.projectGLJ.loadCacheData();        }    });}/** * spreadjs相关初始化 * * @return {void} */function spreadInit() {    projectGLJSpread = new ProjectGLJSpread();    projectGLJSpread.successCallback = successTrigger;    projectGLJSheet = projectGLJSpread.init();    // 绑定单击事件    let lastRow = 0;    projectGLJSheet.bind(GC.Spread.Sheets.Events.CellClick, function (element, info) {        let currentRow = info.row;        if (currentRow === undefined || currentRow === lastRow) {            return;        }        if (currentTag !== 'mix-ratio' && currentTag !== 'machine') {            return;        }        let spread = currentTag === 'mix-ratio' ? mixRatioSpread : machineSpread;        if (spread === null) {            return;        }        let projectGLJId = projectGLJSheet.getActiveDataByField('id');        spread.getRatioData(projectGLJId);        lastRow = currentRow;    });    // 切换tab触发refresh    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {        currentTag = $(e.target).data('name');        if (currentTag === 'ration') {            projectGLJSheet.filterData('unit_price.type', []);        }    });    loadSize("glj-main", function() {        projectGLJSpread.sheetObj.spread.refresh();    });}/** * 单价文件相关初始化 * * @param {String} name * @param {Array} data * @return {void} */function unitPriceFileInit() {    let projectGLJ = projectObj.project.projectGLJ;    let data = projectGLJ.datas;     usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];    usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?        data.constData.usedUnitPriceInfo : {};    $("#used-name").text(usedUnitPriceInfo.name);    let usedCount = usedTenderList.length <= 0 ? 1 : usedTenderList.length;    $("#used-count").text(usedCount);}function getUsedTenderInfo() {   return usedTenderList.join("<br>");}/** * 成功事件 * * @param {string} field * @param {object} info * @return {void} */function successTrigger(field, info) {    let updateData = {};    switch (field) {        case 'unit_price.market_price':            // 计算价格            updateData = projectGLJSpread.priceCalculate(info);            // 触发websocket通知            socket.emit('dataNotify', JSON.stringify(info));            console.log(info);            break;        case 'supply':            // 供货方式更改成功后            projectGLJSpread.changeSupplyType(info);            break;    }    // 重新加载数据到缓存    projectObj.project.projectGLJ.loadData(function () {        projectObj.project.projectGLJ.loadCacheData();    });    // 更新定额工料机    gljOprObj.refreshView();}/** * socket.io相关初始化 * * @return {void} */function socketInit() {    if (socket === null) {        socket = io('http://'+ host +':3300');        socket.on('connect', function () {            socket.emit('join', roomId);            console.log('单价文件同步连接成功');        });    }    // 接收到改变    socket.on('dataChange', function(data) {        data = JSON.parse(data);        if (data.newValue === undefined) {            return false;        }        $("#message").html('市场单位已被修改,<a href="javascript:void(0);" id="load-data">点击加载</a>');        $("#notify").slideDown('fast');    });}//过滤消耗量为0的项目工料机function filterProjectGLJ(jsonData) {    if (jsonData.length > 0) {        // 不显示消耗量为0的数据        let tmpData = [];        for(let data of jsonData) {            if (data.quantity !== 0&&data.quantity !=='0') {                tmpData.push(data);            }        }        jsonData = tmpData;    }    return jsonData;}function sortProjectGLJ(jsonData) {    if (jsonData.length > 0){        jsonData = _.sortByAll(jsonData,[function (item) {            return item.unit_price.type+"";        },'code']);    }    return jsonData}
 |