Browse Source

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

TonyKang 7 years ago
parent
commit
43a99b5e1f

+ 1 - 0
modules/bills_lib/models/bills_lib_schemas.js

@@ -44,6 +44,7 @@ let billsSchema = mongoose.Schema({
     name: String,
     unit: String,
     ruleText: String,
+    engineering: Number,   //工程专业,对应计算程序工程ID
     Expression: String,
     jobs: [],
     items: [],

+ 5 - 0
modules/ration_repository/controllers/coe_controller.js

@@ -27,6 +27,11 @@ class CoeListController extends BaseController{
             callback(req, res, err, 'Get coe', data);
         });
     }
+    getCoeItemsByNos(req,res){
+        coeList.getCoeItemsByNos(JSON.parse(req.body.data), function(err,data){
+            callback(req, res, err, 'Get coe', data);
+        });
+    }
 }
 
 export default CoeListController;

+ 12 - 1
modules/ration_repository/models/coe.js

@@ -25,7 +25,18 @@ coeListDAO.prototype.getCoeItemsByIDs = function (data, callback) {
     coeListModel.find({
             "libID": data.libID,
             "ID": {"$in":data.coeIDs}
-        }, ["libID","ID","name","content","-_id"],
+        }, ["libID","ID","serialNo","name","content","-_id"],
+        function (err, doc) {
+            if (err) callback("批量获取系数明细错误!", null)
+            else callback(null, doc);
+        })
+};
+
+coeListDAO.prototype.getCoeItemsByNos = function (data, callback) {
+    coeListModel.find({
+            "libID": data.libID,
+            "serialNo": {"$in":data.coeNos}
+        }, ["libID","ID","serialNo","name","content","-_id"],
         function (err, doc) {
             if (err) callback("批量获取系数明细错误!", null)
             else callback(null, doc);

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

@@ -19,6 +19,7 @@ let coeSchema = new Schema({
 let coeListSchema = new Schema({
     libID: Number,                      // 所属定额定ID
     ID: Number,                         // 系数ID(流水号ID)
+    serialNo: Number,                  //编号
     name: String,                       // 名称
     content: String,                    // 说明
     coes: [coeSchema]

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

@@ -65,6 +65,7 @@ module.exports =  function (app) {
     apiRouter.post("/getCoeList",coeListController.auth, coeListController.init, coeListController.getCoeList);
     apiRouter.post("/saveCoeList",coeListController.auth, coeListController.init, coeListController.saveCoeList);
     apiRouter.post("/getCoeItemsByIDs",coeListController.auth, coeListController.init, coeListController.getCoeItemsByIDs);
+    apiRouter.post("/getCoeItemsByNos",coeListController.auth, coeListController.init, coeListController.getCoeItemsByNos);
 
     apiRouter.post('/getRationItem',searchController.auth, searchController.init, searchController.getRationItem);
     apiRouter.post('/findRation', searchController.auth, searchController.init, searchController.findRation);

+ 1 - 0
modules/std_glj_lib/models/schemas.js

@@ -56,6 +56,7 @@ let gljSchema = new Schema({
     gljClass: Number,
     gljType: Number,
     shortName: String,
+    adjCoe: Number, //调整系数
     component: [gjlComponentSchema]
 },{versionKey: false});
 

+ 2 - 2
operation.js

@@ -42,8 +42,8 @@ app.set('view options', {
 app.use(partials());
 
 let bodyParser = require('body-parser');
-app.use(bodyParser.urlencoded({extended: true}));
-app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({limit: '3mb', extended: true}));
+app.use(bodyParser.json({limit: '3mb'}));
 
 app.use(session({
     name: 'usersSession',

+ 50 - 0
public/web/sheet/sheet_common.js

@@ -257,5 +257,55 @@ var sheetCommonObj = {
             }
         }
         return rst;
+    },
+    //add by zhong 2017-10-10
+    //动态下拉框
+    getDynamicCombo: function () {
+        let ComboCellForActiveCell = function () { };
+        ComboCellForActiveCell.prototype = new GC.Spread.Sheets.CellTypes.ComboBox();
+        ComboCellForActiveCell.prototype.paintValue = function (ctx, value, x, y, w, h, style, options) {
+            let sheet = options.sheet;
+            if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
+                GC.Spread.Sheets.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
+
+            } else {
+                GC.Spread.Sheets.CellTypes.Base.prototype.paintValue.apply(this, arguments);
+            }
+        };
+        ComboCellForActiveCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, options) {
+            let sheet = options.sheet;
+            if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
+                return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
+
+            } else {
+                return GC.Spread.Sheets.CellTypes.Base.prototype.getHitInfo.apply(this, arguments);
+            }
+        };
+        return new ComboCellForActiveCell();
+    },
+    setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
+        let me = this;
+        sheet.suspendPaint();
+        let combo = me.getDynamicCombo();
+        for(let i = 0, len = rowCount; i < len; i++){
+            if(itemsHeight) combo.itemHeight(itemsHeight);
+            if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
+            else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
+            else combo.items(items);
+            sheet.getCell(beginRow + i, col).cellType(combo);
+        }
+        sheet.resumePaint();
+    },
+    setStaticCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
+        sheet.suspendPaint();
+        let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
+        for(let i = 0, len = rowCount; i < len; i++){
+            if(itemsHeight) combo.itemHeight(itemsHeight);
+            if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
+            else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
+            else combo.items(items);
+            sheet.getCell(beginRow + i, col).cellType(combo);
+        }
+        sheet.resumePaint();
     }
 }

+ 7 - 1
web/maintain/bills_lib/html/qingdan.html

@@ -351,6 +351,7 @@
         billsTree.loadDatas(datas);
         let controller = TREE_SHEET_CONTROLLER.createNew(billsTree.tree, billsSpread.getActiveSheet(), setting);
         controller.showTreeData();
+        sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
         setSheet.formatter(billsSpread.getActiveSheet());
         //setTagId
         setTagID(controller, setting);
@@ -581,6 +582,9 @@
             if(recharge){
                 $('#exampleTextarea').val(recharge);
             }
+            else{
+                $('#exampleTextarea').val('');
+            }
         }
     }
 
@@ -628,6 +632,7 @@
             let maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
             let markRow = orgRow, colLen = sheet.getColumnCount(GC.Spread.Sheets.SheetArea.viewport);
             let validDatas = tools.getValidDatas(sheet, setting, args);
+            sheet.suspendPaint();
             for(let i =orgRow, j=0; i<= maxRow; i++, j++){
                 let id = sheet.getTag(i, 0);
                 if(id && j< validDatas.length){
@@ -653,11 +658,13 @@
                     sheet.setValue(i, 1, sheetBillsDatas.datasIdx['rowIdx'+ i].name);
                     sheet.setValue(i, 2, sheetBillsDatas.datasIdx['rowIdx'+ i].unit);
                     sheet.setValue(i, 3, sheetBillsDatas.datasIdx['rowIdx'+ i].ruleText);
+                    sheet.setValue(i, 4, sheetBillsDatas.datasIdx['rowIdx'+ i].engineering);
                 }
                 else {
                     sheet.clear(i, 0, 1, sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);
                 }
             }
+            sheet.resumePaint();
             billsAjax.pasteBills(userAccount, billsLibId, validDatas);
             setSheet.setMaxRowCount(sheet, sheetBillsDatas);
         });
@@ -765,7 +772,6 @@
                     });
                     if(flag){
                         serialNoUn ++;
-                        console.log(serialNoUn);
                         uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNoUn});
                     }
                     else {

+ 19 - 2
web/maintain/bills_lib/scripts/bills_lib_setting.js

@@ -35,7 +35,7 @@ var billsLibSetting = {
                 hAlign: 0,
                 font: 'Arial'
             },
-            width: 300
+            width: 240
         },
         {
             head: {
@@ -52,7 +52,7 @@ var billsLibSetting = {
                 hAlign: 0,
                 font: 'Arial'
             },
-            width: 160
+            width: 140
         },
         {
             head: {
@@ -70,6 +70,23 @@ var billsLibSetting = {
                 font: 'Arial'
             },
             width: 420
+        },
+        {
+            head: {
+                titleNames: ['工程专业'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: ' Arial'
+            },
+            data: {
+                field: 'engineering',
+                vAlign: 1,
+                hAlign: 1,
+                font: 'Arial'
+            },
+            width: 80
         }
     ],
     headRows: 1,

+ 28 - 38
web/maintain/bills_lib/scripts/db_controller.js

@@ -2,6 +2,7 @@
  * Created by vian on 2017/4/12.
  */
 var dbController = {
+    currentEditData: null,
     insert: function(controller, btn){
         tools.btnClose(btn);
         btn.attr('doing', 'true');
@@ -274,19 +275,24 @@ var dbController = {
     },
 
     editData: function(controller){
+        controller.sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
+            dbController.currentEditData = args.sheet.getValue(args.row, args.col);
+        });
         controller.sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args){
             var node = controller.tree.selected, updateId, field;
             if(node){
                 updateId = node.getID();
-                billsLibSetting.cols.forEach(function(col, idx){
-                    if(args.col === idx){
-                        field = col.data.field;
-                        node.data[field] = args.editingText;
-                        sheetBillsDatas.datasIdx['rowIdx'+ args.row][field] = args.editingText;
+                field = billsLibSetting.cols[args.col].data.field;
+                if(field === 'engineering'){
+                    if(isNaN(args.editingText) || args.editingText % 1 !== 0){
+                        args.sheet.setValue(args.row, args.col, dbController.currentEditData ? dbController.currentEditData : '');
+                        alert('工程专业只能输入整数!');
+                        return;
                     }
-                });
+                }
+                node.data[field] = args.editingText;
+                sheetBillsDatas.datasIdx['rowIdx'+ args.row][field] = args.editingText;
                 billsAjax.updateBills(userAccount, billsLibId, updateId, field, args.editingText);
-                //sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
             }
             else {
                 args.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
@@ -569,7 +575,6 @@ var tools = {
 
     getValidDatas: function(sheet, setting, args){
         let validDatas = [];
-        const colLen = 4;
         let orgRow = args.cellRange.row, orgCol = args.cellRange.col, rowCount = args.cellRange.rowCount, colCount = args.cellRange.colCount;
         let maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
         for(let i =orgRow; i<=maxRow; i++){
@@ -577,45 +582,30 @@ var tools = {
             for(let j= orgCol; j<=maxCol; j++){
                 let value = sheet.getValue(i, j);
                 if(value){
-                    setting.cols.forEach(function(col, colIdx){
+                  /*  setting.cols.forEach(function(col, colIdx){
                         if(colIdx === j){
                             validData[col.data.field] = value;
                         }
-                    });
+                    });*/
+                    if(setting.cols[j].data.field === 'engineering'){
+                        if(!isNaN(value) && value % 1 === 0){
+                            validData[setting.cols[j].data.field] = value;
+                        }
+                    }
+                    else {
+                        validData[setting.cols[j].data.field] = value;
+                    }
                 }
             }
             if(!tools.isEmptyObj(validData)){
                 validDatas.push(validData);
             }
         }
-
-
-
-        //---------------------------------------
-        /*for(let i=orgRow; i<= maxRow; i++){
-            if(tools.getValidRow(sheet, i)){
-                console.log(`validRow: ${i}`);
-                let validData = {code: '', name: '', unit: '', ruleText: ''};
-                for(var j=orgCol; j<=maxCol; j++){
-                    let field;
-                    setting.cols.forEach(function(col, colIdx){
-                        if(colIdx === j){
-                            field = col.data.field;
-                            if(sheet.getValue(i, j)){
-                                validData[field] = sheet.getValue(i, j);
-                            }
-                        }
-                    });
-                    //validData[field] = sheet.getValue(i, j);
-                }
-                validDatas.push(validData);
-            }
-        }*/
         return validDatas;
     },
 
     getValidRow: function(sheet, rowIdx){
-        const colCount = 4;
+        const colCount = 5;
         let isValid = false;
         for(let i=0; i< colCount; i++){
             if(sheet.getValue(rowIdx, i, GC.Spread.Sheets.SheetArea.viewport)){
@@ -1659,7 +1649,7 @@ var jobsController = {
                     field = col.data.field;
                 }
             });
-            if (controller.tree.selected && newData !== me.currentEditData) {
+            if (controller.tree.selected && newData != me.currentEditData) {
                 var isExist = tools.isExist(totalJobs.jobsArr, field, newData);
                 var isRepeat = tools.isRepeat(controller.tree.selected.jobs, field ,newData, 'reference', 'job');
                 //create
@@ -1874,7 +1864,7 @@ var itemsController = {
                     field = col.data.field;
                 }
             });
-            if (controller.tree.selected && newData !== me.currentEditData) {
+            if (controller.tree.selected && newData != me.currentEditData) {
                 var isExist = tools.isExist(totalItems.itemsArr, field, newData);
                 var isRepeat = tools.isRepeat(controller.tree.selected.items, field ,newData, 'reference', 'item');
                 //create
@@ -2194,7 +2184,7 @@ var totalJobsController = {
                     field = col.data.field;
                 }
             });
-            if(newData !== me.currentEditData){
+            if(newData != me.currentEditData){
                 isRepeat = tools.isRepeat(totalJobs.jobsArr, field, newData, 'reference', null);
                 if(!tagId && !isRepeat && newData){//create
                     totalJobsController.createJob(sheet, totalJobs, field, newData, args);
@@ -2282,7 +2272,7 @@ var totalItemsController = {
                     field = col.data.field;
                 }
             });
-            if(newData !== me.currentEditData){
+            if(newData != me.currentEditData){
                 isRepeat = tools.isRepeat(totalItems.itemsArr, field, newData, 'reference', null);
                 if(!tagId && !isRepeat && newData){//create
                     totalItemsController.createItem(sheet, totalItems, field, newData, args);

+ 6 - 6
web/maintain/ration_repository/dinge.html

@@ -399,7 +399,7 @@
                         </button>
                     </div>
                     <div class="modal-body">
-                        <h5 class="text-danger" id="alertRationTxt">编号不可为空!是否取消操作?</h5>
+                        <h5 class="text-danger" id="alertRationTxt">编码不可为空,继续新增定额?</h5>
                     </div>
                     <div class="modal-footer">
                         <button type="button" class="btn btn-secondary" id="rationAlertCac" data-dismiss="modal">取消</button>
@@ -507,18 +507,18 @@
             $(document).ready(function(){
                 pageOprObj.initPage();
                 rationOprObj.buildSheet($("#rationItemsSheet")[0]);
-                sheetCommonObj.shieldAllCells(rationOprObj.workBook.getSheet(0), rationOprObj.setting);
+               // sheetCommonObj.shieldAllCells(rationOprObj.workBook.getSheet(0), rationOprObj.setting);
 
                // tabPanel 下有多个Spread时,相互之间不能正确显示。改成一个Spread下多个Sheet。
                 var rdSpread = sheetCommonObj.createSpread($("#rdSpread")[0], 3);
                 rationGLJOprObj.buildSheet(rdSpread.getSheet(0));
-                sheetCommonObj.shieldAllCells(rdSpread.getSheet(0), rationGLJOprObj.setting);
+               // sheetCommonObj.shieldAllCells(rdSpread.getSheet(0), rationGLJOprObj.setting);
 
                 rationAssistOprObj.buildSheet(rdSpread.getSheet(1));
-                sheetCommonObj.shieldAllCells(rdSpread.getSheet(1), rationAssistOprObj.setting);
+             //   sheetCommonObj.shieldAllCells(rdSpread.getSheet(1), rationAssistOprObj.setting);
 
                 rationCoeOprObj.buildSheet(rdSpread.getSheet(2));
-                sheetCommonObj.shieldAllCells(rdSpread.getSheet(2), rationCoeOprObj.setting);
+              //  sheetCommonObj.shieldAllCells(rdSpread.getSheet(2), rationCoeOprObj.setting);
 
                 $("#linkGLJ").click(function(){
                     rationGLJOprObj.bindRationGljDelOpr();
@@ -526,7 +526,7 @@
                 });
 
                 $("#linkFZDE").click(function(){
-                    rationGLJOprObj.unBindDel();
+                    rationAssistOprObj.bindRationAssDel();
                     rdSpread.setActiveSheetIndex(1);
                 });
 

+ 120 - 25
web/maintain/ration_repository/js/coe.js

@@ -70,10 +70,10 @@ let coeOprObj = {
     workSheet: null,
     currentCoeList: [],
     currentCoe: null,
-    //currentMaxNo: null,
+    currentMaxNo: null,
     setting: {
         header: [
-            {headerName:"编号", headerWidth:60, dataCode:"ID", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
+            {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
             {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
             {headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
         ]
@@ -110,26 +110,64 @@ let coeOprObj = {
     onEditEnded: function (sender, args) {
         let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
         if(args.editingText && args.editingText.toString().trim().length > 0){
+            let inputT = args.editingText.toString().trim();
             //update
             if(args.row < me.currentCoeList.length){
                 let updateObj = me.currentCoeList[args.row];
-                if(updateObj[dataCode] !== args.editingText.toString().trim()){
-                    updateObj[dataCode] = args.editingText;
-                    updateArr.push(updateObj);
-                    me.save([], updateArr, [], true);
+                if(updateObj[dataCode] != inputT){
+                    if(dataCode === 'serialNo'){
+                        if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
+                            me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
+                            updateObj[dataCode] = inputT;
+                            updateArr.push(updateObj);
+                            me.save([], updateArr, [], true);
+                        }
+                        else if(!me.isInt(inputT)){
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
+                            alert('编号只能为整数!');
+                        }
+                        else if(me.hasTisNo(me.currentCoeList, inputT)){
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
+                            alert('该编号已存在!');
+                        }
+                    }
+                    else {
+                        updateObj[dataCode] = inputT;
+                        updateArr.push(updateObj);
+                        me.save([], updateArr, [], true);
+                    }
                 }
             }
             //insert
             else{
                 let newCoe = {};
-                //me.currentMaxNo ++;
                 newCoe.libID = pageObj.libID;
-                //newCoe.serialNo = me.currentMaxNo;
-                newCoe[dataCode] = args.editingText;
-                addArr.push(newCoe);
-                me.save(addArr, [], [], true, function (result) {
-                    me.updateCurrentCoeList(result);
-                });
+                if(dataCode === 'serialNo'){
+                    if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
+                        me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
+                        newCoe[dataCode] = inputT;
+                        addArr.push(newCoe);
+                        me.save(addArr, [], [], true, function (result) {
+                            me.updateCurrentCoeList(result);
+                        });
+                    }
+                    else if(!me.isInt(inputT)){
+                        args.sheet.setValue(args.row, args.col, '');
+                        alert('编号只能为整数!');
+                    }
+                    else if(me.hasTisNo(me.currentCoeList, inputT)){
+                        args.sheet.setValue(args.row, args.col, '');
+                        alert('该编号已存在!');
+                    }
+                }
+                else{
+                    newCoe.serialNo = ++me.currentMaxNo;
+                    newCoe[dataCode] = inputT;
+                    addArr.push(newCoe);
+                    me.save(addArr, [], [], true, function (result) {
+                        me.updateCurrentCoeList(result);
+                    });
+                }
             }
         }
     },
@@ -142,26 +180,40 @@ let coeOprObj = {
     onClipboardPasted: function (sender, info) {
         let me = coeOprObj, addArr = [], updateArr = [];
         let items = sheetCommonObj.analyzePasteData(me.setting, info);
-        for(let i = 0, len = items.length; i < len; i++){
+        let uniqItems = me.makeUniqItems(items);
+        for(let i = 0, len = uniqItems.length; i < len; i++){
             let row = i + info.cellRange.row;
             //update
             if(row < me.currentCoeList.length){
                 let updateObj = me.currentCoeList[row];
-                for(let attr in items[i]){
-                    updateObj[attr] = items[i][attr];
+                for(let attr in uniqItems[i]){
+                    if(attr === 'serialNo'){
+                        if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
+                            me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
+                            updateObj[attr] = uniqItems[i][attr];
+                        }
+                    }
+                    else {
+                        updateObj[attr] = uniqItems[i][attr];
+                    }
                 }
                 updateArr.push(updateObj);
             }
             //insert
             else {
-                //items[i].serialNo = ++ me.currentMaxNo;
-                items[i].libID = pageObj.libID;
-                addArr.push(items[i]);
+                if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
+                    me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
+                }
+                else {
+                    uniqItems[i].serialNo = ++me.currentMaxNo;
+                }
+                uniqItems[i].libID = pageObj.libID;
+                addArr.push(uniqItems[i]);
             }
         }
         if(addArr.length > 0 || updateArr.length > 0){
             me.save(addArr, updateArr, [], true, function (result) {
-                me.updateCurrentCoeList(result)
+                me.updateCurrentCoeList(result);
             });
         }
     },
@@ -197,16 +249,57 @@ let coeOprObj = {
         workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
         workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
     },
+    //粘贴的数据,编号唯一化,去除编号重复的项
+    makeUniqItems: function (items) {
+        let rst = [];
+        for(let i = 0, len = items.length; i < len; i++){
+            if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
+                if(rst.length === 0){
+                    rst.push(items[i]);
+                }
+                else{
+                    let isExist = false;
+                    for(let j = 0, jLen = rst.length; j < jLen; j++){
+                        if(items[i].serialNo === rst[j].serialNo){
+                            isExist = true;
+                            break;
+                        }
+                    }
+                    if(!isExist){
+                        rst.push(items[i]);
+                    }
+                }
+            }
+            else {
+                rst.push(items[i]);
+            }
+        }
+        return rst;
+    },
+    isInt: function (num) {
+        return !isNaN(num) && num % 1 === 0;
+    },
+    hasTisNo: function (coeList, newSerialNo) {
+        let rst = false;
+        for(let i = 0, len = coeList.length; i < len; i++){
+            if(coeList[i].serialNo == newSerialNo){
+                rst = true;
+                break;
+            }
+        }
+        return rst;
+    },
     updateCurrentCoeList: function (newCoeList) {
         let me = coeOprObj;
-        me.currentCoeList = me.currentCoeList.concat(newCoeList);
-        me.sortCoeList(me.currentCoeList);
+        if(newCoeList){
+            me.currentCoeList = me.currentCoeList.concat(newCoeList);
+        }
     },
     sortCoeList: function (coeList) {
         coeList.sort(function (a, b) {
             let rst = 0;
-            if(a.ID > b.ID) rst = 1;
-            else if(a.ID < b.ID) rst = -1;
+            if(a.serialNo > b.serialNo) rst = 1;
+            else if(a.serialNo < b.serialNo) rst = -1;
             return rst;
         });
     },
@@ -222,7 +315,7 @@ let coeOprObj = {
                 if(!result.error){
                     me.currentCoeList = result.data;
                     me.sortCoeList(me.currentCoeList);
-                    //me.currentMaxNo =  me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
+                    me.currentMaxNo =  me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
                     pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
                     me.workSheet.clearSelection();
                 }
@@ -256,6 +349,8 @@ let coeOprObj = {
                         callback(result.data);
                     }
                     if(refresh){
+                        me.sortCoeList(me.currentCoeList);
+                        me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
                         pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
                     }
                 }

+ 77 - 118
web/maintain/ration_repository/js/ration.js

@@ -9,7 +9,6 @@ $("#gongliao").click(function(){
 $("#fuzhu").click(function(){
     $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
 });
-
 let rationOprObj = {
     workBook: null,
     currentRations: {},
@@ -56,10 +55,8 @@ let 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.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;
@@ -68,11 +65,8 @@ let rationOprObj = {
                 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 () {
@@ -90,34 +84,6 @@ let rationOprObj = {
         }
     },
 
-    onCellClick: function(sender, args) {
-        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);
-        if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
-            let cacheSection = me.getCache();
-            if (cacheSection && args.row < cacheSection.length) {
-                rationGLJOprObj.getGljItems(cacheSection[args.row], function () {
-                    me.workBook.focus(true);
-                });
-                rationCoeOprObj.getCoeItems(cacheSection[args.row], function () {
-                    me.workBook.focus(true);
-                });
-                rationAssistOprObj.getAssItems(cacheSection[args.row]);
-            }
-            else {
-                rationGLJOprObj.currentRationItem = null;
-            }
-        };
-        me.workBook.focus(true);
-    },
     isInt: function (num) {
         return !isNaN(num) && num % 1 === 0;
     },
@@ -148,6 +114,8 @@ let rationOprObj = {
                     if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
                         cacheSection[j]["ID"] = result.data.ops[i]["ID"];
                         cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
+                        cacheSection[j]["rationCoeList"] = result.data.ops[i]["rationCoeList"];
+                        cacheSection[j]["rationAssList"] = result.data.ops[i]["rationAssList"];
                     }
                 }
             }
@@ -189,12 +157,9 @@ let rationOprObj = {
                         if(sels[sel].col === 0){
                             $('#alertText').text("编号不能为空,修改失败!");
                             $('#alertModalBtn').click();
-                            rationSheet.options.isProtected = true;
                             $('#alertModalCls').click(function () {
-                                rationSheet.options.isProtected = false;
                             });
                             $('#alertModalCof').click(function () {
-                                rationSheet.options.isProtected = false;
                             })
                         }
                         else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
@@ -218,6 +183,7 @@ let rationOprObj = {
             }
             if(updateArr.length > 0 || removeArr.length > 0){
                 me.mixUpdate = 1;
+                me.mixDel = removeArr.length > 0 ? 1 : 0;
                 me.mixUpdateRequest(updateArr, [], removeArr);
             }
 
@@ -227,6 +193,7 @@ let rationOprObj = {
     },
     onEnterCell: function (sender, args) {
         let me = rationOprObj;
+        args.sheet.repaint();
         me.cellRowIdx = args.row;
         let isHasData = false;
         if(me.addRationItem){
@@ -242,19 +209,17 @@ let rationOprObj = {
                 let focusToCol = !me.addRationItem.code ? 0 : -1;
                 if(focusToCol !== -1){
                     $('#rationAlertBtn').click();
-                    me.workBook.getSheet(0).options.isProtected = true;
                     $('#rationAlertCac').click(function () {
-                        me.workBook.getSheet(0).options.isProtected = false;
+                        me.addRationItem = null;
+                        for(let col=0; col<me.setting.header.length; col++){
+                            me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
+                        }
                     });
                     $('#rationAlertCls').click(function () {
-                        me.workBook.getSheet(0).options.isProtected = false;
+                        me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
                     });
                     $('#rationAlertCof').click(function () {
-                        me.workBook.getSheet(0).options.isProtected = false;
-                        me.addRationItem = null;
-                        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, focusToCol);
                     });
                 }
             }
@@ -262,14 +227,19 @@ let rationOprObj = {
     },
     onCellEditStart: function(sender, args) {
         let me = rationOprObj;
-        let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
-        me.currentEditingRation = rObj;
-        let cacheSection = me.getCache();
-        if (cacheSection) {
-            for (let j = 0; j < cacheSection.length; j++) {
-                if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
-                    rObj["ID"] = cacheSection[j]["ID"];
-                    break;
+        if(!me.canRations || me.setting.view.lockColumns.indexOf(args.col) !== -1){
+            args.cancel = true;
+        }
+        else{
+            let rObj = sheetsOprObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
+            me.currentEditingRation = rObj;
+            let cacheSection = me.getCache();
+            if (cacheSection) {
+                for (let j = 0; j < cacheSection.length; j++) {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
+                        rObj["ID"] = cacheSection[j]["ID"];
+                        break;
+                    }
                 }
             }
         }
@@ -336,22 +306,6 @@ let rationOprObj = {
                         alert('编码已存在!');
                         me.workBook.getSheet(0).setValue(args.row, args.col, '');
                     }
-                    /*else if(!rObj.code && rObj.code === ''){
-                        $('#alertModalBtn').click();
-                        me.workBook.getSheet(0).options.isProtected = true;
-                        $('#alertModalCls').click(function () {
-                            me.workBook.getSheet(0).options.isProtected = false;
-                            me.addRationItem.code = '';
-                            me.workBook.getSheet(0).setValue(args.row, args.col, '');
-                            me.workBook.getSheet(0).setActiveCell(args.row, args.col);
-                        });
-                        $('#alertModalCof').click(function () {
-                            me.workBook.getSheet(0).options.isProtected = false;
-                            me.addRationItem.code = '';
-                            me.workBook.getSheet(0).setValue(args.row, args.col, '');
-                            me.workBook.getSheet(0).setActiveCell(args.row, args.col);
-                        });
-                    }*/
                 }
                 else if(rObj.code && rObj.code.toString.trim().length === 0){
                     me.workBook.getSheet(0).setValue(args.row, args.col, '');
@@ -364,19 +318,31 @@ let rationOprObj = {
             me.mixUpdateRequest(updateArr, addArr, []);
         }
     },
+    canPasted: function (beginCol, maxCol) {
+        let rst = false;
+        if(maxCol < 3 || beginCol > 6){
+            rst = true;
+        }
+        return rst;
+    },
     onClipboardPasting: function(sender, args) {
         let me = rationOprObj;
+        let maxCol = args.cellRange.col + args.cellRange.colCount -1;
+        if(!me.canRations || !me.canPasted(args.cellRange.col, maxCol) || maxCol > me.setting.header.length - 1){
+            args.cancel = true;
+        }
     },
+    //todo: overwrite?
     onClipboardPasted: function(e, info) {
         let me = rationOprObj;
         let cacheSection = me.getCache();
         let updateArr = [], addArr = [];
         let items = sheetCommonObj.analyzePasteData(me.setting, info);
-        //let failPasteArr = [];
-        for (let i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
+        for (let i = 0; i < items.length; i++) {
+            let rowIdx = info.cellRange.row + i;
             if (cacheSection) {
                 if(!me.isValidUnit(items[i], rationUnits)){//无效单位
-                    items[i].unit = typeof cacheSection[rowIdx].unit !== 'undefined' && !cacheSection[rowIdx] ? cacheSection[rowIdx].unit : '';
+                    items[i].unit = rowIdx < cacheSection.length  && typeof cacheSection[rowIdx].unit !== 'undefined' ? cacheSection[rowIdx].unit : '';
                 }
                 if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
                     if(me.rationsCodes.indexOf(items[i].code) === -1){
@@ -392,7 +358,6 @@ let rationOprObj = {
                         me.rationsCodes.push(items[i].code);
                     }
                     else{
-                        //failPasteArr.push(items[i].code);
                         me.workBook.getSheet(0).setValue(rowIdx, 0, '');
                     }
                 }
@@ -439,19 +404,16 @@ let rationOprObj = {
                             me.setInitPrc(items[i]);
                             addArr.push(items[i]);
                         }
-                        /*else{
-                            failPasteArr.push(items[i]);
-                        }*/
                 }
             }
         };
-       /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
-            me.showRationItems(me.currentSectionId);
-        }*/
          if (updateArr.length > 0 || addArr.length > 0) {
              me.mixUpdate = 1;
             me.mixUpdateRequest(updateArr, addArr, []);
         }
+        else{
+             me.getRationItems(me.currentSectionId);
+         }
     },
     setInitPrc: function (obj) {
         obj.labourPrice = 0;
@@ -480,19 +442,18 @@ let rationOprObj = {
             }
         })
     },
-    mixUpdateRequest: function(updateArr, addArr, removeIds) {
+    mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
         let me = rationOprObj;
-        sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
         $.ajax({
             type:"POST",
             url:"api/mixUpdateRationItems",
             data:{"rationLibId": getQueryString("repository"), "lastOpr": userAccount, "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
             dataType:"json",
             cache:false,
-            timeout:5000,
+            timeout:20000,
             success:function(result){
                 if (result.error) {
-                    alert(`error`);
+                    alert('error');
                     me.getRationItems(me.currentSectionId);
                 } else {
                     let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
@@ -526,8 +487,9 @@ let rationOprObj = {
                     }
                     me.showRationItems(me.currentSectionId);
                     me.mixUpdate = 0;
+                    me.mixDel = 0;
                 }
-                sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
+                if(callback) callback();
             },
             error:function(){
             }
@@ -545,11 +507,6 @@ let rationOprObj = {
                 //annotation
                 annotationOprObj.rationAnnotationOpr(me.currentRations["_SEC_ID_" + sectionID]);
                 me.showRationItems(sectionID);
-                ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
-                sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
-                sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
-                sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
-                sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
             } else {
                 $.ajax({
                     type:"POST",
@@ -557,7 +514,7 @@ let rationOprObj = {
                     data:{"sectionID": sectionID},
                     dataType:"json",
                     cache:false,
-                    timeout:1000,
+                    timeout:10000,
                     success:function(result){
                         if (result) {
                             me.currentRations["_SEC_ID_" + sectionID] = result.data;
@@ -568,16 +525,6 @@ let rationOprObj = {
                             //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);
-                            sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
-                            sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
-                            sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
-                        } else {
-                            sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
-                            sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
-                            sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
-                            sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
                         }
                     },
                     error:function(err){
@@ -587,37 +534,49 @@ let rationOprObj = {
             }
         }
     },
-    setCombo: function (sheet, items) {
-        sheet.suspendPaint();
-        for(let i = 0, len = sheet.getRowCount(); i < len; i++){
-            let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
-            combo.items(items);
-            combo.itemHeight(10);
-            sheet.getCell(i, 2).cellType(combo);
-        }
-        sheet.resumePaint();
-    },
     showRationItems: function(sectionID){
-        let me = rationOprObj;
+        let me = rationOprObj,
+            sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
+            sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
+            sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
         if (me.workBook) {
             if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
                 let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
-                //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
                 sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
                 sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
-                sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
                 //combo
-                me.setCombo(me.workBook.getActiveSheet(), rationUnits);
-                if(me.mixUpdate === 1){
-                    rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
-                        me.workBook.focus(true);
-                    });
+                sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 2, cacheSection.length, rationUnits, 10, false);
+                sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), cacheSection.length, 2, me.workBook.getActiveSheet().getRowCount() - cacheSection.length, rationUnits, 10, false);
+                if(me.mixDel === 1){
+                    let row = me.workBook.getSheet(0).getSelections()[0].row;
+                    if (cacheSection && row < cacheSection.length) {
+                        sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
+                        sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
+                        sheetCommonObj.cleanData(sheetAss, settingAss, -1);
+                        rationGLJOprObj.getGljItems(cacheSection[row]);
+                        rationCoeOprObj.getCoeItems(cacheSection[row]);
+                        rationAssistOprObj.getAssItems(cacheSection[row]);
+                    }
+                    else {
+                        rationGLJOprObj.currentRationItem = null;
+                        sheetCommonObj.cleanData(sheetGLJ, settingGLJ, -1);
+                        sheetCommonObj.cleanData(sheetCoe, settingCoe, -1);
+                        sheetCommonObj.cleanData(sheetAss, settingAss, -1);
+                        sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
+                    }
                 }
 
             } else {
+                sheetCommonObj.setDynamicCombo(sheetAss, 0, 5, sheetAss.getRowCount(), rationAssistOprObj.setting.comboItems, false, false);
+                sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, 2, me.workBook.getActiveSheet().getRowCount(), rationUnits, 10, false);
                 //清除ration数据及工料机数据
+                rationGLJOprObj.currentRationItem = null;
                 sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+                sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
+                sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
+                sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
             }
+            me.workBook.focus(true);
         }
     },
     sortByCode: function(arr){

+ 96 - 17
web/maintain/ration_repository/js/ration_assist.js

@@ -11,12 +11,13 @@ var rationAssistOprObj = {
             {headerName:"辅助定额号",headerWidth:120,dataCode:"assistCode", dataType: "String", hAlign: "center"},
             {headerName:"标准值",headerWidth:100,dataCode:"stdValue", dataType: "String", hAlign: "right"},
             {headerName:"步距",headerWidth:100,dataCode:"stepValue", dataType: "String", hAlign: "right"},
-            {headerName:"精度",headerWidth:80,dataCode:"decimal", dataType: "Number", hAlign: "right"},
+            {headerName:"精度",headerWidth:80,dataCode:"decimal",  dataType: "String", hAlign: "right"},
             {headerName:"进位方式",headerWidth:100,dataCode:"carryBit", dataType: "String", hAlign: "center"},
             {headerName:"最小值",headerWidth:100,dataCode:"minValue", dataType: "String", hAlign: "right"},
             {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "String", hAlign: "right"}
         ],
-        view:{}
+        view:{},
+        comboItems: ["四舍五入", "进一"]
     },
 
     buildSheet: function(sheet) {
@@ -27,18 +28,28 @@ var rationAssistOprObj = {
 
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
 
-        var carryBit = new GC.Spread.Sheets.CellTypes.ComboBox();
-        carryBit.items(["四舍五入","进一"]);
-        me.sheet.getRange(-1, 5, -1, 1).cellType(carryBit);
-
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+        me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
         me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
-        me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
+        me.sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
+    },
+
+    onEnterCell: function (sender, args) {
+        let me = rationAssistOprObj;
+        args.sheet.repaint();
+        let cellType = args.sheet.getCellType(args.row, 5);
+        if(cellType.typeName !== 'undefined' && cellType.typeName === '1'){
+            sheetCommonObj.setStaticCombo(args.sheet, 0, 5, 0, me.setting.comboItems, false);
+            sheetCommonObj.setDynamicCombo(args.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+        }
     },
 
     onClipboardPasting: function(sender, args) {
-        var me = rationAssistOprObj;
+        let me = rationAssistOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
         if (!me.ration) {
             args.cancel = true;
         }
@@ -56,28 +67,60 @@ var rationAssistOprObj = {
             me.ration.rationAssList = assList;
         };
 
-        rationOprObj.mixUpdateRequest([me.ration], [], []);
-        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+        rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+            me.sheet.getParent().focus(true);
+        });
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+        sheetCommonObj.setStaticCombo(me.sheet, 0, 5, me.ration.rationAssList.length, me.setting.comboItems, false, false);
+        sheetCommonObj.setDynamicCombo(me.sheet, me.ration.rationAssList.length, 5, me.sheet.getRowCount() - me.ration.rationAssList.length, me.setting.comboItems, false, false);
         sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
     },
 
+    onEditStarting: function (sender, args) {
+        let me = rationAssistOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(!me.ration){
+            args.cancel = true;
+        }
+    },
+
     onEditEnded: function(sender, args){
         var me = rationAssistOprObj;
         if (!me.ration) {return;};
+        if(typeof me.ration.rationAssList === 'undefined'){
+            me.ration.rationAssList = [];
+        }
         var assList = me.ration.rationAssList;
-        //var assObj = sheetCommonObj.combineRowData(me.sheet, me.setting, args.row);
         var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
+        let dataCode = me.setting.header[args.col].dataCode;
+        if((args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7)
+            && args.editingText && args.editingText.toString().trim().length > 0 && isNaN(args.editingText)){
+            args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : '');
+            alert(me.setting.header[args.col].headerName + '只能为数值!');
+            return;
+        }
+        else if(args.col === 4 && args.editingText && (args.editingText.toString().trim().length === 0 ||
+                isNaN(args.editingText) || args.editingText % 1 !== 0)){
+            args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : 0);
+            alert(me.setting.header[args.col].headerName + '只能为整数!');
+            return;
+        }
         // 新增
-        if ((assList == undefined) || (assList && args.row >= assList.length)) {
+        if (args.row >= assList.length) {
             if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};
             if (assObj.carryBit == undefined || assObj.carryBit == null){assObj.carryBit = '四舍五入';};
             assList.push(assObj);
         }
         // 修改
         else{ assList[args.row] = assObj; };
-
-        rationOprObj.mixUpdateRequest([me.ration], [], []);
-        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+        rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+            me.sheet.getParent().focus(true);
+        });
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+        sheetCommonObj.setStaticCombo(me.sheet, 0, 5, assList.length, me.setting.comboItems, false, false);
+        sheetCommonObj.setDynamicCombo(me.sheet, assList.length, 5, me.sheet.getRowCount() - assList.length, me.setting.comboItems, false, false);
         sheetCommonObj.showData(me.sheet, me.setting, assList);
     },
 
@@ -99,6 +142,35 @@ var rationAssistOprObj = {
             sheetCommonObj.showData(me.sheet, me.setting, assList);
         };
     },
+    bindRationAssDel: function () {
+        let me = rationAssistOprObj;
+        let workBook = me.sheet.getParent();
+        workBook.commandManager().register('rationAssDel', function () {
+            let sels = me.sheet.getSelections(), isUpdate = false;
+            if(me.ration){
+                let curCahe = me.ration.rationAssList;
+                for(let i = 0, len = sels.length; i < len; i ++ ){
+                    if(sels[i].colCount === me.setting.header.length){
+                        if(sels[i].row < curCahe.length){
+                            isUpdate = true;
+                            curCahe.splice(sels[i].row, sels[i].rowCount);
+                        }
+                    }
+                }
+                if(isUpdate){
+                    rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+                        workBook.focus(true);
+                    });
+                    sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                    sheetCommonObj.setStaticCombo(me.sheet, 0, 5, curCahe.length, me.setting.comboItems, false);
+                    sheetCommonObj.setDynamicCombo(me.sheet, curCahe.length, 5, me.sheet.getRowCount() - curCahe.length, me.setting.comboItems, false);
+                    sheetCommonObj.showData(me.sheet, me.setting, curCahe);
+                }
+            }
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('rationAssDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
 
     getAssItems: function(ration) {
         var me = this;
@@ -108,8 +180,15 @@ var rationAssistOprObj = {
         sheetCommonObj.unShieldAllCells(me.sheet);
 
         if (ration == undefined || ration.rationAssList == undefined ||
-            ration.rationAssList.length == 0){return;};
-
+            ration.rationAssList.length == 0){
+            sheetCommonObj.setStaticCombo(me.sheet, 0, 5, 0, me.setting.comboItems, false);
+            sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
+            return;
+        }
+        else {
+            sheetCommonObj.setStaticCombo(me.sheet, 0, 5, ration.rationAssList.length, me.setting.comboItems, false);
+            sheetCommonObj.setDynamicCombo(me.sheet, ration.rationAssList.length, 5, me.sheet.getRowCount() - ration.rationAssList.length, me.setting.comboItems, false, false);
+        }
         sheetCommonObj.showData(me.sheet, me.setting, ration.rationAssList);
     }
 }

+ 71 - 50
web/maintain/ration_repository/js/ration_coe.js

@@ -10,9 +10,9 @@ var rationCoeOprObj = {
     cache: {},
     setting: {
         header:[
-            {headerName:"编码",headerWidth:120,dataCode:"ID", dataType: "Number", hAlign: 'left'},
-            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
-            {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String"}
+            {headerName:"编号",headerWidth:120,dataCode:"serialNo", dataType: "Number", hAlign: 'left'},
+            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String", hAlign: 'left'},
+            {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String", hAlign: 'left'}
         ],
         view:{
             comboBox:[],
@@ -28,12 +28,16 @@ var rationCoeOprObj = {
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+        me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
         me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
        // me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
     },
 
     onClipboardPasting: function(sender, args) {
         var me = rationCoeOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.curRation = rationRow < rationSection.length ? rationSection[rationRow] : null;
         if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.curRation)) {
             args.cancel = true;
         }
@@ -45,45 +49,47 @@ var rationCoeOprObj = {
             // 修改第一列(编号)
             if (info.cellRange.col == 0) {
                 me.tempDelArr = [];
-                var coeIDs = [];
-                var items = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
+                var coeNos = [];
+                var items = sheetCommonObj.analyzePasteData({header:[{dataCode: "serialNo"}] }, info);
                 let curCache = typeof me.cache["_Coe_" + me.curRation.ID] !== 'undefined' ? me.cache["_Coe_" + me.curRation.ID] : [];
                 let isRefresh = false;
                 for(let i = 0, len = items.length; i < len; i++){
-                    let row = i + info.cellRange.row;
-                    //update
-                    if(row < curCache.length){
-                        let isExist = false;
-                        for(let j = 0, jLen = curCache.length; j < jLen; j++){
-                            if(items[i].ID === curCache[j].ID && j !== row){
-                                isExist = true;
-                                break;
+                    if(!isNaN(items[i].serialNo)){
+                        let row = i + info.cellRange.row;
+                        //update
+                        if(row < curCache.length){
+                            let isExist = false;
+                            for(let j = 0, jLen = curCache.length; j < jLen; j++){
+                                if(items[i].serialNo === curCache[j].serialNo && j !== row){
+                                    isExist = true;
+                                    break;
+                                }
+                            }
+                            if(!isExist){
+                                me.tempDelArr.push({org: curCache[row], newNo: items[i].serialNo});
+                                coeNos.push(items[i].serialNo);
+                            }
+                            else{
+                                isRefresh = true;
                             }
-                        }
-                        if(!isExist){
-                            me.tempDelArr.push({org: curCache[row], newID: items[i].ID});
-                            coeIDs.push(items[i].ID);
                         }
                         else{
-                            isRefresh = true;
+                            coeNos.push(items[i].serialNo);
                         }
                     }
-                    else{
-                        coeIDs.push(items[i].ID);
-                    }
                 }
                 //delete in front
                 if(me.tempDelArr.length > 0){
                    for(let i = 0, len = me.tempDelArr.length; i < len; i++){
                        for(let j = 0; j < curCache.length; j++){
-                           if(me.tempDelArr[i].org.ID === curCache[j].ID){
+                           if(me.tempDelArr[i].org.serialNo === curCache[j].serialNo){
                                curCache.splice(j, 1);
                                break;
                            }
                        }
                    }
                 }
-                me.addCoeItems(coeIDs);
+                me.addCoeItems(coeNos);
                 if(isRefresh){
                     me.showCoeItems(me.curRation.ID);
                 }
@@ -92,23 +98,32 @@ var rationCoeOprObj = {
             }
         }
     },
+    onEditStarting: function (sender, args) {
+        let me = rationCoeOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.curRation = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(!me.curRation || args.col !== 0){
+            args.cancel = true;
+        }
 
+    },
     onEditEnded: function(sender, args){
         var me = rationCoeOprObj;
         if (args.col == 0 && args.editingText && args.editingText.toString().trim().length > 0 && !isNaN(args.editingText)) {   // 编号列
             let curCahe = typeof me.cache["_Coe_" + me.curRation.ID] !== 'undefined' ? me.cache["_Coe_" + me.curRation.ID] : [];
             me.tempDelArr = [];
             //update
-            if(args.row < curCahe.length && args.editingText != curCahe[args.row].ID){
+            if(args.row < curCahe.length && args.editingText != curCahe[args.row].serialNo){
                 let isExist = false;
                 for(let i = 0, len = curCahe.length; i < len; i++){
-                    if(args.editingText == curCahe[i].ID){
+                    if(args.editingText == curCahe[i].serialNo){
                         isExist = true;
                         break;
                     }
                 }
                 if(!isExist){
-                    me.tempDelArr.push({org: curCahe[args.row], newID: args.editingText});
+                    me.tempDelArr.push({org: curCahe[args.row], newNo: args.editingText});
                     curCahe.splice(args.row, 1);
                     me.addCoeItems([args.editingText]);
                 }
@@ -122,6 +137,7 @@ var rationCoeOprObj = {
             }
         }
         else{
+            sheetCommonObj.cleanData(me.sheet, me.setting, -1);
             me.showCoeItems(me.curRation.ID);
         }
     },
@@ -141,7 +157,9 @@ var rationCoeOprObj = {
                 }
             }
             if(isUpdate){
-                me.updateCurRation();
+                me.updateCurRation(function () {
+                    me.sheet.getParent().focus(true);
+                });
                 sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                 me.showCoeItems(me.curRation.ID);
             }
@@ -154,7 +172,7 @@ var rationCoeOprObj = {
         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].newID == newArr[j].ID){
+                if(tempDelArr[i].newNo == newArr[j].serialNo){
                     isExist = true;
                     break;
                 }
@@ -165,37 +183,37 @@ var rationCoeOprObj = {
         }
         return rst;
     },
-    addCoeItems: function(coeIDs) {
+    addCoeItems: function(coeNos) {
         var me = this;
         sheetCommonObj.cleanData(me.sheet, me.setting, -1);
 
         var curCache = me.cache["_Coe_" + me.curRation.ID];
         var temp = [];
         if (curCache) {
-            for (var i = 0; i < coeIDs.length; i++) {
+            for (var i = 0; i < coeNos.length; i++) {
                 var isExist = false;
                 for (let obj of curCache) {
-                    if (obj.ID == coeIDs[i]) {
+                    if (obj.serialNo == coeNos[i]) {
                         isExist = true;
                         break;
                     };
                 };
                 if (!isExist) {
-                    temp.push(coeIDs[i]);
+                    temp.push(coeNos[i]);
                 };
             };
         }else{
-            for (let obj of coeIDs){temp.push(obj)};
+            for (let obj of coeNos){temp.push(obj)};
         };
 
         if(temp.length == 0){
             me.showCoeItems(me.curRation.ID);
-            sheetCommonObj.lockCells(me.sheet, me.setting);
+            //sheetCommonObj.lockCells(me.sheet, me.setting);
         }else{
             $.ajax({
                 type:"POST",
-                url:"api/getCoeItemsByIDs",
-                data: {"data": JSON.stringify({"libID": me.libID, "coeIDs": temp})},
+                url:"api/getCoeItemsByNos",
+                data: {"data": JSON.stringify({"libID": me.libID, "coeNos": temp})},
                 dataType:"json",
                 cache:false,
                 timeout:5000,
@@ -213,10 +231,12 @@ var rationCoeOprObj = {
                             curCache = curCache.concat(recoveryArr);
                         }
                         me.cache["_Coe_" + me.curRation.ID] = curCache;
-                        me.updateCurRation();
+                        me.updateCurRation(function () {
+                            me.sheet.getParent().focus(true);
+                        });
                         me.showCoeItems(me.curRation.ID);
                     };
-                    sheetCommonObj.lockCells(me.sheet, me.setting);
+                    //sheetCommonObj.lockCells(me.sheet, me.setting);
                 },
                 error:function(err){
                     alert(err);
@@ -229,16 +249,15 @@ var rationCoeOprObj = {
         var me = this;
         me.curRation = ration;
 
-        if (ration == undefined || ration.rationCoeList == undefined ||
-            ration.rationCoeList.length == 0){return;};
+        /*if (ration == undefined || ration.rationCoeList == undefined ||
+            ration.rationCoeList.length == 0){return;};*/
 
         var coeList = ration.rationCoeList;
         var curCache = me.cache["_Coe_" + ration.ID];
-
-        if (curCache && curCache.length > 0) {
+        if (curCache) {
             me.showCoeItems(ration.ID);
-            sheetCommonObj.lockCells(me.sheet, me.setting);
-        } else {
+            //sheetCommonObj.lockCells(me.sheet, me.setting);
+        } else if(!curCache && typeof coeList !== 'undefined' && coeList.length > 0) {
             var data = {"libID": me.libID, "coeIDs": coeList};
             $.ajax({
                 type:"POST",
@@ -259,8 +278,8 @@ var rationCoeOprObj = {
 
                         me.showCoeItems(ration.ID);
                     }
-                    sheetCommonObj.lockCells(me.sheet, me.setting);
-                    callback();
+                    //sheetCommonObj.lockCells(me.sheet, me.setting);
+                    if(callback) callback();
                 },
                 error:function(err){
                     alert(err);
@@ -275,15 +294,15 @@ var rationCoeOprObj = {
         if (curCache) {
             curCache.sort(function(a, b) {
                 var rst = 0;
-                if (a.ID > b.ID) rst = 1
-                else if (a.ID < b.ID) rst = -1;
+                if (a.serialNo > b.serialNo) rst = 1
+                else if (a.serialNo < b.serialNo) rst = -1;
                 return rst;
             });
             sheetsOprObj.showData(me.sheet, me.setting, curCache);
         }
     },
 
-    updateCurRation: function() {
+    updateCurRation: function(callback) {
         var me = this, updateArr = [];
         if (me.curRation) {
             var rst = [];
@@ -294,7 +313,9 @@ var rationCoeOprObj = {
                 };
                 me.curRation.rationCoeList = rst;
                 updateArr.push(me.curRation);
-                rationOprObj.mixUpdateRequest(updateArr, [], []);
+                rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                    if(callback) callback();
+                });
             };
         };
     }

+ 84 - 99
web/maintain/ration_repository/js/ration_glj.js

@@ -83,21 +83,15 @@ var rationGLJOprObj = {
             me.bindRationGljDelOpr();
             me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
             me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+            me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
             me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
-            //me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
         });
     },
-    unBindDel: function () {
-        let me = rationGLJOprObj, spreadBook = me.sheet.getParent();
-        spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
-        spreadBook.commandManager().setShortcutKey('clear', GC.Spread.Commands.Key.del, false, false, false, false);
-    },
     bindRationGljDelOpr: function () {
         let me = rationGLJOprObj, spreadBook = me.sheet.getParent();
         spreadBook.commandManager().register('rationGljDelete', function () {
-            let sels = me.sheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
+            let sels = me.sheet.getSelections(), 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){
@@ -126,39 +120,24 @@ var rationGLJOprObj = {
                 }
             }
             if(isUpdate){
-                me.updateRationItem();
-                sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                me.updateRationItem(function () {
+                    me.sheet.getParent().focus(true);
+                });
+                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                 me.showGljItems(me.currentRationItem.ID);
             }
-           /* if(updateArr.length > 0 || removeArr.length > 0){
-                me.mixUpdateRequest(updateArr, [], removeArr);
-            }*/
-
         });
         spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
         spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
     },
-    onRangeChanged: function(sender, args) {
-        if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
-            var me = rationGLJOprObj, updateArr = [], removeArr = [];
-            if (args.col == 0) {
-                if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
-                    var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
-                    for (var i = args.rowCount - 1; i >= 0; i--) {
-                        if (args.row + i < cacheArr.length) {
-                            cacheArr.splice(args.row + i, 1);
-                        }
-                    }
-                    me.updateRationItem();
-                    sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-                    me.showGljItems(me.currentRationItem.ID);
-                }
-            }
-
-        }
-    },
     onClipboardPasting: function(sender, args) {
         var me = rationGLJOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
+            me.cache["_GLJ_" + me.currentRationItem.ID] = [];
+        }
         if (!(args.cellRange.col === 0 || args.cellRange.col === 5) || !(me.currentRationItem)) {
             args.cancel = true;
         }
@@ -192,7 +171,9 @@ var rationGLJOprObj = {
                             let roundCons = me.round(tempConsumes[i].consumeAmt, 3);
                             me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
                         }
-                        me.updateRationItem();
+                        me.updateRationItem(function () {
+                            me.sheet.getParent().focus(true);
+                        });
                         if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
                             me.sheet.suspendPaint();
                             for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
@@ -212,6 +193,23 @@ var rationGLJOprObj = {
             }
         }
     },
+    onEditStarting: function (sender, args) {
+        let me = rationGLJOprObj;
+        let rationSection = rationOprObj.getCache();
+        let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
+        me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
+        if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
+            me.cache["_GLJ_" + me.currentRationItem.ID] = [];
+        }
+        if(!me.currentRationItem){
+            args.cancel = true;
+        }
+        else {
+            if(args.col !== 0 && args.col !== 5 || args.col === 5 && args.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                args.cancel = true;
+            }
+        }
+    },
     onCellEditEnd: function(sender, args){
         var me = rationGLJOprObj;
         if(me.currentRationItem) {
@@ -225,13 +223,10 @@ var rationGLJOprObj = {
                         if (isNaN(parseFloat(args.editingText))) {
                             $('#alertModalBtn').click();
                             $('#alertText').text("定额消耗只能输入数值!");
-                            args.sheet.options.isProtected = true;
                             $('#alertModalCls').click(function () {
-                                args.sheet.options.isProtected = false;
                                 args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
                             });
                             $('#alertModalCof').click(function () {
-                                args.sheet.options.isProtected = false;
                                 args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
                             })
                         }
@@ -239,7 +234,9 @@ var rationGLJOprObj = {
                             args.sheet.setValue(args.row, args.col, parseNum);
                             let roundNum = me.round(parseNum, 3);
                             editGlj["consumeAmt"] = roundNum;
-                            me.updateRationItem();
+                            me.updateRationItem(function () {
+                                me.sheet.getParent().focus(true);
+                            });
                         }
                     }
                 }
@@ -277,6 +274,9 @@ var rationGLJOprObj = {
                         }
                     }
                 }
+                else {
+                    args.sheet.setValue(args.row, args.col, args.row < cacheArr.length ? cacheArr[args.row].code : '');
+                }
             }
         }
         else {
@@ -307,12 +307,12 @@ var rationGLJOprObj = {
                         callback: function(key, options) {
                         },
                         items: {
-                            /*"insert": {name: "插入", callback: function (key, opt) {
-                            }},*/
                             "delete": {name: "删除", icon: 'fa-remove', disabled: delDis, callback: function (key, opt) {
                                 cacheSection.splice(target.row, 1);
-                                me.updateRationItem();
-                                sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                                me.updateRationItem(function () {
+                                    me.sheet.getParent().focus(true);
+                                });
+                                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                                 me.showGljItems(me.currentRationItem.ID);
                             }}
                         }
@@ -342,7 +342,6 @@ var rationGLJOprObj = {
     },
     addGljItems: function(codes, repId, args) {
         var me = this;
-        sheetCommonObj.setLockCol(me.sheet, 0, true);
         $.ajax({
             type:"POST",
             url:"api/getGljItemsByCodes",
@@ -351,10 +350,8 @@ var rationGLJOprObj = {
             cache:false,
             timeout:5000,
             success:function(result){
-                //sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
                 if (result) {
                     if(result.data.length > 0){
-                        //sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
                         sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                         var rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];
                         for (var i = 0; i < result.data.length; i++) {
@@ -389,7 +386,9 @@ var rationGLJOprObj = {
                         }
                         me.showGljItems(me.currentRationItem.ID);
                         if (newAddArr.length > 0) {
-                            me.updateRationItem();
+                            me.updateRationItem(function () {
+                                me.sheet.getParent().focus(true);
+                            });
                         }
                     }
                     else{
@@ -398,7 +397,6 @@ var rationGLJOprObj = {
                         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;
@@ -408,19 +406,14 @@ var rationGLJOprObj = {
                         });
                         $('#alertModalBtn').click();
                         $('#alertText').text("工料机"+ codes + "不存在,请查找你所需要的工料机,或新增工料机");
-                        me.sheet.options.isProtected = true;
                         $('#alertModalCls').click(function () {
-                            sheetCommonObj.lockCells(me.sheet, me.setting);
                             me.showGljItems(me.currentRationItem.ID);
                         });
                         $('#alertModalCof').click(function () {
-                            sheetCommonObj.lockCells(me.sheet, me.setting);
                             me.showGljItems(me.currentRationItem.ID);
                         })
                     }
                 }
-                sheetCommonObj.lockCells(me.sheet, me.setting);
-                sheetCommonObj.setLockCol(me.sheet, 0, false);
             },
             error:function(err){
                 alert(err);
@@ -480,7 +473,7 @@ var rationGLJOprObj = {
         }
         return rst;
     },
-    updateRationItem: function() {
+    updateRationItem: function(callback) {
         var me = this, updateArr = [];
         if (me.currentRationItem) {
             me.currentRationItem.rationGljList = me.buildRationItemGlj();
@@ -491,7 +484,9 @@ var rationGLJOprObj = {
             me.currentRationItem.machinePrice = price.machinePrice;
             me.currentRationItem.basePrice = price.rationBasePrc;
             updateArr.push(me.currentRationItem);
-            rationOprObj.mixUpdateRequest(updateArr, [], []);
+            rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                if(callback) callback();
+            });
         }
     },
 
@@ -523,54 +518,52 @@ var rationGLJOprObj = {
         me.currentRationItem = rationItem;
         if (me.cache["_GLJ_" + rationID]) {
             me.showGljItems(rationID);
-            sheetCommonObj.lockCells(me.sheet, me.setting);
         } else {
             var gljIds = [];
             for (var i = 0; i < rationGljList.length; i++) {
                 gljIds.push(rationGljList[i].gljId);
             }
-            $.ajax({
-                type:"POST",
-                url:"api/getGljItemsByIds",
-                data:{"gljIds": JSON.stringify(gljIds)},
-                dataType:"json",
-                cache:false,
-                timeout:5000,
-                success:function(result){
-                    sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-                    if (result) {
-                        var cacheArr = [];
-                        for (var i = 0; i < result.data.length; i++) {
-                            for (var j = 0; j < rationGljList.length; j++) {
-                                if (rationGljList[j].gljId == result.data[i].ID) {
-                                    cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
-                                    break;
+                $.ajax({
+                    type:"POST",
+                    url:"api/getGljItemsByIds",
+                    data:{"gljIds": JSON.stringify(gljIds)},
+                    dataType:"json",
+                    cache:false,
+                    timeout:5000,
+                    success:function(result){
+                        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                        if (result) {
+                            var cacheArr = [];
+                            for (var i = 0; i < result.data.length; i++) {
+                                for (var j = 0; j < rationGljList.length; j++) {
+                                    if (rationGljList[j].gljId == result.data[i].ID) {
+                                        cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
+                                        break;
+                                    }
                                 }
                             }
-                        }
-                        function compare(){
-                            return function (a, b) {
-                                let rst = 0;
-                                if (a.code > b.code) {
-                                    rst = 1;
-                                }
-                                else if (a.code < b.code) {
-                                    rst = -1;
+                            function compare(){
+                                return function (a, b) {
+                                    let rst = 0;
+                                    if (a.code > b.code) {
+                                        rst = 1;
+                                    }
+                                    else if (a.code < b.code) {
+                                        rst = -1;
+                                    }
+                                    return rst;
                                 }
-                                return rst;
                             }
+                            cacheArr.sort(compare());
+                            me.cache["_GLJ_" + rationID] = cacheArr;
+                            me.showGljItems(rationID);
                         }
-                        cacheArr.sort(compare());
-                        me.cache["_GLJ_" + rationID] = cacheArr;
-                        me.showGljItems(rationID);
+                        if(callback) callback();
+                    },
+                    error:function(err){
+                        alert(err);
                     }
-                    sheetCommonObj.lockCells(me.sheet, me.setting);
-                    callback();
-                },
-                error:function(err){
-                    alert(err);
-                }
-            })
+                })
         }
     },
     showGljItems: function(rationID) {
@@ -578,14 +571,6 @@ var rationGLJOprObj = {
         if (me.cache["_GLJ_" + rationID]) {
             sheetCommonObj.cleanData(me.sheet, me.setting, -1);
             sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
-            //lock
-            me.sheet.suspendPaint();
-            me.sheet.suspendEvent();
-            for(let i = 0, len = me.sheet.getRowCount(); i < len; i++){
-                me.sheet.getCell(i, 4).locked(true);
-            }
-            me.sheet.resumePaint();
-            me.sheet.resumeEvent();
         }
     }
 }

+ 5 - 2
web/maintain/ration_repository/js/section_tree.js

@@ -349,18 +349,21 @@ var zTreeOprObj = {
         annotationOprObj.clickUpdate($('#fzTxtareaAll'));
         var sectionID = treeNode.ID;
         if (!(treeNode.items) || treeNode.items.length == 0) {
+            rationOprObj.canRations = true;
             rationOprObj.workBook.getSheet(0).clearSelection();
             rationOprObj.getRationItems(sectionID);
         } else {
+            rationOprObj.canRations = false;
+            rationOprObj.currentSectionId = sectionID;
+            rationOprObj.workBook.getSheet(0).setRowCount(30);
+            sheetCommonObj.setDynamicCombo(rationOprObj.workBook.getSheet(0), 0, 2, rationOprObj.workBook.getSheet(0).getRowCount(), rationUnits, 10, false);
             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));
         }
         sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
-        sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
         rationGLJOprObj.sheet.getParent().focus(false);
     }
 };

+ 13 - 13
web/maintain/ration_repository/js/sheetsOpr.js

@@ -32,11 +32,11 @@ let sheetsOprObj = {
         else{
             sheet.setRowCount(typeof repositoryGljObj !== 'undefined' && repositoryGljObj.currentOprParent === 1 ? data.length : data.length + 10);
         }
-        if(data.length === 0){
+        /*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) {
@@ -55,26 +55,26 @@ let sheetsOprObj = {
             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){
+                   /* 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'){
+                    /*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++){
+          /*  for(let i = data.length; i < sheet.getRowCount(); i++){
                 sheet.getCell(i, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
-            }
+            }*/
         }
         sheet.resumeEvent();
         sheet.resumePaint();
@@ -103,21 +103,21 @@ let sheetsOprObj = {
                         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);
+                           // sheetCommonObj.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);
+                               // sheetCommonObj.unLockAllCells(sheet);
+                                //me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
                                 sheet.setValue(row, 0, orgCode);
                                 sheet.getCell(row, 0).formatter("@");
                                 sheet.setActiveCell(row, 0);
                             });
                             $('#codAleClose').click(function () {
                                 //me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
-                                me.unLockAllCells(sheet);
-                                me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
+                                //sheetCommonObj.unLockAllCells(sheet);
+                                //me.reLockSomeCodes(sheet, 0, repositoryGljObj.currentCache.length);
                                 sheet.setValue(row, 0, orgCode);
                                 sheet.getCell(row, 0).formatter("@");
                                 sheet.setActiveCell(row, 0);

+ 92 - 4
web/maintain/std_glj_lib/html/gongliao.html

@@ -10,8 +10,10 @@
     <link rel="stylesheet" href="/web/maintain/std_glj_lib/css/main.css">
     <link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
     <link rel="stylesheet" href="/lib/spreadjs/sheets/css/gc.spread.sheets.excel2013lightGray.10.0.1.css" type="text/css">
+    <link rel="stylesheet" href="/lib/jquery-contextmenu/jquery.contextMenu.css" type="text/css">
     <style type="text/css">
         .ztree li span.button.add{margin-right:2px;background-position:-144px 0;vertical-align:top;*vertical-align:middle}
+        .modal-lg{max-width: 1000px}
     </style>
     <!--zTree-->
   	<link rel="stylesheet" href="/lib/ztree/css/zTreeStyle.css" type="text/css">
@@ -150,7 +152,43 @@
             </div>
         </div>
     </div>
-
+    <!--弹出组成物-->
+    <button id="componentBtn" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#component" style="display: none"></button>
+    <div class="modal fade" id="component" data-backdrop="static">
+        <div class="modal-dialog modal-lg" role="document" id="modalCon">
+            <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">&times;</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <div class="row">
+                        <div class="col-4">
+                            <div  class="modal-auto-height" id="componentTreeDiv" style="overflow: hidden">
+                                <!--<div class="print-list">-->
+                                <div style="width: 100%; height: 100%; overflow: auto">
+                                    <ul id="componentTree" class="ztree"></ul>
+                                </div>
+                                <!--</div>-->
+                            </div>
+                        </div>
+                        <div class="col-8">
+                            <div class="row">
+                                <div class="modal-auto-height col-12" style="overflow: hidden" id="componentSheet">
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" id="componentsCacnel" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <a href="javascript:void(0);" id="componentsConf" class="btn btn-primary">确定</a>
+                </div>
+            </div>
+        </div>
+    </div>
     <button id="gljAlertBtn" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#gljAlert" style="display: none"></button>
     <button id="codeAlertBtn" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#codeAlert" style="display: none"></button>
     <div class="modal fade" id="gljAlert" data-backdrop="static" style="display: none;" aria-hidden="true">
@@ -195,6 +233,8 @@
 
     <!-- JS. -->
     <script src="/lib/jquery/jquery.min.js"></script>
+    <script src="/lib/jquery-contextmenu/jquery.contextMenu.min.js"></script>
+    <script src="/lib/jquery-contextmenu/jquery.ui.position.js"></script>
     <script src="/lib/tether/tether.min.js"></script>
     <script src="/lib/bootstrap/bootstrap.min.js"></script>
     <script src="/web/maintain/std_glj_lib/js/global.js"></script>
@@ -208,9 +248,10 @@
     <script type="text/javascript" src="/public/web/QueryParam.js"></script>
     <script type="text/javascript" src="/web/maintain/std_glj_lib/js/glj.js"></script>
     <script type="text/javascript" src="/web/maintain/std_glj_lib/js/gljComponent.js"></script>
+    <script type="text/javascript" src="/web/maintain/std_glj_lib/js/components.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/std_glj_lib/js/sheetsOpr.js"></script>
     <script type="text/javascript" src="/public/web/storageUtil.js"></script>
     <SCRIPT type="text/javascript">
         let userAccount = '<%=userAccount %>';
@@ -253,9 +294,56 @@
                 onClick: gljTypeTreeOprObj.onClick
             }
         };
+        //组成物弹出窗口组成物分类树
+        let componentSetting = {
+            view: {
+                //addHoverDom: gljTypeTreeOprObj.addHoverDom,
+                //removeHoverDom: gljTypeTreeOprObj.removeHoverDom,
+                expandSpeed: "",
+                selectedMulti: false
+            },
+            edit: {
+                enable: false,
+                editNameSelectAll: true,
+                showRemoveBtn: true,
+                showRenameBtn: true,
+                removeTitle: "删除节点",
+                renameTitle: "更改名称"
+            },
+            data: {
+                keep: {
+                    parent:true,
+                    leaf:true
+                },
+                key: {
+                    children: "items",
+                    name: "Name"
+                },
+                simpleData: {
+                    enable: false,
+                    idKey: "ID",
+                    pIdKey: "ParentID",
+                    rootPId: -1
+                }
+            },
+            callback:{
+                onClick: componentTypeTreeOprObj.onClick
+            }
+        };
         $(document).ready(function(){
-            pageOprObj.initPage($("#GLJListSheet")[0], $('#gljComponentSheet')[0]);
-            //repositoryGljObj.buildSheet($("#GLJListSheet")[0]);
+            //解决spreadjs sheet初始化没高度宽度
+            $('#modalCon').width($(window).width()*0.5);
+            $('#componentTreeDiv').height($(window).height() - 300);
+            $("#componentSheet").height($("#componentTreeDiv").height()-21.6);
+            $("#componentSheet").width($('#modalCon').width() * 0.63);
+            pageOprObj.initPage($("#GLJListSheet")[0], $('#gljComponentSheet')[0], $('#componentSheet')[0]);
+        });
+        //组成物弹出窗大小设置
+        $(window).resize(function () {
+            $('#modalCon').width($(window).width()*0.5);
+            $('#componentTreeDiv').height($(window).height() - 300);
+            $("#componentSheet").height($("#componentTreeDiv").height()-21.6);
+            $("#componentSheet").width($('#modalCon').width()* 0.63);
         });
   	</SCRIPT>
 </body>

+ 200 - 0
web/maintain/std_glj_lib/js/components.js

@@ -0,0 +1,200 @@
+/**
+ * Created by Zhong on 2017/10/16.
+ */
+/*
+ 弹出组成物窗口 组成物表
+ * */
+let componentOprObj = {
+    treeObj:null,
+    rootNode: null,//分类树根节点
+    workBook: null,
+    selectedList: [],//选中的组成物
+    setting: {
+        owner: "components",
+        header: [
+            {headerName:"选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center"},
+            {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
+            {headerName:"名称",headerWidth:120,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
+            {headerName:"规格型号",headerWidth:80,dataCode:"specs", dataType: "String", hAlign: "center", vAlign: "center"},
+            {headerName:"单位",headerWidth:80,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
+            {headerName:"单价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
+            {headerName:"类型",headerWidth:80,dataCode:"gljType", dataType: "String",  hAlign: "center", vAlign: "center"}
+        ]
+    },
+    buildSheet: function (container) {
+        let me = componentOprObj;
+        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
+        me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
+        me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
+        me.workBook.getSheet(0).getRange(-1, 0, -1, 1).cellType(new GC.Spread.Sheets.CellTypes.CheckBox());
+        me.componentsBtnOpr($('#componentsConf'));
+    },
+    onClipboardPasting: function (sender, args) {
+        args.cancel = true;
+    },
+    onCellEditStart: function (sender, args) {
+        args.cancel = true;
+    },
+    onButtonClicked: function (sender, args) {
+        let me = componentOprObj, re = repositoryGljObj;
+        let val = args.sheet.getValue(args.row, args.col);
+        let thisComponent = me.currentCache[args.row];
+        thisComponent.isChecked = val;
+        if(args.sheet.isEditing()){
+            args.sheet.endEdit(true);
+        }
+        else{
+            //维护选中组成物列表
+            if(val === true){
+                let isExist = false;
+                for(let i = 0, len = me.selectedList.length; i < len; i++){
+                    if(me.selectedList[i].ID === thisComponent.ID){
+                        isExist = true;
+                        break;
+                    }
+                }
+                if(!isExist){
+                    me.selectedList.push(thisComponent);
+                }
+            }
+            else if(val === false){
+                for(let i = 0, len = me.selectedList.length; i < len; i++){
+                    if(me.selectedList[i].ID === thisComponent.ID){
+                        me.selectedList.splice(i, 1);
+                        break;
+                    }
+                }
+            }
+        }
+    },
+    setShowGljList: function (gljList, clearChecked) {
+        //初始为所有工料机,机械类型可添加机械组成物、机上人工,混凝土,砂浆、配合比可添加普通材料
+        let machineArr = [302, 303];
+        let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
+        let that = repositoryGljObj, me = componentOprObj;
+        for(let i = 0; i < gljList.length; i++){
+            if(that.currentGlj.gljType === 301 && machineArr.indexOf(gljList[i].gljType) !== -1 ||
+                materialArr.indexOf(that.currentGlj.gljType) !== -1 && gljList[i].gljType === 201){
+                let isExist = false;
+                for(let j = 0; j < that.currentComponent.length; j++){
+                    if(that.currentComponent[j].ID === gljList[i].ID){
+                        isExist = true;
+                        break;
+                    }
+                }
+                if(!isExist){
+                    if(clearChecked){
+                        gljList[i].isChecked = false;
+                    }
+                }
+                else {
+                    gljList[i].isChecked = true;
+                }
+                me.showGljList.push(gljList[i]);
+            }
+        }
+    },
+    //初始默认radio
+    initRadio: function () {
+        let that = repositoryGljObj, me = componentOprObj;
+        //初始化组成物列表
+        me.selectedList = [].concat(that.currentComponent);
+        //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
+        me.showGljList = [];
+        me.setShowGljList(that.gljList, true);
+        that.sortGlj(me.showGljList);
+
+    },
+    getParentCache: function (nodes) {
+        let me = componentOprObj, rst = [];
+        for(let i = 0; i < me.showGljList.length; i++){
+            if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
+                rst.push(me.showGljList[i]);
+            }
+        }
+        rst.sort(function (a, b) {
+            let rst = 0;
+            if(a.code > b.code) rst = 1;
+            else if(a.code < b.code)rst = -1;
+            return rst;
+        });
+        return rst;
+    },
+    getCache: function() {
+        let me = componentOprObj, rst = [];
+        for (let i = 0; i < me.showGljList.length; i++) {
+            if (me.showGljList[i].gljClass == me.gljCurTypeId) {
+                rst.push(me.showGljList[i]);
+            }
+        }
+        return rst;
+    },
+    showGljItems: function(data, type) {
+        let me = componentOprObj, re = repositoryGljObj;
+        if (me.workBook) {
+            let cacheSection = [];
+            let pArr = re.parentNodeIds["_pNodeId_" + type];
+            for (let i = 0; i < data.length; i++) {
+                if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
+                    cacheSection.push(data[i]);
+                } else if (type == data[i].gljClass) {
+                    cacheSection.push(data[i]);
+                }
+            }
+            sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+            sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
+            me.workBook.getSheet(0).setRowCount(cacheSection.length);
+            cacheSection = null;
+        }
+    },
+    //组成物窗口按钮操作
+    componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
+        let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
+        conf.click(function () {
+            //添加选择添加的组成物
+            let updateArr = [];
+            let newComponent = [];
+            for(let i = 0, len = me.selectedList.length; i < len; i++){
+                let isExist = false;
+                for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
+                    if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
+                        newComponent.push({ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
+                        isExist = true;
+                        break;
+                    }
+                }
+                if(!isExist){
+                    newComponent.push({ID: me.selectedList[i].ID, consumeAmt: 0});
+                }
+            }
+            re.currentGlj.component = newComponent;
+            let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
+            if(gljBasePrc !== re.currentGlj.basePrice){
+                re.currentGlj.basePrice = gljBasePrc;
+                re.reshowGljBasePrc(re.currentGlj);
+            }
+            updateArr.push(re.currentGlj);
+            that.updateComponent(updateArr);
+            $('#componentsCacnel').click();
+        });
+    }
+};
+
+let componentTypeTreeOprObj = {
+    onClick: function(event,treeId,treeNode) {
+        let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
+        if(me.gljCurTypeId !== treeNode.ID){
+            me.gljCurTypeId = treeNode.ID;
+            if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
+                me.currentOprParent = 1;
+                me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
+            } else {
+                me.currentCache = me.getCache();
+            }
+        }
+        me.showGljItems(me.showGljList, gljTypeId);
+    }
+}

+ 182 - 152
web/maintain/std_glj_lib/js/glj.js

@@ -4,12 +4,13 @@
 let pageOprObj = {
     gljLibName : null,
     gljLibId: null,
-    initPage : function(container, containerComponent) {
+    initPage : function(container, containerComponent, containerC) {
         let me = this, gljLibId = getQueryString("gljLibId");//获取定额库参数
         me.gljLibId = gljLibId;
         repositoryGljObj.getGljLib(gljLibId, function () {
             repositoryGljObj.buildSheet(container);
             gljComponentOprObj.buildSheet(containerComponent);
+            componentOprObj.buildSheet(containerC);
             //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
             //repositoryGljObj.getRationGljIds(gljLibId);
             repositoryGljObj.getGljDistType(function () {
@@ -17,7 +18,6 @@ let pageOprObj = {
                 repositoryGljObj.getGljTree(gljLibId, function () {
                     repositoryGljObj.getGljItems(gljLibId);
                 });
-                sheetCommonObj.shieldAllCells(repositoryGljObj.workBook.getSheet(0), repositoryGljObj.setting);
             });
         });
     }
@@ -38,10 +38,11 @@ let repositoryGljObj = {
         header:[
             {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:220,dataCode:"specs", dataType: "String", formatter: "@", 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"}
+            {headerName:"类型",headerWidth:120,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"},
+            {headerName:"调整系数",headerWidth:80,dataCode:"adjCoe", dataType: "Number", hAlign: "center", vAlign: "center"},
         ],
         view:{
             comboBox:[
@@ -78,10 +79,6 @@ let 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 !== '材料' && distTypeObj.data.fullName !== '机械'){
                 distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
             }
@@ -98,9 +95,6 @@ let repositoryGljObj = {
                 if(!result.error && callback){
                     me.distTypeTree = me.getComboData(result.data);
                     console.log(me.distTypeTree);
-                    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);
                     callback();
                 }
             }
@@ -139,6 +133,7 @@ let repositoryGljObj = {
             success:function(result,textStatus,status){
                 if(status.status == 200) {
                     zTreeHelper.createTree(result.data, gljSetting, "repositoryTree", me);
+                    zTreeHelper.createTree(result.data, componentSetting, "componentTree", componentOprObj);
                     if (result.data && result.data.length > 0) {
                         me.gljCurTypeId = result.data[0].ID;
                     } else {
@@ -167,8 +162,10 @@ let repositoryGljObj = {
                     me.gljList = result.data;
                     me.workBook.getSheet(0).setRowCount(result.data.length);
                     me.sortGlj();
+                    me.currentGlj = me.gljList.length > 0 ? me.gljList[0] : null;//初始
                     let rootNode = me.treeObj.getNodes()[0];
                     if(rootNode && rootNode.isParent && rootNode.isFirstNode){
+                        componentOprObj.rootNode = rootNode;
                         me.treeObj.selectNode(rootNode);
                         gljTypeTreeOprObj.onClick(null, 'repositoryTree', rootNode);
                     }
@@ -191,10 +188,10 @@ let repositoryGljObj = {
                     cacheSection.push(data[i]);
                 }
             }
-            //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
             sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
             sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
-
+            sheetCommonObj.setStaticCombo(me.workBook.getActiveSheet(), 0, 5, cacheSection.length, me.distTypeTree.comboDatas, false, 'text');
+            sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), cacheSection.length, 5, me.workBook.getActiveSheet().getRowCount() - cacheSection.length, me.distTypeTree.comboDatas, false, 'text');
             cacheSection = null;
         }
     },
@@ -287,10 +284,6 @@ let repositoryGljObj = {
         //混凝土202、砂浆203、配合比204、机械3
         if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
             let row = info.newSelections[0].row;
-            sheetCommonObj.lockCells(that.workBook.getSheet(0), that.setting);
-            that.workBook.getSheet(0).getRange(-1, 0 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
-            that.workBook.getSheet(0).getRange(-1, 4 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
-            //that.workBook.getSheet(0).options.isProtected = true;
             sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, -1);
             me.workBook.focus(true);
             me.currentComponent = [];
@@ -299,10 +292,6 @@ let repositoryGljObj = {
                 //标记当前工料机
                 me.currentGlj = me.currentCache[row];
                 if(me.allowComponent.indexOf(me.currentCache[row].gljType) !== -1){
-                    that.workBook.getSheet(0).getRange(-1, 0 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
-                    that.workBook.getSheet(0).getRange(-1, 4 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
-                    //that.workBook.getSheet(0).options.isProtected = false;
-                    //sheetCommonObj.lockCells(that.workBook.getSheet(0), that.setting);
                     //展示数据
                     if(me.currentGlj.component.length > 0){
                         me.currentComponent = me.getCurrentComponent(me.currentGlj.component);
@@ -319,6 +308,7 @@ let repositoryGljObj = {
     },
     onEnterCell: function (sender, args) {
         let me = repositoryGljObj;
+        args.sheet.repaint();
         me.cellRowIdx = args.row;
         let isHasData = false;
         if(me.addGljObj){
@@ -356,24 +346,13 @@ let repositoryGljObj = {
                 }
                 else {
                     $('#gljAlertBtn').click();
-                    //me.workBook.getSheet(0).options.isProtected = true;
-                    sheetCommonObj.lockAllCells(args.sheet);
                     $('#aleConfBtn').click(function () {
-                        // me.workBook.getSheet(0).options.isProtected = false;
-                        sheetCommonObj.unLockAllCells(args.sheet);
-                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
                         me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
                     });
                     $('#gljAleClose').click(function () {
-                        // me.workBook.getSheet(0).options.isProtected = false;
-                        sheetCommonObj.unLockAllCells(args.sheet);
-                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
                         me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
                     });
                     $('#aleCanceBtn').click(function () {
-                        // me.workBook.getSheet(0).options.isProtected = false;
-                        sheetCommonObj.unLockAllCells(args.sheet);
-                        sheetsOprObj.reLockSomeCodes(args.sheet, 0, repositoryGljObj.currentCache.length);
                         me.addGljObj = null;
                         for(let col=0; col<me.setting.header.length; col++){
                             if(col === 0){
@@ -392,16 +371,20 @@ let repositoryGljObj = {
         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;
-        if (cacheSection) {
-            for (let j = 0; j < cacheSection.length; j++) {
-                if (cacheSection[j][me.setting.header[0].dataCode] && cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
-                    rObj["ID"] = cacheSection[j]["ID"];
-                    rObj.gljClass = cacheSection[j].gljClass;
-                    break;
-                }
+        if(args.row < me.currentCache.length){
+            me.currentGlj = me.currentCache[args.row];
+            if(args.col === 0 || (args.col === 4 && me.allowComponent.indexOf(me.currentGlj.gljType) !== -1)
+                || (args.col === 6 && me.currentGlj.gljType !== 1 && me.currentGlj.gljType !== 303)){
+                args.cancel = true;
+            }
+            else {
+                rObj.ID = me.currentGlj.ID;
+                rObj.gljClass = me.currentGlj.gljClass;
             }
         }
+        else {
+            me.currentGlj = null;
+        }
     },
     onCellEditEnd: function(sender, args) {
         let me = repositoryGljObj, that = gljComponentOprObj,
@@ -410,7 +393,7 @@ let repositoryGljObj = {
         me.editingRowIdx = args.row;
         rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
         //更新
-        if (me.currentEditingGlj["ID"]) {
+        if (me.currentEditingGlj["ID"] && me.currentGlj) {
             rObj["ID"] = me.currentEditingGlj["ID"];
             rObj.gljClass = me.currentEditingGlj.gljClass;
                 if(me.currentEditingGlj[me.setting.header[args.col].dataCode] !== rObj[me.setting.header[args.col].dataCode]){
@@ -423,6 +406,10 @@ let repositoryGljObj = {
                             if(me.allowComponent.indexOf(rObj.gljType) !== -1){
                                 rObj.basePrice = 0;
                             }
+                            //调整系数,工料机类型为人工和机上人工时,可输入整数
+                            if((me.currentEditingGlj.gljType === 1 || me.currentEditingGlj.gljType === 303) && !(rObj.gljType === 1 || rObj.gljType === 303)){
+                                rObj.adjCoe = null;
+                            }
                             if(me.componentGljType.indexOf(me.currentEditingGlj.gljType) !== -1 &&
                                 !(me.currentEditingGlj.gljType === 302 && rObj.gljType === 303) && !(me.currentEditingGlj.gljType === 303 && rObj.gljType === 302)){//修改了原本是组成物的工料机
                                //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
@@ -438,6 +425,14 @@ let repositoryGljObj = {
                             }
                             sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, 5);
                         }
+                        else if(rObj.adjCoe !== me.currentEditingGlj.adjCoe){//修改调整系数,整数控制
+                            if(isNaN(rObj.adjCoe) || rObj.adjCoe % 1 !== 0){
+                                args.sheet.setValue(args.row, args.col, me.currentEditingGlj.adjCoe ? me.currentEditingGlj.adjCoe : '');
+                                alert('调整系数只能输入整数!');
+                                return;
+                            }
+
+                        }
                         else if(rObj.basePrice !== me.currentEditingGlj.basePrice){//修改了单价,可修改单价的必为可成为组成物的
                             //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
                             let updateGljs = me.getUpdateGljs(rObj);
@@ -519,7 +514,6 @@ let repositoryGljObj = {
         }
         if(updateArr.length >0 || addArr.length >0){
             me.currentEditingGlj = null;
-            //me.workBook.getSheet(0).setValue(11, 5, "人工");
             me.mixUpdateRequest(updateArr, addArr, []);
         }
     },
@@ -593,12 +587,9 @@ let repositoryGljObj = {
                                 }
                                 $('#alertText').text(text + "不可为空!");
                                 $('#codeAlertBtn').click();
-                                sheet.options.isProtected = true;
                                 $('#codAleConfBtn').click(function () {
-                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                                 });
                                 $('#codAleClose').click(function () {
-                                    sheetsOprObj.lockSomeCodes(sheet, 0, cacheSection.length);
                                 });
                             }
                         }
@@ -666,7 +657,13 @@ let repositoryGljObj = {
                 if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
                     isExsit = true;
                     reCalBasePrc = true;
-                    //
+                    //调整系数
+                    if(me.distTypeTree.comboDatas[i].value !== 1 && me.distTypeTree.comboDatas[i].value !== 303){
+                        tempObj.adjCoe = null;
+                    }
+                    else if((me.distTypeTree.comboDatas[i].value === 1 || me.distTypeTree.comboDatas[i].value === 303) && typeof pasteObj.adjCoe !== 'undefined' && !isNaN(pasteObj.adjCoe) && pasteObj.adjCoe % 1 === 0) {
+                        tempObj.adjCoe = pasteObj.adjCoe;
+                    }
                     if(me.componentGljType.indexOf(tempObj.gljType) !== -1 &&
                         !(tempObj.gljType === 302 && pasteObj.gljType === 303) && !(tempObj.gljType === 303 && pasteObj.gljType === 302)){//修改了原本是组成物的工料机
                         //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
@@ -680,15 +677,26 @@ let repositoryGljObj = {
                             }
                         }
                     }
-                    tempObj.gljType = me.distTypeTree.comboDatas[i].value;
-                    tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
+                    tempObj.component = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.component : [];
                     if(me.allowComponent.indexOf(tempObj.gljType) !== -1){
-                        tempObj.basePrice = 0;
+                        tempObj.basePrice = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.basePrice : 0;
                     }
+                    tempObj.gljType = me.distTypeTree.comboDatas[i].value;
+                    tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
                     break;
                 }
             }
-            if(!isExsit) isValid = false;
+            if(!isExsit) {
+                isValid = false;
+            }
+        }
+        if(typeof pasteObj.adjCoe !== 'undefined' && typeof pasteObj.gljType === 'undefined'){
+            if(tempObj.gljType && (tempObj.gljType === 1 || tempObj.gljType === 303) && typeof pasteObj.adjCoe !== 'undefined' && !isNaN(pasteObj.adjCoe) && pasteObj.adjCoe % 1 === 0) {
+                tempObj.adjCoe = pasteObj.adjCoe;
+            }
+            else {
+                isValid = false;
+            }
         }
         if(typeof pasteObj.basePrice !== 'undefined'){
             pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? that.round(parseFloat(pasteObj.basePrice), 2) :
@@ -751,131 +759,161 @@ let repositoryGljObj = {
                 }
             }
         }
+        if(pasteObj.adjCoe && typeof pasteObj.adjCoe !== 'undefined'){
+            if(isNaN(pasteObj.adjCoe) || pasteObj.adjCoe % 1 !== 0){
+                return false;
+            }
+        }
         pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
         pasteObj.gljClass = me.gljCurTypeId;
         return true;
     },
-    onClipboardPasting: function(sender, args) {
+    canPasted: function (info) {
+        let rst = true;
         let me = repositoryGljObj;
-        if (me.gljCurTypeId < 0 ) {
-            args.cancel = true;
+        if(me.gljCurTypeId < 0){
+            return false;
+        }
+        if(info.cellRange.col + info.cellRange.colCount - 1 > me.setting.header.length - 1){
+            return false;
+        }
+        if(info.cellRange.row < me.currentCache.length){
+            if(info.cellRange.col === 0){
+                return false;
+            }
+            else if(info.cellRange.col <= 4 && info.cellRange.col + info.cellRange.colCount - 1 >= 4){
+                for(let i = 0, len = info.cellRange.rowCount; i < len; i++){
+                    let row = i + info.cellRange.row;
+                    if(row < me.currentCache.length){
+                        if(me.allowComponent.indexOf(me.currentCache[row].gljType) !== -1){
+                            rst = false;
+                        }
+                    }
+                    else {
+                        break;
+                    }
+                }
+            }
         }
-        let maxCol = args.cellRange.col + args.cellRange.colCount - 1;
+        return rst;
+    },
+    onClipboardPasting: function(sender, args) {
+        let me = repositoryGljObj;
         //复制的列数超过正确的列数,不可复制
-        if(maxCol >= me.setting.header.length){
+        if(!me.canPasted(args)){
             args.cancel = true;
         }
     },
     onClipboardPasted: function(e, info) {
         let me = repositoryGljObj;
-            let updateArr = [], addArr = [];
-            let items = sheetCommonObj.analyzePasteData(me.setting, info);
-            let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,
-                maxRow = me.currentCache.length - 1,
-                updateBasePrcArr = [] ,
-                updateCount, resumeArr = [];
-            if(endRow <= maxRow){
-                //updateItems = items;
-                for(let i = 0; i < items.length; i++){
-                    let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
-                    if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
-                        //updateArr = updateObj.updateGlj;
-                        updateArr = updateArr.concat(updateObj.updateGlj);
-                        if(typeof updateObj.updateBasePrc !== 'undefined'){
-                            //updateBasePrcArr = updateObj.updateBasePrc;
-                            updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrc);
-                        }
+        let updateArr = [], addArr = [];
+        let items = sheetCommonObj.analyzePasteData(me.setting, info);
+        let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,
+            maxRow = me.currentCache.length - 1,
+            updateBasePrcArr = [] ,
+            updateCount, resumeArr = [];
+        if(endRow <= maxRow){
+            //updateItems = items;
+            for(let i = 0; i < items.length; i++){
+                let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
+                if(updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0){
+                    //updateArr = updateObj.updateGlj;
+                    updateArr = updateArr.concat(updateObj.updateGlj);
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                        //updateBasePrcArr = updateObj.updateBasePrc;
+                        updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrc);
                     }
-                    else{
-                        resumeArr.push(info.cellRange.row + i);
+                }
+                else{
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        else if(beginRow <= maxRow && endRow > maxRow){
+            updateCount = maxRow - beginRow + 1;
+            for(let i = 0; i < updateCount; i++){
+                let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
+                if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
+                    updateArr = updateArr.concat(updateObj.updateGlj);
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                        updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrc);
                     }
                 }
+                else{
+                    resumeArr.push(info.cellRange.row + i);
+                }
             }
-            else if(beginRow <= maxRow && endRow > maxRow){
-                updateCount = maxRow - beginRow + 1;
-                for(let i = 0; i < updateCount; i++){
-                    let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
-                    if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
-                        updateArr = updateArr.concat(updateObj.updateGlj);
-                        if(typeof updateObj.updateBasePrc !== 'undefined'){
-                            updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrc);
+            if(info.cellRange.colCount === me.setting.header.length){
+                for(let i = updateCount ; i < items.length; i++){
+                    if(me.isValidObj(items[i])){
+                        items[i].component = [];
+                        //类型为混凝土、砂浆、配合比、机械时,基价只能组成物计算
+                        if(me.allowComponent.indexOf(items[i].gljType) !== -1){
+                            items[i].basePrice = 0;
                         }
+                        addArr.push(items[i]);
                     }
                     else{
                         resumeArr.push(info.cellRange.row + i);
                     }
                 }
-                if(info.cellRange.colCount === me.setting.header.length){
-                    for(let i = updateCount ; i < items.length; i++){
-                        if(me.isValidObj(items[i])){
-                            items[i].component = [];
-                            //类型为混凝土、砂浆、配合比、机械时,基价只能组成物计算
-                            if(me.allowComponent.indexOf(items[i].gljType) !== -1){
-                                items[i].basePrice = 0;
-                            }
-                            addArr.push(items[i]);
-                        }
-                        else{
-                            resumeArr.push(info.cellRange.row + i);
+            }
+            else{
+                for(let i = updateCount ; i < items.length; i++){
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        else{
+            if(info.cellRange.colCount === me.setting.header.length - 1 && info.cellRange.col + info.cellRange.colCount - 1 >= 5){
+                for(let i = 0; i < items.length; i++){
+                    if(me.isValidObj(items[i])){
+                        items[i].component = [];
+                        if(me.allowComponent.indexOf(items[i].gljType) !== -1){
+                            items[i].basePrice = 0;
                         }
+                        addArr.push(items[i]);
                     }
-                }
-                else{
-                    for(let i = updateCount ; i < items.length; i++){
+                    else{
                         resumeArr.push(info.cellRange.row + i);
                     }
                 }
             }
             else{
-                if(info.cellRange.colCount === me.setting.header.length){
-                    for(let i = 0; i < items.length; i++){
-                        if(me.isValidObj(items[i])){
-                            items[i].component = [];
-                            if(me.allowComponent.indexOf(items[i].gljType) !== -1){
-                                items[i].basePrice = 0;
-                            }
-                            addArr.push(items[i]);
+                for(let i = 0; i < items.length; i++){
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        //repaint
+        if(resumeArr.length > 0){
+            info.sheet.suspendPaint();
+            for(let i = 0; i < resumeArr.length ; i++){
+                if(resumeArr[i] < me.currentCache.length){
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        if(me.setting.header[col].dataCode === 'gljType'){
+                            let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
+                            info.sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
                         }
                         else{
-                            resumeArr.push(info.cellRange.row + i);
+                            info.sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
                         }
                     }
                 }
                 else{
-                    for(let i = 0; i < items.length; i++){
-                        resumeArr.push(info.cellRange.row + i);
-                    }
-                }
-            }
-            //repaint
-            if(resumeArr.length > 0){
-                info.sheet.suspendPaint();
-                for(let i = 0; i < resumeArr.length ; i++){
-                    if(resumeArr[i] < me.currentCache.length){
-                        for(let col = 0; col < me.setting.header.length; col++){
-                            if(me.setting.header[col].dataCode === 'gljType'){
-                                let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
-                                info.sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
-                            }
-                            else{
-                                info.sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
-                            }
-                        }
-                    }
-                    else{
-                        for(let col = 0; col < me.setting.header.length; col++){
-                            info.sheet.setValue(resumeArr[i], col, '');
-                        }
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        info.sheet.setValue(resumeArr[i], col, '');
                     }
                 }
-                info.sheet.resumePaint();
-            }
-            if (updateArr.length > 0 || addArr.length > 0) {
-                me.mixUpdateRequest(updateArr, addArr, []);
-            }
-            if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
-                me.updateRationBasePrcRq(updateBasePrcArr);
             }
+            info.sheet.resumePaint();
+        }
+        if (updateArr.length > 0 || addArr.length > 0) {
+            me.mixUpdateRequest(updateArr, addArr, []);
+        }
+        if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
+            me.updateRationBasePrcRq(updateBasePrcArr);
+        }
     },
     updateRationBasePrcRq: function (basePrcArr) {
         $.ajax({
@@ -916,7 +954,6 @@ let repositoryGljObj = {
             success:function(result){
                 if (result.error) {
                     alert(result.message);
-                    me.getRationItems(me.currentRepositoryId);
                 } else {
                     me.updateCache(addArr, updateArr, removeIds, result);
                     me.sortGlj();
@@ -925,14 +962,18 @@ let repositoryGljObj = {
                     }
                     else{
                         me.currentCache = me.getCache();
-                        //sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-                        sheetsOprObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
-                        //sheetCommonObj.lockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
                     }
                     me.showGljItems(me.gljList, me.gljCurTypeId);
+                    //getCurrentGlj
+                    let row = me.workBook.getSheet(0).getSelections()[0].row;
+                    me.currentGlj = row < me.currentCache.length ? me.currentCache[row] : null;
+                    me.currentComponent = me.currentGlj ?  me.getCurrentComponent(me.currentGlj.component) : [];
+                    sheetCommonObj.cleanData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, -1);
+                    sheetsOprObj.showData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, me.currentComponent);
                 }
             },
             error:function(err){
+                console.log(err);
                 alert("保存失败");
             }
         })
@@ -1015,25 +1056,14 @@ let gljTypeTreeOprObj = {
             gljTypeId = treeNode.ID;
         me.gljCurTypeId = treeNode.ID;
         me.addGljObj = null;
-        //me.currentCache = me.getCache();
         sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
-        that.workBook.getSheet(0).getRange(-1, 0 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
-        that.workBook.getSheet(0).getRange(-1, 4 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
-        //that.workBook.getSheet(0).options.isProtected = true;
         if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
             me.currentOprParent = 1;
             me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
-            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 {
             me.currentOprParent = 0;
             me.currentCache = me.getCache();
-            //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
-            /*sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-             sheetCommonObj.lockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);*/
-            sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-            sheetsOprObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
         }
         me.showGljItems(me.gljList, gljTypeId);
     },

+ 91 - 11
web/maintain/std_glj_lib/js/gljComponent.js

@@ -9,12 +9,12 @@ let gljComponentOprObj = {
         header:[
             {headerName:"编码",headerWidth:50,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
             {headerName:"名称",headerWidth:60,dataCode:"name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
-            {headerName:"计量单位",headerWidth:60,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
+            {headerName:"单位",headerWidth:60,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
             {headerName:"单价",headerWidth:50,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
             {headerName:"消耗量",headerWidth:55,dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", hAlign: "right", vAlign: "center"}
         ],
         view: {
-            lockedCells:[1, 2, 3]
+            lockedCols:[1, 2, 3]
         }
     },
     buildSheet: function(container) {
@@ -22,20 +22,14 @@ let gljComponentOprObj = {
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
         me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
         me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
-        me.workBook.getSheet(0).options.isProtected = true;
         sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
 
         me.gljComponentDelOpr();
+        me.onContextmenuOpr();
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
-       /* me.repositoryGljDelOpr();
-        me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
-        me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
-        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
-        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
-        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);*/
     },
     getRowData: function (sheet, row, setting) {
         let rst = {};
@@ -135,10 +129,96 @@ let gljComponentOprObj = {
         me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
         me.workBook.commandManager().setShortcutKey('gljComponentDel', GC.Spread.Commands.Key.del, false, false, false, false);
     },
+    onContextmenuOpr: function () {
+        let me = gljComponentOprObj, that = repositoryGljObj, co = componentOprObj;
+        $.contextMenu({
+            selector: '#gljComponentSheet',
+            build: function($triggerElement, e){
+                //控制允许右键菜单在哪个位置出现
+                let sheet = me.workBook.getSheet(0);
+                let offset = $("#gljComponentSheet").offset(),
+                    x = e.pageX - offset.left,
+                    y = e.pageY - offset.top;
+                let target = sheet.hitTest(x, y);
+                if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
+                    sheet.setActiveCell(target.row, target.col);
+                    //getCurrentGlj
+                    let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
+                    that.currentGlj = thatRow < that.currentCache.length ? that.currentCache[thatRow] : null;
+                    that.currentComponent = that.currentGlj ?  that.getCurrentComponent(that.currentGlj.component) : [];
+                    //控制按钮是否可用
+                    let insertDis = false,
+                        delDis = false;
+                    if(!(that.currentGlj && that.allowComponent.indexOf(that.currentGlj.gljType) !== -1)){
+                        insertDis = true;
+                    }
+                    if(!that.currentGlj || typeof that.currentComponent === 'undefined' || (typeof that.currentComponent !== 'undefined' && target.row >= that.currentComponent.length)){//右键定位在有组成物的行,删除键才显示可用
+                        delDis = true;
+                    }
+                    return {
+                        callback: function(){},
+                        items: {
+                            "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
+                                //默认radio所有工料机
+                                co.initRadio();
+                                co.gljCurTypeId = null;
+                                //默认点击树根节点
+                                if(co.rootNode){
+                                    co.treeObj.selectNode(co.rootNode);
+                                    componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
+                                }
+                                //弹出窗口
+                                $('#componentBtn').click();
+                            }},
+                            "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
+                                //删除
+                                let deleteObj = that.currentComponent[target.row];
+                                let gljComponent = that.currentGlj.component;
+                                let updateArr = [], updateBasePrcArr = [];
+                                //更新当前工料机的组成物列表
+                                for(let i = 0, len = gljComponent.length; i < len; i++){
+                                    if(gljComponent[i].ID === deleteObj.ID){
+                                        gljComponent.splice(i, 1);
+                                        break;
+                                    }
+                                }
+                                //重新计算工料机
+                                let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(gljComponent));
+                                if(gljBasePrc !== that.currentGlj.basePrice){
+                                    that.currentGlj.basePrice = gljBasePrc;
+                                    that.reshowGljBasePrc(that.currentGlj);
+                                    updateBasePrcArr.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
+                                }
+                                updateArr.push(that.currentGlj);
+                                me.updateComponent(updateArr);
+                                if(updateBasePrcArr.length > 0 && that.rationLibs.length > 0){
+                                    that.updateRationBasePrcRq(updateBasePrcArr);
+                                }
+                            }}
+                        }
+                    };
+                }
+                else{
+                    return false;
+                }
+            }
+        });
+    },
     onCellEditStart: function(sender, args) {
         let me = gljComponentOprObj, that = repositoryGljObj;
         let rObj = me.getRowData(args.sheet, args.row, me.setting);
         me.currentEditingComponent = rObj;
+        let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
+        if(thatRow < that.currentCache.length){
+            that.currentGlj = that.currentCache[thatRow];
+            if(me.setting.view.lockedCols.indexOf(args.col) !== -1 || that.allowComponent.indexOf(that.currentGlj.gljType) === -1 ||
+                (args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
+                args.cancel = true;
+            }
+        }
+        else {
+            args.cancel = true;
+        }
     },
     onCellEditEnd: function (sender, args) {
         let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
@@ -270,7 +350,7 @@ let gljComponentOprObj = {
         let me = gljComponentOprObj;
         let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
         //复制的列数超过正确的列数,不可复制
-        if(maxCol >= me.setting.header.length){
+        if(info.cellRange.col !== 0 && info.cellRange.col !== 4 || info.cellRange.colCount > 1){
             args.cancel = true;
         }
     },
@@ -278,6 +358,7 @@ let gljComponentOprObj = {
         let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [] ,materialComponent = [202, 203, 204], machineComponent = [302, 303],
             component = that.currentGlj.component, newComponent = [], concatComponent = [], isChange = false, updateBasePrc = [];
         let items = sheetCommonObj.analyzePasteData(me.setting, info);
+        console.log(items);
         let gljCache = that.gljList;
         if(info.cellRange.col === 0){
             for(let i = 0; i < items.length; i++){
@@ -398,7 +479,6 @@ let gljComponentOprObj = {
                     if(result.data[0]){
                         that.currentComponent =  that.getCurrentComponent(result.data[0].component);
                         me.workBook.getSheet(0).getSelections()[0]
-                        //sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
                         sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
                         sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
                     }

+ 85 - 71
web/maintain/std_glj_lib/js/main.js

@@ -3,78 +3,90 @@
  */
 $(function () {
     let dispNameArr;
-    getAllGljLib(function (dispNames, compilationsUsedArr) {
-        dispNameArr = dispNames;
-        //添加
-        $('#addBtn').click(function () {
-            let compilationName = $('#compilationSels option:selected').text();
-            let compilationId = $('#compilationSels option:selected').val();
-            let libName = $('#libNameTxt').val();
-            if(libName.trim().length === 0){
-                alert('名称不可为空!');
-                $('#libNameTxt').val('')
-            }
-            else if(compilationsUsedArr.indexOf(compilationId) !== -1){// compilationsUsedArr;//在该编办下已建库,限制一个编办只能有一个库
-                alert('该编办已被绑定!');
-                $('#libNameTxt').val('')
-            }
-            else if(dispNames.indexOf(libName) !== -1){
-                alert('此工料机库已存在!');
-                $('#libNameTxt').val('')
-            }
-            else if(compilationName.trim().length === 0){
-                alert('编办不可为空!');
-            }
-            else{
-                let newGljLib = {};
-                newGljLib.dispName = libName;
-                newGljLib.compilationId = compilationId;
-                newGljLib.compilationName = compilationName;
-                newGljLib.creator = oprtor;
-                newGljLib.appType = "建筑";
-                $('#libNameTxt').val('');
-                createGljLib(newGljLib, dispNameArr);
-            }
-        });
-        //重命名
-        $("#showArea").on("click", "[data-target = '#edit']", function(){
-            let renameId = $(this).parent().parent().attr("id");
-            let compilationName = $(this).parent().parent().children()[1].textContent;
-            $('#compilationEdit option').text(compilationName);
-            $("#renameA").attr("renameId", renameId);
-        });
-        $("#renameA").click(function(){
-            let newName = $("#renameText").val();
-            let libId = $(this).attr("renameId");
-            let jqSel = "#" + libId + " td:first" + " a";
-            let orgName = $(jqSel).text();
-            if(newName.trim().length === 0){
-                alert("名称不可为空!");
-                $("#renameText").val('');
-            }
-            else if(dispNameArr.indexOf(newName) !== -1){
-                alert("该工料机库已存在!");
-                $("#renameText").val('');
-            }
-           else{
-               renameGljLib({ID: libId, newName: newName, orgName: orgName}, dispNameArr);
-            }
-        });
-        //删除
-        $("#showArea").on("click", "[data-target = '#del']", function(){
-            let deleteId = $(this).parent().parent().attr("id");
-            $("#deleteA").attr("deleteId", deleteId);
-        });
-        $("#deleteA").click(function(){
-            let deleteId = $(this).attr("deleteId");
-            let jqSel = "#" + deleteId + " td:first" + " a";
-            let libName = $(jqSel).text();
-            removeGljLib({libId: deleteId, libName: libName}, dispNameArr);
-        });
+    let compilationsArr;
+    let usedCom;
+    getCompilationList(function (datas) {
+        compilationsArr = datas;
+        getAllGljLib(function (dispNames, compilationsUsedArr) {
+            usedCom = compilationsUsedArr;
+            dispNameArr = dispNames;
+            //添加
+            $('#addBtn').click(function () {
+                let compilationName = $('#compilationSels option:selected').text();
+                let compilationId = $('#compilationSels option:selected').val();
+                let libName = $('#libNameTxt').val();
+                if(libName.trim().length === 0){
+                    alert('名称不可为空!');
+                    $('#libNameTxt').val('')
+                }
+                else if(compilationsUsedArr.indexOf(compilationId) !== -1){// compilationsUsedArr;//在该编办下已建库,限制一个编办只能有一个库
+                    alert('该编办已被绑定!');
+                    $('#libNameTxt').val('')
+                }
+                else if(dispNames.indexOf(libName) !== -1){
+                    alert('此工料机库已存在!');
+                    $('#libNameTxt').val('')
+                }
+                else if(compilationName.trim().length === 0){
+                    alert('编办不可为空!');
+                }
+                else{
+                    let newGljLib = {};
+                    newGljLib.dispName = libName;
+                    newGljLib.compilationId = compilationId;
+                    newGljLib.compilationName = compilationName;
+                    newGljLib.creator = oprtor;
+                    newGljLib.appType = "建筑";
+                    $('#libNameTxt').val('');
+                    createGljLib(newGljLib, dispNameArr, usedCom);
+                }
+            });
+            //重命名
+            $("#showArea").on("click", "[data-target = '#edit']", function(){
+                let renameId = $(this).parent().parent().attr("id");
+                let compilationName = $(this).parent().parent().children()[1].textContent;
+                $('#compilationEdit option').text(compilationName);
+                $("#renameA").attr("renameId", renameId);
+            });
+            $("#renameA").click(function(){
+                let newName = $("#renameText").val();
+                let libId = $(this).attr("renameId");
+                let jqSel = "#" + libId + " td:first" + " a";
+                let orgName = $(jqSel).text();
+                if(newName.trim().length === 0){
+                    alert("名称不可为空!");
+                    $("#renameText").val('');
+                }
+                else if(dispNameArr.indexOf(newName) !== -1){
+                    alert("该工料机库已存在!");
+                    $("#renameText").val('');
+                }
+                else{
+                    renameGljLib({ID: libId, newName: newName, orgName: orgName}, dispNameArr);
+                }
+            });
+            //删除
+            $("#showArea").on("click", "[data-target = '#del']", function(){
+                let deleteId = $(this).parent().parent().attr("id");
+                $("#deleteA").attr("deleteId", deleteId);
+            });
+            $("#deleteA").click(function(){
+                let deleteId = $(this).attr("deleteId");
+                let jqSel = "#" + deleteId + " td:first" + " a";
+                let libName = $(jqSel).text();
+                let compilationName = $("#" + deleteId + " td:eq(1)").text();
+                for(let i = 0, len = compilationsArr.length; i < len; i++){
+                    if(compilationsArr[i].name === compilationName.trim()){
+                        usedCom.splice(usedCom.indexOf(compilationsArr[i]._id), 1);
+                        break;
+                    }
+                }
+                removeGljLib({libId: deleteId, libName: libName}, dispNameArr);
+            });
 
 
+        });
     });
-    getCompilationList();
 });
 
 function getAllGljLib(callback){
@@ -116,7 +128,7 @@ function getAllGljLib(callback){
         }
     });
 }
-function getCompilationList(){
+function getCompilationList(callback){
     $.ajax({
         type: 'post',
         url: 'api/getCompilationList',
@@ -130,10 +142,11 @@ function getCompilationList(){
             }
             $('#compilationSels').on("change", function () {
             });
+            callback(result.data);
         }
     });
 }
-function createGljLib(gljLibObj, dispNamesArr){
+function createGljLib(gljLibObj, dispNamesArr, usedCom){
     $.ajax({
         type: 'post',
         url: 'api/createGljLib',
@@ -146,6 +159,7 @@ function createGljLib(gljLibObj, dispNamesArr){
                 let createDate = result.data.createDate.split(' ')[0];
                 let compilationName = result.data.compilationName;
                 dispNamesArr.push(libName);
+                usedCom.push(gljLibObj.compilationId);
                 $("#showArea").append(
                     "<tr id='tempId'>" +
                     "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +

+ 5 - 29
web/maintain/std_glj_lib/js/sheetsOpr.js

@@ -32,11 +32,6 @@ let sheetsOprObj = {
         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) {
@@ -47,38 +42,27 @@ let sheetsOprObj = {
             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 if(setting.header[col].dataCode === 'select'){
+                    if(data[row].isChecked === true){
+                        sheet.getCell(row, col).value(1);
+                    }
+                }
                 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;
@@ -103,26 +87,18 @@ let sheetsOprObj = {
                         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
                         }
                     }

+ 2 - 1
web/users/js/col_setting.js

@@ -47,7 +47,8 @@ let ColSettingObj = {
         this.cellType.readOnly.items([true, false,
             'readOnly.bills', 'readOnly.ration', 'readOnly.volumePrice',
             'readOnly.non_bills', 'readOnly.non_ration', 'readOnly.non_volumePrice',
-            'readOnly.billsParent', 'readOnly.forCalcBase'
+            'readOnly.billsParent', 'readOnly.forCalcBase', 'readOnly.forUnitFee',
+            'readOnly.forTotalFee', 'readOnly.leafBillsWithDetail'
         ]);
 
         this.cellType.getText = new GC.Spread.Sheets.CellTypes.ComboBox();