Browse Source

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionOperation

TonyKang 7 years ago
parent
commit
8e3cedf99f

+ 8 - 0
modules/ration_repository/controllers/ration_controller.js

@@ -88,6 +88,14 @@ class RationController extends BaseController{
             callback(req, res, err, '', null);
         });
     }
+    updateAnnotation(req, res){
+        let repId = req.body.repId,
+            updateArr = JSON.parse(req.body.updateArr),
+            lastOpr = req.body.lastOpr;
+        rationItem.updateAnnotation(lastOpr, repId, updateArr, function (err) {
+            callback(req, res, err, '', null);
+        });
+    }
 }
 
 export default RationController;

+ 9 - 1
modules/ration_repository/controllers/ration_section_tree_controller.js

@@ -77,7 +77,15 @@ class RationChapterTreeController extends BaseController{
         rationChapterTreeData.updateSituation(lastOpr, repId, nodeId, situation, function (err) {
             callback(req, res, err, '', null);
         });
-
+    }
+    updateAnnoSituation(req, res){
+        let repId = req.body.repId,
+            nodeId = req.body.nodeId,
+            situation = req.body.situation,
+            lastOpr = req.body.lastOpr;
+        rationChapterTreeData.updateAnnoSituation(lastOpr, repId, nodeId, situation, function (err) {
+            callback(req, res, err, '', null);
+        });
     }
 }
 

+ 22 - 0
modules/ration_repository/models/ration_item.js

@@ -403,5 +403,27 @@ rationItemDAO.prototype.updateJobContent = function (lastOpr, repId, updateArr,
     });
 }
 
+rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr, callback) {
+    rationRepositoryDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
+        async.each(updateArr, function (obj, cb) {
+            rationItemModel.update({rationRepId: repId, code: obj.code}, {$set: {annotation: obj.annotation}}, function (err) {
+                if(err){
+                    cb(err);
+                }
+                else{
+                    cb(null);
+                }
+            })
+        }, function (err) {
+            if(err){
+                callback(err);
+            }
+            else{
+                callback(null);
+            }
+        });
+    });
+}
+
 module.exports = new rationItemDAO()
 

+ 12 - 0
modules/ration_repository/models/ration_section_tree.js

@@ -139,6 +139,18 @@ rationChapterTreeDAO.prototype.updateSituation = function (lastOpr, repId, nodeI
         }
     });
 };
+rationChapterTreeDAO.prototype.updateAnnoSituation = function (lastOpr, repId, nodeId, situation, callback) {
+    rationChapterTreeModel.update({rationRepId: repId, ID: nodeId}, {$set: {annotationSituation: situation}}, function (err, result) {
+        if(err){
+            callback(err);
+        }
+        else{
+            rationRepositoryDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
+                callback(null);
+            });
+        }
+    });
+};
 
 rationChapterTreeDAO.prototype.updateNodes = function(repId, lastOpr, nodes,callback){
     var functions = [];

+ 3 - 1
modules/ration_repository/models/schemas.js

@@ -56,7 +56,8 @@ let rationChapterTreeSchema = new Schema({
     name: String,
     explanation: String,//说明
     ruleText: String,//计算规则
-    jobContentSituation: String,//工作内容适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额
+    jobContentSituation: String,//工作内容适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额,NONE无
+    annotationSituation: String,//附注的适用情况,ALL适用本项全部定额,PARTIAL适用本项部分定额,NONE无
     isDeleted: Boolean
 });
 
@@ -95,6 +96,7 @@ var rationItemSchema = new Schema({
     caption: String,
     feeType: Number,
     jobContent: String,
+    annotation: String,
     rationGljList: [rationGljItemSchema],
     rationCoeList: Array,
     rationAssList: [rationAssItemSchema],

+ 2 - 0
modules/ration_repository/routes/ration_rep_routes.js

@@ -42,6 +42,7 @@ module.exports =  function (app) {
     apiRouter.post("/updateExplanation",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateExplanation);
     apiRouter.post("/updateRuleText",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateRuleText);
     apiRouter.post("/updateSituation",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateSituation);
+    apiRouter.post("/updateAnnoSituation",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.updateAnnoSituation);
 
     apiRouter.post("/getRationItems",rationController.auth, rationController.init, rationController.getRationItemsBySection);
     apiRouter.post("/mixUpdateRationItems",rationController.auth, rationController.init, rationController.mixUpdateRationItems);
@@ -49,6 +50,7 @@ module.exports =  function (app) {
     apiRouter.post("/getRationGljIds",rationController.auth, rationController.init, rationController.getRationGljIds);
     apiRouter.post("/getRationsCodes",rationController.auth, rationController.init, rationController.getRationsCodes);
     apiRouter.post("/updateJobContent",rationController.auth, rationController.init, rationController.updateJobContent);
+    apiRouter.post("/updateAnnotation",rationController.auth, rationController.init, rationController.updateAnnotation);
 
     apiRouter.post("/createNewGljTypeNode",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.createNewGljTypeNode);
     apiRouter.post("/updateGljNodes",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.updateGljNodes);

+ 22 - 142
public/web/sheet/sheet_common.js

@@ -111,21 +111,13 @@ var sheetCommonObj = {
             area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
         }
     },
-    showData: function(sheet, setting, data, distTypeTree) {
+    showData: function(sheet, setting, data) {
         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);
-            }
-        }
+        //sheet.addRows(row, 1);
+
+        sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
         for (var col = 0; col < setting.header.length; col++) {
             var hAlign = "left", vAlign = "center";
             if (setting.header[col].hAlign) {
@@ -141,30 +133,30 @@ var sheetCommonObj = {
                 //sheet.setStyle(row,col,style,GC.Spread.Sheets.SheetArea.viewport);
                 sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
             }
+            if(setting.header[col].cellType === "checkBox"||setting.header[col].cellType === "button"){//clear and reset
+                var me = this, header = GC.Spread.Sheets.SheetArea.colHeader;
+                sheet.deleteColumns(col,1);
+                sheet.addColumns(col, 1);
+                sheet.setValue(0, col, setting.header[col].headerName, header);
+                sheet.setColumnWidth(col, setting.header[col].headerWidth?setting.header[col].headerWidth:100);
+            }
             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);
+                var val = data[row][setting.header[col].dataCode];
+                if(val&&setting.header[col].dataType === "Number"){
+                    if(setting.header[col].hasOwnProperty('tofix')){
+                        val =parseFloat(val).toFixed(setting.header[col].tofix);
+                    }else {
+                        val =parseFloat(val).toFixed(2);
                     }
-                    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);
-                    }
+                if(val!=null&&setting.header[col].cellType === "checkBox"){
+                    this.setCheckBoxCell(row,col,sheet,val)
                 }
-            }
-            for(let i = data.length; i < sheet.getRowCount(); i++){
-                sheet.getCell(i, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+                sheet.setValue(row, col, val, ch);
             }
         }
+        this.lockCells(sheet,setting);
         sheet.resumeEvent();
         sheet.resumePaint();
         //me.shieldAllCells(sheet);
@@ -195,67 +187,7 @@ var sheetCommonObj = {
         }
         return rst;
     },
-    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){
-                                me.lockAllCells(sheet);
-                                $('#alertText').text("输入的编号已存在,请重新输入!");
-                                $('#codeAlertBtn').click();
-                                $('#codAleConfBtn').click(function () {
-                                   // me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
-                                    me.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);
-                                    me.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) {
+    combineRowData: function(sheet, setting, row) {
         var rst = {};
         for (var col = 0; col < setting.header.length; col++) {
             rst[setting.header[col].dataCode] = sheet.getValue(row, col);
@@ -268,26 +200,6 @@ var sheetCommonObj = {
     unShieldAllCells: function(sheet) {
         sheet.options.isProtected = false;
     },
-    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();
-    },
     unLockAllCells: function (sheet) {
         sheet.suspendPaint();
         sheet.suspendEvent();
@@ -312,38 +224,6 @@ var sheetCommonObj = {
         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();
-    },
     lockCells: function(sheet, setting){
         sheet.suspendPaint();
         sheet.suspendEvent();

+ 75 - 2
web/maintain/ration_repository/dinge.html

@@ -69,6 +69,9 @@
                           <li class="nav-item">
                               <a class="nav-link" data-toggle="tab" href="#tgz" role="tab">工作内容</a>
                           </li>
+                          <li class="nav-item">
+                              <a class="nav-link" data-toggle="tab" href="#tfz" role="tab">附注</a>
+                          </li>
                       </ul>
                       <div class="tab-content">
                           <!--定额-->
@@ -132,9 +135,23 @@
                                       </tr>
                                   </table>
                                   <table class="table table-sm table-bordered m-0" id="tablePartial">
-                              </table>
+                                  </table>
+                              </div>
+                          </div>
+                          <!--附注-->
+                          <div class="tab-pane" id="tfz" role="tabpanel">
+                              <div class="main-data">
+                                  <div class="form-check m-2"><label class="form-check-label"><input type="radio" class="form-check-input" name="fzRadios" value="ALL" disabled=""> 适合本项所有定额</label>&nbsp;&nbsp;<label class="form-check-label"><input type="radio" class="form-check-input" name="fzRadios" value="PARTIAL" disabled> 适合本项部分定额</label></div>
+                                  <!-- <p class="m-2">适合本项所有定额</p> -->
+                                  <table class="table table-sm table-bordered m-0" id="fzTableAll">
+                                      <tr>
+                                          <td><textarea class="form-control" rows="30" id="fzTxtareaAll"></textarea></td>
+                                      </tr>
+                                  </table>
+                                  <table class="table table-sm table-bordered m-0" id="fzTablePartial">
+                                  </table>
+                              </div>
                           </div>
-                      </div>
                   </div>
                 </div>
             </div>
@@ -314,6 +331,61 @@
                 </div>
             </div>
         </div>
+        <!--弹出附注-->
+        <div class="modal fade" id="fzEditBianmaQ" data-backdrop="static" style="display: none;" aria-hidden="true">
+            <div class="modal-dialog" role="document">
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <h5 class="modal-title">修改编码</h5>
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                            <span aria-hidden="true">×</span>
+                        </button>
+                    </div>
+                    <div class="modal-body">
+                        <form>
+                            <div class="form-group">
+                                <label>编码</label>
+                                <div class="form-control">
+                                    <div class="row code" id="fzUpdateCon">
+                                    </div>
+                                </div>
+                            </div>
+                        </form>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                        <a href="javascript: void(0);" class="btn btn-primary" data-dismiss="modal" id="fzUpdateConBtn">确定</a>
+                    </div>
+                </div>
+            </div>
+        </div>
+        <div class="modal fade" id="fzEditBianma" data-backdrop="static" style="display: none;" aria-hidden="true">
+            <div class="modal-dialog" role="document">
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <h5 class="modal-title">勾选编码</h5>
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                            <span aria-hidden="true">×</span>
+                        </button>
+                    </div>
+                    <div class="modal-body">
+                        <form>
+                            <div class="form-group">
+                                <label>编码</label>
+                                <div class="form-control">
+                                    <div class="row code" id="fzAddCon">
+                                    </div>
+                                </div>
+                            </div>
+                        </form>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                        <a href="javascript: void(0);" class="btn btn-primary" data-dismiss="modal" id="fzAddConBtn">确定</a>
+                    </div>
+                </div>
+            </div>
+        </div>
         <!--弹出警告窗-->
         <button id="rationAlertBtn" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#rationAlert" style="display: none"></button>
         <div class="modal fade" id="rationAlert" data-backdrop="static" style="display: none;" aria-hidden="true">
@@ -372,6 +444,7 @@
         <script type="text/javascript" src="/web/maintain/ration_repository/js/section_tree.js"></script>
         <script type="text/javascript" src="/public/web/ztree_common.js"></script>
         <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
+        <script type="text/javascript" src="/web/maintain/ration_repository/js/sheetsOpr.js"></script>
         <script type="text/javascript" src="/web/maintain/ration_repository/js/rationUnits.js"></script>
         <script type="text/javascript" src="/web/maintain/ration_repository/js/ration.js"></script>
         <script type="text/javascript" src="/web/maintain/ration_repository/js/ration_glj.js"></script>

+ 1 - 0
web/maintain/ration_repository/fuzhu.html

@@ -89,6 +89,7 @@
     <script src="/public/common_util.js"></script>
     <script src="/public/debug.js"></script>
     <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
+    <script type="text/javascript" src="/web/maintain/ration_repository/js/sheetsOpr.js"></script>
     <script type="text/javascript" src="/public/web/storageUtil.js"></script>
     <script type="text/javascript" src="/web/maintain/ration_repository/js/coe.js"></script>
     <script type="text/javascript">

+ 1 - 0
web/maintain/ration_repository/gongliao.html

@@ -227,6 +227,7 @@
     <script type="text/javascript" src="/web/maintain/ration_repository/js/repository_glj.js"></script>
     <script type="text/javascript" src="/public/web/ztree_common.js"></script>
     <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
+    <script type="text/javascript" src="/web/maintain/ration_repository/js/sheetsOpr.js"></script>
     <script type="text/javascript" src="/public/web/storageUtil.js"></script>
     <script type="text/javascript">
         let userAccount = '<%=userAccount %>';

+ 121 - 99
web/maintain/ration_repository/js/ration.js

@@ -10,18 +10,17 @@ $("#fuzhu").click(function(){
     $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
 });
 
-var rationOprObj = {
+let rationOprObj = {
     workBook: null,
     currentRations: {},
     currentEditingRation: null,
     currentSectionId: -1,
-    activeCell: null,
     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:"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"},
@@ -43,7 +42,7 @@ var rationOprObj = {
     },
     buildSheet: function(container) {
         let rationRepId = getQueryString("repository");
-        var me = rationOprObj;
+        let me = rationOprObj;
         let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
         if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
             alert("没有引用工料机库!");
@@ -57,16 +56,45 @@ var rationOprObj = {
         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.RangeChanged, me.onRangeChanged);
-        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
+        //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
+    },
+
+    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.shieldAllCells(sheetGLJ);
+            sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
+            sheetCommonObj.shieldAllCells(sheetCoe);
+            sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
+            sheetCommonObj.shieldAllCells(sheetAss);
+            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);
+        }
     },
 
     onCellClick: function(sender, args) {
-        var me = rationOprObj,
+        let me = rationOprObj,
             sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
             sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
             sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
-        me.activeCell = {row: args.row, col: args.col};
         sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
         sheetCommonObj.shieldAllCells(sheetGLJ);
         sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
@@ -74,7 +102,7 @@ var rationOprObj = {
         sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
         sheetCommonObj.shieldAllCells(sheetAss);
         if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
-            var cacheSection = me.getCache();
+            let cacheSection = me.getCache();
             if (cacheSection && args.row < cacheSection.length) {
                 rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
                     me.workBook.focus(true);
@@ -90,9 +118,11 @@ var rationOprObj = {
         };
         me.workBook.focus(true);
     },
-
+    isInt: function (num) {
+        return !isNaN(num) && num % 1 === 0;
+    },
     getCache: function() {
-        var me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
+        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];
@@ -100,21 +130,21 @@ var rationOprObj = {
         return rst;
     },
     updateCache: function(addArr, updateArr, removeIds, result) {
-        var me = this, cacheSection = me.getCache();
+        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 (var i = removeIds.length - 1; i >= 0; i--) {
-            for (var j = cacheSection.length - 1; j >= 0 ; j--) {
+        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 (var i = 0; i < result.data.ops.length; i++) {
-                for (var j = 0; j < cacheSection.length; j++) {
+            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"];
@@ -122,8 +152,8 @@ var rationOprObj = {
                 }
             }
         }
-        for (var i = 0; i < updateArr.length; i++) {
-            for (var j = 0; j < cacheSection.length; j++) {
+        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];
@@ -195,48 +225,6 @@ var rationOprObj = {
         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);
     },
-    onRangeChanged: function(sender, args) {
-        if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
-            var me = rationOprObj, updateArr = [], removeArr = [];
-            var cacheSection = me.getCache();
-            if (cacheSection) {
-                for (var i = 0; i < args.rowCount; i++) {
-                    //var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
-                    var hasUpdate = false, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row + i),
-                        isEmpty = sheetCommonObj.chkIfEmpty(rObj, me.setting);
-                    for (var 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"];
-                            hasUpdate = true;
-                            break;
-                        }
-                    }
-                    if(isEmpty){
-                        if(args.row + i < cacheSection.length){
-                            rObj.ID = cacheSection[args.row + i].ID;
-                            removeArr.push(rObj.ID);
-                        }
-                    }
-                    else{
-
-                    }
-
-                    if (hasUpdate) {
-                        if (isEmpty) {
-                            removeArr.push(rObj);
-                        } else updateArr.push(rObj);
-                    } else if (isEmpty) {
-                        if (args.row + i < cacheSection.length) {
-                            rObj["ID"] = cacheSection[args.row + i]["ID"];
-                            removeArr.push(rObj["ID"]);
-                        }
-                    }
-                }
-              //  me.mixUpdateRequest(updateArr, [], removeArr);
-                //removeRationItems
-            }
-        }
-    },
     onEnterCell: function (sender, args) {
         let me = rationOprObj;
         me.cellRowIdx = args.row;
@@ -252,17 +240,14 @@ var rationOprObj = {
         if(isHasData){
             if(me.editingRowIdx !== me.cellRowIdx) {
                 let focusToCol = !me.addRationItem.code ? 0 : -1;
-             //   else {
                 if(focusToCol !== -1){
                     $('#rationAlertBtn').click();
                     me.workBook.getSheet(0).options.isProtected = true;
                     $('#rationAlertCac').click(function () {
                         me.workBook.getSheet(0).options.isProtected = false;
-                        //me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
                     });
                     $('#rationAlertCls').click(function () {
                         me.workBook.getSheet(0).options.isProtected = false;
-                       // me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
                     });
                     $('#rationAlertCof').click(function () {
                         me.workBook.getSheet(0).options.isProtected = false;
@@ -270,21 +255,18 @@ var rationOprObj = {
                         for(let col=0; col<me.setting.header.length; col++){
                             me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingRation[me.setting.header[col].dataCode]);
                         }
-                        //me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
                     });
                 }
-               // }
             }
         }
     },
     onCellEditStart: function(sender, args) {
-        var me = rationOprObj;
-        //var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
-        var rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
+        let me = rationOprObj;
+        let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
         me.currentEditingRation = rObj;
-        var cacheSection = me.getCache();
+        let cacheSection = me.getCache();
         if (cacheSection) {
-            for (var j = 0; j < cacheSection.length; j++) {
+            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;
@@ -293,13 +275,16 @@ var rationOprObj = {
         }
     },
     onCellEditEnd: function(sender, args) {
-        //var me = rationOprObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row),
-        var me = rationOprObj, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
+        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"]) {
-            rObj["ID"] = 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'){
@@ -314,10 +299,20 @@ var rationOprObj = {
 
                         }
                     }
+                    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)) {
@@ -329,6 +324,9 @@ var rationOprObj = {
                         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);
@@ -367,35 +365,34 @@ var rationOprObj = {
         }
     },
     onClipboardPasting: function(sender, args) {
-        var me = rationOprObj;
-      /*  if (args.cellRange.colCount != me.setting.header.length) {
-            args.cancel = true;
-        }*/
+        let me = rationOprObj;
     },
     onClipboardPasted: function(e, info) {
-        var me = rationOprObj;
-        var cacheSection = me.getCache();
-        var updateArr = [], addArr = [];
-        var items = sheetCommonObj.analyzePasteData(me.setting, info);
-        let failPasteArr = [];
-        for (var i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
+        let me = rationOprObj;
+        let cacheSection = me.getCache();
+        let updateArr = [], addArr = [];
+        let items = sheetCommonObj.analyzePasteData(me.setting, info);
+        //let failPasteArr = [];
+        for (let i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
             if (cacheSection) {
                 if(!me.isValidUnit(items[i], rationUnits)){//无效单位
                     items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
                 }
-                //var hasCacheItem = false;
                 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{
-                        failPasteArr.push(items[i].code);
+                        //failPasteArr.push(items[i].code);
                         me.workBook.getSheet(0).setValue(rowIdx, 0, '');
                     }
                 }
@@ -405,6 +402,10 @@ var rationOprObj = {
                             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;
@@ -432,12 +433,15 @@ var rationOprObj = {
                             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]);
                         }
-                        else{
+                        /*else{
                             failPasteArr.push(items[i]);
-                        }
+                        }*/
                 }
             }
         };
@@ -477,7 +481,7 @@ var rationOprObj = {
         })
     },
     mixUpdateRequest: function(updateArr, addArr, removeIds) {
-        var me = rationOprObj;
+        let me = rationOprObj;
         sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
         $.ajax({
             type:"POST",
@@ -491,21 +495,37 @@ var rationOprObj = {
                     alert(`error`);
                     me.getRationItems(me.currentSectionId);
                 } else {
-                    var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
+                    let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
                     cacheSection.sort(function(a, b){
-                        var rst = 0;
+                        let rst = 0;
                         if (a.code > b.code) rst = 1
                         else if (a.code < b.code) rst = -1;
                         return rst;
                     });
                     //jobContent
-                    if(jobContentOprObj && jobContentOprObj.currentSituation === jobContentOprObj.situations.PARTIAL){
+                    if(jobContentOprObj ){
                         jobContentOprObj.currentRationItems = cacheSection;
-                        jobContentOprObj.buildTablePartial(jobContentOprObj.tablePartial, jobContentOprObj.getGroup(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.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
                 }
                 sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
             },
@@ -515,14 +535,15 @@ var rationOprObj = {
     },
     getRationItems: function(sectionID){
         if (sectionID != -1) {
-            var me = rationOprObj;
+            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]);
-                //jobContent--
+                //annotation
+                annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
                 me.showRationItems(sectionID);
                 ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
                 sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
@@ -544,7 +565,8 @@ var rationOprObj = {
                             //job--
                             jobContentOprObj.currentRationItems = me.currentRations["_SEC_ID_" + sectionID];
                             jobContentOprObj.rationJobContentOpr(me.currentRations["_SEC_ID_" + sectionID]);
-                            //job--
+                            //annotation
+                            annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
                             me.showRationItems(sectionID);
                             //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
                             sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
@@ -576,13 +598,13 @@ var rationOprObj = {
         sheet.resumePaint();
     },
     showRationItems: function(sectionID){
-        var me = rationOprObj;
+        let me = rationOprObj;
         if (me.workBook) {
             if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
-                var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
+                let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
                 //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
                 sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
-                sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
+                sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
                 sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
                 //combo
                 me.setCombo(me.workBook.getActiveSheet(), rationUnits);

+ 1 - 1
web/maintain/ration_repository/js/ration_assist.js

@@ -66,7 +66,7 @@ var rationAssistOprObj = {
         if (!me.ration) {return;};
         var assList = me.ration.rationAssList;
         //var assObj = sheetCommonObj.combineRowData(me.sheet, me.setting, args.row);
-        var assObj = sheetCommonObj.combineRationRowData(me.sheet, me.setting, args.row);
+        var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
         // 新增
         if ((assList == undefined) || (assList && args.row >= assList.length)) {
             if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};

+ 1 - 1
web/maintain/ration_repository/js/ration_coe.js

@@ -279,7 +279,7 @@ var rationCoeOprObj = {
                 else if (a.ID < b.ID) rst = -1;
                 return rst;
             });
-            sheetCommonObj.showData(me.sheet, me.setting, curCache);
+            sheetsOprObj.showData(me.sheet, me.setting, curCache);
         }
     },
 

+ 33 - 13
web/maintain/ration_repository/js/ration_glj.js

@@ -12,7 +12,7 @@ var rationGLJOprObj = {
         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: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},
@@ -97,16 +97,13 @@ var rationGLJOprObj = {
         spreadBook.commandManager().register('rationGljDelete', function () {
             let sels = me.sheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
             let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID], isUpdate = false;
+            console.log(cacheSection);
             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){
-                                    isUpdate = true;
-                                    cacheSection.splice(sels[sel].row + i, 1);
-                                }
-                            }
+                        if(cacheSection && sels[sel].row < cacheSection.length){
+                            isUpdate = true;
+                            cacheSection.splice(sels[sel].row, sels[sel].rowCount);
                         }
                     }
                     else{
@@ -179,7 +176,7 @@ var rationGLJOprObj = {
                     for (var i = 0; i < tmpCodes.length; i++) {
                         let rowIdx = info.cellRange.row + i;
                         if(rowIdx < cacheArr.length){//更新
-                            me.tempCacheArr.push(cacheArr[rowIdx]);
+                            me.tempCacheArr.push({org: cacheArr[rowIdx], newCode: tmpCodes[i].code});
                             cacheArr.splice(rowIdx--, 1);
                         }
                         codes.push(tmpCodes[i].code);
@@ -261,7 +258,7 @@ var rationGLJOprObj = {
                     }
                     else {
                         if (args.row < cacheArr.length && args.editingText !== cacheArr[args.row].code) {//更新
-                            me.tempCacheArr.push(cacheArr[args.row]);
+                            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);
@@ -327,7 +324,22 @@ var rationGLJOprObj = {
             }
         });
     },
-
+    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;
         sheetCommonObj.setLockCol(me.sheet, 0, true);
@@ -364,6 +376,10 @@ var rationGLJOprObj = {
                                 }
                             }
                             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
@@ -378,7 +394,11 @@ var rationGLJOprObj = {
                     }
                     else{
                         let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]?  me.cache["_GLJ_" + me.currentRationItem.ID] : [];
-                        me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(me.tempCacheArr);
+                        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] = cacheArr.concat(me.tempCacheArr);
                         //更新的工料机不存在
                         me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
                             var rst = 0;
@@ -557,7 +577,7 @@ var rationGLJOprObj = {
         var me = this;
         if (me.cache["_GLJ_" + rationID]) {
             sheetCommonObj.cleanData(me.sheet, me.setting, -1);
-            sheetCommonObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
+            sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
             //lock
             me.sheet.suspendPaint();
             me.sheet.suspendEvent();

+ 15 - 140
web/maintain/ration_repository/js/repository_glj.js

@@ -51,7 +51,7 @@ repositoryGljObj = {
         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: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"}
@@ -91,17 +91,11 @@ repositoryGljObj = {
             }
         });
         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});
             }
         });
-        //me.distTypeTree = distTypeTree;
         return distTypeTree;
-        //return distTypeTree.comboDatas;
     },
     getGljDistType: function (callback) {
         let me = this;
@@ -112,9 +106,9 @@ repositoryGljObj = {
             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).cellType(combo).value(me.distTypeTree.comboDatas[0].text);
+                    /*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();
                 }
             }
@@ -186,7 +180,7 @@ repositoryGljObj = {
                 }
             }
             sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
-            sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
+            sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
 
             cacheSection = null;
         }
@@ -247,19 +241,19 @@ repositoryGljObj = {
                     $('#aleCanceBtn').click(function () {
                         // me.workBook.getSheet(0).options.isProtected = false;
                         sheetCommonObj.unLockAllCells(args.sheet);
-                        sheetCommonObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        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);
-                        sheetCommonObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        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);
-                        sheetCommonObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        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;
@@ -279,7 +273,7 @@ repositoryGljObj = {
     },
     onCellEditStart: function(sender, args) {
         var me = repositoryGljObj;
-        var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
+        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;
@@ -294,7 +288,7 @@ repositoryGljObj = {
         }
     },
     onCellEditEnd: function(sender, args) {
-        var me = repositoryGljObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
+        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;
@@ -404,10 +398,10 @@ repositoryGljObj = {
                                 $('#codeAlertBtn').click();
                                 sheet.options.isProtected = true;
                                 $('#codAleConfBtn').click(function () {
-                                    sheetCommonObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                                 });
                                 $('#codAleClose').click(function () {
-                                    sheetCommonObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                                 });
                             }
                         }
@@ -442,13 +436,13 @@ repositoryGljObj = {
                     $('#codeAlertBtn').click();
                     sheet.options.isProtected = true;
                     $('#codAleConfBtn').click(function () {
-                        sheetCommonObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                        sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                         if(removeArr.length > 0){
                             me.mixUpdateRequest(updateArr, [], removeArr);
                         }
                     });
                     $('#codAleClose').click(function () {
-                        sheetCommonObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                        sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                         me.mixUpdateRequest(updateArr, [], removeArr);
                     });
                 }
@@ -465,125 +459,6 @@ repositoryGljObj = {
         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);
     },
-    onRangeChanged: function(sender, args) {
-        if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
-            var me = repositoryGljObj, updateArr = [], removeArr = [], cancelArr = [], isMisCode = true;
-            var cacheSection = me.currentCache;
-            if (cacheSection) {
-                for (var i = 0; i < args.rowCount; i++) {
-                    let rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
-                        isEmpty = sheetCommonObj.chkIfEmpty(rObj, me.setting);
-                    if(isEmpty){
-                        if(args.row + i < cacheSection.length){
-                            rObj.ID = cacheSection[args.row + i].ID
-                            removeArr.push(rObj.ID);
-                        }
-                    }
-                    else {
-                        if(!rObj.code){
-                            cancelArr.push(args.row + i);
-                        }
-                        else if(!rObj.gljType){
-                            isMisCode = false;
-                            cancelArr.push(args.row + i);
-                        }
-                        else{
-                            rObj.gljClass = me.gljCurTypeId;
-                            updateArr.push(rObj);
-                        }
-                    }
-                }
-                //reshow datas
-                function resetDatas(args, repositoryGljObj, cancelArr){
-                    args.sheet.options.isProtected = false;
-                    args.sheet.suspendPaint();
-                    for(let i =0; i <cancelArr.length; i++){
-                        for(let col =args.col; col< repositoryGljObj.setting.header.length; col++){
-                            let value = repositoryGljObj.setting.header[col].dataCode === 'gljType' ?
-                                repositoryGljObj.distTypeTree.distTypes[repositoryGljObj.distTypeTree.prefix + cacheSection[cancelArr[i]].gljType].data.fullName :
-                                cacheSection[cancelArr[i]][repositoryGljObj.setting.header[col].dataCode];
-                            args.sheet.setValue(args.row + i, col, value);
-                        }
-                    }
-                    args.sheet.resumePaint();
-                    args.sheet.setActiveCell(args.row, 0);
-                }
-                if(cancelArr.length > 0){
-                    let text = isMisCode === true ? "编号不可为空,编辑失败!": "类型不可为空,编辑失败!"
-                    $('#alertText').text(text);
-                    $('#codeAlertBtn').click();
-                    args.sheet.options.isProtected = true;
-                    $('#codAleConfBtn').click(function () {
-                        resetDatas(args, me, cancelArr);
-                    });
-                    $('#codAleClose').click(function () {
-                        resetDatas(args, me, cancelArr);
-                    });
-                }
-                let refGljIds = [], refGljCodes = [], alertText;
-                if(removeArr.length > 0){
-                    for(let i =0; i <removeArr.length; i++){
-                        if(me.rationGljIds.indexOf(removeArr[i]) !== -1){
-                            refGljIds.push(removeArr[i]);
-                            removeArr.splice(i--, 1);
-                        }
-                    }
-                    for(let i =0; i< me.currentCache.length; i++){
-                        for(let j=0; j< refGljIds.length; j++){
-                            if(me.currentCache[i].ID === refGljIds[j]){
-                                refGljCodes.push(me.currentCache[i].code);
-                            }
-                        }
-                    }
-                }
-                if(refGljIds.length > 0){
-                    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();
-                    args.sheet.options.isProtected = true;
-                    $('#codAleConfBtn').click(function () {
-                        if(removeArr.length > 0){
-                            me.mixUpdateRequest(updateArr, [], removeArr);
-                        }
-                        else{
-                            let resetArr = [];
-                            for(let i=0; i<args.rowCount; i++){
-                                resetArr.push(args.row + i);
-                            }
-                            resetDatas(args, me, resetArr);
-                        }
-                    });
-                    $('#codAleClose').click(function () {
-                        if(removeArr.length > 0){
-                            me.mixUpdateRequest(updateArr, [], removeArr);
-                        }
-                        else{
-                            let resetArr = [];
-                            for(let i=0; i<args.rowCount; i++){
-                                resetArr.push(args.row + i);
-                            }
-                            resetDatas(args, me, resetArr);
-                        }
-                    });
-                }
-                else if(refGljIds.length === 0 && removeArr.length > 0){
-                    me.mixUpdateRequest(updateArr, [], removeArr);
-                }
-                if(updateArr.length > 0){
-                    me.mixUpdateRequest(updateArr, [], removeArr);
-                }
-            }
-        }
-    },
     validUpdateObj: function (pasteObj, rowIdx) {
         let rst = {}, backUpObj = {},
             me = repositoryGljObj,
@@ -842,7 +717,7 @@ repositoryGljObj = {
                     else{
                         me.currentCache = me.getCache();
                         //sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-                        sheetCommonObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
+                        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);

+ 467 - 60
web/maintain/ration_repository/js/section_tree.js

@@ -19,19 +19,12 @@ var pageOprObj = {
             jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
             $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
             $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
-            $('#txtareaAll').bind('change', function () {
-                let met = this;
-                let jobContent = $(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.updateJobContent(me.rationLibId, jobContentOprObj.getUpdateArr(updateCodes, jobContent), function () {
-                    $(met).attr('disabled', false);
-                    jobContentOprObj.currentJobContent = jobContent;
-                })
-            });
+            jobContentOprObj.bindAllEvents($('#txtareaAll'));
+            //fz
+            annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
+            $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
+            $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
+            annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
         }
     }
 }
@@ -347,15 +340,22 @@ var zTreeOprObj = {
         explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : treeNode, treeNode, treeNode.explanation, treeNode.ruleText);
         explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
         explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), treeNode.explanation, treeNode.ruleText);
+        //job
         jobContentOprObj.currentSituation = typeof treeNode.jobContentSituation !== 'undefined'? treeNode.jobContentSituation : jobContentOprObj.situations.NONE;
+        jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : treeNode, treeNode);
+        jobContentOprObj.clickUpdate($('#txtareaAll'));
+        //fz
+        annotationOprObj.currentSituation = typeof treeNode.annotationSituation !== 'undefined'? treeNode.annotationSituation : annotationOprObj.situations.NONE;
+        annotationOprObj.clickUpdate($('#fzTxtareaAll'));
         var sectionID = treeNode.ID;
         if (!(treeNode.items) || treeNode.items.length == 0) {
-            jobContentOprObj.setRadiosDisabled(false, jobContentOprObj.radios);
             rationOprObj.workBook.getSheet(0).clearSelection();
             rationOprObj.getRationItems(sectionID);
         } else {
             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.shieldAllCells(rationOprObj.workBook.getSheet(0));
         }
@@ -459,8 +459,10 @@ let explanatoryOprObj = {
 
 //工作内容
 let jobContentOprObj = {
-    situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},//所有ALL(包括未定义本项工作内容)、部分PARTIA,不可用NONE(非章节树最底层节点时)
+    situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},//所有ALL(包括未定义本项工作内容)、部分PARTIA,不可用NONE(无定额时)
     currentSituation: null,//本项适用情况
+    currentTreeNode: null,
+    preTreeNode: null,
     radios: $("input[name = 'optionsRadios']"),
     tableAll: $('#tableAll'),
     tablePartial: $('#tablePartial'),
@@ -469,21 +471,32 @@ let jobContentOprObj = {
     currentRationItems: null,
     addCon: $('#addCon'),//勾选编码模态框
     updateCon: $('#updateCon'),//编辑编码模态框
-    //获取本项适用情况
-    getSituation: function (rationItems) {
-        let me = this;
-        let rst = me.situations.ALL;
-        if(rationItems.length > 1){
-            for(let i = 0, len = rationItems.length; i < len; i++){
-                for(let j = i + 1, len = rationItems.length; j < len; j++){
-                    if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent !== rationItems[j].jobContent){
-                        rst = me.situations.PARTIAL;
-                        break;
-                    }
+    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.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();
             }
         }
-        return rst;
     },
     getGroup: function (rationItems) {
         let rst = [];//rst = [{jobContent: String, items: Array}]
@@ -584,21 +597,6 @@ let jobContentOprObj = {
         let me = jobContentOprObj;
         me.buildEditableCodesCon(me.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
     },
-    //更新显示的编码table
-    updateCodesTable: function (table, codes) {
-        let me = jobContentOprObj;
-        table.empty();
-        table.append("<a href data-toggle='modal' data-target='#editBianmaQ' class='m-0'>编辑编码</a>");
-        table.children().bind('click', function (){
-            me.currentOprTr = table.parent();
-            me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
-            me.onclickFuncEdit($(this));
-        });
-        for(let i = 0, len = codes.length; i < len; i++){
-            let $p = $("<p class='m-0'>" + codes[i] + "</p>");
-            table.append($p[0]);
-        }
-    },
     //获取编码td中的编码
     getUpdateCodes: function (jq) {
         let rst = [];
@@ -691,7 +689,7 @@ let jobContentOprObj = {
             radios[0].checked = true;
             radios[1].checked = false;
             $('#txtareaAll').val(me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '');
-            me.currentJobContent = me.currentRationItems[0].jobContent;
+            me.currentJobContent = me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '';
             me.tableAll.show();
             me.tablePartial.hide();
         }
@@ -746,21 +744,6 @@ let jobContentOprObj = {
             });
         });
     },
-    sortRationItems: function (rationItems, field) {
-        rationItems.sort(function (a, b) {
-            let rst = 0;
-            if(a[field] > b[field]){
-                rst = 1;
-            }
-            else if (a[field] < b[field]){
-                rst = -1;
-            }
-            return rst;
-        });
-    },
-    addCodeNode: function (container, codeNode) {
-        container.append(codeNode);
-    },
     setTextareaHeight: function (textarea, nodesCount) {
         const perHeight = 21.6;
         textarea.height(nodesCount * 21.6);
@@ -777,12 +760,30 @@ let jobContentOprObj = {
             });
         });
     },
-    unbindEvetns: function (txtarea) {
+    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));
     },
@@ -844,7 +845,7 @@ let jobContentOprObj = {
             dataType: 'json',
             success: function (result) {
                 if(!result.error){
-                    me.updateRationItem(me.currentRationItems, updateArr);
+                    me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
                     callback();
                 }
             }
@@ -859,9 +860,415 @@ let jobContentOprObj = {
             dataType: 'json',
             success: function (result) {
                 if(!result.error){
+                    if(callback){
+                        callback();
+                    }
+                }
+            }
+        })
+    }
+};
+
+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.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 = zTreeOprObj.treeObj.getSelectedNodes()[0];
+            me.updateAnnoSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
+                selectedNode.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();
+                    }
+                }
+            }
         })
     }
+
 };

+ 202 - 0
web/maintain/ration_repository/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){
+                            me.lockAllCells(sheet);
+                            $('#alertText').text("输入的编号已存在,请重新输入!");
+                            $('#codeAlertBtn').click();
+                            $('#codAleConfBtn').click(function () {
+                                // me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                                me.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);
+                                me.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();
+    }
+};

+ 1 - 0
web/maintain/std_glj_lib/html/gongliao.html

@@ -210,6 +210,7 @@
     <script type="text/javascript" src="/web/maintain/std_glj_lib/js/gljComponent.js"></script>
     <script type="text/javascript" src="/public/web/ztree_common.js"></script>
     <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
+    <script type="text/javascript" src="/web/maintain/ration_repository/js/sheetsOpr.js"></script>
     <script type="text/javascript" src="/public/web/storageUtil.js"></script>
     <SCRIPT type="text/javascript">
         let userAccount = '<%=userAccount %>';

+ 22 - 27
web/maintain/std_glj_lib/js/glj.js

@@ -39,7 +39,7 @@ let repositoryGljObj = {
             {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
             {headerName:"名称",headerWidth:260,dataCode:"name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
             {headerName:"规格型号",headerWidth:260,dataCode:"specs", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
-            {headerName:"计量单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center", 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"}
         ],
@@ -193,7 +193,7 @@ let repositoryGljObj = {
             }
             //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
             sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
-            sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
+            sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
 
             cacheSection = null;
         }
@@ -294,6 +294,7 @@ let repositoryGljObj = {
             sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, -1);
             me.workBook.focus(true);
             me.currentComponent = [];
+            that.workBook.getSheet(0).setRowCount(5);
             if(row < me.currentCache.length){
                 //标记当前工料机
                 me.currentGlj = me.currentCache[row];
@@ -306,7 +307,7 @@ let repositoryGljObj = {
                     if(me.currentGlj.component.length > 0){
                         me.currentComponent = me.getCurrentComponent(me.currentGlj.component);
                         if(me.currentComponent.length > 0){
-                            sheetCommonObj.showData(that.workBook.getSheet(0), that.setting, me.currentComponent);
+                            sheetsOprObj.showData(that.workBook.getSheet(0), that.setting, me.currentComponent);
                         }
                     }
                 }
@@ -334,15 +335,15 @@ let repositoryGljObj = {
                 let focusToCol;
                 function getFocusToCol (me){
                     if(!me.addGljObj[me.setting.header[0].dataCode]){
-                        $('#alertGljTxt').text('编号不能为空,是否取消增加工料机?');
+                        $('#alertGljTxt').text('编号不能为空,继续增加工料机?');
                         return 0;
                     }
                     else if(!me.addGljObj[me.setting.header[1].dataCode]){
-                        $('#alertGljTxt').text('名称不能为空,是否取消增加工料机?');
+                        $('#alertGljTxt').text('名称不能为空,继续增加工料机?');
                         return 1;
                     }
                     else if(!me.addGljObj[me.setting.header[5].dataCode]){
-                        $('#alertGljTxt').text('类型不能为空,是否取消增加工料机?');
+                        $('#alertGljTxt').text('类型不能为空,继续增加工料机?');
                         return 5;
                     }
                     else {
@@ -357,35 +358,28 @@ let repositoryGljObj = {
                     $('#gljAlertBtn').click();
                     //me.workBook.getSheet(0).options.isProtected = true;
                     sheetCommonObj.lockAllCells(args.sheet);
-                    $('#aleCanceBtn').click(function () {
+                    $('#aleConfBtn').click(function () {
                         // me.workBook.getSheet(0).options.isProtected = false;
                         sheetCommonObj.unLockAllCells(args.sheet);
-                        sheetCommonObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        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);
-                        sheetCommonObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
                         me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
                     });
-                    $('#aleConfBtn').click(function () {
+                    $('#aleCanceBtn').click(function () {
                         // me.workBook.getSheet(0).options.isProtected = false;
                         sheetCommonObj.unLockAllCells(args.sheet);
-                        sheetCommonObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
+                        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(
-                                    typeof me.currentEditingGlj[field] !== 'undefined'?
-                                        me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[field]].data.fullName
-                                        : '');
-                            }
-                            else{
+                            if(col === 0){
                                 me.workBook.getSheet(0).getCell(me.editingRowIdx, 0).formatter("@");
-                                me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value(me.currentEditingGlj[me.setting.header[col].dataCode]);
                             }
+                            me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
                         }
                         me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
                     });
@@ -395,7 +389,7 @@ let repositoryGljObj = {
     },
     onCellEditStart: function(sender, args) {
         let me = repositoryGljObj;
-        let rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
+        let rObj = sheetsOprObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
         me.currentEditingGlj = rObj;
         me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
         let cacheSection = me.gljList;
@@ -411,7 +405,7 @@ let repositoryGljObj = {
     },
     onCellEditEnd: function(sender, args) {
         let me = repositoryGljObj, that = gljComponentOprObj,
-            rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
+            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;
@@ -442,6 +436,7 @@ let repositoryGljObj = {
                                     }
                                 }
                             }
+                            sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, 5);
                         }
                         else if(rObj.basePrice !== me.currentEditingGlj.basePrice){//修改了单价,可修改单价的必为可成为组成物的
                             //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
@@ -600,10 +595,10 @@ let repositoryGljObj = {
                                 $('#codeAlertBtn').click();
                                 sheet.options.isProtected = true;
                                 $('#codAleConfBtn').click(function () {
-                                    sheetCommonObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                                 });
                                 $('#codAleClose').click(function () {
-                                    sheetCommonObj.lockSomeCodes(sheet, 0, cacheSection.length);
+                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                                 });
                             }
                         }
@@ -931,7 +926,7 @@ let repositoryGljObj = {
                     else{
                         me.currentCache = me.getCache();
                         //sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-                        sheetCommonObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
+                        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);
@@ -1028,7 +1023,7 @@ let gljTypeTreeOprObj = {
         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);
+            sheetsOprObj.lockCodeCells(me.workBook.getSheet(0), me.currentCache.length);
             me.workBook.getSheet(0).setRowCount(me.currentCache.length);
             //sheetCommonObj.shieldAllCells(me.workBook.getSheet(0), me.setting);
         } else {
@@ -1038,7 +1033,7 @@ let gljTypeTreeOprObj = {
             /*sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
              sheetCommonObj.lockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);*/
             sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-            sheetCommonObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
+            sheetsOprObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
         }
         me.showGljItems(me.gljList, gljTypeId);
     },

+ 1 - 1
web/maintain/std_glj_lib/js/gljComponent.js

@@ -400,7 +400,7 @@ let gljComponentOprObj = {
                         me.workBook.getSheet(0).getSelections()[0]
                         //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
                         sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
-                        sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
+                        sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
                     }
                 }
             }

+ 202 - 0
web/maintain/std_glj_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){
+                            me.lockAllCells(sheet);
+                            $('#alertText').text("输入的编号已存在,请重新输入!");
+                            $('#codeAlertBtn').click();
+                            $('#codAleConfBtn').click(function () {
+                                // me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                                me.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);
+                                me.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();
+    }
+};

+ 1 - 1
web/users/js/template.js

@@ -183,7 +183,7 @@ $(document).ready(function () {
         }
     }
 
-    billsTemplateData = billsTemplateData.replace('\n', '\\n');
+    billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
     let templateData = JSON.parse(billsTemplateData);
     for (let data of templateData) {
         if (data.flags) {