zhongzewei преди 7 години
родител
ревизия
942199f91a

+ 54 - 0
web/building_saas/complementary_ration_lib/html/main.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+    <meta http-equiv="x-ua-compatible" content="ie=edge">
+    <title>定额库编辑器</title>
+    <link rel="stylesheet" href="/lib/bootstrap/css/bootstrap.min.css">
+   <!-- <link rel="stylesheet" href="css/bootstrap/themes.css">-->
+    <link rel="stylesheet" href="/web/building_saas/css/main.css">
+    <link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
+</head>
+
+<body>
+    <div class="header">
+        <nav class="navbar navbar-toggleable-lg navbar-light bg-faded p-0 ">
+            <span class="header-logo px-2">Smartcost</span>
+            <div class="navbar-text"></div>
+        </nav>
+    </div>
+    <div class="main">
+        <div class="content">
+            <div class="container-fluid">
+                <div class="row">
+                  <div class="col-md-8">
+                    <div class="warp-p2 mt-3">
+                      <table class="table table-hover table-bordered">
+                        <thead><tr><th>定额库名称</th></tr></thead>
+                        <tbody id="showArea">
+                        </tbody>
+                      </table>
+                    </div>
+                  </div>
+                </div>
+            </div>
+        </div>
+    </div>
+    <!-- JS. -->
+    <script src="/lib/popper/popper.min.js"></script>
+    <script src="/lib/jquery/jquery-3.2.1.min.js"></script>
+    <script src="/lib/bootstrap/bootstrap.min.js"></script>
+    <script src="/web/building_saas/js/global.js"></script>
+    <!-- zTree -->
+    <script type="text/javascript" src="/public/web/date_util.js"></script>
+    <script type="text/javascript" src="/public/web/common_ajax.js"></script>
+    <script type="text/javascript" src="/web/building_saas/complementary_ration_lib/js/main.js"></script>
+    <script type="text/javascript" src="/public/web/storageUtil.js"></script>
+</body>
+<script type="text/javascript">
+    let userID = '<%=userID %>';
+</script>
+
+</html>

+ 407 - 0
web/building_saas/complementary_ration_lib/js/annotation.js

@@ -0,0 +1,407 @@
+/**
+ * Created by Zhong on 2017/12/20.
+ */
+//附注
+let annotationOprObj = {
+    situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},
+    currentSituation: null,//本项适用情况
+    radios: $("input[name = 'fzRadios']"),
+    fzTableAll: $('#fzTableAll'),
+    fzTablePartial: $('#fzTablePartial'),
+    currentOprTr: null,
+    currentAnnotation: null,
+    addCon: $('#fzAddCon'),//勾选编码模态框
+    updateCon: $('#fzUpdateCon'),//编辑编码模态框
+    clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
+        let me = annotationOprObj;
+        if(txtarea.is(':focus')){
+            let annotation = txtarea.val();
+            if(annotation !== me.currentAnnotation){
+                jobContentOprObj.preTreeNode.data.annotation = annotation;
+                me.unbindEvents(txtarea);
+                txtarea.blur();
+                let updateCodes = [];
+                for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
+                    updateCodes.push(jobContentOprObj.currentRationItems[i].code);
+                    jobContentOprObj.currentRationItems[i].annotation = annotation;
+                }
+                me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
+                    me.bindAllEvents(txtarea);
+                });
+            }
+            else {
+                txtarea.blur();
+            }
+        }
+    },
+    getGroup: function (rationItems) {
+        let rst = [];//rst = [{jobContent: String, items: Array}]
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
+                let isExist = false;
+                for(let j = 0, jLen = rst.length; j < jLen; j++){
+                    if(rst[j].annotation === rationItems[i].annotation){
+                        isExist = true;
+                        rst[j].items.push(rationItems[i].code);
+                        break;
+                    }
+                }
+                if(!isExist){
+                    rst.push({annotation: rationItems[i].annotation, items: [rationItems[i].code]});
+                }
+            }
+        }
+        return rst;
+    },
+    hideTable: function (tableAll, tablePartial) {
+        if(tableAll){
+            tableAll.hide();
+        }
+        if(tablePartial){
+            tablePartial.hide();
+        }
+    },
+    //建table
+    buildTablePartial: function (table, group) {
+        let me = annotationOprObj;
+        table.empty();
+        let $thead = $("<thead><tr><th></th><th>编码</th><th>附注</th>/tr></thead>");
+        let $tbody = $("<tbody></tbody>");
+        let count = 1;
+        for(let i = 0, len = group.length; i < len; i++){
+            let $newTr = me.getNewTr($tbody, group[i].items, group[i].annotation);
+            $tbody.append($newTr);
+            count++;
+        }
+        let $trEnd = $("<tr><td>"+ count +"</td><td><a href data-toggle='modal' data-target='#fzEditBianma' class='m-0'>点击勾选编码</a></td><td><textarea class='form-control'></textarea></td></tr>");//勾选行
+        $($trEnd.children().children()[0]).bind('click', function () {
+            me.onclickFuncAdd($(this));
+            me.currentOprTr = $trEnd;
+            me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
+        });
+        $tbody.append($trEnd);
+        table.append($thead);
+        table.append($tbody);
+    },
+    //新增一行tr
+    getNewTr: function (tbody, codes, jobContent) {
+        let me = annotationOprObj;
+        let count = tbody.children().length > 0 ? tbody.children().length : 1;
+        let $textTd = $("<td></td>");
+        let $textarea = $("<textarea class='form-control'></textarea>");
+        $textarea.val(jobContent);
+        $textTd.append($textarea);
+        let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#fzEditBianmaQ' class='m-0'>编辑编码</a></td></tr>");
+        $tr.children().children().bind('click', function () {
+            me.currentOprTr = $tr;
+            me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
+            me.onclickFuncEdit($(this));
+        });
+        //文本变化;
+        $textarea.bind('change', function () {
+            let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
+            let annotation = $(this).val();
+            me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(codes, annotation), function () {
+                if(annotation.trim().length === 0){
+                    me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
+                }
+            });
+        });
+        $tr.append($textTd);
+        for(let i = 0, len = codes.length; i < len; i ++){
+            let $p = $("<p class='m-0'>" + codes[i] + "</p>");
+            $tr.children()[1].append($p[0]);
+        }
+        me.setTextareaHeight($textarea, codes.length + 1);
+        return $tr[0];
+    },
+    onclickFuncAdd: function (obj) {
+        let me = annotationOprObj;
+        let txtarea = $(obj.parent().parent().children().children()[1]);
+        let annotation = txtarea.val();
+        if(annotation.trim().length > 0){
+            let codesObj = me.getAddCodes(jobContentOprObj.currentRationItems);
+            me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
+            obj.attr('data-target', '#fzEditBianma');
+        }
+        else{
+            obj.attr('data-target', '');
+            alert("附注不能为空!");
+        }
+    },
+    onclickFuncEdit: function (obj) {
+        let me = annotationOprObj;
+        me.buildEditableCodesCon(jobContentOprObj.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
+    },
+    //获取编码td中的编码
+    getUpdateCodes: function (jq) {
+        let rst = [];
+        let nodes = jq.parent().children();
+        for(let i = 1, len = nodes.length; i < len; i++){
+            rst.push(nodes[i].textContent);
+        }
+        return rst;
+    },
+    //建一个编码checkbox Div
+    buildCodeOption: function (code, attr) {
+        let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
+        let $checkBox = $div.children().children();
+        if(attr){
+            $checkBox.attr(attr, true);
+        }
+        return $div;
+    },
+    //建修改编码弹窗
+    buildEditableCodesCon: function (rationItems, container, codes) {
+        let me = annotationOprObj;
+        let codeDivs = [];
+        container.empty();
+        for(let i = 0, len = codes.length; i < len; i++){
+            codeDivs.push({code: codes[i], attr: 'checked'});
+        }
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            if(codes.indexOf(rationItems[i].code) === -1){
+                if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
+                    codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
+                }
+                else{
+                    codeDivs.push({code: rationItems[i].code, attr: ''});
+                }
+            }
+        }
+        //排序
+        codeDivs.sort(function (a, b) {
+            let rst = 0;
+            if(a.code > b.code) rst = 1;
+            else if(a.code < b.code) rst = -1;
+            return rst;
+        });
+        for(let i = 0, len = codeDivs.length; i < len; i++){
+            container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
+        }
+    },
+    //建勾选编码弹窗
+    buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
+        let me = annotationOprObj;
+        container.empty();
+        for(let i = 0, len = checkedCodes.length; i < len; i++){
+            let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
+            container.append($codeDiv);
+        }
+        for(let i = 0, len = disabledCodes.length; i < len; i++){
+            let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
+            container.append($codeDiv);
+        }
+    },
+    getAddCodes: function (rationItems) {
+        let me = annotationOprObj;
+        let rst = {checkedCodes: [], disabledCodes: []};
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
+                rst.disabledCodes.push(rationItems[i].code);
+            }
+            else{
+                rst.checkedCodes.push(rationItems[i].code);
+            }
+        }
+        return rst;
+    },
+    //获取选择后的编码窗口的编码及状态
+    getCodesAfterS: function (checkNodes) {
+        let rst = {checked: [], unchecked: []};
+        for(let i = 0, len = checkNodes.length; i < len; i++){
+            if(checkNodes[i].checked){
+                rst.checked.push(checkNodes[i].value);
+            }
+            else if(!checkNodes[i].checked && !checkNodes[i].disabled){
+                rst.unchecked.push(checkNodes[i].value);
+            }
+        }
+        return rst;
+    },
+    setRadiosChecked: function (situation, radios) {
+        let me = annotationOprObj;
+        if(situation === me.situations.ALL){
+            radios[0].checked = true;
+            radios[1].checked = false;
+            $('#fzTxtareaAll').val(jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '');
+            me.currentAnnotation = jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '';
+            me.fzTableAll.show();
+            me.fzTablePartial.hide();
+        }
+        else if(situation === me.situations.PARTIAL){
+            radios[0].checked = false;
+            radios[1].checked = true;
+            me.fzTableAll.hide();
+            me.fzTablePartial.show();
+        }
+        else if(situation === me.situations.NONE){
+            radios[0].checked = false;
+            radios[1].checked = false;
+            me.fzTableAll.hide();
+            me.fzTablePartial.hide();
+        }
+    },
+    //radios是否可用,只有在定额章节树的底层节点才可用
+    setRadiosDisabled: function (val, radios) {
+        let me =annotationOprObj;
+        if(val){
+            radios[0].checked = false;
+            radios[1].checked = false;
+            me.currentSituation = me.situations.NONE;
+        }
+        radios.attr('disabled', val);
+    },
+    radiosChange: function (radios, tableAll, tablePartial) {
+        let me = annotationOprObj;
+        radios.change(function () {
+            let val = $("input[name = 'fzRadios']:checked").val();
+            let selectedNode = sectionTreeObj.tree.selected;
+            me.updateAnnoSituation(pageOprObj.rationLibId, selectedNode.getID(), val, function () {
+                selectedNode.data.annotationSituation = val;
+                me.currentSituation = val;
+                if(val === me.situations.ALL){
+                    let updateCodes = [];
+                    for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
+                        updateCodes.push(jobContentOprObj.currentRationItems[i].code);
+                    }
+                    me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
+                        me.currentAnnotation = '';
+                        $('#fzTxtareaAll').val('');
+                        tableAll.show();
+                        tablePartial.hide();
+                    });
+                }
+                else{
+                    me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
+                    tableAll.hide();
+                    tablePartial.show();
+                }
+            });
+        });
+    },
+    setTextareaHeight: function (textarea, nodesCount) {
+        const perHeight = 21.6;
+        textarea.height(nodesCount * 21.6);
+    },
+    bindEvents: function (txtarea) {
+        let me = annotationOprObj;
+        txtarea.bind('change', function () {
+            let annotation = txtarea.val();
+            let jqNodes = txtarea.parent().parent().children()[1].children;
+            let updateCodes = me.getUpdateCodes(jqNodes);
+            txtarea.attr('disabled', true);
+            me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
+                txtarea.attr('disabled', false);
+            });
+        });
+    },
+    bindAllEvents: function (txtarea) {
+        let me = annotationOprObj;
+        txtarea.bind('change', function () {
+            let met = this;
+            let annotation = $(met).val();
+            $(met).attr('disabled', true);
+            let updateCodes = [];
+            for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
+                updateCodes.push(jobContentOprObj.currentRationItems[i].code);
+                jobContentOprObj.currentRationItems[i].annotation = annotation;
+            }
+            me.currentAnnotation = annotation;
+            me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
+                $(met).attr('disabled', false);
+            });
+        });
+    },
+    unbindEvents: function (txtarea) {
+        txtarea.unbind();
+    },
+    //定额工作内容相关操作
+    rationAnnotationOpr: function (rationItems) {
+        let me = annotationOprObj;
+        me.setRadiosDisabled(rationItems.length > 0 ? false : true, me.radios);
+        me.setRadiosChecked(me.currentSituation, me.radios);
+        me.buildTablePartial(me.fzTablePartial, me.getGroup(rationItems));
+    },
+    getUpdateArr: function (updateCodes, annotation) {
+        let rst = [];
+        for(let i = 0, len = updateCodes.length; i < len; i++){
+            rst.push({code: updateCodes[i], annotation: annotation});
+        }
+        return rst;
+    },
+    bindAddConBtn: function () {
+        let me = annotationOprObj;
+        return function () {
+            let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
+            let $tbody = $('#fzTablePartial tbody');
+            let lastEle = $tbody[0].lastElementChild;
+            let txtare = lastEle.lastElementChild.children[0];
+            if(me.currentAnnotation.trim().length > 0){//工作内容不为空才可添加编码
+                let updateArr = me.getUpdateArr(codesObj.checked, me.currentAnnotation);
+                me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
+                    me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
+                    $(txtare).val('');
+                });
+            }
+            else{
+                alert("附注不能为空!");
+            }
+        }
+    },
+    bindUpdateConBtn: function () {
+        let me = annotationOprObj;
+        return function () {
+            let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
+            let updateC = me.getUpdateArr(codesObj.checked, me.currentAnnotation),
+                updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
+                updateArr = updateC.concat(updateUnC);
+            me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
+                me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
+            });
+        }
+    },
+    //更新缓存的定额
+    updateRationItem: function (rationItems, updateArr) {
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            for(let j = 0, jLen = updateArr.length; j < jLen; j++){
+                if(rationItems[i].code === updateArr[j].code){
+                    rationItems[i].annotation = updateArr[j].annotation;
+                    break;
+                }
+            }
+        }
+    },
+    updateAnnotation: function (repId, updateArr, callback){
+        let me = annotationOprObj;
+        $.ajax({
+            type: 'post',
+            url: 'api/updateAnnotation',
+            data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error){
+                    me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
+                    callback();
+                }
+            }
+        });
+    },
+    updateAnnoSituation: function (repId, nodeId, situation, callback) {
+        let me = annotationOprObj;
+        $.ajax({
+            type: 'post',
+            url: 'api/updateAnnoSituation',
+            data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error){
+                    if(callback){
+                        callback();
+                    }
+                }
+            }
+        })
+    }
+
+};

+ 645 - 0
web/building_saas/complementary_ration_lib/js/coe.js

@@ -0,0 +1,645 @@
+/**
+ * Created by CSL on 2017-05-18.
+ */
+//modiyied by zhong on 2017/9/21
+
+
+var pageObj = {
+    libID: null,
+    gljLibID: null,
+    initPage: function (){
+        $("#drirect-dinge").click(function(){
+            $(this).attr('href', "/rationRepository/ration" + "?repository=" + getQueryString("repository"))
+        });
+
+        $("#gongliao").click(function(){
+            $(this).attr('href', "/rationRepository/lmm" + "?repository=" + getQueryString("repository"))
+        });
+
+        var libID = getQueryString("repository");
+        var libName = storageUtil.getSessionCache("RationGrp","repositoryID_" + libID);
+        if (libName) {
+            var html = $("#rationname")[0].outerHTML;
+            html = html.replace("XXX定额库", libName);
+            $("#rationname")[0].outerHTML = html;
+        };
+        this.gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + libID);
+        this.libID = libID;
+        coeOprObj.buildSheet($('#mainSpread')[0]);
+        gljAdjOprObj.buildSheet($('#contentSpread')[0]);
+        coeOprObj.getCoeList();
+        gljAdjOprObj.getGljItemsOcc();
+
+    },
+    showData: function(sheet, setting, data) {
+        let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
+        sheet.setRowCount(data.length + 3);
+        for (let col = 0; col < setting.header.length; col++) {
+            var hAlign = "left", vAlign = "center";
+            if (setting.header[col].hAlign) {
+                hAlign = setting.header[col].hAlign;
+            } else if (setting.header[col].dataType !== "String"){
+                hAlign = "right";
+            }
+            if(setting.header[col].readOnly){
+                sheet.getRange(-1, col, -1, 1).locked(true);
+            }
+            else{
+                sheet.getRange(-1, col, -1, 1).locked(false);
+            }
+            vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
+            sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
+            if (setting.header[col].formatter) {
+                sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
+            }
+            for (let row = 0; row < data.length; row++) {
+                let val = data[row][setting.header[col].dataCode];
+                sheet.setValue(row, col, val, ch);
+            }
+        }
+        sheet.resumeEvent();
+        sheet.resumePaint();
+    }
+};
+
+let coeOprObj = {
+    workBook: null,
+    workSheet: null,
+    currentCoeList: [],
+    currentCoe: null,
+    currentMaxNo: null,
+    setting: {
+        header: [
+            {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
+            {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
+            {headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
+        ]
+    },
+    buildSheet: function (container) {
+        let me = coeOprObj;
+        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
+        me.workSheet = me.workBook.getSheet(0);
+        me.workSheet.options.isProtected = true;
+        me.onDelOpr(me.workBook, me.setting);
+        me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
+        me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
+        me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+    },
+    onSelectionChanged: function (sender, info) {
+        let me = coeOprObj, that = gljAdjOprObj;
+        if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
+            let row = info.newSelections[0].row;
+            if(row < me.currentCoeList.length){
+                me.currentCoe = me.currentCoeList[row];
+                that.currentGljAdjList = me.currentCoe.coes;
+                that.buildDynamicComboBox(that.workSheet);
+            }
+            else{
+                me.currentCoe = null;
+                that.currentGljAdjList = [];
+                that.buildBaseCell(that.workSheet);
+            }
+            //refresh & show coes
+            sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
+            me.workBook.focus(true);
+            that.show(that.currentGljAdjList);
+        }
+    },
+    onEditEnded: function (sender, args) {
+        let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
+        if(args.editingText && args.editingText.toString().trim().length > 0){
+            let inputT = args.editingText.toString().trim();
+            //update
+            if(args.row < me.currentCoeList.length){
+                let updateObj = me.currentCoeList[args.row];
+                if(updateObj[dataCode] != inputT){
+                    if(dataCode === 'serialNo'){
+                        if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
+                            me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
+                            updateObj[dataCode] = inputT;
+                            updateArr.push(updateObj);
+                            me.save([], updateArr, [], true);
+                        }
+                        else if(!me.isInt(inputT)){
+                            alert('编号只能为整数!');
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
+                        }
+                        else if(me.hasTisNo(me.currentCoeList, inputT)){
+                            alert('该编号已存在!');
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
+                        }
+                    }
+                    else {
+                        updateObj[dataCode] = inputT;
+                        updateArr.push(updateObj);
+                        me.save([], updateArr, [], true);
+                    }
+                }
+            }
+            //insert
+            else{
+                let newCoe = {};
+                newCoe.libID = pageObj.libID;
+                if(dataCode === 'serialNo'){
+                    if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
+                        me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
+                        newCoe[dataCode] = inputT;
+                        addArr.push(newCoe);
+                        me.save(addArr, [], [], true, function (result) {
+                            me.updateCurrentCoeList(result);
+                        });
+                    }
+                    else if(!me.isInt(inputT)){
+                        args.sheet.setValue(args.row, args.col, '');
+                        alert('编号只能为整数!');
+                    }
+                    else if(me.hasTisNo(me.currentCoeList, inputT)){
+                        args.sheet.setValue(args.row, args.col, '');
+                        alert('该编号已存在!');
+                    }
+                }
+                else{
+                    newCoe.serialNo = ++me.currentMaxNo;
+                    newCoe[dataCode] = inputT;
+                    addArr.push(newCoe);
+                    me.save(addArr, [], [], true, function (result) {
+                        me.updateCurrentCoeList(result);
+                    });
+                }
+            }
+        }
+    },
+    onClipboardPasting: function (sender, info) {
+        let me = coeOprObj, maxCol = info.cellRange.col + info.cellRange.colCount - 1;
+        if(maxCol > me.setting.header.length){
+            info.cancel = true;
+        }
+    },
+    onClipboardPasted: function (sender, info) {
+        let me = coeOprObj, addArr = [], updateArr = [];
+        let items = sheetCommonObj.analyzePasteData(me.setting, info);
+        let uniqItems = me.makeUniqItems(items);
+        for(let i = 0, len = uniqItems.length; i < len; i++){
+            let row = i + info.cellRange.row;
+            //update
+            if(row < me.currentCoeList.length){
+                let updateObj = me.currentCoeList[row];
+                for(let attr in uniqItems[i]){
+                    if(attr === 'serialNo'){
+                        if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
+                            me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
+                            updateObj[attr] = uniqItems[i][attr];
+                        }
+                    }
+                    else {
+                        updateObj[attr] = uniqItems[i][attr];
+                    }
+                }
+                updateArr.push(updateObj);
+            }
+            //insert
+            else {
+                if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
+                    me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
+                }
+                else {
+                    uniqItems[i].serialNo = ++me.currentMaxNo;
+                }
+                uniqItems[i].libID = pageObj.libID;
+                addArr.push(uniqItems[i]);
+            }
+        }
+        if(addArr.length > 0 || updateArr.length > 0){
+            me.save(addArr, updateArr, [], true, function (result) {
+                me.updateCurrentCoeList(result);
+            });
+        }
+    },
+    onDelOpr: function (workBook, setting) {
+        let me = coeOprObj, that = gljAdjOprObj;
+        workBook.commandManager().register('coeListDel', function () {
+            let deleteArr = [];
+            let sheet = workBook.getSheet(0);
+            let sels = sheet.getSelections();
+            let idx = sels[0].row;
+            for(let i = 0, len = sels.length; i < len; i++){
+                if(idx > sels[i].row){
+                    idx = sels[i].row;
+                }
+                if(sels[i].colCount === setting.header.length){//can del
+                    for(let r = 0, rLen = sels[i].rowCount; r < rLen; r++){
+                        let row = sels[i].row + r;
+                        if(row < me.currentCoeList.length){
+                            deleteArr.push({libID: me.currentCoeList[row].libID, ID: me.currentCoeList[row].ID});
+                        }
+                    }
+                    me.currentCoeList.splice(sels[i].row, sels[i].rowCount);
+                }
+            }
+            if(deleteArr.length > 0){
+                me.save([], [], deleteArr, true);
+                me.currentCoe = typeof me.currentCoeList[idx] !== 'undefined' ? me.currentCoeList[idx] : null;
+                that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : [];
+                gljAdjOprObj.show(that.currentGljAdjList);
+            }
+
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    //粘贴的数据,编号唯一化,去除编号重复的项
+    makeUniqItems: function (items) {
+        let rst = [];
+        for(let i = 0, len = items.length; i < len; i++){
+            if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
+                if(rst.length === 0){
+                    rst.push(items[i]);
+                }
+                else{
+                    let isExist = false;
+                    for(let j = 0, jLen = rst.length; j < jLen; j++){
+                        if(items[i].serialNo === rst[j].serialNo){
+                            isExist = true;
+                            break;
+                        }
+                    }
+                    if(!isExist){
+                        rst.push(items[i]);
+                    }
+                }
+            }
+            else {
+                rst.push(items[i]);
+            }
+        }
+        return rst;
+    },
+    isInt: function (num) {
+        return !isNaN(num) && num % 1 === 0;
+    },
+    hasTisNo: function (coeList, newSerialNo) {
+        let rst = false;
+        for(let i = 0, len = coeList.length; i < len; i++){
+            if(coeList[i].serialNo == newSerialNo){
+                rst = true;
+                break;
+            }
+        }
+        return rst;
+    },
+    updateCurrentCoeList: function (newCoeList) {
+        let me = coeOprObj;
+        if(newCoeList){
+            me.currentCoeList = me.currentCoeList.concat(newCoeList);
+        }
+    },
+    sortCoeList: function (coeList) {
+        coeList.sort(function (a, b) {
+            let rst = 0;
+            if(a.serialNo > b.serialNo) rst = 1;
+            else if(a.serialNo < b.serialNo) rst = -1;
+            return rst;
+        });
+    },
+    getCoeList: function () {
+        let me = coeOprObj;
+        $.ajax({
+            type: 'post',
+            url: '/rationRepository/api/getCoeList',
+            data: {libID: pageObj.libID},
+            dataType: 'json',
+            timeout:20000,
+            success: function (result) {
+                if(!result.error){
+                    me.currentCoeList = result.data;
+                    me.sortCoeList(me.currentCoeList);
+                    me.currentMaxNo =  me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
+                    pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
+                    me.workSheet.clearSelection();
+                }
+            },
+            error:function(err){
+                alert("内部程序错误!");
+            }
+        });
+    },
+    save: function (addArr, updateArr, deleteArr, refresh, callback) {
+        let me = coeOprObj;
+        $.ajax({
+            type:"POST",
+            url:"api/saveCoeList",
+            data: {data: JSON.stringify({addArr: addArr, updateArr: updateArr, deleteArr: deleteArr})},
+            dataType:"json",
+            timeout:5000,
+            success:function(result){
+                if (result.error) {
+                    alert(result.message);
+                } else{
+                    if(callback){
+                        if(result.message === 'mixed'){
+                            for(let i = 0, len = result.data.length; i < len; i++){
+                                if(result.data[i][0] === 'addSc'){
+                                    result.data = result.data[i][1];
+                                    break;
+                                }
+                            }
+                        }
+                        callback(result.data);
+                    }
+                    if(refresh){
+                        me.sortCoeList(me.currentCoeList);
+                        me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
+                        pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
+                    }
+                }
+            },
+            error:function(err){
+                alert("内部程序错误!");
+            }
+        });
+    }
+};
+
+let gljAdjOprObj = {
+    workBook: null,
+    workSheet: null,
+    currentGljAdjList: [],
+    gljList: [],//只含编号和名称的总工料机列表
+    setting: {
+        header: [
+            {headerName:"调整类型", headerWidth:100, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
+            {headerName:"工料机编码", headerWidth:100, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
+            {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
+            {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
+            {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
+        ],
+        comboItems: {
+            //调整类型下拉菜单
+            coeType: ['定额子目', '人工类', '材料类', '机械类', '主材类', '设备类', '单个工料机'],
+            //操作符下拉菜单
+            operator: ['+', '-', '*', '/', '=']
+        }
+    },
+    buildSheet: function (container) {
+        let me = gljAdjOprObj;
+        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
+        me.workSheet = me.workBook.getSheet(0);
+        me.workSheet.options.isProtected = true;
+        me.onDelOpr(me.workBook, me.setting);
+        me.workSheet.clearSelection();
+        me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
+        me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
+        me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
+        me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+    },
+    buildBaseCell: function (sheet) {
+        let me = gljAdjOprObj;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        let baseCell = GC.Spread.Sheets.CellTypes.Base();
+        sheet.getCell(-1, 0).cellType(baseCell);
+        sheet.getCell(-1, 3).cellType(baseCell);
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+    buildDynamicComboBox: function (sheet) {
+        let me = gljAdjOprObj;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        let dynamicCombo = sheetCommonObj.getDynamicCombo();
+        dynamicCombo.items(me.setting.comboItems.coeType);
+        let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
+        dynamicOprCombo.items(me.setting.comboItems.operator);
+        sheet.getCell(-1, 0).cellType(dynamicCombo);
+        sheet.getCell(-1, 3).cellType(dynamicOprCombo);
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+    onEnterCell: function (sender, args) {
+        args.sheet.repaint();
+    },
+    onEditStart: function (sender, args) {
+        let me = gljAdjOprObj;
+        if(!coeOprObj.currentCoe || args.row >= me.currentGljAdjList.length && args.col === 1
+            || args.row < me.currentGljAdjList.length && args.col === 1 && me.currentGljAdjList[args.row].coeType !== '单个工料机'){
+            args.cancel = true;
+        }
+    },
+    onEditEnded: function (sender, args) {
+        let me = gljAdjOprObj, isUpdate = false,
+            dataCode = me.setting.header[args.col].dataCode;
+        if(args.editingText && args.editingText.toString().trim().length > 0){
+            if(dataCode === 'amount' &&  isNaN(args.editingText)){
+                alert("只能输入数值!");
+                args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
+                    ? me.currentGljAdjList[args.row][dataCode] + '' : '');
+            }
+            else {
+                //update
+                if(args.row < me.currentGljAdjList.length && args.editingText.toString().trim() !== me.currentGljAdjList[args.row][dataCode]){
+                    let updateObj = me.currentGljAdjList[args.row];
+                    if(dataCode === 'gljCode' && typeof updateObj.coeType !== 'undefined' && updateObj.coeType === '单个工料机'){
+                        let gljName = me.getGljName(args.editingText, me.gljList);
+                        if(gljName){
+                            updateObj.gljCode = args.editingText;
+                            updateObj.gljName = gljName;
+                            isUpdate = true;
+                        }
+                        else {
+                            alert("不存在编号为"+ args.editingText +"的工料机");
+                        }
+                    }
+                    else if(dataCode !== 'gljCode') {
+                        isUpdate = true;
+                        updateObj[dataCode] = args.editingText;
+                    }
+                }
+                //insert
+                else if(args.row >= me.currentGljAdjList.length){
+                    isUpdate = true;
+                    let newAdjGlj = {};
+                    newAdjGlj[dataCode] = args.editingText;
+                    me.currentGljAdjList.push(newAdjGlj);
+                }
+                if(isUpdate){
+                    coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
+                        me.show(me.currentGljAdjList);
+                    });
+                }
+                else {
+                    args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
+                        ? me.currentGljAdjList[args.row][dataCode] + '' : '');
+                }
+            }
+        }
+    },
+    onClipboardPasting: function (sender, info) {
+
+    },
+    getValidPasteDatas: function (pasteItems, info) {
+        let me = gljAdjOprObj;
+        let rst = [];
+        for(let i = 0, len = pasteItems.length; i < len; i++){
+            let row = i + info.cellRange.row;
+            let validObj = {};
+            //update
+            if(row < me.currentGljAdjList.length){
+                let updateObj = me.currentGljAdjList[row];
+                if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
+                    let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
+                    if(pasteItems[i].coeType === '单个工料机' && gljName){
+                        validObj.coeType = pasteItems[i].coeType;
+                        validObj.gljCode = pasteItems[i].gljCode;
+                        validObj.gljName = gljName;
+                    }
+                    else if(pasteItems[i].coeType !== '单个工料机' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
+                        validObj.coeType = pasteItems[i].coeType;
+                    }
+                }
+                else if(typeof pasteItems[i].coeType === 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
+                    let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
+                    if(typeof updateObj.coeType !== 'undefined' && updateObj.coeType === '单个工料机' && gljName){
+                        validObj.gljCode = pasteItems[i].gljCode;
+                        validObj.gljName = gljName;
+                    }
+                }
+                else if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode === 'undefined'){
+                    if(me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
+                        validObj.coeType = pasteItems[i].coeType;
+                        if(validObj.coeType !== '单个工料机' && typeof updateObj.gljCode !== '单个工料机' && updateObj.gljCode.toString().trim().length > 0){
+                            validObj.gljCode = '';
+                            validObj.gljName = '';
+                        }
+                    }
+                }
+                else {
+                    if(typeof pasteItems[i].operator !== 'undefined' && me.setting.comboItems.operator.indexOf(pasteItems[i].operator) !== -1){
+                        validObj.operator = pasteItems[i].operator;
+                    }
+                    if(typeof pasteItems[i].amount !== 'undefined' && !isNaN(pasteItems[i].amount)){
+                        validObj.amount = pasteItems[i].amount;
+                    }
+                }
+            }
+            else {
+                if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
+                    let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
+                    if(pasteItems[i].coeType === '单个工料机' && gljName){
+                        validObj.coeType = pasteItems[i].coeType;
+                        validObj.gljCode = pasteItems[i].gljCode;
+                        validObj.gljName = gljName;
+                    }
+                    else if(pasteItems[i].coeType !== '单个工料机' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
+                        validObj.coeType = pasteItems[i].coeType;
+                    }
+                }
+                else if(typeof pasteItems[i].gljCode === 'undefined') {
+                    if(typeof pasteItems[i].coeType !== 'undefined' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
+                        validObj.coeType = pasteItems[i].coeType;
+                    }
+                    if(typeof pasteItems[i].operator !== 'undefined' && me.setting.comboItems.operator.indexOf(pasteItems[i].operator) !== -1){
+                        validObj.operator = pasteItems[i].operator;
+                    }
+                    if(typeof pasteItems[i].amount !== 'undefined' && !isNaN(pasteItems[i].amount)){
+                        validObj.amount = pasteItems[i].amount;
+                    }
+                }
+            }
+            if(Object.keys(validObj).length > 0){
+                rst.push(validObj);
+            }
+        }
+        return rst;
+    },
+    onClipboardPasted: function (sender, info) {
+        let me = gljAdjOprObj, row;
+        let items = sheetCommonObj.analyzePasteData(me.setting, info);
+        let validDatas = me.getValidPasteDatas(items, info);
+        for(let i = 0, len = validDatas.length; i < len; i++){
+            row = i + info.cellRange.row;
+            //update
+            if(row < me.currentGljAdjList.length){
+                let updateObj = me.currentGljAdjList[row];
+                for(let attr in validDatas[i]){
+                    updateObj[attr] = validDatas[i][attr];
+                }
+            }
+            //insert
+            else{
+                me.currentGljAdjList.push(validDatas[i]);
+            }
+        }
+        if(validDatas.length > 0){
+            coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
+                me.show(me.currentGljAdjList);
+            });
+        }
+        else {
+            me.show(me.currentGljAdjList);
+        }
+    },
+    onDelOpr: function (workBook, setting) {
+        let me = gljAdjOprObj;
+        workBook.commandManager().register('gljAdjDel', function () {
+            let sheet = workBook.getSheet(0);
+            let sels = sheet.getSelections();
+            let isUpdate = false;
+            for(let i = 0, len = sels.length; i < len; i++){
+                if(sels[i].colCount === setting.header.length){//can del
+                    if(sels[i].row < me.currentGljAdjList.length){
+                        isUpdate = true;
+                        me.currentGljAdjList.splice(sels[i].row, sels[i].rowCount);
+                    }
+                }
+            }
+            if(isUpdate){
+                coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
+                    me.show(me.currentGljAdjList);
+                });
+            }
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('gljAdjDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    getGljName: function (gljCode, gljList) {
+        let rst = null;
+        for(let i = 0, len = gljList.length; i < len; i++){
+            if(gljCode === gljList[i].code){
+                rst = gljList[i].name;
+                break;
+            }
+        }
+        return rst;
+    },
+    show: function (coes) {
+        let me = gljAdjOprObj;
+        pageObj.showData(me.workSheet, me.setting, coes)
+    },
+    getGljItemsOcc: function () {
+        let me = gljAdjOprObj;
+        $.ajax({
+            type: 'post',
+            url: '/stdGljRepository/api/getGljItemsOccupied',
+            data: {repId: pageObj.gljLibID, occupation: '-_id code name'},
+            dataType: 'json',
+            timeout: 5000,
+            success:function(result){
+                if (result.error) {
+                    alert(result.message);
+                } else{
+                    me.gljList = result.data;
+                }
+            },
+            error:function(err){
+                alert("内部程序错误!");
+            }
+        });
+    }
+};
+
+

+ 95 - 0
web/building_saas/complementary_ration_lib/js/explanatory.js

@@ -0,0 +1,95 @@
+/**
+ * Created by Zhong on 2017/12/20.
+ */
+//定额章节节点说明、计算规则
+let explanatoryOprObj = {
+    preTreeNode: null,
+    currentTreeNode: null,//定额章节树节点
+    currentExplanation: null,
+    currentRuleText: null,
+    setAttribute: function (preNode, currentNode, explanation, ruleText) {
+        let me = explanatoryOprObj;
+        me.preTreeNode = preNode;
+        me.currentTreeNode = currentNode;
+        me.currentExplanation = explanation;
+        me.currentRuleText = ruleText;
+    },
+    clickUpdate: function (exarea, ruarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
+        let me = explanatoryOprObj;
+        if(exarea.is(':focus')){
+            let explanation = exarea.val();
+            if(explanation !== me.currentExplanation){
+                me.preTreeNode.data.explanation = explanation;
+                me.unbindEvents(exarea, ruarea);
+                exarea.blur();
+                me.updateExplanation(pageOprObj.rationLibId, me.preTreeNode.getID(), explanation, function () {
+                    me.bindEvents(exarea, ruarea);
+                });
+            }
+        }
+        if(ruarea.is(':focus')){
+            let ruleText = ruarea.val();
+            if(ruleText !== me.currentRuleText){
+                me.preTreeNode.data.ruleText = ruleText;
+                me.unbindEvents(exarea, ruarea);
+                ruarea.blur();
+                me.updateRuleText(pageOprObj.rationLibId, me.preTreeNode.getID(), ruleText, function () {
+                    me.bindEvents(exarea, ruarea);
+                });
+            }
+        }
+    },
+    unbindEvents: function (exarea, ruarea) {
+        exarea.unbind();
+        ruarea.unbind();
+    },
+    bindEvents: function (exarea, ruarea) {
+        let me = explanatoryOprObj;
+        exarea.bind('change', function () {
+            let explanation = exarea.val();
+            let node = me.currentTreeNode;
+            exarea.attr('disabled', true);
+            me.updateExplanation(pageOprObj.rationLibId, node.getID(), explanation, function () {
+                node.data.explanation = explanation;
+                exarea.attr('disabled', false);
+            });
+        });
+        ruarea.bind('change', function () {
+            let ruleText = ruarea.val();
+            let node = me.currentTreeNode;
+            ruarea.attr('disabled', true);
+            me.updateRuleText(pageOprObj.rationLibId, node.getID(), ruleText, function () {
+                node.data.ruleText = ruleText;
+                ruarea.attr('disabled', false);
+            });
+        });
+    },
+    showText: function (exarea, ruarea, explanation, ruleText) {
+        exarea.val(explanation && explanation !== 'undefined' ? explanation : '');
+        ruarea.val(ruleText && ruleText !== 'undefined' ? ruleText : '');
+    },
+    //更新说明
+    updateExplanation: function (repId, nodeId, explanation, callback) {
+        $.ajax({
+            type: 'post',
+            url: 'api/updateExplanation',
+            data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, explanation: explanation},
+            dataType: 'json',
+            success: function () {
+                callback();
+            }
+        });
+    },
+    //更新计算规则
+    updateRuleText: function (repId, nodeId, explanation, callback) {
+        $.ajax({
+            type: 'post',
+            url: 'api/updateRuleText',
+            data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, ruleText: explanation},
+            dataType: 'json',
+            success: function () {
+                callback();
+            }
+        });
+    }
+};

+ 414 - 0
web/building_saas/complementary_ration_lib/js/jobContent.js

@@ -0,0 +1,414 @@
+/**
+ * Created by Zhong on 2017/12/20.
+ */
+//工作内容
+let jobContentOprObj = {
+    situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},//所有ALL(包括未定义本项工作内容)、部分PARTIA,不可用NONE(无定额时)
+    currentSituation: null,//本项适用情况
+    currentTreeNode: null,
+    preTreeNode: null,
+    radios: $("input[name = 'optionsRadios']"),
+    tableAll: $('#tableAll'),
+    tablePartial: $('#tablePartial'),
+    currentOprTr: null,
+    currentJobContent: null,
+    currentRationItems: null,
+    addCon: $('#addCon'),//勾选编码模态框
+    updateCon: $('#updateCon'),//编辑编码模态框
+    setAttribute: function (preNode, currentNode) {
+        let me = jobContentOprObj;
+        me.preTreeNode = preNode;
+        me.currentTreeNode = currentNode;
+    },
+    clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
+        let me = jobContentOprObj;
+        if(txtarea.is(':focus')){
+            let jobContent = txtarea.val();
+            if(jobContent !== me.currentJobContent){
+                me.preTreeNode.data.jobContent = jobContent;
+                me.unbindEvents(txtarea);
+                txtarea.blur();
+                let updateCodes = [];
+                for(let i = 0, len = me.currentRationItems.length; i < len; i++){
+                    updateCodes.push(me.currentRationItems[i].code);
+                    me.currentRationItems[i].jobContent = jobContent;
+                }
+                me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
+                    me.bindAllEvents(txtarea);
+                })
+            }
+            else {
+                txtarea.blur();
+            }
+        }
+    },
+    getGroup: function (rationItems) {
+        let rst = [];//rst = [{jobContent: String, items: Array}]
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
+                let isExist = false;
+                for(let j = 0, jLen = rst.length; j < jLen; j++){
+                    if(rst[j].jobContent === rationItems[i].jobContent){
+                        isExist = true;
+                        rst[j].items.push(rationItems[i].code);
+                        break;
+                    }
+                }
+                if(!isExist){
+                    rst.push({jobContent: rationItems[i].jobContent, items: [rationItems[i].code]});
+                }
+            }
+        }
+        return rst;
+    },
+    hideTable: function (tableAll, tablePartial) {
+        if(tableAll){
+            tableAll.hide();
+        }
+        if(tablePartial){
+            tablePartial.hide();
+        }
+    },
+    //建table
+    buildTablePartial: function (table, group) {
+        let me = jobContentOprObj;
+        table.empty();
+        let $thead = $("<thead><tr><th></th><th>编码</th><th>工作内容</th>/tr></thead>");
+        let $tbody = $("<tbody></tbody>");
+        let count = 1;
+        for(let i = 0, len = group.length; i < len; i++){
+            let $newTr = me.getNewTr($tbody, group[i].items, group[i].jobContent);
+            $tbody.append($newTr);
+            count++;
+        }
+        let $trEnd = $("<tr><td>"+ count +"</td><td><a href data-toggle='modal' data-target='#editBianma' class='m-0'>点击勾选编码</a></td><td><textarea class='form-control'></textarea></td></tr>");//勾选行
+        $($trEnd.children().children()[0]).bind('click', function () {
+            me.onclickFuncAdd($(this));
+            me.currentOprTr = $trEnd;
+            me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
+        });
+        $tbody.append($trEnd);
+        table.append($thead);
+        table.append($tbody);
+    },
+    //新增一行tr
+    getNewTr: function (tbody, codes, jobContent) {
+        let me = jobContentOprObj;
+        let count = tbody.children().length > 0 ? tbody.children().length : 1;
+        let $textTd = $("<td></td>");
+        let $textarea = $("<textarea class='form-control'></textarea>");
+        $textarea.val(jobContent);
+        $textTd.append($textarea);
+        let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#editBianmaQ' class='m-0'>编辑编码</a></td></tr>");
+        $tr.children().children().bind('click', function () {
+            me.currentOprTr = $tr;
+            me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
+            me.onclickFuncEdit($(this));
+        });
+        //文本变化;
+        $textarea.bind('change', function () {
+            let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
+            let jobContent = $(this).val();
+            me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(codes, jobContent), function () {
+                if(jobContent.trim().length === 0){
+                    me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
+                }
+            });
+        });
+        $tr.append($textTd);
+        for(let i = 0, len = codes.length; i < len; i ++){
+            let $p = $("<p class='m-0'>" + codes[i] + "</p>");
+            $tr.children()[1].append($p[0]);
+        }
+        me.setTextareaHeight($textarea, codes.length + 1);
+        return $tr[0];
+    },
+    onclickFuncAdd: function (obj) {
+        let me = jobContentOprObj;
+        let txtarea = $(obj.parent().parent().children().children()[1]);
+        let jobContent = txtarea.val();
+        if(jobContent.trim().length > 0){//工作内容不为空才可添加编码
+            let codesObj = me.getAddCodes(me.currentRationItems);
+            me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
+            obj.attr('data-target', '#editBianma');
+        }
+        else{
+            obj.attr('data-target', '');
+            alert("工作内容不能为空!");
+        }
+    },
+    onclickFuncEdit: function (obj) {
+        let me = jobContentOprObj;
+        me.buildEditableCodesCon(me.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
+    },
+    //获取编码td中的编码
+    getUpdateCodes: function (jq) {
+        let rst = [];
+        let nodes = jq.parent().children();
+        for(let i = 1, len = nodes.length; i < len; i++){
+            rst.push(nodes[i].textContent);
+        }
+        return rst;
+    },
+    //建一个编码checkbox Div
+    buildCodeOption: function (code, attr) {
+        let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
+        let $checkBox = $div.children().children();
+        if(attr){
+            $checkBox.attr(attr, true);
+        }
+        return $div;
+    },
+    //建修改编码弹窗
+    buildEditableCodesCon: function (rationItems, container,codes) {
+        let me = jobContentOprObj;
+        let codeDivs = [];
+        container.empty();
+        for(let i = 0, len = codes.length; i < len; i++){
+            codeDivs.push({code: codes[i], attr: 'checked'});
+        }
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            if(codes.indexOf(rationItems[i].code) === -1){
+                if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
+                    codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
+                }
+                else{
+                    codeDivs.push({code: rationItems[i].code, attr: ''});
+                }
+            }
+        }
+        //排序
+        codeDivs.sort(function (a, b) {
+            let rst = 0;
+            if(a.code > b.code) rst = 1;
+            else if(a.code < b.code) rst = -1;
+            return rst;
+        });
+        for(let i = 0, len = codeDivs.length; i < len; i++){
+            container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
+        }
+    },
+    //建勾选编码弹窗
+    buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
+        let me = jobContentOprObj;
+        container.empty();
+        for(let i = 0, len = checkedCodes.length; i < len; i++){
+            let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
+            container.append($codeDiv);
+        }
+        for(let i = 0, len = disabledCodes.length; i < len; i++){
+            let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
+            container.append($codeDiv);
+        }
+    },
+    getAddCodes: function (rationItems) {
+        let me = jobContentOprObj;
+        let rst = {checkedCodes: [], disabledCodes: []};
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
+                rst.disabledCodes.push(rationItems[i].code);
+            }
+            else{
+                rst.checkedCodes.push(rationItems[i].code);
+            }
+        }
+        return rst;
+    },
+    //获取选择后的编码窗口的编码及状态
+    getCodesAfterS: function (checkNodes) {
+        let rst = {checked: [], unchecked: []};
+        for(let i = 0, len = checkNodes.length; i < len; i++){
+            if(checkNodes[i].checked){
+                rst.checked.push(checkNodes[i].value);
+            }
+            else if(!checkNodes[i].checked && !checkNodes[i].disabled){
+                rst.unchecked.push(checkNodes[i].value);
+            }
+        }
+        return rst;
+    },
+    setRadiosChecked: function (situation, radios) {
+        let me = jobContentOprObj;
+        if(situation === me.situations.ALL){
+            radios[0].checked = true;
+            radios[1].checked = false;
+            $('#txtareaAll').val(me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '');
+            me.currentJobContent = me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '';
+            me.tableAll.show();
+            me.tablePartial.hide();
+        }
+        else if(situation === me.situations.PARTIAL){
+            radios[0].checked = false;
+            radios[1].checked = true;
+            me.tableAll.hide();
+            me.tablePartial.show();
+        }
+        else if(situation === me.situations.NONE){
+            radios[0].checked = false;
+            radios[1].checked = false;
+            me.tableAll.hide();
+            me.tablePartial.hide();
+        }
+    },
+    //radios是否可用,只有在定额章节树的底层节点才可用
+    setRadiosDisabled: function (val, radios) {
+        let me =jobContentOprObj;
+        if(val){
+            radios[0].checked = false;
+            radios[1].checked = false;
+            me.currentSituation = me.situations.NONE;
+        }
+        radios.attr('disabled', val);
+    },
+    radiosChange: function (radios, tableAll, tablePartial) {
+        let me = jobContentOprObj;
+        radios.change(function () {
+            let val = $("input[name = 'optionsRadios']:checked").val();
+            let selectedNode = sectionTreeObj.tree.selected;
+            me.updateSituation(pageOprObj.rationLibId, selectedNode.getID(), val, function () {
+                selectedNode.data.jobContentSituation = val;
+                me.currentSituation = val;
+                if(val === me.situations.ALL){
+                    let updateCodes = [];
+                    for(let i = 0, len = me.currentRationItems.length; i < len; i++){
+                        updateCodes.push(me.currentRationItems[i].code);
+                    }
+                    me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
+                        me.currentJobContent = '';
+                        $('#txtareaAll').val('');
+                        tableAll.show();
+                        tablePartial.hide();
+                    });
+                }
+                else{
+                    me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
+                    tableAll.hide();
+                    tablePartial.show();
+                }
+            });
+        });
+    },
+    setTextareaHeight: function (textarea, nodesCount) {
+        const perHeight = 21.6;
+        textarea.height(nodesCount * 21.6);
+    },
+    bindEvents: function (txtarea) {
+        let me = jobContentOprObj;
+        txtarea.bind('change', function () {
+            let jobContent = txtarea.val();
+            let jqNodes = txtarea.parent().parent().children()[1].children;
+            let updateCodes = me.getUpdateCodes(jqNodes);
+            txtarea.attr('disabled', true);
+            me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
+                txtarea.attr('disabled', false);
+            });
+        });
+    },
+    bindAllEvents: function (txtarea) {
+        let me = jobContentOprObj;
+        txtarea.bind('change', function () {
+            let met = this;
+            let jobContent = $(met).val();
+            $(met).attr('disabled', true);
+            let updateCodes = [];
+            for(let i = 0, len = me.currentRationItems.length; i < len; i++){
+                updateCodes.push(me.currentRationItems[i].code);
+                me.currentRationItems[i].jobContent = jobContent;
+            }
+            me.currentJobContent = jobContent;
+            me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
+                $(met).attr('disabled', false);
+            });
+        });
+    },
+    unbindEvents: function (txtarea) {
+        txtarea.unbind();
+    },
+    //定额工作内容相关操作
+    rationJobContentOpr: function (rationItems) {
+        let me = jobContentOprObj;
+        me.setRadiosDisabled(me.currentRationItems.length > 0 ? false : true, me.radios);
+        me.setRadiosChecked(me.currentSituation, me.radios);
+        me.buildTablePartial(me.tablePartial, me.getGroup(rationItems));
+    },
+    getUpdateArr: function (updateCodes, jobContent) {
+        let rst = [];
+        for(let i = 0, len = updateCodes.length; i < len; i++){
+            rst.push({code: updateCodes[i], jobContent: jobContent});
+        }
+        return rst;
+    },
+    bindAddConBtn: function () {
+        let me = jobContentOprObj;
+        return function () {
+            let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
+            let $tbody = $('#tablePartial tbody');
+            let lastEle = $tbody[0].lastElementChild;
+            let txtare = lastEle.lastElementChild.children[0];
+            if(me.currentJobContent.trim().length > 0){//工作内容不为空才可添加编码
+                let updateArr = me.getUpdateArr(codesObj.checked, me.currentJobContent);
+                me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
+                    me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
+                    $(txtare).val('');
+                });
+            }
+            else{
+                alert("工作内容不能为空!");
+            }
+        }
+    },
+    bindUpdateConBtn: function () {
+        let me = jobContentOprObj;
+        return function () {
+            let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
+            let updateC = me.getUpdateArr(codesObj.checked, me.currentJobContent),
+                updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
+                updateArr = updateC.concat(updateUnC);
+            me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
+                me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
+            });
+        }
+    },
+    //更新缓存的定额
+    updateRationItem: function (rationItems, updateArr) {
+        for(let i = 0, len = rationItems.length; i < len; i++){
+            for(let j = 0, jLen = updateArr.length; j < jLen; j++){
+                if(rationItems[i].code === updateArr[j].code){
+                    rationItems[i].jobContent = updateArr[j].jobContent;
+                    break;
+                }
+            }
+        }
+    },
+    updateJobContent: function (repId, updateArr, callback){
+        let me = jobContentOprObj;
+        $.ajax({
+            type: 'post',
+            url: 'api/updateJobContent',
+            data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, updateArr: JSON.stringify(updateArr)},
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error){
+                    me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
+                    callback();
+                }
+            }
+        });
+    },
+    updateSituation: function (repId, nodeId, situation, callback) {
+        let me = jobContentOprObj;
+        $.ajax({
+            type: 'post',
+            url: 'api/updateSituation',
+            data: {lastOpr: userAccount, repId: pageOprObj.rationLibId, nodeId: nodeId, situation: situation},
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error){
+                    if(callback){
+                        callback();
+                    }
+                }
+            }
+        })
+    }
+};

+ 659 - 0
web/building_saas/complementary_ration_lib/js/ration.js

@@ -0,0 +1,659 @@
+/**
+ * Created by Tony on 2017/4/28.
+ */
+
+$("#gongliao").click(function(){
+    $(this).attr('href', "/rationRepository/lmm" + "?repository=" + getQueryString("repository"))
+});
+
+$("#fuzhu").click(function(){
+    $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
+});
+const digital = {
+    gljPrc: -3,//计算定额基价时单个工料机价格取三位
+    rationBasePrc: -2,
+    consumeAmt: -3
+};
+let rationOprObj = {
+    workBook: null,
+    currentRations: {},
+    currentEditingRation: null,
+    currentSectionId: -1,
+    rationsCodes: [],
+    setting: {
+        header:[
+            {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
+            {headerName:"名称",headerWidth:280,dataCode:"name", dataType: "String"},
+            {headerName:"计量单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
+            {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
+            {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00",  hAlign: "right"},
+            {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
+            {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
+            {headerName:"显示名称(以%s表示参数)",headerWidth:280,dataCode:"caption", dataType: "String"},
+            {headerName:"取费专业",headerWidth:100,dataCode:"feeType", dataType: "Number", hAlign: "center"}
+        ],
+        view:{
+            comboBox:[
+                {row:-1,col:2,rowCount:-1,colCount:1}
+            ],
+            lockedCells:[
+                {row:-1,col:3,rowCount:-1, colCount:1}
+            ],
+            lockColumns: [
+                3, 4, 5, 6
+            ]
+        }
+    },
+    buildSheet: function(container) {
+        let rationRepId = getQueryString("repository");
+        let me = rationOprObj;
+        let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+        if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
+            alert("没有引用工料机库!");
+            window.location.href = "/rationRepository/main";
+        }
+        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
+        me.getRationsCodes(rationRepId);
+        me.rationDelOpr();
+        me.setCombo(me.workBook.getSheet(0), 'dynamic');
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
+    },
+    setCombo: function (sheet, combo) {
+        let me = rationOprObj;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        if(combo){
+            combo = sheetCommonObj.getDynamicCombo();
+            combo.items(rationUnits).itemHeight(10).editable(true);
+        }
+        sheet.getRange(-1, me.setting.view.comboBox[0].col, -1, 1).cellType(combo);
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+    onSelectionChanged: function (sender, info) {
+        if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
+            let row = info.newSelections[0].row;
+            let me = rationOprObj,
+                sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
+                sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
+                sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
+            sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
+            sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
+            sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
+            let cacheSection = me.getCache();
+            if (cacheSection && row < cacheSection.length) {
+                rationGLJOprObj.getGljItems(cacheSection[row], function () {
+                    me.workBook.focus(true);
+                });
+                rationCoeOprObj.getCoeItems(cacheSection[row], function () {
+                    me.workBook.focus(true);
+                });
+                rationAssistOprObj.getAssItems(cacheSection[row]);
+            }
+            else {
+                rationGLJOprObj.currentRationItem = null;
+            }
+            me.workBook.focus(true);
+        }
+    },
+
+    isInt: function (num) {
+        return !isNaN(num) && num % 1 === 0;
+    },
+    getCache: function() {
+        let me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
+        if (!(rst)) {
+            me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
+            rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
+        }
+        return rst;
+    },
+    updateCache: function(addArr, updateArr, removeIds, result) {
+        let me = this, cacheSection = me.getCache();
+        if (addArr.length > 0) {
+            me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
+            cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
+        }
+        for (let i = removeIds.length - 1; i >= 0; i--) {
+            for (let j = cacheSection.length - 1; j >= 0 ; j--) {
+                if (cacheSection[j]["ID"] == removeIds[i]) {
+                    cacheSection.splice(j,1);
+                }
+            }
+        }
+        if (result && result.data.ops && result.data.ops.length > 0) {
+            for (let i = 0; i < result.data.ops.length; i++) {
+                for (let j = 0; j < cacheSection.length; j++) {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
+                        cacheSection[j]["ID"] = result.data.ops[i]["ID"];
+                        cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
+                        cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
+                        cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
+                    }
+                }
+            }
+        }
+        for (let i = 0; i < updateArr.length; i++) {
+            for (let j = 0; j < cacheSection.length; j++) {
+                if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
+                    if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
+                        cacheSection[j] = updateArr[i];
+                    }
+                } else {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
+                        cacheSection[j] = updateArr[i];
+                    }
+                }
+            }
+        }
+        return cacheSection;
+    },
+    rationDelOpr: function () {
+        let me = rationOprObj;
+        me.workBook.commandManager().register('rationDelete', function () {
+            let rationSheet = me.workBook.getActiveSheet();
+            let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
+            let cacheSection = me.getCache();
+            if(sels.length > 0){
+                for(let sel = 0; sel < sels.length; sel++){
+                    if(sels[sel].colCount === me.setting.header.length){
+                        if(cacheSection){
+                            for(let i = 0; i < sels[sel].rowCount; i++){
+                                if(sels[sel].row + i < cacheSection.length){
+                                    removeArr.push(cacheSection[sels[sel].row + i].ID);
+                                    me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
+                                }
+                            }
+                        }
+                    }
+                    else{
+                        if(sels[sel].col === 0){
+                            $('#alertText').text("编号不能为空,修改失败!");
+                            $('#alertModalBtn').click();
+                            $('#alertModalCls').click(function () {
+                            });
+                            $('#alertModalCof').click(function () {
+                            })
+                        }
+                        else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
+                            if(cacheSection){
+                                for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
+                                    if(sels[sel].row + i < cacheSection.length){
+                                        for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
+                                            if(lockCols.indexOf(col) === -1){
+                                                cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
+                                            }
+                                        }
+                                    }
+                                    if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
+                                        updateArr.push(cacheSection[sels[sel].row + i]);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if(updateArr.length > 0 || removeArr.length > 0){
+                me.mixUpdate = 1;
+                me.mixDel = removeArr.length > 0 ? 1 : 0;
+                me.mixUpdateRequest(updateArr, [], removeArr);
+            }
+
+        });
+        me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    onLeaveCell: function (sender, args) {
+        let me = rationOprObj;
+        me.lastCol = me.setting.header[args.col];
+    },
+    onEnterCell: function (sender, args) {
+        let me = rationOprObj;
+        if(me.setting.header[args.col]['dataCode'] === 'unit' || me.lastCol.dataCode === 'unit'){
+            args.sheet.repaint();
+        }
+        me.cellRowIdx = args.row;
+        let isHasData = false;
+        if(me.addRationItem){
+            for(let i=0; i<me.setting.header.length; i++){
+                if(me.addRationItem[me.setting.header[i].dataCode]){
+                    isHasData = true;
+                    break;
+                }
+            }
+        }
+        if(isHasData){
+            if(me.editingRowIdx !== me.cellRowIdx) {
+                let focusToCol = !me.addRationItem.code ? 0 : -1;
+                if(focusToCol !== -1){
+                    $('#rationAlertBtn').click();
+                    $('#rationAlertCac').click(function () {
+                        me.addRationItem = null;
+                        for(let col=0; col<me.setting.header.length; col++){
+                            me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
+                        }
+                    });
+                    $('#rationAlertCls').click(function () {
+                        me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
+                    });
+                    $('#rationAlertCof').click(function () {
+                        me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
+                    });
+                }
+            }
+        }
+    },
+    onCellEditStart: function(sender, args) {
+        let me = rationOprObj;
+        if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
+            args.cancel = true;
+        }
+        else{
+            let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
+            me.currentEditingRation = rObj;
+            let cacheSection = me.getCache();
+            if (cacheSection) {
+                for (let j = 0; j < cacheSection.length; j++) {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
+                        rObj["ID"] = cacheSection[j]["ID"];
+                        break;
+                    }
+                }
+            }
+        }
+    },
+    onCellEditEnd: function(sender, args) {
+        let me = rationOprObj, rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
+            updateArr = [], addArr = [];
+        let dataCode = me.setting.header[args.col].dataCode;
+        me.editingRowIdx = args.row;
+        if (me.currentEditingRation["ID"]) {
+            if((!args.editingText || args.editingText.toString().trim().length === 0) && args.col === 0){
+                args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode] + '');
+            }
+            else {
+                rObj["ID"] = me.currentEditingRation["ID"];
+                if(me.currentEditingRation[dataCode] !== rObj[dataCode]){
+                    me.addRationItem = rObj;
+                    if(dataCode === 'code'){
+                        if(me.rationsCodes.indexOf(rObj.code) === -1){
+                            me.rationsCodes.splice(me.rationsCodes.indexOf(rObj.code), 1);
+                            me.rationsCodes.push(rObj.code);
+                            updateArr.push(rObj);
+                        }
+                        else{
+                            alert("编码已存在!");
+                            args.sheet.setValue(args.row, args.col, me.currentEditingRation[dataCode]);
+
+                        }
+                    }
+                    else if(dataCode === 'feeType'){//取费专业控制为整数
+                        if(me.isInt(rObj[dataCode])){
+                            updateArr.push(rObj);
+                        }
+                        else {
+                            rObj[dataCode] = '';
+                            args.sheet.setValue(args.row, args.col, typeof me.currentEditingRation[dataCode] !== 'undefined' && me.currentEditingRation[dataCode] ? me.currentEditingRation[dataCode] : '');
+                        }
+                    }
+                    else{
+                        updateArr.push(rObj);
+                    }
+                }
+            }
+        }
+        else if(!me.currentEditingRation["ID"]) {
+            if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
+                //addArr.push(rObj);
+                me.addRationItem = rObj;
+                if(rObj.code && rObj.code.toString().trim().length > 0){
+                    if(me.rationsCodes.indexOf(rObj.code) === -1){
+                        //jobContent
+                        if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
+                            rObj.jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
+                        }
+                        if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
+                            rObj.annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
+                        }
+                        me.setInitPrc(rObj);
+                        addArr.push(rObj);
+                        me.rationsCodes.push(rObj.code);
+                        me.addRationItem = null;
+                    }
+                    else{
+                        alert('编码已存在!');
+                        me.workBook.getSheet(0).setValue(args.row, args.col, '');
+                    }
+                }
+                else if(rObj.code && rObj.code.toString.trim().length === 0){
+                    me.workBook.getSheet(0).setValue(args.row, args.col, '');
+                }
+            }
+        }
+        if (updateArr.length > 0 || addArr.length > 0) {
+            me.currentEditingRation = null;
+            me.mixUpdate = 1;
+            me.mixUpdateRequest(updateArr, addArr, []);
+        }
+    },
+    canPasted: function (beginCol, maxCol) {
+        let rst = false;
+        if(maxCol < 3 || beginCol > 6){
+            rst = true;
+        }
+        return rst;
+    },
+    onClipboardPasting: function(sender, args) {
+        let me = rationOprObj;
+        let maxCol = args.cellRange.col + args.cellRange.colCount -1;
+        if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
+            args.cancel = true;
+        }
+    },
+    //todo: overwrite?
+    onClipboardPasted: function(e, info) {
+        let me = rationOprObj;
+        let cacheSection = me.getCache();
+        let updateArr = [], addArr = [];
+        let items = sheetCommonObj.analyzePasteData(me.setting, info);
+        for (let i = 0; i < items.length; i++) {
+            let rowIdx = info.cellRange.row + i;
+            if (cacheSection) {
+                if(!me.isValidUnit(items[i], rationUnits)){//无效单位
+                    items[i].unit = rowIdx < cacheSection.length  && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
+                }
+                if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
+                    if(me.rationsCodes.indexOf(items[i].code) === -1){
+                        //jobConten
+                        if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
+                            items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
+                        }
+                        if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
+                            items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
+                        }
+                        me.setInitPrc(items[i]);
+                        addArr.push(items[i]);
+                        me.rationsCodes.push(items[i].code);
+                    }
+                    else{
+                        me.workBook.getSheet(0).setValue(rowIdx, 0, '');
+                    }
+                }
+                else if(cacheSection[rowIdx]){
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
+                            items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
+                        }
+                    }
+                    if(items[i].feeType && !me.isInt(items[i].feeType)){
+                        items[i].feeType = '';
+                        me.workBook.getSheet(0).setValue(rowIdx, 8, '');
+                    }
+                    if(info.cellRange.col === 0){
+                        if(me.rationsCodes.indexOf(items[i].code) === -1){
+                            items[i].ID = cacheSection[rowIdx].ID;
+                            updateArr.push(items[i]);
+                        }
+                        else{
+                            me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
+                        }
+                    }
+                    else{
+                        items[i].ID = cacheSection[rowIdx].ID;
+                        updateArr.push(items[i]);
+                    }
+                }
+
+            } else {
+                if(!me.isValidUnit(items[i], rationUnits)){//无效单位
+                    items[i].unit = '';
+                }
+                //add
+                if(info.cellRange.col === 0){
+                    //是否含有已存在的编号
+                        if(me.rationsCodes.indexOf(items[i].code) === -1){
+                            //jobConten
+                            if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.ALL){
+                                items[i].jobContent = jobContentOprObj.currentJobContent ? jobContentOprObj.currentJobContent : '';
+                            }
+                            if(annotationOprObj && annotationOprObj.currentSituation === annotationOprObj.situations.ALL){
+                                items[i].annotation = annotationOprObj.currentAnnotation ? annotationOprObj.currentAnnotation : '';
+                            }
+                            me.setInitPrc(items[i]);
+                            addArr.push(items[i]);
+                        }
+                }
+            }
+        };
+         if (updateArr.length > 0 || addArr.length > 0) {
+             me.mixUpdate = 1;
+            me.mixUpdateRequest(updateArr, addArr, []);
+        }
+        else{
+             me.getRationItems(me.currentSectionId);
+         }
+    },
+    setInitPrc: function (obj) {
+        obj.labourPrice = 0;
+        obj.materialPrice = 0;
+        obj.machinePrice = 0;
+        obj.basePrice = 0;
+    },
+    isValidUnit: function (rationObj, validUnits) {
+        let rst = true;
+        if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
+            rst = false;
+        }
+        return rst;
+    },
+    getRationsCodes: function (repId) {
+        let me = rationOprObj;
+        $.ajax({
+            type: 'post',
+            url: 'api/getRationsCodes',
+            data: {data: JSON.stringify({repId: repId})},
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error){
+                    me.rationsCodes = result.data;
+                }
+            }
+        })
+    },
+    mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
+        let me = rationOprObj;
+        me.saveInString(updateArr);
+        $.ajax({
+            type:"POST",
+            url:"api/mixUpdateRationItems",
+            data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
+            dataType:"json",
+            cache:false,
+            timeout:20000,
+            success:function(result){
+                if (result.error) {
+                    alert('error');
+                    me.getRationItems(me.currentSectionId);
+                } else {
+                    let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
+                    cacheSection.sort(function(a, b){
+                        let rst = 0;
+                        if (a.code > b.code) rst = 1
+                        else if (a.code < b.code) rst = -1;
+                        return rst;
+                    });
+                    //jobContent
+                    if(jobContentOprObj ){
+                        jobContentOprObj.currentRationItems = cacheSection;
+                        jobContentOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, jobContentOprObj.radios);
+                        if(cacheSection.length === 0){
+                            jobContentOprObj.updateSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
+                        }
+                        jobContentOprObj.setRadiosChecked(jobContentOprObj.currentSituation, jobContentOprObj.radios);
+                        if(jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
+                            jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(cacheSection));
+                        }
+                    }
+                    if(annotationOprObj ){
+                        annotationOprObj.setRadiosDisabled(cacheSection.length > 0 ? false : true, annotationOprObj.radios);
+                        if(cacheSection.length === 0){
+                            annotationOprObj.updateAnnoSituation(pageOprObj.rationLibId, me.currentSectionId, 'NONE');
+                        }
+                        annotationOprObj.setRadiosChecked(annotationOprObj.currentSituation, annotationOprObj.radios);
+                        if(annotationOprObj.currentSituation === annotationOprObj.situations.PARTIAL){
+                            annotationOprObj.buildTablePartial(annotationOprObj.fzTablePartial, annotationOprObj.getGroup(cacheSection));
+                        }
+                    }
+                    me.showRationItems(me.currentSectionId);
+                    me.mixUpdate = 0;
+                    me.mixDel = 0;
+                }
+                if(callback) callback();
+            },
+            error:function(){
+            }
+        });
+    },
+    getRationItems: function(sectionID){
+        if (sectionID != -1) {
+            let me = rationOprObj;
+            me.mixUpdate = 0;
+            me.currentSectionId = sectionID;
+            if (me.currentRations["_SEC_ID_" + sectionID]) {
+                //jobContent--
+                jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
+                jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
+                //annotation
+                annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
+                me.showRationItems(sectionID);
+            } else {
+                CommonAjax.post('api/getRationItems', {rationRepId: pageOprObj.rationLibId, sectionId: sectionID}, function (rstData) {
+                    me.currentRations["_SEC_ID_" + sectionID] = rstData;
+                    me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
+                    //job--
+                    jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
+                    jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
+                    //annotation
+                    annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
+                    me.showRationItems(sectionID);
+                });
+         /*       $.ajax({
+                    type:"POST",
+                    url:"api/getRationItems",
+                    data:{"rationRepId": pageOprObj.rationLibId, "sectionID": sectionID},
+                    dataType:"json",
+                    cache:false,
+                    timeout:10000,
+                    success:function(result){
+                        if (result) {
+                            me.currentRations["_SEC_ID_" + sectionID] = result.data;
+                            me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
+                            //job--
+                            jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
+                            jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
+                            //annotation
+                            annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
+                            me.showRationItems(sectionID);
+                        }
+                    },
+                    error:function(err){
+                        alert(err);
+                    }
+                })*/
+            }
+        }
+    },
+    showRationItems: function(sectionID){
+        let me = rationOprObj,
+            sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
+            sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
+            sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
+        if (me.workBook) {
+            if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
+                let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
+                sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
+                sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
+                //combo
+                //sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
+                //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
+                if(me.mixDel === 1){
+                    let row = me.workBook.getSheet(0).getSelections()[0].row;
+                    if (cacheSection && row < cacheSection.length) {
+                        sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
+                        sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
+                        sheetCommonObj.cleanData(sheetAss, settingAss, -1);
+                        rationGLJOprObj.getGljItems(cacheSection[row]);
+                        rationCoeOprObj.getCoeItems(cacheSection[row]);
+                        rationAssistOprObj.getAssItems(cacheSection[row]);
+                    }
+                    else {
+                        rationGLJOprObj.currentRationItem = null;
+                        sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
+                        sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
+                        sheetCommonObj.cleanData(sheetAss, settingAss, -1);
+                        sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
+                    }
+                }
+
+            } else {
+                sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
+                //--sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
+                //清除ration数据及工料机数据
+                rationGLJOprObj.currentRationItem = null;
+                sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+                sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
+                sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
+                sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
+            }
+           //--- me.workBook.focus(true);
+        }
+        sectionTreeObj.workBook.focus(true);
+    },
+    sortByCode: function(arr){
+        function compare(){
+            return function (a, b) {
+                let rst = 0;
+                if (a.code > b.code) {
+                    rst = 1;
+                }
+                else if (a.code < b.code) {
+                    rst = -1;
+                }
+                return rst;
+            }
+        }
+        arr.sort(compare());
+    },
+    saveInString(datas){
+        for(let i = 0, len = datas.length; i < len; i++){
+            let data = datas[i];
+            if(data.labourPrice !== undefined && data.labourPrice){
+                data.labourPrice = data.labourPrice.toString();
+            }
+            if(data.materialPrice !== undefined && data.materialPrice){
+                data.materialPrice = data.materialPrice.toString();
+            }
+            if(data.machinePrice !== undefined && data.machinePrice){
+                data.machinePrice = data.machinePrice.toString();
+            }
+            if(data.basePrice !== undefined && data.basePrice){
+                data.basePrice = data.basePrice.toString();
+            }
+            if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
+                for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
+                    let raGljObj = data.rationGljList[j];
+                    if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
+                        raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
+                    }
+                }
+            }
+        }
+    }
+}

+ 49 - 0
web/building_saas/complementary_ration_lib/js/rationUnits.js

@@ -0,0 +1,49 @@
+/**
+ * Created by Zhong on 2017/9/8.
+ * 定额列表单位下拉表
+ */
+let rationUnits =[
+    'm',
+    'km',
+    'm2',
+    'm3',
+    'kg',
+    't',
+    '10m',
+    '10m2',
+    '10m3',
+    '100m',
+    '100m2',
+    '100m3',
+    '1000m2',
+    '1000m3',
+    'à·km',
+    '总额',
+    '月',
+    '项',
+    '处',
+    '个',
+    '根',
+    '棵',
+    '块',
+    '每一试桩',
+    '桥长米',
+    '公路公里',
+    '株',
+    '组',
+    '座',
+    '元',
+    '工日',
+    '套',
+    '台班',
+    '艘班',
+    'm/处',
+    'm/道',
+    'm/座',
+    'm2/m',
+    'm3/m',
+    'm3/处',
+    '根/米',
+    '亩',
+    'm3/m2'
+];

+ 194 - 0
web/building_saas/complementary_ration_lib/js/ration_assist.js

@@ -0,0 +1,194 @@
+/**
+ * Created by CSL on 2017-06-14.
+ */
+var rationAssistOprObj = {
+    sheet: null,
+    libID: null,
+    ration: null,
+    setting: {
+        header:[
+            {headerName:"调整名称",headerWidth:200,dataCode:"name", dataType: "String", hAlign: "left"},
+            {headerName:"辅助定额号",headerWidth:120,dataCode:"assistCode", dataType: "String", hAlign: "center"},
+            {headerName:"标准值",headerWidth:100,dataCode:"stdValue", dataType: "String", hAlign: "right"},
+            {headerName:"步距",headerWidth:100,dataCode:"stepValue", dataType: "String", hAlign: "right"},
+            {headerName:"精度",headerWidth:80,dataCode:"decimal",  dataType: "String", hAlign: "right"},
+            {headerName:"进位方式",headerWidth:100,dataCode:"carryBit", dataType: "String", hAlign: "center"},
+            {headerName:"最小值",headerWidth:100,dataCode:"minValue", dataType: "String", hAlign: "right"},
+            {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "String", hAlign: "right"}
+        ],
+        view:{},
+        comboItems: ["四舍五入", "进一"]
+    },
+
+    buildSheet: function(sheet) {
+        var me = this;
+        me.sheet = sheet;
+        me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        if (me.libID == undefined){me.libID = getQueryString('repository')};
+
+        sheetCommonObj.initSheet(me.sheet, me.setting, 30);
+
+        me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+        me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
+        me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
+        me.sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
+    },
+
+    onEnterCell: function (sender, args) {
+        let me = rationAssistOprObj;
+        args.sheet.repaint();
+        let cellType = args.sheet.getCellType(args.row, 5);
+        if(cellType.typeName !== 'undefined' && cellType.typeName === '1'){
+          //  sheetCommonObj.setStaticCombo(args.sheet, 0, 5, 0, me.setting.comboItems, false);
+            sheetCommonObj.setDynamicCombo(args.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+        }
+    },
+
+    onClipboardPasting: function(sender, args) {
+        let me = rationAssistOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if (!me.ration) {
+            args.cancel = true;
+        }
+    },
+
+    onClipboardPasted: function(e, info) {
+        var me = rationAssistOprObj;
+        if (!me.ration) {return;};
+        var tempArr = sheetCommonObj.analyzePasteData(me.setting, info);
+        var assList = me.ration.rationAssList;
+        if (assList == undefined) {
+            me.ration.rationAssList = tempArr;
+        }else{
+            assList = assList.concat(tempArr);
+            me.ration.rationAssList = assList;
+        };
+
+        rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+            me.sheet.getParent().focus(true);
+        });
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+        //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, me.ration.rationAssList.length, me.setting.comboItems, false, false);
+        sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+        sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
+    },
+
+    onEditStarting: function (sender, args) {
+        let me = rationAssistOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(!me.ration){
+            args.cancel = true;
+        }
+    },
+
+    onEditEnded: function(sender, args){
+        var me = rationAssistOprObj;
+        if (!me.ration) {return;};
+        if(typeof me.ration.rationAssList === 'undefined'){
+            me.ration.rationAssList = [];
+        }
+        var assList = me.ration.rationAssList;
+        var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
+        let dataCode = me.setting.header[args.col].dataCode;
+        if((args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7)
+            && args.editingText && args.editingText.toString().trim().length > 0 && isNaN(args.editingText)){
+            args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : '');
+            alert(me.setting.header[args.col].headerName + '只能为数值!');
+            return;
+        }
+        else if(args.col === 4 && args.editingText && (args.editingText.toString().trim().length === 0 ||
+                isNaN(args.editingText) || args.editingText % 1 !== 0)){
+            args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : 0);
+            alert(me.setting.header[args.col].headerName + '只能为整数!');
+            return;
+        }
+        // 新增
+        if (args.row >= assList.length) {
+            if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};
+            if (assObj.carryBit == undefined || assObj.carryBit == null){assObj.carryBit = '四舍五入';};
+            assList.push(assObj);
+        }
+        // 修改
+        else{ assList[args.row] = assObj; };
+        rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+            me.sheet.getParent().focus(true);
+        });
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+        //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, assList.length, me.setting.comboItems, false, false);
+        sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+        sheetCommonObj.showData(me.sheet, me.setting, assList);
+    },
+
+    onRangeChanged: function(sender, args) {
+        if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
+            if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
+
+            var me = rationAssistOprObj;
+            if (!me.ration) {return;};
+            var assList = me.ration.rationAssList;
+            for (var i = args.rowCount - 1; i >= 0; i--) {
+                if (args.row + i < assList.length) {
+                    assList.splice(args.row + i, 1);
+                };
+            };
+
+            rationOprObj.mixUpdateRequest([me.ration], [], []);
+            sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+            sheetCommonObj.showData(me.sheet, me.setting, assList);
+        };
+    },
+    bindRationAssDel: function () {
+        let me = rationAssistOprObj;
+        let workBook = me.sheet.getParent();
+        workBook.commandManager().register('rationAssDel', function () {
+            let sels = me.sheet.getSelections(), isUpdate = false;
+            if(me.ration){
+                let curCahe = me.ration.rationAssList;
+                for(let i = 0, len = sels.length; i < len; i ++ ){
+                    if(sels[i].colCount === me.setting.header.length){
+                        if(sels[i].row < curCahe.length){
+                            isUpdate = true;
+                            curCahe.splice(sels[i].row, sels[i].rowCount);
+                        }
+                    }
+                }
+                if(isUpdate){
+                    rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+                        workBook.focus(true);
+                    });
+                    sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                    //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, curCahe.length, me.setting.comboItems, false);
+                    sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false);
+                    sheetCommonObj.showData(me.sheet, me.setting, curCahe);
+                }
+            }
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('rationAssDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+
+    getAssItems: function(ration) {
+        var me = this;
+        me.ration = ration;
+
+        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+        sheetCommonObj.unShieldAllCells(me.sheet);
+
+        if (ration == undefined || ration.rationAssList == undefined ||
+            ration.rationAssList.length == 0){
+            //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, 0, me.setting.comboItems, false);
+            sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+            return;
+        }
+        else {
+            //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, ration.rationAssList.length, me.setting.comboItems, false);
+            sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+        }
+        sheetCommonObj.showData(me.sheet, me.setting, ration.rationAssList);
+    }
+}

+ 324 - 0
web/building_saas/complementary_ration_lib/js/ration_coe.js

@@ -0,0 +1,324 @@
+/**
+ * Created by CSL on 2017-06-08.
+ */
+ //modified by zhong on 2017-09-25
+var rationCoeOprObj = {
+    sheet: null,
+    libID: null,
+    curRation: null,
+    tempDelArr: [],
+    cache: {},
+    setting: {
+        header:[
+            {headerName:"编号",headerWidth:120,dataCode:"serialNo", dataType: "Number", hAlign: 'left'},
+            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String", hAlign: 'left'},
+            {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String", hAlign: 'left'}
+        ],
+        view:{
+            comboBox:[],
+            lockColumns:[1,2]
+        }
+    },
+
+    buildSheet: function(sheet) {
+        var me = this;
+        me.sheet = sheet;
+        me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
+        if (me.libID == undefined){me.libID = getQueryString('repository')};
+        sheetCommonObj.initSheet(me.sheet, me.setting, 30);
+        me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+        me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
+        me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
+       // me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
+    },
+
+    onClipboardPasting: function(sender, args) {
+        var me = rationCoeOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.curRation = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.curRation)) {
+            args.cancel = true;
+        }
+    },
+
+    onClipboardPasted: function(e, info) {
+        var me = rationCoeOprObj;
+        if (me.libID) {
+            // 修改第一列(编号)
+            if (info.cellRange.col == 0) {
+                me.tempDelArr = [];
+                var coeNos = [];
+                var items = sheetCommonObj.analyzePasteData({header:[{dataCode: "serialNo"}] }, info);
+                let curCache = typeof me.cache["_Coe_" + me.curRation.ID] !== 'undefined' ? me.cache["_Coe_" + me.curRation.ID] : [];
+                let isRefresh = false;
+                for(let i = 0, len = items.length; i < len; i++){
+                    if(!isNaN(items[i].serialNo)){
+                        let row = i + info.cellRange.row;
+                        //update
+                        if(row < curCache.length){
+                            let isExist = false;
+                            for(let j = 0, jLen = curCache.length; j < jLen; j++){
+                                if(items[i].serialNo === curCache[j].serialNo && j !== row){
+                                    isExist = true;
+                                    break;
+                                }
+                            }
+                            if(!isExist){
+                                me.tempDelArr.push({org: curCache[row], newNo: items[i].serialNo});
+                                coeNos.push(items[i].serialNo);
+                            }
+                            else{
+                                isRefresh = true;
+                            }
+                        }
+                        else{
+                            coeNos.push(items[i].serialNo);
+                        }
+                    }
+                }
+                //delete in front
+                if(me.tempDelArr.length > 0){
+                   for(let i = 0, len = me.tempDelArr.length; i < len; i++){
+                       for(let j = 0; j < curCache.length; j++){
+                           if(me.tempDelArr[i].org.serialNo === curCache[j].serialNo){
+                               curCache.splice(j, 1);
+                               break;
+                           }
+                       }
+                   }
+                }
+                me.addCoeItems(coeNos);
+                if(isRefresh){
+                    me.showCoeItems(me.curRation.ID);
+                }
+            } else {
+                //修改其它列。
+            }
+        }
+    },
+    onEditStarting: function (sender, args) {
+        let me = rationCoeOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.curRation = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(!me.curRation || args.col !== 0){
+            args.cancel = true;
+        }
+
+    },
+    onEditEnded: function(sender, args){
+        var me = rationCoeOprObj;
+        if (args.col == 0 && args.editingText && args.editingText.toString().trim().length > 0 && !isNaN(args.editingText)) {   // 编号列
+            let curCahe = typeof me.cache["_Coe_" + me.curRation.ID] !== 'undefined' ? me.cache["_Coe_" + me.curRation.ID] : [];
+            me.tempDelArr = [];
+            //update
+            if(args.row < curCahe.length && args.editingText != curCahe[args.row].serialNo){
+                let isExist = false;
+                for(let i = 0, len = curCahe.length; i < len; i++){
+                    if(args.editingText == curCahe[i].serialNo){
+                        isExist = true;
+                        break;
+                    }
+                }
+                if(!isExist){
+                    me.tempDelArr.push({org: curCahe[args.row], newNo: args.editingText});
+                    curCahe.splice(args.row, 1);
+                    me.addCoeItems([args.editingText]);
+                }
+                else{
+                    me.showCoeItems(me.curRation.ID);
+                }
+            }
+            //insert
+            else{
+                me.addCoeItems([args.editingText]);
+            }
+        }
+        else{
+            sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+            me.showCoeItems(me.curRation.ID);
+        }
+    },
+
+    bindRationCoeDel: function () {
+        let me = rationCoeOprObj;
+        let workBook = me.sheet.getParent();
+        workBook.commandManager().register('rationCoeDel', function () {
+            let sels = me.sheet.getSelections(), isUpdate = false;
+            let curCahe = me.cache["_Coe_" + me.curRation.ID];
+            for(let i = 0, len = sels.length; i < len; i ++ ){
+                if(sels[i].colCount === me.setting.header.length){
+                    if(sels[i].row < curCahe.length){
+                        isUpdate = true;
+                        curCahe.splice(sels[i].row, sels[i].rowCount);
+                    }
+                }
+            }
+            if(isUpdate){
+                me.updateCurRation(function () {
+                    me.sheet.getParent().focus(true);
+                });
+                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                me.showCoeItems(me.curRation.ID);
+            }
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('rationCoeDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    getRecoveryArr: function (tempDelArr, newArr) {//获得更新的coe不存在,恢复删除的被更新数据
+        let rst = [];
+        for(let i = 0, len = tempDelArr.length; i < len; i++){
+            let isExist = false;
+            for(let j = 0, jLen = newArr.length; j < jLen; j++){
+                if(tempDelArr[i].newNo == newArr[j].serialNo){
+                    isExist = true;
+                    break;
+                }
+            }
+            if(!isExist){
+                rst.push(tempDelArr[i].org);
+            }
+        }
+        return rst;
+    },
+    addCoeItems: function(coeNos) {
+        var me = this;
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+
+        var curCache = me.cache["_Coe_" + me.curRation.ID];
+        var temp = [];
+        if (curCache) {
+            for (var i = 0; i < coeNos.length; i++) {
+                var isExist = false;
+                for (let obj of curCache) {
+                    if (obj.serialNo == coeNos[i]) {
+                        isExist = true;
+                        break;
+                    };
+                };
+                if (!isExist) {
+                    temp.push(coeNos[i]);
+                };
+            };
+        }else{
+            for (let obj of coeNos){temp.push(obj)};
+        };
+
+        if(temp.length == 0){
+            me.showCoeItems(me.curRation.ID);
+            //sheetCommonObj.lockCells(me.sheet, me.setting);
+        }else{
+            $.ajax({
+                type:"POST",
+                url:"api/getCoeItemsByNos",
+                data: {"data": JSON.stringify({"libID": me.libID, "coeNos": temp})},
+                dataType:"json",
+                cache:false,
+                timeout:5000,
+                success:function(result){
+                    if (result) {
+                        var rstArr = [];
+                        for (let obj of result.data){rstArr.push(obj)};
+                        if (curCache) {
+                            curCache = curCache.concat(rstArr);
+                        }else{
+                            curCache = rstArr;
+                        }
+                        let recoveryArr = me.getRecoveryArr(me.tempDelArr, result.data);
+                        if(recoveryArr.length > 0){
+                            curCache = curCache.concat(recoveryArr);
+                        }
+                        me.cache["_Coe_" + me.curRation.ID] = curCache;
+                        me.updateCurRation(function () {
+                            me.sheet.getParent().focus(true);
+                        });
+                        me.showCoeItems(me.curRation.ID);
+                    };
+                    //sheetCommonObj.lockCells(me.sheet, me.setting);
+                },
+                error:function(err){
+                    alert(err);
+                }
+            });
+        };
+    },
+
+    getCoeItems: function(ration, callback) {
+        var me = this;
+        me.curRation = ration;
+
+        /*if (ration == undefined || ration.rationCoeList == undefined ||
+            ration.rationCoeList.length == 0){return;};*/
+
+        var coeList = ration.rationCoeList;
+        var curCache = me.cache["_Coe_" + ration.ID];
+        if (curCache) {
+            me.showCoeItems(ration.ID);
+            //sheetCommonObj.lockCells(me.sheet, me.setting);
+        } else if(!curCache && typeof coeList !== 'undefined' && coeList.length > 0) {
+            var data = {"libID": me.libID, "coeIDs": coeList};
+            $.ajax({
+                type:"POST",
+                url:"api/getCoeItemsByIDs",
+                data: {"data": JSON.stringify(data)},
+                dataType:"json",
+                cache:false,
+                timeout:5000,
+                success:function(result){
+                    sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                    if (result.data) {
+                        var tempResult = [];
+                        for (let obj of result.data) {
+                            tempResult.push(obj);
+                        };
+
+                        me.cache["_Coe_" + ration.ID] = tempResult;
+
+                        me.showCoeItems(ration.ID);
+                    }
+                    //sheetCommonObj.lockCells(me.sheet, me.setting);
+                    if(callback) callback();
+                },
+                error:function(err){
+                    alert(err);
+                }
+            });
+        };
+    },
+
+    showCoeItems: function(rationID) {
+        var me = this;
+        var curCache = me.cache["_Coe_" + rationID];
+        if (curCache) {
+            curCache.sort(function(a, b) {
+                var rst = 0;
+                if (a.serialNo > b.serialNo) rst = 1
+                else if (a.serialNo < b.serialNo) rst = -1;
+                return rst;
+            });
+            sheetsOprObj.showData(me.sheet, me.setting, curCache);
+        }
+    },
+
+    updateCurRation: function(callback) {
+        var me = this, updateArr = [];
+        if (me.curRation) {
+            var rst = [];
+            var curCache = me.cache["_Coe_" + me.curRation.ID];
+            if (curCache) {
+                for (let obj of curCache) {
+                    rst.push(obj.ID);
+                };
+                me.curRation.rationCoeList = rst;
+                updateArr.push(me.curRation);
+                rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                    if(callback) callback();
+                });
+            };
+        };
+    }
+}
+
+

+ 576 - 0
web/building_saas/complementary_ration_lib/js/ration_glj.js

@@ -0,0 +1,576 @@
+/**
+ * Created by Tony on 2017/4/28.
+ */
+var rationGLJOprObj = {
+    sheet: null,
+    currentRationItem: null,
+    distTypeTree: null,
+    activeCell: null,
+    tempCacheArr: [],//被更新的工料机,若更新的工料机不存在,则恢复
+    cache: {},
+    setting: {
+        header:[
+            {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
+            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
+            {headerName:"规格型号",headerWidth:120,dataCode:"specs", dataType: "String"},
+            {headerName:"单位",headerWidth:160,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
+            {headerName:"基价单价",headerWidth:160, dataCode:"basePrice", dataType: "Number", formatter:"0.00",  precision: 2},
+            {headerName:"定额消耗",headerWidth:160, dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", precision: 3},
+            {headerName:"类型",headerWidth:160,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
+        ],
+        view:{
+            comboBox:[],
+            lockColumns:[1,2,3,4,6]
+        }
+    },
+    getDistTypeTree: function (gljDistType) {
+        let me = this;
+        let distType;
+        let distTypeTree = {
+            prefix : 'gljDistType',
+            distTypes: {},
+            comboDatas: [],
+            distTypesArr: []
+        };
+        gljDistType.forEach(function (typeData) {
+            let typeObj = {
+                data: typeData,
+                children: [],
+                parent: null
+            }
+            distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
+            distTypeTree.distTypesArr.push(typeObj);
+        });
+        gljDistType.forEach(function (typeData) {
+            distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
+            let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
+            if(parent){
+                distType.parent = parent;
+                parent.children.push(distType);
+            }
+        });
+        distTypeTree.distTypesArr.forEach(function (distTypeObj) {
+            if(distTypeObj.children.length === 0 && distTypeObj.data.fullName !== '普通机械' &&distTypeObj.data.fullName !== '机械组成物'
+                && distTypeObj.data.fullName !== '机上人工'){
+                distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
+            }
+            if(distTypeObj.data.fullName === '机械'){
+                distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
+            }
+        });
+        return distTypeTree;
+    },
+    getGljDistType: function (callback) {
+        let me = this;
+        $.ajax({
+            type: 'post',
+            url: "api/getGljDistType",
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error && callback){
+                    me.distTypeTree = me.getDistTypeTree(result.data);
+                    callback();
+                }
+            }
+        })
+    },
+    buildSheet: function(sheet) {
+        var me = this;
+        me.sheet = sheet;
+        me.getGljDistType(function () {
+           // me.onContextmenuOpr();
+            sheetCommonObj.initSheet(me.sheet, me.setting, 30);
+            me.bindRationGljDelOpr();
+            me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+            me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+            me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
+            me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
+        });
+    },
+    bindRationGljDelOpr: function () {
+        let me = rationGLJOprObj, spreadBook = me.sheet.getParent();
+        spreadBook.commandManager().register('rationGljDelete', function () {
+            let sels = me.sheet.getSelections(), lockCols = me.setting.view.lockColumns;
+            let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID], isUpdate = false;
+            if(sels.length > 0){
+                for(let sel = 0; sel < sels.length; sel++){
+                    if(sels[sel].colCount === me.setting.header.length){
+                        if(cacheSection && sels[sel].row < cacheSection.length){
+                            isUpdate = true;
+                            cacheSection.splice(sels[sel].row, sels[sel].rowCount);
+                        }
+                    }
+                    else{
+                         if(sels[sel].col !== 0 && sels[sel].col !== 5 && !(sels[sel].col === 1 && sels.col + sels[sel].colCount -1 === 3)){
+                            if(cacheSection){
+                                for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
+                                    if(sels[sel].row + i < cacheSection.length){
+                                        for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
+                                            if(lockCols.indexOf(col) === -1){
+                                                isUpdate = true;
+                                                cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = 0;
+                                                me.sheet.setValue(sels[sel].row + i, col, 0.00);
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if(isUpdate){
+                me.updateRationItem(function () {
+                    me.sheet.getParent().focus(true);
+                });
+                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                me.showGljItems(me.currentRationItem.ID);
+            }
+        });
+        spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    onClipboardPasting: function(sender, args) {
+        var me = rationGLJOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
+            me.cache["_GLJ_" + me.currentRationItem.ID] = [];
+        }
+        if (!(args.cellRange.col === 0 || args.cellRange.col === 5) || !(me.currentRationItem)) {
+            args.cancel = true;
+        }
+    },
+    onClipboardPasted: function(e, info) {
+        var me = rationGLJOprObj, repId = storageUtil.getSessionCache("RationGrp","repositoryID");
+        me.tempCacheArr = [];
+        if (repId) {
+            let gljLibId = storageUtil.getSessionCache("gljLib", "repositoryID_" + repId);
+            if(gljLibId){
+                if (info.cellRange.col == 0) {
+                    let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+                    var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
+                    var codes = [];
+                    for (var i = 0; i < tmpCodes.length; i++) {
+                        let rowIdx = info.cellRange.row + i;
+                        if(rowIdx < cacheArr.length){//更新
+                            me.tempCacheArr.push({org: cacheArr[rowIdx], newCode: tmpCodes[i].code});
+                            cacheArr.splice(rowIdx--, 1);
+                        }
+                        codes.push(tmpCodes[i].code);
+                    }
+                    me.addGljItems(codes, gljLibId, info.cellRange);
+                } else {
+                    //修改用量
+                    if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                        let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
+                        let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
+                        me.cache["_GLJ_" + me.currentRationItem.ID].length - info.cellRange.row : info.cellRange.rowCount;
+                        for(let i = 0; i < maxCount; i++){
+                            let roundCons = scMathUtil.roundTo(tempConsumes[i].consumeAmt, -3);
+                            me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
+                        }
+                        me.updateRationItem(function () {
+                            me.sheet.getParent().focus(true);
+                        });
+                        if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
+                            me.sheet.suspendPaint();
+                            for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
+                                me.sheet.setValue(rowIdx, info.cellRange.col, '');
+                            }
+                            me.sheet.resumePaint();
+                        }
+                    }
+                    else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                        me.sheet.suspendPaint();
+                        for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
+                            me.sheet.setValue(rowIdx, info.cellRange.col, '');
+                        }
+                        me.sheet.resumePaint();
+                    }
+                }
+            }
+        }
+    },
+    onEditStarting: function (sender, args) {
+        let me = rationGLJOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
+            me.cache["_GLJ_" + me.currentRationItem.ID] = [];
+        }
+        if(!me.currentRationItem){
+            args.cancel = true;
+        }
+        else {
+            if(args.col !== 0 && args.col !== 5 || args.col === 5 && args.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                args.cancel = true;
+            }
+        }
+    },
+    onCellEditEnd: function(sender, args){
+        var me = rationGLJOprObj;
+        if(me.currentRationItem) {
+            var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+            me.tempCacheArr = [];
+            if (args.col != 0) {
+                if (args.row < cacheArr.length) {
+                    var editGlj = cacheArr[args.row];
+                    if (editGlj["consumeAmt"] != args.editingText) {
+                        let parseNum = parseFloat(args.editingText);
+                        if (isNaN(parseFloat(args.editingText))) {
+                            $('#alertModalBtn').click();
+                            $('#alertText').text("定额消耗只能输入数值!");
+                            $('#alertModalCls').click(function () {
+                                args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
+                            });
+                            $('#alertModalCof').click(function () {
+                                args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
+                            })
+                        }
+                        else {
+                            args.sheet.setValue(args.row, args.col, parseNum);
+                            let roundNum = scMathUtil.roundTo(parseNum, -3);
+                            editGlj["consumeAmt"] = roundNum;
+                            me.updateRationItem(function () {
+                                me.sheet.getParent().focus(true);
+                            });
+                        }
+                    }
+                }
+            } else {
+                if (args.editingText && args.editingText.toString().trim().length !== 0) {
+                    let isExist = false;
+                    for (let i = 0, len = cacheArr.length; i < len; i++) {
+                        if (cacheArr[i].code === args.editingText && i !== args.row) {
+                            isExist = true;
+                            break;
+                        }
+                    }
+                    if (isExist) {
+                        alert("该工料机已存在!");
+                        args.sheet.setValue(args.row, args.col, typeof cacheArr[args.row] !== 'undefined' ? cacheArr[args.row].code + '' : '');
+                    }
+                    else {
+                        if (args.row < cacheArr.length && args.editingText !== cacheArr[args.row].code) {//更新
+                            me.tempCacheArr.push({org: cacheArr[args.row], newCode: args.editingText.toString().trim()});
+                            cacheArr.splice(args.row, 1);
+                            let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
+                            let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+                            let codes = [];
+                            codes.push(args.editingText.toString().trim());
+                            me.addGljItems(codes, gljLibID, args);
+                        }
+                        else if (args.row >= cacheArr.length) {//新增
+                            let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
+                            let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+                            if (gljLibID) {
+                                var codes = [];
+                                codes.push(args.editingText.toString().trim());
+                                me.addGljItems(codes, gljLibID, args);
+                            }
+                        }
+                    }
+                }
+                else {
+                    args.sheet.setValue(args.row, args.col, args.row < cacheArr.length ? cacheArr[args.row].code : '');
+                }
+            }
+        }
+        else {
+            args.sheet.setValue(args.row, args.col, '');
+        }
+    },
+    onContextmenuOpr: function () {
+        let me = rationGLJOprObj;
+        $.contextMenu({
+            selector: '#rdSpread',
+            build: function ($triggerElement, e) {
+                //控制允许右键菜单在哪个位置出现
+                let sheet = me.sheet;
+                let offset = $triggerElement.offset(),
+                    x = e.pageX - offset.left,
+                    y = e.pageY - offset.top;
+                let target = sheet.hitTest(x, y);
+                if(sheet.parent.getActiveSheetIndex() === 0 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){
+                    let delDis = true, cacheSection;
+                    sheet.setActiveCell(target.row, target.col);
+                    if(me.currentRationItem){
+                        let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID];
+                        if(target.row < cacheSection.length){
+                            delDis = false;
+                        }
+                    }
+                    return {
+                        callback: function(key, options) {
+                        },
+                        items: {
+                            "delete": {name: "删除", icon: 'fa-remove', disabled: delDis, callback: function (key, opt) {
+                                cacheSection.splice(target.row, 1);
+                                me.updateRationItem(function () {
+                                    me.sheet.getParent().focus(true);
+                                });
+                                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                                me.showGljItems(me.currentRationItem.ID);
+                            }}
+                        }
+                    };
+                }
+                else{
+                    return false;
+                }
+            }
+        });
+    },
+    getRecoveryArr: function (tempDelArr, newArr) {//获得更新的code不存在,恢复删除的被更新数据
+        let rst = [];
+        for(let i = 0, len = tempDelArr.length; i < len; i++){
+            let isExist = false;
+            for(let j = 0, jLen = newArr.length; j < jLen; j++){
+                if(tempDelArr[i].newCode == newArr[j].code){
+                    isExist = true;
+                    break;
+                }
+            }
+            if(!isExist){
+                rst.push(tempDelArr[i].org);
+            }
+        }
+        return rst;
+    },
+    addGljItems: function(codes, repId, args) {
+        var me = this;
+        $.ajax({
+            type:"POST",
+            url:"api/getGljItemsByCodes",
+            data:{"gljCodes": JSON.stringify(codes), repId: repId},
+            dataType:"json",
+            cache:false,
+            timeout:5000,
+            success:function(result){
+                if (result) {
+                    if(result.data.length > 0){
+                        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                        var rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];
+                        for (var i = 0; i < result.data.length; i++) {
+                            dummyR.gljId = result.data[i].ID;
+                            rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
+                        }
+                        if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
+                            var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+                            for (var i = 0; i < rstArr.length; i++) {
+                                var hasDup = false;
+                                for (var j = 0; j < cacheArr.length; j++) {
+                                    if (cacheArr[j].gljId == rstArr[i].gljId) {
+                                        hasDup = true;
+                                        break;
+                                    }
+                                }
+                                if (!hasDup) {
+                                    newAddArr.push(rstArr[i]);
+                                }
+                            }
+                            me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
+                            let recoveryArr = me.getRecoveryArr(me.tempCacheArr, result.data);
+                            if(recoveryArr.length > 0){
+                                me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
+                            }
+                            me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
+                                var rst = 0;
+                                if (a.code > b.code) rst = 1
+                                else if (a.code < b.code) rst = -1;
+                                return rst;
+                            });
+                        }
+                        me.showGljItems(me.currentRationItem.ID);
+                        if (newAddArr.length > 0) {
+                            me.updateRationItem(function () {
+                                me.sheet.getParent().focus(true);
+                            });
+                        }
+                    }
+                    else{
+                        let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]?  me.cache["_GLJ_" + me.currentRationItem.ID] : [];
+                        let recoveryArr = me.getRecoveryArr(me.tempCacheArr, []);
+                        if(recoveryArr.length > 0){
+                            me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(recoveryArr);
+                        }
+                        //更新的工料机不存在
+                        me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
+                            var rst = 0;
+                            if (a.code > b.code) rst = 1
+                            else if (a.code < b.code) rst = -1;
+                            return rst;
+                        });
+                        $('#alertModalBtn').click();
+                        $('#alertText').text("工料机"+ codes + "不存在,请查找你所需要的工料机,或新增工料机");
+                        $('#alertModalCls').click(function () {
+                            me.showGljItems(me.currentRationItem.ID);
+                        });
+                        $('#alertModalCof').click(function () {
+                            me.showGljItems(me.currentRationItem.ID);
+                        })
+                    }
+                }
+            },
+            error:function(err){
+                alert(err);
+            }
+        })
+    },
+    round(v, e){
+        var t=1;
+        for(;e>0;t*=10,e--);
+        for(;e<0;t/=10,e++);
+        return Math.round(v*t)/t;
+    },
+    rationCal: function () {
+        let me = rationGLJOprObj;
+        let price = {gljType1: [], gljType2: [], gljType3: []}, rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0}, rationBasePrc = 0;
+        if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
+            let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
+            cacheArr.forEach(function (gljData) {
+                if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
+                    let parent = me.distTypeTree.distTypes[me.distTypeTree.prefix + gljData.gljType].parent;
+                    if(parent && parent.data.ID <= 3){
+                        price['gljType' + parent.data.ID].push(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
+                    }
+                    if(!parent && gljData.gljType <= 3){
+                        price['gljType' + gljData.gljType].push(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
+                    }
+                }
+            });
+            if(price.gljType1.length > 0){
+                let labourPrice = 0;
+                price.gljType1.forEach(function (singlePrc) {
+                    labourPrice += singlePrc;
+                });
+                let roundPrice = scMathUtil.roundTo(labourPrice, -2);
+                rst.labourPrice = roundPrice;
+                rationBasePrc += roundPrice;
+            }
+            if(price.gljType2.length > 0){
+                let materialPrice = 0;
+                price.gljType2.forEach(function (singlePrc) {
+                    materialPrice += singlePrc;
+                });
+                let roundPrice = scMathUtil.roundTo(materialPrice, -2);
+                rst.materialPrice = roundPrice;
+                rationBasePrc += roundPrice;
+            }
+            if(price.gljType3.length > 0){
+                let machinePrice = 0;
+                price.gljType3.forEach(function (singlePrc) {
+                    machinePrice += singlePrc;
+                });
+                let roundPrice = scMathUtil.roundTo(machinePrice, -2);
+                rst.machinePrice = roundPrice;
+                rationBasePrc += roundPrice;
+            }
+            rst.rationBasePrc = rationBasePrc;
+        }
+        return rst;
+    },
+    updateRationItem: function(callback) {
+        var me = this, updateArr = [];
+        if (me.currentRationItem) {
+            me.currentRationItem.rationGljList = me.buildRationItemGlj();
+            //recalculate ration basePrice
+            let price = me.rationCal();
+            me.currentRationItem.labourPrice = price.labourPrice;
+            me.currentRationItem.materialPrice = price.materialPrice;
+            me.currentRationItem.machinePrice = price.machinePrice;
+            me.currentRationItem.basePrice = price.rationBasePrc;
+            updateArr.push(me.currentRationItem);
+            rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                if(callback) callback();
+            });
+        }
+    },
+
+    buildRationItemGlj: function(){
+        var me = this, rst = [];
+        if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
+            var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+            for (var i = 0; i < cacheArr.length; i++) {
+                rst.push({gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, proportion: 0});
+            }
+        }
+        return rst;
+    },
+
+    createRationGljDisplayItem: function(rItem, repGlj) {
+        var rst = {};
+        rst.gljId = rItem.gljId;
+        rst.consumeAmt = rItem.consumeAmt;
+        rst.code = repGlj.code;
+        rst.name = repGlj.name;
+        rst.specs = repGlj.specs;
+        rst.unit = repGlj.unit;
+        rst.basePrice = repGlj.basePrice;
+        rst.gljType = repGlj.gljType;
+        return rst;
+    },
+    getGljItems: function(rationItem, callback) {
+        var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList;
+        me.currentRationItem = rationItem;
+        if (me.cache["_GLJ_" + rationID]) {
+            me.showGljItems(rationID);
+        } else {
+            var gljIds = [];
+            for (var i = 0; i < rationGljList.length; i++) {
+                gljIds.push(rationGljList[i].gljId);
+            }
+                $.ajax({
+                    type:"POST",
+                    url:"api/getGljItemsByIds",
+                    data:{"gljIds": JSON.stringify(gljIds)},
+                    dataType:"json",
+                    cache:false,
+                    timeout:5000,
+                    success:function(result){
+                        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                        if (result) {
+                            var cacheArr = [];
+                            for (var i = 0; i < result.data.length; i++) {
+                                for (var j = 0; j < rationGljList.length; j++) {
+                                    if (rationGljList[j].gljId == result.data[i].ID) {
+                                        cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
+                                        break;
+                                    }
+                                }
+                            }
+                            function compare(){
+                                return function (a, b) {
+                                    let rst = 0;
+                                    if (a.code > b.code) {
+                                        rst = 1;
+                                    }
+                                    else if (a.code < b.code) {
+                                        rst = -1;
+                                    }
+                                    return rst;
+                                }
+                            }
+                            cacheArr.sort(compare());
+                            me.cache["_GLJ_" + rationID] = cacheArr;
+                            me.showGljItems(rationID);
+                        }
+                        if(callback) callback();
+                    },
+                    error:function(err){
+                        alert(err);
+                    }
+                })
+        }
+    },
+    showGljItems: function(rationID) {
+        var me = this;
+        if (me.cache["_GLJ_" + rationID]) {
+            sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+            sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
+        }
+    }
+}

+ 984 - 0
web/building_saas/complementary_ration_lib/js/repository_glj.js

@@ -0,0 +1,984 @@
+/**
+ * Created by Tony on 2017/5/5.
+ */
+
+$("#drirect-dinge").click(function(){
+    $(this).attr('href', "/rationRepository/ration" + "?repository=" + getQueryString("repository"))
+});
+
+$("#fuzhu").click(function(){
+    $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
+});
+
+var pageOprObj = {
+    rationLibName : null,
+    rationLibId: null,
+    initPage : function(container) {
+        var me = this, rationLibId = getQueryString("repository"),//获取定额库参数
+            rationLibName = storageUtil.getSessionCache("RationGrp","repositoryID_" + rationLibId);
+        me.rationLibId = rationLibId;
+        if (rationLibName) {
+            var html = $("#rationname")[0].outerHTML;
+            html = html.replace("XXX定额库", rationLibName);
+            $("#rationname")[0].outerHTML = html;
+            me.rationLibName = rationLibName;
+            repositoryGljObj.buildSheet(container);
+            repositoryGljObj.getRationGljIds(rationLibId);
+            repositoryGljObj.getGljDistType(function () {
+                repositoryGljObj.currentRepositoryId = parseInt(rationLibId);
+                //引用的工料机库
+                let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationLibId);
+                if(gljLibID && typeof gljLibID !== 'undefined'){
+                    repositoryGljObj.getGljTree(gljLibID, function () {
+                        repositoryGljObj.getGljItems(gljLibID);
+                    });
+                }
+                sheetCommonObj.shieldAllCells(repositoryGljObj.workBook.getSheet(0), repositoryGljObj.setting);
+            });
+        }
+    }
+}
+repositoryGljObj = {
+    treeObj : null,
+    workBook: null,
+    gljCurTypeId: -1,
+    currentRepositoryId: -1,
+    currentCache: null,
+    parentNodeIds: {},
+    gljList: [],
+    distTypeTree: null,//add
+    setting: {
+        header:[
+            {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
+            {headerName:"名称",headerWidth:260,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
+            {headerName:"规格型号",headerWidth:260,dataCode:"specs", dataType: "String", hAlign: "left", vAlign: "center"},
+            {headerName:"单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
+            {headerName:"定额价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
+            {headerName:"类型",headerWidth:120,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
+        ],
+        view:{
+            comboBox:[
+                {row:-1,col:3,rowCount:-1,colCount:1}
+            ],
+            lockedCells:[
+            ]
+        }
+    },
+    getComboData: function (gljDistType) {
+        let me = this;
+        let distType;
+        let distTypeTree = {
+            prefix : 'gljType',
+            distTypes: {},
+            comboDatas: [],
+            distTypesArr: []
+        };
+        gljDistType.forEach(function (typeData) {
+            let typeObj = {
+                data: typeData,
+                children: [],
+                parent: null
+            }
+            distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
+            distTypeTree.distTypesArr.push(typeObj);
+        });
+        gljDistType.forEach(function (typeData) {
+            distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
+            let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
+            if(parent){
+                distType.parent = parent;
+                parent.children.push(distType);
+            }
+        });
+        distTypeTree.distTypesArr.forEach(function (distTypeObj) {
+            if(distTypeObj.data.fullName !== '材料'){
+                distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
+            }
+        });
+        return distTypeTree;
+    },
+    getGljDistType: function (callback) {
+        let me = this;
+        $.ajax({
+            type: 'post',
+            url: "api/getGljDistType",
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error && callback){
+                    me.distTypeTree = me.getComboData(result.data);
+                    /*let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
+                    combo.items(me.distTypeTree.comboDatas).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);*/
+                    me.workBook.getSheet(0).getCell(-1, 5, GC.Spread.Sheets.SheetArea.viewport).value(me.distTypeTree.comboDatas[0].text);
+                    callback();
+                }
+            }
+        })
+    },
+    getGljTree: function(gljLibID, callback) {
+        var me = this;
+        $.ajax({
+            type:"POST",
+            url:"api/getGljTree",
+            data:{"gljLibID": gljLibID},
+            dataType:"json",
+            cache:false,
+            timeout:20000,
+            success:function(result,textStatus,status){
+                if(status.status == 200) {
+                    zTreeHelper.createTree(result.data, gljSetting, "repositoryTree", me);
+                    if (result.data && result.data.length > 0) {
+                        me.gljCurTypeId = result.data[0].ID;
+                    } else {
+                        gljTypeTreeOprObj.addRootNode();
+                    }
+                    callback();
+                }
+            },
+            error:function(err){
+                alert(err.responseJSON.error);
+            }
+        })
+    },
+    getGljItems: function(gljLibID) {
+        var me = this;
+        $.ajax({
+            type:"POST",
+            url:"api/getGljItems",
+            data:{"repositoryId": gljLibID},
+            dataType:"json",
+            cache:false,
+            timeout:5000,
+            success:function(result){
+                if(!result.error) {
+                    me.gljList = result.data;
+                    me.workBook.getSheet(0).setRowCount(result.data.length);
+                    me.sortGlj();
+                    let rootNode = me.treeObj.getNodes()[0];
+                    if(rootNode && rootNode.isParent && rootNode.isFirstNode){
+                        me.treeObj.selectNode(rootNode);
+                        gljTypeTreeOprObj.onClick(null, 'repositoryTree', rootNode);
+                    }
+                    //me.showGljItems(result.data, me.gljCurTypeId);
+                }
+            },
+            error:function(err){
+                alert(err.responseJSON.error);
+            }
+        })
+    },
+    showGljItems: function(data, type) {
+        var me = repositoryGljObj;
+        if (me.workBook) {
+            var cacheSection = [];
+            var pArr = me.parentNodeIds["_pNodeId_" + type];
+            for (var i = 0; i < data.length; i++) {
+                if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
+                    cacheSection.push(data[i]);
+                } else if (type == data[i].gljClass) {
+                    //data[i].gljDistType = me.distTypeTree.distTypes[me.distTypeTree.prefix + data[i].gljDistType].data.fullName;
+                    cacheSection.push(data[i]);
+                }
+            }
+            sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+            sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
+
+            cacheSection = null;
+        }
+    },
+    buildSheet: function(container) {
+        var me = repositoryGljObj;
+        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
+        me.workBook.getSheet(0).options.isProtected = true;
+        /* me.repositoryGljDelOpr();
+         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
+         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
+         //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
+         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);*/
+    },
+    onEnterCell: function (sender, args) {
+        let me = repositoryGljObj;
+        me.cellRowIdx = args.row;
+        let isHasData = false;
+        if(me.addGljObj){
+            for(let i=0; i<me.setting.header.length; i++){
+                if(me.addGljObj[me.setting.header[i].dataCode]){
+                    isHasData = true;
+                    break;
+                }
+            }
+        }
+        if(isHasData){
+            if(me.editingRowIdx !== me.cellRowIdx) {
+                let isComple = true;
+                let focusToCol;
+                function getFocusToCol (me){
+                    if(!me.addGljObj[me.setting.header[0].dataCode]){
+                        $('#alertGljTxt').text('编号不能为空,是否取消增加工料机?');
+                        return 0;
+                    }
+                    else if(!me.addGljObj[me.setting.header[1].dataCode]){
+                        $('#alertGljTxt').text('名称不能为空,是否取消增加工料机?');
+                        return 1;
+                    }
+                    else if(!me.addGljObj[me.setting.header[5].dataCode]){
+                        $('#alertGljTxt').text('类型不能为空,是否取消增加工料机?');
+                        return 5;
+                    }
+                    else {
+                        return -1;
+                    }
+                }
+                focusToCol = getFocusToCol(me);
+                if(focusToCol === -1){
+
+                }
+                else {
+                    $('#gljAlertBtn').click();
+                    //me.workBook.getSheet(0).options.isProtected = true;
+                    sheetCommonObj.lockAllCells(args.sheet);
+                    $('#aleCanceBtn').click(function () {
+                        // me.workBook.getSheet(0).options.isProtected = false;
+                        sheetCommonObj.unLockAllCells(args.sheet);
+                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
+                    });
+                    $('#gljAleClose').click(function () {
+                        // me.workBook.getSheet(0).options.isProtected = false;
+                        sheetCommonObj.unLockAllCells(args.sheet);
+                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
+                    });
+                    $('#aleConfBtn').click(function () {
+                        // me.workBook.getSheet(0).options.isProtected = false;
+                        sheetCommonObj.unLockAllCells(args.sheet);
+                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        me.addGljObj = null;
+                        for(let col=0; col<me.setting.header.length; col++){
+                            let field = me.setting.header[col].dataCode;
+                            if(field === 'gljType'){
+                                me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(
+                                    me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[field]].data.fullName);
+                            }
+                            else{
+                                me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingGlj[me.setting.header[col].dataCode]);
+                            }
+                        }
+                        me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
+                    });
+                }
+            }
+        }
+    },
+    onCellEditStart: function(sender, args) {
+        var me = repositoryGljObj;
+        var rObj = sheetsOprObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
+        me.currentEditingGlj = rObj;
+        me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
+        var cacheSection = me.gljList;
+        if (cacheSection) {
+            for (var j = 0; j < cacheSection.length; j++) {
+                if (cacheSection[j][me.setting.header[0].dataCode] && cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
+                    rObj["ID"] = cacheSection[j]["ID"];
+                    rObj.gljClass = cacheSection[j].gljClass;
+                    break;
+                }
+            }
+        }
+    },
+    onCellEditEnd: function(sender, args) {
+        var me = repositoryGljObj, rObj = sheetsOprObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
+            updateArr = [], addArr = [], updateBasePrcArr = [];
+        me.editingRowIdx = args.row;
+        rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
+        if (me.currentEditingGlj["ID"]) {
+            rObj["ID"] = me.currentEditingGlj["ID"];
+            rObj.gljClass = me.currentEditingGlj.gljClass;
+            for(let col =0; col< me.setting.header.length; col++){
+                if(me.currentEditingGlj[me.setting.header[col].dataCode] !== rObj[me.setting.header[col].dataCode]){
+                    me.addGljObj = rObj;
+                    if(rObj[me.setting.header[0].dataCode] && rObj[me.setting.header[1].dataCode] && rObj[me.setting.header[5].dataCode]){
+                        updateArr.push(rObj);
+                        break;
+                    }
+                }
+            }
+            if(me.currentEditingGlj.basePrice !== rObj.basePrice){
+                //update basePrice of ration when editting basePrice of glj
+                let gljType = -1;
+                let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
+                if(gljTypeParent && gljTypeParent.data.ID <=3){
+                    gljType = gljTypeParent.data.ID;
+                }
+                if(!gljTypeParent && me.currentEditingGlj.gljType <= 3){
+                    gljType = me.currentEditingGlj.gljType;
+                }
+                let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
+                if(gljBasePrcObj.gljType !== -1){
+                    updateBasePrcArr.push(gljBasePrcObj);
+                    me.updateRationBasePrcRq(updateBasePrcArr);
+                }
+            }
+            //update basePrice of ration when editting gljType of glj
+            if(me.currentEditingGlj.gljType !== rObj.gljType){
+                let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
+                updateBasePrcArr.push(gljTypeObj);
+                me.updateRationBasePrcRq(updateBasePrcArr);
+            }
+        } else {
+            me.addGljObj = rObj;
+            let isCanSav = true;
+            if(!rObj[me.setting.header[0].dataCode] || !rObj[me.setting.header[1].dataCode] || !rObj[me.setting.header[5].dataCode]){
+                isCanSav = false;
+            }
+            if(isCanSav){
+                me.addGljObj = null;
+                addArr.push(rObj);
+            }
+        }
+        if(me.gljCurTypeId !== 1){
+            rObj.gljClass = me.gljCurTypeId;
+        }
+        if(updateArr.length >0 || addArr.length >0){
+            me.currentEditingGlj = null;
+            //me.workBook.getSheet(0).setValue(11, 5, "人工");
+            me.mixUpdateRequest(updateArr, addArr, []);
+        }
+    },
+    repositoryGljDelOpr: function () {
+        let me = repositoryGljObj;
+        me.workBook.commandManager().register('repositoryGljDel', function () {
+            let sheet = me.workBook.getSheet(0),
+                updateArr = [], removeArr = [],
+                tempRemoveArr= [],
+                refGljCodes = [], //已被引用的工料机
+                updateBasePrcArr = [],//删除基价单位后重新计算
+                sels = sheet.getSelections(),
+                cacheSection = me.currentCache;
+            if(sels.length > 0 && cacheSection.length > 0){
+                for(let i = 0; i < sels.length; i++){
+                    if(sels[i].colCount === me.setting.header.length){
+                        for(let j = 0; j < sels[i].rowCount; j++){
+                            if(sels[i].row + j < cacheSection.length){
+                                tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
+                            }
+                        }
+                    }
+                    else{
+                        let maxCol = sels[i].col + sels[i].colCount - 1;
+                        if(sels[i].col >= 2 && maxCol <= 4){
+                            for(let j = 0; j < sels[i].rowCount; j++){
+                                if(sels[i].row + j < cacheSection.length){
+                                    let updateObj = cacheSection[sels[i].row + j];
+                                    for(let col = sels[i].col; col <= maxCol; col++){
+                                        if(me.setting.header[col].dataCode === 'basePrice'){
+                                            updateObj[me.setting.header[col].dataCode] = 0;
+                                            updateBasePrcArr.push({gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0});
+                                        }
+                                        else{
+                                            updateObj[me.setting.header[col].dataCode] = '';
+                                        }
+                                    }
+                                    updateArr.push(updateObj);
+                                }
+                            }
+                        }
+                        //编号、名称、类型不可为空
+                        else{
+                            if(sels[i].row < cacheSection.length){
+                                let text = '', cantNullStr =['编码', '名称', '类型'];
+                                for(let col = sels[i].col; col <= sels[i].col + sels[i].colCount -1; col++){
+                                    if(cantNullStr.indexOf(me.setting.header[col].headerName) !== -1){
+                                        text += me.setting.header[col].headerName + " ";
+                                    }
+                                }
+                                $('#alertText').text(text + "不可为空!");
+                                $('#codeAlertBtn').click();
+                                sheet.options.isProtected = true;
+                                $('#codAleConfBtn').click(function () {
+                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                                });
+                                $('#codAleClose').click(function () {
+                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                                });
+                            }
+                        }
+                    }
+                }
+                //提取已被引用工料机
+                if(tempRemoveArr.length > 0){
+                    for(let i = 0; i < tempRemoveArr.length; i++){
+                        if(me.rationGljIds.indexOf(tempRemoveArr[i].ID) !== -1){
+                            refGljCodes.push(tempRemoveArr[i].code);
+                            tempRemoveArr.splice(i--, 1);
+                        }
+                        else{
+                            removeArr.push(tempRemoveArr[i].ID);
+                        }
+                    }
+                }
+                //提示
+                if(refGljCodes.length > 0){
+                    let alertText;
+                    if(refGljCodes.length > 3){
+                        alertText = "编号: " + refGljCodes[0]+" 、" + refGljCodes[1] + " 、" + refGljCodes[2] + "...等工料机已有定额引用,删除失败!";
+                    }
+                    else {
+                        let alertCode = " ";
+                        for(let i=0; i< refGljCodes.length; i++){
+                            alertCode += refGljCodes[i] + " 、";
+                        }
+                        alertText = "编号:" + alertCode + "工料机已有定额引用,删除失败!"
+                    }
+                    $('#alertText').text(alertText);
+                    $('#codeAlertBtn').click();
+                    sheet.options.isProtected = true;
+                    $('#codAleConfBtn').click(function () {
+                        sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                        if(removeArr.length > 0){
+                            me.mixUpdateRequest(updateArr, [], removeArr);
+                        }
+                    });
+                    $('#codAleClose').click(function () {
+                        sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                        me.mixUpdateRequest(updateArr, [], removeArr);
+                    });
+                }
+                else if(removeArr.length > 0 || updateArr.length > 0){
+                    me.mixUpdateRequest(updateArr, [], removeArr);
+                    if(updateBasePrcArr.length > 0){
+                        me.updateRationBasePrcRq(updateBasePrcArr);
+                    }
+                }
+            }
+
+        });
+
+        me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    validUpdateObj: function (pasteObj, rowIdx) {
+        let rst = {}, backUpObj = {},
+            me = repositoryGljObj,
+            tempObj = me.currentCache[rowIdx],
+            reCalBasePrc = false, isValid = true;
+        //备份原始数据
+        for(let atr in tempObj){
+            backUpObj[atr] = tempObj[atr];
+        }
+        if(typeof pasteObj.code !== 'undefined'){
+            if(pasteObj.code.trim().length !== 0){
+                let isExist = false;
+                for(let i = 0; i < me.gljList.length; i++){
+                    if(me.gljList[i].code === pasteObj.code){
+                        isExist = true;
+                        break;
+                    }
+                }
+                if(!isExist){
+                    tempObj.code = pasteObj.code;
+                }
+                else isValid = false;
+            }
+            else isValid = false;
+        }
+        if(typeof pasteObj.name !== 'undefined'){
+            if(pasteObj.name.trim().length === 0) isValid = false;
+            else tempObj.name = pasteObj.name;
+        }
+        if(typeof pasteObj.specs !== 'undefined'){
+            tempObj.specs = pasteObj.specs;
+        }
+        if(typeof pasteObj.unit !== 'undefined'){
+            tempObj.unit = pasteObj.unit;
+        }
+        if(typeof pasteObj.gljType !== 'undefined'){
+            let isExsit = false;
+            for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
+                if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
+                    isExsit = true;
+                    reCalBasePrc = true;
+                    tempObj.gljType = me.distTypeTree.comboDatas[i].value;
+                    tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
+
+                }
+            }
+            if(!isExsit) isValid = false;
+        }
+        //
+        pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) :
+            me.currentCache[rowIdx].basePrice;
+        if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
+            reCalBasePrc = true;
+            tempObj.basePrice = pasteObj.basePrice;
+        }
+        if(isValid){
+            rst.updateGlj = tempObj;
+            if(reCalBasePrc){
+                //重新计算定额基价对象
+                rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
+            }
+        }
+        else {
+            for(let attr in backUpObj){
+                tempObj[attr] = backUpObj[attr];
+            }
+        }
+        return rst;
+    },
+    //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
+    isValidObj: function(pasteObj) {
+        let me = repositoryGljObj;
+        if(!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
+            !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')){
+            return false;
+        }
+        if(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined'){
+            let isExist = false;
+            for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
+                if(me.distTypeTree.comboDatas[i].text === pasteObj.gljType){
+                    isExist = true;
+                    pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
+                    pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
+                    break;
+                }
+            }
+            if(!isExist){
+                return false;
+            }
+        }
+        if(pasteObj.code && typeof pasteObj.code !== 'undefined'){
+            for(let i = 0; i < me.gljList.length; i++){
+                if(me.gljList[i].code === pasteObj.code){
+                    return false;
+                }
+            }
+        }
+        pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
+        pasteObj.gljClass = me.gljCurTypeId;
+        return true;
+    },
+    onClipboardPasting: function(sender, args) {
+        var me = repositoryGljObj;
+        /*if (args.cellRange.colCount != me.setting.header.length || me.gljCurTypeId < 0 || me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
+         args.cancel = true;
+         }*/
+        if (me.gljCurTypeId < 0 ) {
+            args.cancel = true;
+        }
+    },
+    onClipboardPasted: function(e, info) {
+        var me = repositoryGljObj;
+        var updateArr = [], addArr = [];
+        var items = sheetCommonObj.analyzePasteData(me.setting, info);
+        let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,
+            maxRow = me.currentCache.length - 1, updateItems = [], addItems = [], updateBasePrcArr = [] , updateCount, resumeArr = [];
+        if(endRow <= maxRow){
+            //updateItems = items;
+            for(let i = 0; i < items.length; i++){
+                let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
+                if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
+                    updateArr.push(updateObj.updateGlj);
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                        updateBasePrcArr.push(updateObj.updateBasePrc);
+                    }
+                }
+                else{
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        else if(beginRow <= maxRow && endRow > maxRow){
+            updateCount = maxRow - beginRow + 1;
+            for(let i = 0; i < updateCount; i++){
+                let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
+                if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
+                    updateArr.push(updateObj.updateGlj);
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                        updateBasePrcArr.push(updateObj.updateBasePrc);
+                    }
+                }
+                else{
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+            if(info.cellRange.colCount === me.setting.header.length){
+                for(let i = updateCount ; i < items.length; i++){
+                    if(me.isValidObj(items[i])){
+                        addItems.push(items[i]);
+                        addArr.push(items[i]);
+                    }
+                    else{
+                        resumeArr.push(info.cellRange.row + i);
+                    }
+                }
+            }
+            else{
+                for(let i = updateCount ; i < items.length; i++){
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        else{
+            if(info.cellRange.colCount === me.setting.header.length){
+                for(let i = 0; i < items.length; i++){
+                    if(me.isValidObj(items[i])){
+                        addArr.push(items[i]);
+                    }
+                    else{
+                        resumeArr.push(info.cellRange.row + i);
+                    }
+                }
+            }
+            else{
+                for(let i = 0; i < items.length; i++){
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        //repaint
+        if(resumeArr.length > 0){
+            info.sheet.suspendPaint();
+            for(let i = 0; i < resumeArr.length ; i++){
+                if(resumeArr[i] < me.currentCache.length){
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        if(me.setting.header[col].dataCode === 'gljType'){
+                            let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
+                            info.sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
+                        }
+                        else{
+                            info.sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
+                        }
+                    }
+                }
+                else{
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        info.sheet.setValue(resumeArr[i], col, '');
+                    }
+                }
+            }
+            info.sheet.resumePaint();
+        }
+        if (updateArr.length > 0 || addArr.length > 0) {
+            me.mixUpdateRequest(updateArr, addArr, []);
+        }
+        if(updateBasePrcArr.length > 0){
+            me.updateRationBasePrcRq(updateBasePrcArr);
+        }
+    },
+    updateRationBasePrcRq: function (basePrcArr) {
+        $.ajax({
+            type: 'post',
+            url: 'api/updateRationBasePrc',
+            data:{data: JSON.stringify({repId: pageOprObj.rationLibId, lastOpr: userAccount, basePrcArr: basePrcArr})},
+            dataType: 'json',
+            success: function (result) {
+                if(result.error){
+                    alert("计算定额基价失败");
+                }
+            }
+        });
+    },
+    getRationGljIds: function (repId) {
+        let me = repositoryGljObj;
+        $.ajax({
+            type: 'post',
+            url: 'api/getRationGljIds',
+            data: {data: JSON.stringify({repId: repId})},
+            dataType: 'json',
+            success: function(result){
+                if(!result.error){
+                    me.rationGljIds = result.data;
+                }
+            }
+        });
+    },
+    mixUpdateRequest: function(updateArr, addArr, removeIds) {
+        var me = repositoryGljObj;
+        $.ajax({
+            type:"POST",
+            url:"api/mixUpdateGljItems",
+            data:{"repositoryId": me.currentRepositoryId, "lastOpr": userAccount, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
+            dataType:"json",
+            cache:false,
+            timeout:5000,
+            success:function(result){
+                if (result.error) {
+                    alert(result.message);
+                    me.getRationItems(me.currentRepositoryId);
+                } else {
+                    me.updateCache(addArr, updateArr, removeIds, result);
+                    me.sortGlj();
+                    if(me.currentOprParent === 1){
+                        me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
+                    }
+                    else{
+                        me.currentCache = me.getCache();
+                        //sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
+                        sheetsOprObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
+                        //sheetCommonObj.lockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
+                    }
+                    me.showGljItems(me.gljList, me.gljCurTypeId);
+                }
+            },
+            error:function(err){
+                alert("保存失败");
+            }
+        })
+    },
+    getParentCache: function (nodes) {
+        let me = repositoryGljObj, rst = [];
+        for(let i = 0; i < me.gljList.length; i++){
+            if(nodes.indexOf(me.gljList[i].gljClass) !== -1){
+                rst.push(me.gljList[i]);
+            }
+        }
+        rst.sort(function (a, b) {
+            let rst = 0;
+            if(a.code > b.code) rst = 1;
+            else if(a.code < b.code)rst = -1;
+            return rst;
+        });
+        return rst;
+    },
+    getCache: function() {
+        var me = this, rst = [];
+        for (var i = 0; i < me.gljList.length; i++) {
+            if (me.gljList[i].gljClass == me.gljCurTypeId) {
+                rst.push(me.gljList[i]);
+            }
+        }
+        return rst;
+    },
+    updateCache: function(addArr, updateArr, removeIds, result) {
+        var me = this, cacheSection = me.gljList;
+        if (addArr.length > 0) {
+            me.gljList = me.gljList.concat(addArr);
+            cacheSection = me.gljList;
+        }
+        for (var i = removeIds.length - 1; i >= 0; i--) {
+            for (var j = cacheSection.length - 1; j >= 0 ; j--) {
+                if (cacheSection[j]["ID"] == removeIds[i]) {
+                    cacheSection.splice(j,1);
+                }
+            }
+        }
+        if (result && result.data.ops && result.data.ops.length > 0) {
+            for (var i = 0; i < result.data.ops.length; i++) {
+                for (var j = 0; j < cacheSection.length; j++) {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
+                        cacheSection[j]["ID"] = result.data.ops[i]["ID"];
+                    }
+                }
+            }
+        }
+        for (var i = 0; i < updateArr.length; i++) {
+            for (var j = 0; j < cacheSection.length; j++) {
+                if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
+                    if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
+                        cacheSection[j] = updateArr[i];
+                    }
+                } else {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
+                        cacheSection[j] = updateArr[i];
+                    }
+                }
+            }
+        }
+    },
+    sortGlj: function() {
+        var me = this;
+        me.gljList.sort(function(a, b){
+            var rst = 0;
+            if (a.code > b.code) rst = 1
+            else if (a.code < b.code) rst = -1;
+            return rst;
+        });
+    }
+}
+
+var gljTypeTreeOprObj = {
+    onClick: function(event,treeId,treeNode) {
+        var me = repositoryGljObj,
+            gljTypeId = treeNode.ID;
+        me.gljCurTypeId = treeNode.ID;
+        if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
+            me.currentOprParent = 1;
+            me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
+           // sheetCommonObj.lockCodeCells(me.workBook.getSheet(0), me.currentCache.length);
+            me.workBook.getSheet(0).setRowCount(me.currentCache.length);
+        } else {
+            me.currentOprParent = 0;
+            me.currentCache = me.getCache();
+            me.workBook.getSheet(0).setRowCount(me.currentCache.length);
+            /*sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
+            sheetCommonObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);*/
+        }
+        me.showGljItems(me.gljList, gljTypeId);
+        me.workBook.getSheet(0).setRowCount(me.currentCache.length);
+    },
+    beforeRename: function(treeId, treeNode, newName, isCancel) {
+        if (newName.length == 0) {
+            return false;
+        }
+        return true;
+    },
+    onRename : function(e, treeId, treeNode, isCancel) {
+        var nodes = [];
+        nodes.push(treeNode);
+        gljTypeTreeOprObj.updateNodes(nodes);
+    },
+    onBeforeRemove: function(treeId, treeNode){
+        let me = this;
+        if (treeNode.ParentID == -1 && treeNode.isFirstNode) {
+            alert("不允许删除全部!");
+            return false;
+        }
+        if (!confirm("您确定要删除此节点及所有子节点的数据?删除后不可恢复!")) {
+            return false;
+        }
+        var nodeIds = [], preNode = treeNode.getPreNode(), preNodeId = -1;
+        if (preNode) {
+            preNodeId = preNode.ID;
+        }
+        private_fetchAllSubItems = function(pItem){
+            nodeIds.push(pItem.ID);
+            if (pItem.items && pItem.items.length > 0) {
+                for (var i = 0; i < pItem.items.length; i++) {
+                    private_fetchAllSubItems(pItem.items[i]);
+                }
+            }
+        };
+        nodeIds.push(treeNode.ID);
+        for (var i = 0; i < treeNode.items.length; i++) {
+            private_fetchAllSubItems(treeNode.items[i]);
+        }
+        $.ajax({
+            type:"POST",
+            url:"api/deleteGljNodes",
+            data:{"repId": pageOprObj.rationLibId, "lastOpr": userAccount, "nodes": JSON.stringify(nodeIds), "preNodeId": preNodeId, "preNodeNextId": treeNode.NextSiblingID},
+            dataType:"json",
+            cache:false,
+            timeout:5000,
+            success:function(result,textStatus,status){
+                var pNode = treeNode.getParentNode();
+                if (pNode && pNode.items && pNode.items.length == 1) {
+                    pNode.isParent = false;
+                }
+            },
+            error:function(){
+            }
+        });
+        return true;
+    },
+    onRemove: function(e, treeId, treeNode){
+        var me = repositoryGljObj, pNode = me.treeObj.getNodeByTId(treeNode.parentTId);
+        if (pNode && pNode.items && pNode.items.length == 0) {
+            pNode.isParent = false;
+            me.treeObj.refresh();
+        }
+    },
+    updateNodes: function(nodes){
+        if (nodes && nodes.length > 0) {
+            var reqData = []
+            for (var i = 0; i < nodes.length; i++) {
+                var node = {};
+                node.repositoryId = nodes[i].repositoryId;
+                node.ID = nodes[i].ID;
+                node.ParentID = nodes[i].ParentID;
+                node.NextSiblingID = nodes[i].NextSiblingID;
+                node.Name = nodes[i].Name;
+                if (nodes[i].__v != null) node.__v = nodes[i].__v + 1
+                else node.__v = 0;
+                reqData.push(node);
+            }
+            $.ajax({
+                type:"POST",
+                url:"api/updateGljNodes",
+                data:{"repId": pageOprObj.rationLibId, "lastOpr": userAccount, "nodes": JSON.stringify(reqData)},
+                dataType:"json",
+                cache:false,
+                timeout:5000,
+                success:function(result,textStatus,status){
+                    console.log(status + ' : ' + result);
+                },
+                error:function(){
+                }
+            })
+        }
+    },
+    addRootNode: function() {
+        var me = repositoryGljObj, rawNode = {ParentID: -1, NextSiblingID: -1, Name: "所有"}, lastNodeId = -1;
+        if (me.treeObj) {
+            var rootNodes = me.treeObj.getNodes();
+            if (rootNodes.length == 0) {
+                gljTypeTreeOprObj.addNewNode(rawNode, lastNodeId, function(err, rst){
+                    if (!(err)) {
+                        var newNodes = [], isSilent = false;
+                        newNodes.push({ repositoryId: rst.data.repositoryId, ID: rst.data.ID, ParentID: rst.data.ParentID, NextSiblingID:-1, Name:"所有",isParent:false, items:[]});
+                        me.treeObj.addNodes(null, -1, newNodes, isSilent);
+                    }
+                });
+            }
+        }
+    },
+    addNewNode : function(rawNode, lastNodeId, callback){
+        $.ajax({
+            type:"POST",
+            url:"api/createNewGljTypeNode",
+            data:{"lastOpr": userAccount, "repositoryId": repositoryGljObj.currentRepositoryId,"lastNodeId": lastNodeId, "rawNodeData": JSON.stringify(rawNode)},
+            dataType:"json",
+            cache:false,
+            timeout:1000,
+            success: function(result,textStatus,status){
+                callback(false, result);
+            },
+            error:function(err){
+                callback(err);
+            }
+        })
+    },
+    addHoverDom: function(treeId, treeNode) {
+        if(typeof treeNode.doing !== 'undefined' && treeNode.doing){
+            return false;
+        }
+        hoverOpr();
+        function hoverOpr(){
+            //console.log(treeNode);
+            var me = repositoryGljObj, sObj = $("#" + treeNode.tId + "_span");
+            if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
+            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增子节点' onfocus='this.blur();'></span>";
+            sObj.after(addStr);
+            var btn = $("#addBtn_"+treeNode.tId);
+            if (btn) btn.bind("click", function(){
+                treeNode.doing = true;
+                var rawNode = {ParentID: treeNode.ID, NextSiblingID: -1, Name: "新增子节点"}, lastNodeId = -1;
+                if (treeNode.items.length > 0) {
+                    lastNodeId = treeNode.items[treeNode.items.length - 1].ID;
+                }
+                gljTypeTreeOprObj.addNewNode(rawNode, lastNodeId, function(err, rst){
+                    if (!(err)) {
+                        var newNodes = [], isSilent = false;
+                        if(treeNode.items.length > 0){
+                            treeNode.items[treeNode.items.length - 1].NextSiblingID = rst.data.ID;
+                        }
+                        newNodes.push({ repositoryId: rst.data.repositoryId, ID: rst.data.ID, ParentID: rst.data.ParentID, NextSiblingID:-1, Name:"新增子节点",isParent:false, items:[]});
+                        treeNode.isParent = true;
+                        if (me.treeObj) {
+                            me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
+                        } else {
+                            me.treeObj = $.fn.zTree.init($("#rationChapterTree"), gljSetting, newNodes);
+                        }
+                        treeNode.doing = false;
+                        hoverOpr();
+                    }
+                });
+            });
+        }
+    },
+    removeHoverDom: function(treeId, treeNode) {
+        $("#addBtn_"+treeNode.tId).unbind().remove();
+    }
+
+}

+ 526 - 0
web/building_saas/complementary_ration_lib/js/section_tree.js

@@ -0,0 +1,526 @@
+/**
+ * Created by Zhong on 2017/12/18.
+ */
+let pageOprObj = {
+    rationLibName : null,
+    rationLibId : null,
+    initPage : function() {
+        var me = this, rationLibId = getQueryString("repository"),//获取定额库参数
+            rationLibName = storageUtil.getSessionCache("RationGrp","repositoryID_" + rationLibId);
+        if (rationLibName) {
+            var html = $("#rationname")[0].outerHTML;
+            html = html.replace("XXX定额库", rationLibName);
+            $("#rationname")[0].outerHTML = html;
+            me.rationLibName = rationLibName;
+            me.rationLibId = rationLibId;
+            sectionTreeObj.getSectionTree(rationLibId);
+            //job
+            jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
+            $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
+            $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
+            jobContentOprObj.bindAllEvents($('#txtareaAll'));
+            //fz
+            annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
+            $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
+            $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
+            annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
+        }
+    }
+}
+
+let sectionTreeObj = {
+    cache: null,//ref to tree.items
+    tree: null,
+    controller: null,
+    workBook: null,
+    sheet: null,
+    updateType: {new: 'new', update: 'update'},
+    insertBtn: $('#tree_Insert'),
+    removeBtn: $('#tree_remove'),
+    upLevelBtn: $('#tree_upLevel'),
+    downLevelBtn: $('#tree_downLevel'),
+    downMoveBtn: $('#tree_downMove'),
+    upMoveBtn: $('#tree_upMove'),
+    setting: {
+        sheet: {
+            cols:[
+                {
+                    head: {
+                        titleNames: ['名称'],
+                        spanCols: [1],
+                        spanRows: [2],
+                        vAlign: [1, 1],
+                        hAlign: [1, 1],
+                        font: 'Arial'
+                    },
+                    data: {
+                        field: 'name',
+                        vAlign: 1,
+                        hAlign: 0,
+                        font: 'Arial'
+                    },
+                    width: 400
+                }
+            ],
+            headRows: 1,
+            headRowHeight: [47],
+            emptyRows: 0,
+            treeCol: 0
+        },
+        tree: {
+            id: 'ID',
+            pid: 'ParentID',
+            nid: 'NextSiblingID',
+            rootId: -1
+        },
+        options: {
+            tabStripVisible:  false,
+            allowCopyPasteExcelStyle : false,
+            allowExtendPasteRange: false,
+            allowUserDragDrop : false,
+            allowUserDragFill: false,
+            scrollbarMaxAlign : true
+        }
+    },
+
+    isDef: function (v) {
+        return v !== undefined && v !== null;
+    },
+    isFunc: function (v) {
+        return this.isDef(v) && typeof v === 'function';
+    },
+    //sheet things
+    setOptions: function (workbook, opts) {
+        for(let opt in opts){
+            workbook.options[opt] = opts[opt];
+        }
+    },
+
+    renderFunc: function (sheet, func) {
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        if(this.isFunc(func)){
+            func();
+        }
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+
+    buildSheet: function () {
+        if(!this.isDef(this.workBook)){
+            this.workBook = new GC.Spread.Sheets.Workbook($('#sectionSpread')[0], {sheetCount: 1});
+            this.sheet = this.workBook.getSheet(0);
+            this.bindEvents(this.sheet);
+            this.setOptions(this.workBook, this.setting.options);
+            this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
+        }
+    },
+
+    bindEvents: function (sheet) {
+        let me = sectionTreeObj;
+        const Events = GC.Spread.Sheets.Events;
+        sheet.bind(Events.SelectionChanging, me.onSelectionChanging);
+        sheet.bind(Events.EditEnded, me.onEditEnded);
+        sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
+    },
+
+    onSelectionChanging: function (sender, info) {
+        let me = sectionTreeObj;
+        if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
+            let row = info.newSelections[0].row;
+            let section = me.cache[row];
+            me.initSelection(section);
+        }
+        else {
+            me.refreshBtn(null);
+        }
+    },
+
+    onEditEnded: function (sender, args) {
+        let me = sectionTreeObj;
+        let postData = [];
+        let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : '';
+        let node = me.cache[args.row];
+        if(me.isDef(node) && node.data.name !== v){
+            let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, v, null);
+            postData.push(updateObj);
+            //ajax
+            //update
+            me.sectionTreeAjax(postData, function (rstData) {
+                node.data.name = v;
+            }, function () {
+                args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : '');
+            });
+        }
+    },
+
+    onClipboardPasted: function (sender, info) {
+        let me = sectionTreeObj;
+        let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'name'}]}, info);
+        let postData = [];
+        let frontData = [];
+        for(let i = 0, len = items.length; i < len; i++){
+            let row = info.cellRange.row + i;
+            let node = me.cache[row];
+            if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){
+                let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, items[i].name, null);
+                postData.push(updateObj);
+                frontData.push({row: row, name: items[i].name});
+                node.data.name = items[i].name;
+            }
+        }
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                for(let i = 0, len = frontData.length; i < len; i++){
+                    let node = me.cache[frontData[i]['row']];
+                    if(me.isDef(node)){
+                        node.data.name = frontData[i]['name'];
+                    }
+                }
+            }, function () {
+                for(let i = 0, len = frontData.length; i < len; i++){
+                    let node = me.cache[frontData[i]['row']];
+                    me.sheet.setValue(frontData[i]['row'], 0, me.isDef(node) ? node.data.name : '');
+                }
+            });
+        }
+    },
+
+    getSectionTree: function (repId) {
+        let me = sectionTreeObj;
+        let url = 'api/getRationTree';
+        let postData = {rationRepId: repId};
+        let sucFunc = function (rstData) {
+            if(rstData.length > 0){
+                storageUtil.setSessionCache("RationGrp","repositoryID",rstData[0].rationRepId);
+            }
+            //init
+            me.buildSheet();
+            me.initTree(rstData);
+            me.cache = me.tree.items;
+            me.bindBtn();
+            me.initController(me.tree, me.sheet, me.setting.sheet);
+            me.controller.showTreeData();
+            me.sheet.setFormatter(-1, 0, '@');
+            me.initSelection(me.tree.selected);
+            explanatoryOprObj.bindEvents($('#explanationShow'), $('#ruleTextShow'));
+        };
+        let errFunc = function () {
+
+        };
+        CommonAjax.post(url, postData, sucFunc, errFunc);
+    },
+    
+    initTree: function (datas) {
+        this.tree = idTree.createNew(this.setting.tree);
+        this.tree.loadDatas(datas);
+        this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
+    },
+
+    initController: function (tree, sheet, setting) {
+        this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
+    },
+    
+    refreshBtn: function (selected) {
+        let me = this;
+        me.insertBtn.removeClass('disabled');
+        me.removeBtn.removeClass('disabled');
+        me.upLevelBtn.removeClass('disabled');
+        me.downLevelBtn.removeClass('disabled');
+        me.downMoveBtn.removeClass('disabled');
+        me.upMoveBtn.removeClass('disabled');
+        if(!me.isDef(selected)){
+            me.removeBtn.addClass('disabled');
+            me.upLevelBtn.addClass('disabled');
+            me.downLevelBtn.addClass('disabled');
+            me.downMoveBtn.addClass('disabled');
+            me.upMoveBtn.addClass('disabled');
+        }
+        else {
+            if(!me.isDef(selected.preSibling)){
+                me.downLevelBtn.addClass('disabled');
+                me.upMoveBtn.addClass('disabled');
+            }
+            if(!me.isDef(selected.nextSibling)){
+                me.downMoveBtn.addClass('disabled');
+            }
+            if(!me.isDef(selected.parent)){
+                me.upLevelBtn.addClass('disabled');
+            }
+        }
+    },
+    
+    bindBtn: function () {
+        let me = this;
+        me.insertBtn.click(function () {
+            me.insert();
+        });
+        me.removeBtn.click(function () {
+           me.remove(me.tree.selected);
+        });
+        me.upLevelBtn.click(function () {
+            me.upLevel(me.tree.selected);
+        });
+        me.downLevelBtn.click(function () {
+            me.downLevel(me.tree.selected);
+        });
+        me.downMoveBtn.click(function () {
+            me.downMove(me.tree.selected);
+        });
+        me.upMoveBtn.click(function () {
+            me.upMove(me.tree.selected);
+        });
+    },
+    
+    insert: function () {
+        let me = this;
+        me.insertBtn.addClass('disabled');
+        let postData = [];
+        let newID = me.tree.newNodeID();
+        let selected = me.tree.selected;
+        let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
+        if(me.isDef(selected)) {
+            let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
+            postData.push(updateObj);
+            insertObj.updateData.ParentID = selected.getParentID();
+            if(me.isDef(selected.nextSibling)){
+                insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
+            }
+        }
+        postData.push(insertObj);
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                me.controller.insert();
+                me.refreshBtn(me.tree.selected);
+                //fresh tools
+                me.initTools(me.tree.selected);
+            });
+        }
+    },
+    remove: function (selected) {
+        let me = this;
+        me.removeBtn.addClass('disabled');
+        let postData = [], IDs = [];
+        if(!selected){
+            return;
+        }
+        getDelIds(selected);
+        function getDelIds(node){
+            if(me.isDef(node)){
+                IDs.push(node.getID());
+                if(node.children.length > 0){
+                    for(let i = 0, len = node.children.length; i < len; i++){
+                        getDelIds(node.children[i]);
+                    }
+                }
+            }
+        }
+        if(me.isDef(selected.preSibling)){
+            let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
+            postData.push(updateObj);
+        }
+        if(IDs.length > 0){
+            for(let i = 0, len = IDs.length; i < len; i++){
+                let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
+                postData.push(delObj);
+            }
+        }
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                me.controller.delete();
+                me.refreshBtn(me.tree.selected);
+                me.initTools(me.tree.selected);
+            });
+        }
+    },
+    upLevel: function (selected) {
+        let me = this;
+        me.upLevelBtn.addClass('disabled');
+        let postData = [];
+        if(!me.isDef(selected)){
+            return;
+        }
+        if(!me.isDef(selected.parent)){
+            return;
+        }
+        if(me.isDef(selected.preSibling)){
+            let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), -1, null, null, null);
+            postData.push(updateObj);
+        }
+        let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.parent.getNextSiblingID(), selected.parent.getParentID(), null, null);
+        postData.push(updateObj);
+        let updateParent = me.getUpdateObj(me.updateType.update, selected.getParentID(), selected.getID(), null, null, null);
+        postData.push(updateParent);
+        let nextIDs = [];
+        getNext(selected);
+        function getNext(node){
+            if(me.isDef(node.nextSibling)){
+                nextIDs.push(node.getNextSiblingID());
+                getNext(node.nextSibling);
+            }
+        }
+        for(let i = 0, len = nextIDs.length; i < len; i++){
+            postData.push(me.getUpdateObj(me.updateType.update, nextIDs[i], null, selected.getID(), null, null));
+        }
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                me.controller.upLevel();
+                me.refreshBtn(me.tree.selected);
+            });
+        }
+
+    },
+    downLevel: function (selected) {
+        let me = this;
+        me.downLevelBtn.addClass('disabled');
+        let postData = [];
+        if(!me.isDef(selected)){
+            return;
+        }
+        if(!me.isDef(selected.preSibling)){
+            return;
+        }
+        let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
+        postData.push(updatePre);
+        if(selected.preSibling.children.length > 0){
+            let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.children[selected.preSibling.children.length - 1].getID(), selected.getID(), null, null, null);
+            postData.push(updateObj);
+        }
+        let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), -1, selected.preSibling.getID(), null, null);
+        postData.push(updateObj);
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                me.controller.downLevel();
+                me.refreshBtn(me.tree.selected);
+            });
+        }
+    },
+    upMove: function (selected) {
+        let me = this;
+        me.upMoveBtn.addClass('disabled');
+        let postData = [];
+        if(!me.isDef(selected)){
+            return;
+        }
+        if(!me.isDef(selected.preSibling)){
+            return;
+        }
+        let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
+        postData.push(updateObj);
+        let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
+        postData.push(updatePre);
+        if(me.isDef(selected.preSibling.preSibling)){
+            let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
+            postData.push(updatePrepre);
+        }
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                me.controller.upMove();
+                me.refreshBtn(me.tree.selected);
+            });
+        }
+    },
+    downMove: function (selected) {
+        let me = this;
+        me.downMoveBtn.addClass('disabled');
+        let postData = [];
+        if(!me.isDef(selected)){
+            return;
+        }
+        if(!me.isDef(selected.nextSibling)){
+            return;
+        }
+        if(me.isDef(selected.preSibling)){
+            let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
+            postData.push(updatePre);
+        }
+        let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
+        postData.push(updateObj);
+        let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
+        postData.push(updateNext);
+        if(postData.length > 0){
+            //ajax
+            me.sectionTreeAjax(postData, function (rstData) {
+                me.controller.downMove();
+                me.refreshBtn(me.tree.selected);
+            });
+        }
+    },
+    getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
+        let updateObj = Object.create(null);
+        updateObj.updateType = '';
+        updateObj.updateData = Object.create(null);
+        updateObj.updateData.rationRepId = pageOprObj.rationLibId;
+        if(this.isDef(updateType)){
+            updateObj.updateType = updateType;
+        }
+        if(this.isDef(id)){
+            updateObj.updateData.ID = id;
+        }
+        if(this.isDef(nid)){
+            updateObj.updateData.NextSiblingID = nid;
+        }
+        if(this.isDef(pid)){
+            updateObj.updateData.ParentID = pid;
+        }
+        if(this.isDef(name)){
+            updateObj.updateData.name = name;
+        }
+        if(this.isDef(deleted)){
+            updateObj.updateData.isDeleted = true;
+        }
+        return updateObj;
+    },
+    sectionTreeAjax: function (postData, scFunc, errFunc) {
+        CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
+    },
+    initTools: function (node) {
+        if(this.isDef(node)){
+            explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
+            explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
+            explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), node.data.explanation, node.data.ruleText);
+            //job
+            jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.NONE;
+            jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
+            jobContentOprObj.clickUpdate($('#txtareaAll'));
+            //fz
+            annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.NONE;
+            annotationOprObj.clickUpdate($('#fzTxtareaAll'));
+        }
+    },
+    //模仿默认点击
+    initSelection: function (node) {
+        let me = this;
+        if(!me.isDef(node)){
+            return;
+        }
+        me.initTools(node);
+        me.refreshBtn(node);
+        if(!me.isDef(node.children) || node.children.length === 0){
+            rationOprObj.canRations = true;
+            rationOprObj.workBook.getSheet(0).clearSelection();
+            rationOprObj.getRationItems(node.data.ID);
+            rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
+        }
+        else {
+            rationOprObj.canRations = false;
+            rationOprObj.currentSectionId = node.data.ID;
+            rationOprObj.workBook.getSheet(0).setRowCount(30);
+            rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
+            jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
+            jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
+            annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
+            annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
+            sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
+        }
+        sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
+        rationGLJOprObj.sheet.getParent().focus(false);
+        me.workBook.focus(true);
+    }
+};

+ 202 - 0
web/building_saas/complementary_ration_lib/js/sheetsOpr.js

@@ -0,0 +1,202 @@
+/**
+ * Created by Zhong on 2017/9/29.
+ */
+let sheetsOprObj = {
+    setAreaAlign: function(area, hAlign, vAlign){
+        if (!(hAlign) || hAlign === "left") {
+            area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
+        } else if (hAlign === "right") {
+            area.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
+        } else if (hAlign === "center") {
+            area.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
+        } else {
+            area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
+        }
+        if (!(vAlign) || vAlign === "center") {
+            area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
+        } else if (vAlign === "top") {
+            area.vAlign(GC.Spread.Sheets.VerticalAlign.top);
+        } else if (vAlign === "bottom") {
+            area.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
+        } else {
+            area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
+        }
+    },
+    showData: function(sheet, setting, data, distTypeTree) {
+        var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        if(typeof setting.owner !== 'undefined' && setting.owner === 'gljComponent'){
+            sheet.setRowCount(data.length + 5);
+        }
+        else{
+            sheet.setRowCount(typeof repositoryGljObj !== 'undefined' && repositoryGljObj.currentOprParent === 1 ? data.length : data.length + 10);
+        }
+        /*if(data.length === 0){
+            for(let i = 0; i < sheet.getRowCount(); i++){
+                sheet.getCell(i, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+            }
+        }*/
+        for (var col = 0; col < setting.header.length; col++) {
+            var hAlign = "left", vAlign = "center";
+            if (setting.header[col].hAlign) {
+                hAlign = setting.header[col].hAlign;
+            } else if (setting.header[col].dataType !== "String"){
+                hAlign = "right";
+            }
+            vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
+            me.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
+            if (setting.header[col].formatter) {
+                //var style = new GC.Spread.Sheets.Style();
+                //style.formatter = setting.header[col].formatter;
+                //sheet.setStyle(row,col,style,GC.Spread.Sheets.SheetArea.viewport);
+                sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
+            }
+            for (var row = 0; row < data.length; row++) {
+                //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
+                if(setting.header[col].dataCode === 'gljType' && data[row].gljType){
+                   /* if(typeof repositoryGljObj !== 'undefined' && typeof repositoryGljObj.allowComponent !== 'undefined' && repositoryGljObj.allowComponent.indexOf(data[row].gljType) !== -1){
+                        sheet.getCell(row, 4, GC.Spread.Sheets.SheetArea.viewport).locked(true);
+                    }
+                    else if(typeof repositoryGljObj !== 'undefined' && typeof repositoryGljObj.allowComponent !== 'undefined' && repositoryGljObj.allowComponent.indexOf(data[row].gljType) === -1){
+                        sheet.getCell(row, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+                    }*/
+                    let distTypeVal =  distTypeTree.distTypes[distTypeTree.prefix + data[row].gljType].data.fullName;
+                    sheet.setValue(row, col, distTypeVal, ch);
+                }
+                else {
+                    sheet.setValue(row, col, data[row][setting.header[col].dataCode], ch);
+                    sheet.setTag(row, 0, data[row].ID, ch);
+                    /*if(typeof setting.owner !== 'undefined' && setting.owner !== 'gljComponent'){
+                        sheet.getCell(row, 0, GC.Spread.Sheets.SheetArea.viewport).locked(true);
+                    }*/
+                }
+            }
+          /*  for(let i = data.length; i < sheet.getRowCount(); i++){
+                sheet.getCell(i, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+            }*/
+        }
+        sheet.resumeEvent();
+        sheet.resumePaint();
+        //me.shieldAllCells(sheet);
+    },
+    combineRowData: function(sheet, setting, row, repositoryGljObj) {
+        let me = this;
+        var rst = {};
+        let comboBoxCellType = sheet.getCellType(row, 5);
+        let items = comboBoxCellType.items();
+        for (var col = 0; col < setting.header.length; col++) {
+            if(setting.header[col].dataCode === 'gljType'){
+                items.forEach(function(item){
+                    if(sheet.getValue(row, col) === item.text){
+                        rst[setting.header[col].dataCode] = item.value;
+                        if(repositoryGljObj){
+                            rst.shortName = repositoryGljObj.distTypeTree.distTypes[repositoryGljObj.distTypeTree.prefix + item.value].data.shortName;
+                        }
+                    }
+                });
+            }
+            else if (setting.header[col].dataCode === 'code'){
+                if(repositoryGljObj){
+                    let gljList = repositoryGljObj.gljList,
+                        orgCode = repositoryGljObj.orgCode,
+                        isExist = false;
+                    for(let i=0; i< gljList.length; i++){
+                        if(gljList[i].code === sheet.getValue(row, col) && sheet.getValue(row, col)!== orgCode){
+                           // sheetCommonObj.lockAllCells(sheet);
+                            $('#alertText').text("输入的编号已存在,请重新输入!");
+                            $('#codeAlertBtn').click();
+                            $('#codAleConfBtn').click(function () {
+                                // me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                               // sheetCommonObj.unLockAllCells(sheet);
+                                //me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                                sheet.setValue(row, 0, orgCode);
+                                sheet.getCell(row, 0).formatter("@");
+                                sheet.setActiveCell(row, 0);
+                            });
+                            $('#codAleClose').click(function () {
+                                //me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                                //sheetCommonObj.unLockAllCells(sheet);
+                                //me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                                sheet.setValue(row, 0, orgCode);
+                                sheet.getCell(row, 0).formatter("@");
+                                sheet.setActiveCell(row, 0);
+                            });
+                            // sheet.setValue(row, col, orgCode);
+                            isExist = true
+                        }
+                    }
+                    if(!isExist){
+                        rst[setting.header[col].dataCode] = sheet.getValue(row, col);
+                    }
+                }
+                else{
+                    rst[setting.header[col].dataCode] = sheet.getValue(row, col);
+                }
+            }
+            else{
+                rst[setting.header[col].dataCode] = sheet.getValue(row, col);
+            }
+        }
+        return rst;
+    },
+    combineRationRowData: function(sheet, setting, row) {
+        var rst = {};
+        for (var col = 0; col < setting.header.length; col++) {
+            rst[setting.header[col].dataCode] = sheet.getValue(row, col);
+        }
+        return rst;
+    },
+    reLockSomeCodes: function (sheet, beginRow, endRow) {
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        let defaultStyle = new GC.Spread.Sheets.Style();
+        defaultStyle.locked = false;
+        sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
+        let unLockStyle = new GC.Spread.Sheets.Style();
+        unLockStyle.locked = false;
+        let lockStyle = new GC.Spread.Sheets.Style();
+        lockStyle.locked = true;
+        for(let row = beginRow; row < endRow; row++){
+            sheet.setStyle(row, 0, lockStyle);
+        }
+        for(let row = endRow; row < sheet.getRowCount(); row++){
+            sheet.setStyle(row, 0, unLockStyle);
+        }
+        sheet.options.isProtected = true;
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+    lockSomeCodes: function (sheet, beginRow, endRow) {
+        let defaultStyle = new GC.Spread.Sheets.Style();
+        defaultStyle.locked = false;
+        sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
+        let style = new  GC.Spread.Sheets.Style();
+        style.locked = true;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        for(let i = beginRow; i < endRow; i++){
+            sheet.setStyle(i, 0, style);
+        }
+        sheet.options.isProtected = true;
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    },
+    lockCodeCells: function (sheet, rowCount) {
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        let sheetRowCount = sheet.getRowCount();
+        let defaultStyle = new GC.Spread.Sheets.Style();
+        defaultStyle.locked = false;
+        sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
+        let style = new GC.Spread.Sheets.Style();
+        style.locked = true;
+        sheet.setStyle(-1, 0, style);
+        for(let i =rowCount; i<sheetRowCount; i++){
+            sheet.setStyle(i, -1, style);
+        }
+        sheet.options.isProtected = true;
+        sheet.resumePaint();
+        sheet.resumeEvent();
+    }
+};

+ 2 - 1
web/common/html/header.html

@@ -10,7 +10,8 @@
         <li class="nav-item dropdown">
             <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-wrench"></i> 工具</a>
             <div class="dropdown-menu">
-                <a class="dropdown-item" href="#">定额库编辑器</a>
+                <!--<a class="dropdown-item" href="/complementaryRation/main">定额库编辑器</a>-->
+                <a class="dropdown-item" href="javascript:void(0);" data-toggle="modal" data-target="#comple-ration">定额库编辑器</a>
                 <a class="dropdown-item" href="/complementaryGlj">工料机库编辑器</a>
             </div>
         </li>