Browse Source

内容表和和项目表操作

zhongzewei 8 years ago
parent
commit
1873ff8502

+ 10 - 4
modules/billsLib/billsLibControllers/billsLibControllers.js

@@ -72,6 +72,12 @@ module.exports = {
             callback(req, res, err, message, null);
         });
     },
+    updateBillsArr: function(req, res){
+        var data = JSON.parse(req.body.data);
+        billsLibDao.updateBillsArr(data, function(err, message){
+           callback(req, res, err, message, null);
+        });
+    },
     deleteBills: function(req, res){
         var data = JSON.parse(req.body.data);
         billsLibDao.deleteBills(data, function(err, message){
@@ -92,14 +98,14 @@ module.exports = {
     },
     createJobContent: function(req, res){
         var data = JSON.parse(req.body.data);
-        billsLibDao.createJobContent(data, function(err, message){
-            callback(req, res, err, message, null);
+        billsLibDao.createJobContent(data, function(err, message, id){
+            callback(req, res, err, message, id);
         });
     },
     updateJobContent: function(req, res){
         var data = JSON.parse(req.body.data);
-        billsLibDao.updateJobContent(data, function(err, message){
-            callback(req, res, err, message, null);
+        billsLibDao.updateJobContent(data, function(err, message, id){
+            callback(req, res, err, message, id);
         });
     },
     deleteJobContent: function(req, res){

+ 59 - 5
modules/billsLib/billsLibModel/billsLibInterfaces.js

@@ -228,6 +228,58 @@ billsLibDao.prototype.updateBills = function(ubillsData, callback){
     }
 }
 
+billsLibDao.prototype.updateBillsArr = function(updateData, callback){
+    var billsLibId = updateData.billsLibId;
+    var updateId = updateData.updateId;
+    var field = updateData.field;
+    var id = updateData.id;
+    var updateData = updateData.updateData;
+    if(field === 'jobs'){
+        if(field == 'code'){
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'jobs.id': id}, {$set: {'jobs.$.code': updateData}}, function(err){
+                if(err){
+                    callback(1, 'Error');
+                }
+                else {
+                    callback(0, '');
+                }
+            });
+        }
+        else {
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'jobs.id': id}, {$set: {'jobs.$.content': updateData}}, function(err){
+                if(err){
+                    callback(1, 'Error');
+                }
+                else {
+                    callback(0, '');
+                }
+            });
+        }
+    }
+    else {
+        if(field == 'code'){
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'items.id': id}, {$set: {'items.$.code': updateData}}, function(err){
+                if(err){
+                    callback(1, 'Error');
+                }
+                else {
+                    callback(0, '');
+                }
+            });
+        }
+        else {
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'items.id': id}, {$set: {'items.$.content': updateData}}, function(err){
+                if(err){
+                    callback(1, 'Error');
+                }
+                else {
+                    callback(0, '');
+                }
+            });
+        }
+    }
+}
+
 billsLibDao.prototype.deleteBills = function(delData, callback){
     var deleteIds = delData.deleteIds;
     var billsLibId = delData.billsLibId;
@@ -296,19 +348,21 @@ billsLibDao.prototype.createJobContent = function(cJobData, callback){
         }
         JobContent.create(newJobContent, function(err){
             if(err){
-                callback(1, "Error");
+                callback(1, "Error", null);
+                console.log('error');
             }
             else{
-                callback(0, "");
+                console.log(id);
+                callback(0, "", id);
             }
         });
     });
 }
 
 billsLibDao.prototype.updateJobContent = function(uJobData, callback){
-    var field = cJobData.field;
-    var updateData = cJobData.data;
-    var updateid = cJobData.updateId;
+    var field = uJobData.field;
+    var updateData = uJobData.data;
+    var updateid = uJobData.updateId;
     if(field == "code"){
         JobContent.update({id: updateid}, {$set: {code: updateData}}, function(err){
             if(err){

+ 1 - 0
modules/billsLib/billsLibRoutes/billsLibRoutes.js

@@ -37,6 +37,7 @@ billsRouter.post("/getBills", billsController.getBills);
 billsRouter.post("/createBills", billsController.createBills);
 billsRouter.post("/updatePNId", billsController.updatePNId);
 billsRouter.post("/updateBills", billsController.updateBills);
+billsRouter.post("/updateBillsArr", billsController.updateBillsArr);
 billsRouter.post("/deleteBills", billsController.deleteBills);
 billsRouter.post("/getJobContent", billsController.getJobContent);
 billsRouter.post('/getSomeJobs', billsController.getSomeJobs);

+ 3 - 0
web/billsLib/html/neirong.html

@@ -180,6 +180,9 @@
                 return 'stdBills?billsLibId=' + billsLibId;
             });
             buildAllJobs();
+            jobsAjax.getJobContent(billsLibId, function(result){
+
+            });
         });
         function buildAllJobs(){
             var spread = new GC.Spread.Sheets.Workbook($("#spreadAllJobs")[0], {sheetCount: 1});

+ 163 - 19
web/billsLib/html/qingdan.html

@@ -229,13 +229,16 @@
     autoFlashHeight();
     var billsTree = billsLibTree.createBillsTree();
     var billsLibId = getQueryString("billsLibId");
+    var jobsSpread = new GC.Spread.Sheets.Workbook($("#spreadJobs")[0], {sheetCount: 1});
     $(document).ready(function(){
         $("#aStdJobs").attr('href', function(){
             return 'stdJobs?billsLibId=' + billsLibId;
         });
         billsAjax.getStdBillsLibName(billsLibId);
-        billsAjax.getBills(billsLibId);
-        buildJobs();
+        billsAjax.getBills(billsLibId, function(bills){
+            showBillsSheet(bills, jobsSpread.getActiveSheet(), billsLibSetting)
+        });
+        buildJobs(jobsSpread);
         buildItems();
     });
     //test
@@ -270,11 +273,11 @@
         });
     }
 
-    function showBillsSheet(datas){
+    function showBillsSheet(datas, jobsSheet, setting){
         var billsSpread = new GC.Spread.Sheets.Workbook($('#spreadBills')[0], {sheetCount: 1});
         initSheet(billsSpread);
         billsTree.loadDatas(datas);
-        var controller = TREE_SHEET_CONTROLLER.createNew(billsTree.tree, billsSpread.getActiveSheet(), billsLibSetting);
+        var controller = TREE_SHEET_CONTROLLER.createNew(billsTree.tree, billsSpread.getActiveSheet(), setting);
         controller.showTreeData();
         if(!controller.tree.selected && controller.tree.findNode(controller.sheet.getTag(0, 0, GC.Spread.Sheets.SheetArea.viewport))){
             controller.setTreeSelected(controller.tree.findNode(controller.sheet.getTag(0, 0, GC.Spread.Sheets.SheetArea.viewport)));
@@ -295,35 +298,176 @@
         });
         controller.setTreeSelected(controller.tree.findNode(controller.sheet.getTag(0,0)));
         nodeOpration(controller);
+        bindSheet(controller, jobsSheet, jobsSetting);
+        jobsController(controller, jobsSheet, jobsSetting);
+        //testNodeID:
+        console.log('newNodeID: '+controller.tree.newNodeID());
+        console.log('maxNodeID: '+controller.tree.maxNodeID());
+        console.log('rangeNodeID: '+controller.tree.rangeNodeID());
+        controller.tree.maxNodeID(100);
+        console.log('newNodeID: '+controller.tree.newNodeID());
+        //test
     }
 
-    function buildJobs(){
-        var jobsSpread = new GC.Spread.Sheets.Workbook($("#spreadJobs")[0], {sheetCount: 1});
-        initSheet(jobsSpread);
-        TREE_SHEET_HELPER.loadSheetHeader(jobsSetting, jobsSpread.getActiveSheet());
+
+    var Job = function(node, data){
+        this.node = node;
+        this.data = data;
+    }
+
+    var TotalJobs = function(tree){
+        this.tree = tree;
+        this.jobs = {};
+        this.prefix = '_id';
+    }
+
+    TotalJobs.prototype.loadJobs = function (nodes){
+        var me = this;
+        nodes.forEach(function(node){
+            node.data.jobs.forEach(function(jobData){
+                var job = new Job(node, jobData);
+                me.jobs[me.prefix + jobData.id] = job;
+                node.jobs.push(job);
+            });
+        });
+    }
+    function bindSheet(controller, sheet, field, setting){
+        controller.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function(sender, args){
+            if(controller.tree.selected && args.oldSelections[0].row !== args.newSelections[0].row|| args.oldSelections[0].row === 0){
+                sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);
+                sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.tag);
+                if(field === 'jobs'){
+                    var jobs = controller.tree.selected.jobs;
+                    if(jobs.length > 0){
+                        for(var i=0; i<jobs.length; i++){
+                            setting.cols.forEach(function(col, cidx){
+                                sheet.setTag(i, cidx, jobs[i].data.id, GC.Spread.Sheets.SheetArea.viewport);
+                                if(jobs[i].data[col.data.field]){
+                                    sheet.getCell(i, cidx, GC.Spread.Sheets.SheetArea.viewport).value(jobs[i].data[col.data.field]);
+                                }
+                                else {
+                                    sheet.getCell(i, cidx, GC.Spread.Sheets.SheetArea.viewport).value('');
+                                }
+                            });
+                        }
+                    }
+                }
+                if(field === 'items'){
+                    var items = controller.tree.selected.data.items;
+                    if(items.length > 0){
+                        for(var i=0; i<items.length; i++){
+                            setting.cols.forEach(function(col, cidx){
+                                sheet.setTag(i, cidx, result[i].id, GC.Spread.Sheets.SheetArea.viewport);
+                                if(result[i][col.data.field]){
+                                    sheet.getCell(i, cidx, GC.Spread.Sheets.SheetArea.viewport).value(result[i][col.data.field]);
+                                }
+                                else {
+                                    sheet.getCell(i, cidx, GC.Spread.Sheets.SheetArea.viewport).value('');
+                                }
+                            });
+                        }
+                    }
+                }
+            }
+        });
     }
 
-    function jobsController(sheet, jobsSetting){
-        jobsAjax.getJobContent(billsLibId, function(jobsArr){
+    function jobsController(controller, sheet, setting){
+   //     jobsAjax.getJobContent(billsLibId, function(jobsArr){
+        var totalJobs = new TotalJobs(controller.tree);
+        totalJobs.loadJobs(controller.tree.items);
 
-            sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args){
-                var field, oldData = args.sheet.getValue(args.row, args.col), newData = args.editingText, id = sheet.getTag(args.row, args.col) ;
-                jobsSetting.cols.forEach(function(col, idx){
-                    if(args.col === idx){
-                        field = col.data.field;
+        sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args){
+            var field, newData = args.editingText, id = sheet.getTag(args.row, args.col) ;
+            setting.cols.forEach(function(col, idx){
+                if(args.col === idx){
+                    field = col.data.field;
+                }
+            });
+            if(controller.tree.selected){
+                var isExist = false;
+                var isRepeat = false;
+                controller.tree.selected.jobs.forEach(function(job){
+                    if(job.data[field] === newData && id !== job.data.id){
+                        isRepeat = true;
                     }
                 });
                 //create
-                if(!id && !newData){
-                    jobsAjax.createJobContent(billsLibId, field, newData);
+                if(!id && newData && !isRepeat){
+                    if(totalJobs.jobs){
+                        totalJobs.jobs.forEach(function(job){
+                            //todo:整合代码
+                            if(field === 'content'&& newData === job.data.content){
+                                isExist = true;
+                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job );
+                                controller.tree.selected.jobs.push(job);
+                                sheet.getCell(args.row, 0).value(job.data.code);
+                                sheet.setTag(args.row, 0, job.data.id);
+                                sheet.setTag(args.row, 1, job.data.id);
+                            }
+                            else if(field === 'code' && newData === job.data.code){
+                                isExist = true;
+                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job);
+                                controller.tree.selected.data.jobs.push(job);
+                                sheet.getCell(args.row, 1).value(job.data.content);
+                                sheet.setTag(args.row, 0, job.data.id);
+                                sheet.setTag(args.row, 1, job.data.id);
+                            }
+                        });
+                        if(!isExist){
+                            jobsAjax.createJobContent(billsLibId, field, newData, function(id){
+                                var newJobData, newJob;
+                                if(field === 'code'){
+                                    newJobData = {id: id, code: newData, content: ''};
+                                }
+                                else {
+                                    newJobData = {id: id, content: newData, code: ''};
+                                }
+                                newJob = new Job(controller.tree.selected, newJobData);
+                                totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                                controller.tree.selected.jobs.push(newJob);
+                                sheet.setTag(args.row, 0, id);
+                                sheet.setTag(args.row, 1, id);
+                            });
+                        }
+                    }
+                    else {
+                        jobsAjax.createJobContent(billsLibId, field, newData, function(id){
+                            var newJobData, newJob;
+                            if(field === 'code'){
+                                newJobData = {id: id, code: newData, content: ''};
+                            }
+                            else {
+                                newJobData = {id: id, content: newData, code: ''};
+                            }
+                            newJob = new Job(controller.tree.selected, newJobData);
+                            totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                            billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                            controller.tree.selected.jobs.push(newJob);
+                            sheet.setTag(args.row, 0, id);
+                            sheet.setTag(args.row, 1, id);
+                        });
+                    }
                 }
                 //update
-                if(id && newData !== oldData ){
+                if(id && newData && !isRepeat){
+                    totalJobs.jobs[totalJobs.prefix + id].data[field] = newData;
                     jobsAjax.updateJobContent(id, field, newData);
+                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), field, id, newData);
                 }
-            });
+                if(isRepeat){
+                    sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
+                }
+            }
         });
+     //   });
+
+    }
 
+    function buildJobs(jobsSpread){
+        initSheet(jobsSpread);
+        TREE_SHEET_HELPER.loadSheetHeader(jobsSetting, jobsSpread.getActiveSheet());
     }
 
     function buildItems(){

+ 26 - 6
web/billsLib/scripts/billsLibAjax.js

@@ -99,7 +99,7 @@ var billsAjax = {
             }
         });
     },
-    getBills: function(billsLibId){
+    getBills: function(billsLibId, callback){
         $.ajax({
             type: "post",
             url: "/stdBillsEditor/getBills",
@@ -107,7 +107,10 @@ var billsAjax = {
             dataType: "json",
             success: function(result){
                 if(!result.error){
-                    showBillsSheet(result.data);
+                    if(callback) {
+                        callback(result.data);
+                    }
+                    //showBillsSheet(result.data);
                 }
             }
         });
@@ -154,6 +157,17 @@ var billsAjax = {
 
             }
         });
+    },
+    updateBillsArr: function(billsLibId, updateId, field, id, data){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/updateBillsArr',
+            data: {data: JSON.stringify({billsLibId: billsLibId, updateId: updateId, field: field, id: id, data: data})},
+            dataType: 'json',
+            success: function(result){
+
+            }
+        });
     }
 }
 
@@ -171,25 +185,31 @@ var jobsAjax = {
             }
         });
     },
-    getSomeJobs: function(billsLibId, ids){
+    getSomeJobs: function(billsLibId, ids, callback){
         $.ajax({
             type: 'post',
             url: 'stdBillsEditor/getSomeJobs',
             data: {data: JSON.stringify({billsLibId: billsLibId, ids: ids})},
             dataType: 'json',
             success: function(result){
-
+                if(!result.error && callback){
+                    callback(result.data);
+                }
             }
         });
     },
-    createJobContent: function(billsLibId, field, data){
+    createJobContent: function(billsLibId, field, data, callback){
         $.ajax({
             type: 'post',
             url: 'stdBillsEditor/createJobContent',
             data: {data: JSON.stringify({billsLibId: billsLibId, field: field, data: data})},
             dataType: 'json',
             success: function(result){
-
+                if(!result.error){
+                    if(callback){
+                        callback(result.data);
+                    }
+                }
             }
         });
     },

+ 130 - 1
web/billsLib/scripts/billsLibSetting.js

@@ -142,7 +142,7 @@ var itemsSetting = {
         },
         {
             head: {
-                titleNames: ['项目 特征'],
+                titleNames: ['项目特征'],
                 spanCols: [1],
                 spanRows: [2],
                 vAlign: [1, 1],
@@ -162,4 +162,133 @@ var itemsSetting = {
     headRowHeight: [20, 30, 30],
     emptyRows: 3,
     treeCol: 0
+};
+
+var totalJobsSetting = {
+    cols:[
+        {
+            head: {
+                titleNames: ['编号'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '16px Arial'
+            },
+            data: {
+                field: 'code',
+                vAlign: 1,
+                hAlign: 0,
+                font: '14px Arial'
+            },
+            width: 200
+        },
+        {
+            head: {
+                titleNames: ['工作内容'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '16px Arial'
+            },
+            data: {
+                field: 'character',
+                vAlign: 1,
+                hAlign: 0,
+                font: '14px Arial'
+            },
+            width: 850
+        },
+    ],
+    headRows: 2,
+    headRowHeight: [20, 30, 30],
+    emptyRows: 3,
+    treeCol: 0
+};
+
+var totalItemsSetting = {
+    cols:[
+        {
+            head: {
+                titleNames: ['编号'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '16px Arial'
+            },
+            data: {
+                field: 'code',
+                vAlign: 1,
+                hAlign: 0,
+                font: '14px Arial'
+            },
+            width: 200
+        },
+        {
+            head: {
+                titleNames: ['项目特征'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '16px Arial'
+            },
+            data: {
+                field: 'character',
+                vAlign: 1,
+                hAlign: 0,
+                font: '14px Arial'
+            },
+            width: 850
+        },
+    ],
+    headRows: 2,
+    headRowHeight: [20, 30, 30],
+    emptyRows: 3,
+    treeCol: 0
+};
+
+var eigenValueSetting = {
+    cols:[
+        {
+            head: {
+                titleNames: ['编号'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '16px Arial'
+            },
+            data: {
+                field: 'code',
+                vAlign: 1,
+                hAlign: 0,
+                font: '14px Arial'
+            },
+            width: 200
+        },
+        {
+            head: {
+                titleNames: ['特征值'],
+                spanCols: [1],
+                spanRows: [2],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '16px Arial'
+            },
+            data: {
+                field: 'itemValue',
+                vAlign: 1,
+                hAlign: 0,
+                font: '14px Arial'
+            },
+            width: 550
+        },
+    ],
+    headRows: 2,
+    headRowHeight: [20, 30, 30],
+    emptyRows: 3,
+    treeCol: 0
 }

+ 0 - 1
web/billsLib/scripts/dbController.js

@@ -55,7 +55,6 @@ var dbController = {
                 //parent
                 billsAjax.updatePNId(billsLibId, node.getParentID(), null, node.getID());
                 if(node.nextSibling){
-                    //node.nextSibling
                     billsAjax.updatePNId(billsLibId, node.getNextSiblingID(), node.getID(), null);
                 }
                 if(node.preSibling){

+ 0 - 5
web/billsLib/scripts/setSheets.js

@@ -12,11 +12,6 @@ function initSheet(spread){
     sheet.defaults.rowHeight = 30;
 }
 
-function initHeader(spread, setting){
-    var sheet = spread.getActiveSheet();
-    sheet.setColumnCount(setting.cols.length);
-    sheet.setRowCount();
-}
 
 function setCell(sheet){
     var colCount = sheet.getColumnCount();