zhongzewei 8 年之前
父節點
當前提交
5dabf1d625

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

@@ -17,6 +17,12 @@ var callback = function(req, res, err, message, data){
 }
 
 module.exports = {
+    getMaxNumber: function(req, res){
+        var data = JSON.parse(req.body.data);
+        billsLibDao.getMaxNumber(data, function(err, message, maxNumber){
+            callback(req, res, err, message, maxNumber);
+        });
+    },
     getStdBillsLib: function(req, res){
         var data = JSON.parse(req.body.data);
         billsLibDao.getStdBillsLib(data.userId, function(err, message, stdBillsLib){
@@ -110,20 +116,20 @@ module.exports = {
     },
     deleteJobContent: function(req, res){
         var data = JSON.parse(req.body.data);
-        billsLibDao.deleteJobContent(data.jobId, function(err, message){
+        billsLibDao.deleteJobContent(data.id, function(err, message){
             callback(req, res, err, message, null);
         });
     },
     getItemCharacter: function(req, res){
         var data = JSON.parse(req.body.data);
-        billsLibDao.getItemCharacter(data.billsLibId, function(err, message, items){
+        billsLibDao.getItemCharacter(data, function(err, message, items){
             callback(req, res, err, message, items);
         });
     },
     createItemCharacter: function(req, res){
         var data = JSON.parse(req.body.data);
-        billsLibDao.createItemCharacter(data, function(err, message){
-            callback(req, res, err, message, null);
+        billsLibDao.createItemCharacter(data, function(err, message, id){
+            callback(req, res, err, message, id);
         });
     },
     updateItemCharacter: function(req, res){

+ 141 - 77
modules/billsLib/billsLibModel/billsLibInterfaces.js

@@ -11,6 +11,31 @@ var ItemCharacter = model.itemCharacterMod;
 var fieldArr = ["code", "name", "unit", "ruleText", "Expression"];
 
 var billsLibDao = function(){};
+
+billsLibDao.prototype.getMaxNumber = function(gData, callback){
+    var billsLibId = gData.billsLibId;
+    var field = gData.field;
+    if(field === 'jobs'){
+        JobContent.find().sort({code: -1}).limit(1).exec(function(err, result){
+            if(err){
+                callback(1, 'Error', null);
+            }
+            else {
+                callback(0, '', result.code);
+            }
+        });
+    }
+    else if(field === 'items'){
+        ItemCharacter.find().sort({code: -1}).limit(1).exec(function(err, result){
+            if(err){
+                callback(1, 'Error', null);
+            }
+            else {
+                callback(0, '', result.code);
+            }
+        });
+    }
+};
 //----------StdBillsLib-------------------
 billsLibDao.prototype.getStdBillsLib = function(userId, callback){
     StdBillsLib.find({}, "-_id", function(err, data){
@@ -24,7 +49,7 @@ billsLibDao.prototype.getStdBillsLib = function(userId, callback){
 }
 
 billsLibDao.prototype.createStdBillsLib = function(clibData, callback){
-    counter.getIDAfterCount("bills", 1, function(err, result){
+    counter.counterDAO.getIDAfterCount(counter.moduleName.bills, 1, function(err, result){
         var billsLibId = result.value.sequence_value;
         var billsLibName = clibData.name;
         var createDate = Date.now();
@@ -129,6 +154,7 @@ billsLibDao.prototype.updatePNId= function(updateData, callback){
     var updateId = updateData.updateId;
     var updatepid= updateData.ParentID;
     var updatenid = updateData.NextSiblingID;
+    var success = true;
     if(!updatepid){
         Bills.update({billsLibId: billsLibId, ID: updateId}, {$set: {NextSiblingID: updatenid}}, function(err){
             if(err){
@@ -140,14 +166,19 @@ billsLibDao.prototype.updatePNId= function(updateData, callback){
         });
     }
     else if(!updatenid){
-        Bills.update({billsLibId: billsLibId, ID: updateId}, {$set: {ParentID: updatepid}}, function(err){
-            if(err){
-                callback(1, "Error")
-            }
-            else{
-                callback(0, "");
-            }
+        updateId.forEach(function(uid){
+            Bills.update({billsLibId: billsLibId, ID: uid}, {$set: {ParentID: updatepid}}, function(err){
+                if(err){
+                    success = false;
+                }
+            });
         });
+        if(!success){
+            callback(1, 'Error');
+        }
+        else {
+            callback(0, '');
+        }
     }
     else {
         Bills.update({billsLibId: billsLibId, ID: updateId}, {$set: {ParentID: updatepid, NextSiblingID: updatenid}}, function(err){
@@ -231,51 +262,69 @@ 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){
+    var data = updateData.data;
+    var classify = updateData.classify;
+    var success = true;
+    if(classify === 'jobs'){
+        if(data.id){
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'jobs.id': id}, {$set: {'jobs.$.id': data.id}}, function(err){
                 if(err){
-                    callback(1, 'Error');
+                    success = false;
                 }
-                else {
-                    callback(0, '');
+            });
+        }
+        else if(data.code){
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'jobs.id': id}, {$set: {'jobs.$.code': data.code}}, function(err){
+                if(err){
+                    success = false;
                 }
             });
         }
         else {
-            Bills.update({billsLibId: billsLibId, ID: updateId, 'jobs.id': id}, {$set: {'jobs.$.content': updateData}}, function(err){
+            Bills.update({billsLibId: billsLibId, ID: updateId, 'jobs.id': id}, {$set: {'jobs.$.content': data.content}}, function(err){
                 if(err){
-                    callback(1, 'Error');
-                }
-                else {
-                    callback(0, '');
+                    success =false
                 }
             });
         }
+       /* if(!success){
+            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 if(classify === 'items') {
+        if(field === 'code'){
+            updateIds.forEach(function(updateId){
+                Bills.update({billsLibId: billsLibId, ID: updateId, 'items.id': id}, {$set: {'items.$.code': data}}, function(err){
+                    if(err){
+                        success = false;
+                    }
+                });
             });
+            if(!success){
+                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, '');
-                }
+            updateIds.forEach(function(updateId){
+                Bills.update({billsLibId: billsLibId, ID: updateId, 'items.id': id}, {$set: {'items.$.content': data}}, function(err){
+                    if(err){
+                        success = false;
+                    }
+                });
             });
+            if(!success){
+                callback(1, 'Error');
+            }
+            else {
+                callback(0, '');
+            }
         }
     }
 }
@@ -285,29 +334,30 @@ billsLibDao.prototype.deleteBills = function(delData, callback){
     var billsLibId = delData.billsLibId;
     if(deleteIds){
         //deleteIds.forEach(function(deleteId){
-           Bills.remove({billsLibId: billsLibId, ID: {$in: deleteIds}}, function(err){
-               if(err){
-                   callback(1, 'Error');
-               }
-               else {
-                   callback(0, '');
-               }
-           });
-      //  });
+        Bills.remove({billsLibId: billsLibId, ID: {$in: deleteIds}}, function(err){
+            if(err){
+                callback(1, 'Error');
+            }
+            else {
+                callback(0, '');
+            }
+        });
+        //  });
     }
 }
 
 //--------------JobContent------------------
+
 billsLibDao.prototype.getJobContent = function(gJobData, callback){
     var billsLibId = gJobData.billsLibId;
-        JobContent.find({billsLibId: billsLibId}, "-_id", function(err, jobs){
-            if(err){
-                callback(1, "Error", null);
-            }
-            else{
-                callback(0, "", jobs)
-            }
-        });
+    JobContent.find({billsLibId: billsLibId}, "-_id", function(err, jobs){
+        if(err){
+            callback(1, "Error", null);
+        }
+        else{
+            callback(0, "", jobs)
+        }
+    });
 }
 
 billsLibDao.prototype.getSomeJobs = function(gJobData, callback){
@@ -327,22 +377,23 @@ billsLibDao.prototype.createJobContent = function(cJobData, callback){
     var field = cJobData.field;
     var data = cJobData.data;
     var billsLibId = cJobData.billsLibId;
-    counter.getIDAfterCount("bills", 1, function(err, result){
+    var serialNo = cJobData.serialNo;
+    counter.counterDAO.getIDAfterCount(counter.moduleName.bills, 1, function(err, result){
         var id = result.value.sequence_value;
         var newJobContent;
-        if(field == "code"){
+        /*if(field == "code"){
             newJobContent = {
                 id: id,
                 billsLibId: billsLibId,
                 code: data,
                 content: ''
             }
-        }
-        else if(field == "content"){
+        }*/
+         if(field == "content"){
             newJobContent = {
                 id: id,
                 billsLibId: billsLibId,
-                code: '',
+                code: serialNo,
                 content: data,
             }
         }
@@ -398,7 +449,8 @@ billsLibDao.prototype.deleteJobContent = function(jobId, callback){
 
 
 //----------------------ItemCharacter---------------------
-billsLibDao.prototype.getItemCharacter = function(billsLibId, callback){
+billsLibDao.prototype.getItemCharacter = function(gdata, callback){
+    var billsLibId = gdata.billsLibId;
     ItemCharacter.find({billsLibId: billsLibId}, "-_id", function(err, items){
         if(err){
             callback(1, "Error", null);
@@ -412,30 +464,42 @@ billsLibDao.prototype.getItemCharacter = function(billsLibId, callback){
 billsLibDao.prototype.createItemCharacter = function(cItemData, callback){
     var field = cItemData.field;
     var data = cItemData.data;
-    var id = counter.getIDAfterCount("billsLib", 1);
     var billsLibId = cItemData.billsLibId;
     var newItemCharacter;
-    if(field == "code"){
-        newItemCharacter = {
-            id: id,
-            billsLibId: billsLibId,
-            code: data
+    counter.counterDAO.getIDAfterCount(counter.moduleName.bills, 1, function(err, result){
+        var id = result.value.sequence_value;
+        if(field === 'code'){
+            newItemCharacter = {
+                id: id,
+                billsLibId: billsLibId,
+                code: data,
+                content: ''
+            }
         }
-    }
-    else if(field == "content"){
-        newItemCharacter = {
-            id: id,
-            billsLibId: billsLibId,
-            content: data
+        else if(field === 'content'){
+            newItemCharacter = {
+                id: id,
+                billsLibId: billsLibId,
+                content: data,
+                code: ''
+            }
         }
-    }
+        ItemCharacter.create(newItemCharacter, function(err){
+            if(err){
+                callback(1, "Error", null);
+            }
+            else{
+                callback(0, "", id);
+            }
+        });
+    });
 }
 
 billsLibDao.prototype.updateItemCharacter = function(uItemData, callback){
     var field = uItemData.field;
     var updateData = uItemData.data;
-    var id = uItemData.id;
-    if(field == "code"){
+    var id = uItemData.updateId;
+    if(field === "code"){
         ItemCharacter.update({id: id}, {$set: {code: updateData}}, function(err){
             if(err){
                 callback(1, "Error");
@@ -445,8 +509,8 @@ billsLibDao.prototype.updateItemCharacter = function(uItemData, callback){
             }
         });
     }
-    else if(field == "character"){
-        ItemCharacter.update({id: id}, {$set: {character: updateData}}, function(err){
+    else if(field === "content"){
+        ItemCharacter.update({id: id}, {$set: {content: updateData}}, function(err){
             if(err){
                 callback(1, "Error");
             }

+ 9 - 6
modules/billsLib/billsLibModel/billsLibSchemas.js

@@ -20,26 +20,29 @@ var billsSchema = mongoose.Schema({
     jobs: Array,
     items: Array,
     recharge:String,
-    billsLibId: Number
+    billsLibId: Number,
+    deleted: Boolean
 },
     {versionKey: false}
 );
 
 var jobContentSchema = mongoose.Schema({
     id: Number,
-    code: String,
+    code: Number,
     content: String,
-    billsLibId: Number
+    billsLibId: Number,
+    deleted: Boolean
 },
     {versionKey: false}
 );
 
 var itemCharacterSchema = mongoose.Schema({
     id: Number,
-    code: String,
-    character: String,
+    code: Number,
+    content: String,
     itemValue: Array,
-    billsLibId: Number
+    billsLibId: Number,
+    deleted: Boolean
 },
     {versionKey: false}
 );

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

@@ -28,6 +28,7 @@ billsRouter.get("/items", function(req, res){
     res.render("billsLib/html/tezheng.html");
 });*/
 
+billsRouter.post('/getMaxNumber', billsController.getMaxNumber);
 billsRouter.post("/getStdBillsLib", billsController.getStdBillsLib);
 billsRouter.post("/createStdBillsLib", billsController.createStdBillsLib);
 billsRouter.post("/deleteStdBillsLib", billsController.deleteStdBillsLib);

+ 1 - 1
modules/reports/controllers/rpt_controller.js

@@ -36,7 +36,7 @@ module.exports = {
             }
         }).then(function(tplData){
                 if (tplData) {
-                    var printCom = JpcEx.createNew();
+                    var printCom = JpcEx.createInit();
                     rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
                     var defProperties = rptUtil.getReportDefaultCache();
                     printCom.initialize(rptTpl);

+ 9 - 9
modules/reports/rpt_component/JpcEx.js

@@ -11,7 +11,7 @@ var JpcCommonHelper = require('./helper/Jpc_Helper_Common');
 var JE = require('./Jpc_RTE'); //Important: for self-define function execution purpose
 
 var JpcExSrv = function(){};
-JpcExSrv.prototype.createNew = function(){
+JpcExSrv.prototype.createInit = function(){
     function private_buildDftItems(rptTpl, dftCollection, propArray, nodeName) {
         var rst = {};
         if (dftCollection) {
@@ -85,29 +85,29 @@ JpcExSrv.prototype.createNew = function(){
     JpcResult.initialize = function(rptTpl) {
         var me = this;
         if (rptTpl[JV.NODE_FLOW_INFO]) {
-            me.flowTab = JpcFlowTab.createNew();
+            me.flowTab = JpcFlowTab.createInit();
             me.flowTab.initialize();
         }
         if (rptTpl[JV.NODE_BILL_INFO]) {
-            me.billTab = JpcBillTab.createNew();
+            me.billTab = JpcBillTab.createInit();
             me.billTab.initialize();
         }
         //var dt1 = new Date();
         if (rptTpl[JV.NODE_CROSS_INFO]) {
-            me.crossTab = JpcCrossTab.createNew();
+            me.crossTab = JpcCrossTab.createInit();
             me.crossTab.initialize();
         }
         me.totalPages = 0;
         me.runTimePageData = {};
-        me.fields = JpcField.createNew(rptTpl);
-        me.params = JpcParam.createNew(rptTpl);
-        me.formulas = JpcFunc.createNew(rptTpl);
+        me.fields = JpcField.createInit(rptTpl);
+        me.params = JpcParam.createInit(rptTpl);
+        me.formulas = JpcFunc.createInit(rptTpl);
     };
 
     JpcResult.analyzeData = function(rptTpl, dataObj, defProperties) {
         var me = this;
         //1. data object
-        var dataHelper = JpcData.createNew();
+        var dataHelper = JpcData.createInit();
         dataHelper.analyzeData(rptTpl, dataObj);
         //2. tab object
         //pre-condition: the data should be sorted in SQL/NoSQL level!
@@ -157,7 +157,7 @@ JpcExSrv.prototype.createNew = function(){
             rst[JV.NODE_FONT_COLLECTION] = private_buildDftFonts(rptTpl, (defProperties == null)?null:defProperties.fonts);
             rst[JV.NODE_PAGE_INFO] = JpcCommonHelper.getPageSize(rptTpl);
             rst.items = [];
-            var bands = JpcBand.createNew(rptTpl, defProperties);
+            var bands = JpcBand.createInit(rptTpl, defProperties);
             try {
                 for (var page = startPage; page <= endPage; page++) {
                     me.runTimePageData.currentPage = page;

+ 1 - 1
modules/reports/rpt_component/Jpc_BillTab.js

@@ -10,7 +10,7 @@ var JpcCommonOutputHelper = require('./helper/Jpc_Helper_CommonOutput');
 var JpcAreaHelper = require('./helper/Jpc_Helper_Area');
 
 var JpcBillTabSrv = function(){};
-JpcBillTabSrv.prototype.createNew = function(){
+JpcBillTabSrv.prototype.createInit = function(){
     var JpcBillTabResult = {};
     JpcBillTabResult.initialize = function() {
         var me = this;

+ 2 - 2
modules/reports/rpt_component/Jpc_CrossTab.js

@@ -11,7 +11,7 @@ var JpcCommonOutputHelper = require('./helper/Jpc_Helper_CommonOutput');
 var JpcAreaHelper = require('./helper/Jpc_Helper_Area');
 
 var JpcCrossTabSrv = function(){};
-JpcCrossTabSrv.prototype.createNew = function(){
+JpcCrossTabSrv.prototype.createInit = function(){
     function private_addTabValue(tabValuedIdxLst, sortedSequence, segIdx, preRec, nextRec, dispSerialIdxLst, sorted_sum_value_Lst, rst_sum_value_Lst) {
         if (tabValuedIdxLst) {
             var serial1stTier = null;
@@ -232,7 +232,7 @@ JpcCrossTabSrv.prototype.createNew = function(){
         var maxRowRec = 1, maxColRec = 1, counterRowRec = 0, counterColRec = 0, pageIdx = 0, segCnt = me.sortedContentSequence.length;
         var pageStatus = [true, true, false, true, false, false, false, false];
         //2. calculate the page info one by one
-        var bands = JpcBand.createNew(rptTpl, defProperties);
+        var bands = JpcBand.createInit(rptTpl, defProperties);
         function private_resetBandArea() {
             JpcBandHelper.setBandArea(bands, rptTpl, pageStatus);
             maxRowRec = JpcCrossTabHelper.getMaxRowsPerPage(bands, rptTpl);

+ 2 - 2
modules/reports/rpt_component/Jpc_FlowTab.js

@@ -11,7 +11,7 @@ var JpcCommonOutputHelper = require('./helper/Jpc_Helper_CommonOutput');
 var JpcAreaHelper = require('./helper/Jpc_Helper_Area');
 
 var JpcFlowTabSrv = function(){};
-JpcFlowTabSrv.prototype.createNew = function(){
+JpcFlowTabSrv.prototype.createInit = function(){
     function private_addPageValue(ValuedIdxLst, sortedSequence, preRec, nextRec,page_seg_map, segIdx, pageIdx) {
         var vIdx = [];
         for (var vi = 0; vi < nextRec; vi++) {
@@ -73,7 +73,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
     JpcFlowTabResult.preSetupPages = function (rptTpl, dataOjb, defProperties) {
         var rst = 0, me = this, counterRowRec = 0, maxRowRec = 1, pageIdx = 0;
         JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], null, me.disp_fields_idx);
-        var bands = JpcBand.createNew(rptTpl, defProperties);
+        var bands = JpcBand.createInit(rptTpl, defProperties);
         var pageStatus = [true, true, false, false, false, false, false, false];
         if (rptTpl[JV.NODE_FLOW_INFO][JV.PROP_MULTI_COLUMN]) {
             me.multiCols = 1 * rptTpl[JV.NODE_FLOW_INFO][JV.PROP_MULTI_COLUMN];

+ 3 - 2
public/counter/counter.js

@@ -23,7 +23,8 @@ const COUNTER_MODULE_NAME = {
     ration: 'rations',
     report: 'rptTemplates',
     fee: 'fees',
-    template_bills: 'temp_bills'
+    template_bills: 'temp_bills',
+    billsLib: 'billsLib'
 }
 /*const PROJECT_COUNTER = 'projects', USER_COUNTER = 'users', BILL_COUNTER = 'bills', RATION_COUNTER = 'rations',
     REPORT_COUNTER = 'rptTemplates', FEE_COUNTER = 'fees'*/
@@ -32,7 +33,7 @@ var counterDAO = function(){};
 
 /*
  * callback = function (err, result) {
- *     result.value.sequence_value 为修改后的id
+ *     result.value.sequence_value 为锟睫改猴拷锟絠d
  * }
  */
 counterDAO.prototype.getIDAfterCount = function(moduleName, stepCount, callback) {

+ 6 - 3
public/web/idTree.js

@@ -65,7 +65,7 @@ var idTree = {
                     nodes[i].nextSibling = (i === nodes.length - 1) ? null : nodes[i + 1];
                 }
             },
-            // 在nodes中,从iIndex(包括)开始全部移除
+            // 锟斤拷nodes锟叫o拷锟斤拷iIndex锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷始全锟斤拷锟狡筹拷
             removeNodes: function (tree, parent, iIndex, count) {
                 var children = parent ? parent.children : tree.roots;
                 var pre = (iIndex < 0 || iIndex >= children.length) ? null : children[iIndex].preSibling;
@@ -82,7 +82,7 @@ var idTree = {
                     children.splice(iIndex, children.length - iIndex);
                 }
             },
-            // 在nodes中增加addNodes, 位置从index开
+            // 锟斤拷nodes锟斤拷锟斤拷锟斤拷addNodes, 位锟矫达拷index锟斤拷
             addNodes: function (tree, parent, nodes, iIndex) {
                 var children = parent ? parent.children : tree.roots;
                 var pre, next, i;
@@ -135,7 +135,7 @@ var idTree = {
         };
 
         var Node = function (tree, data) {
-            // 以下的属性,本单元外均不可直接修改
+            // ���µ����ԣ�����Ԫ�������ֱ���޸�
             this.tree = tree;
             this.data = data;
             this.children = [];
@@ -148,6 +148,9 @@ var idTree = {
             this.visible = true;
 
             this.visible = true;
+
+            this.jobs = [];
+            this.items = [];
         };
 
         Node.prototype.getID = function () {

+ 1 - 1
test/unit/reports/testRpt.js

@@ -32,7 +32,7 @@ test('test get report pages function: ', function (t) {
         tplData = rst;
         t.equal(tplData != null, true);
         if (tplData) {
-            var printCom = JpcEx.createNew();
+            var printCom = JpcEx.createInit();
             rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
             var defProperties = rptUtil.getReportDefaultCache();
             printCom.initialize(rptTpl);

+ 158 - 48
web/billsLib/html/qingdan.html

@@ -230,16 +230,17 @@
     var billsTree = billsLibTree.createBillsTree();
     var billsLibId = getQueryString("billsLibId");
     var jobsSpread = new GC.Spread.Sheets.Workbook($("#spreadJobs")[0], {sheetCount: 1});
+    var itemsSpread = new GC.Spread.Sheets.Workbook($("#spreadItems")[0], {sheetCount: 1});
     $(document).ready(function(){
         $("#aStdJobs").attr('href', function(){
             return 'stdJobs?billsLibId=' + billsLibId;
         });
         billsAjax.getStdBillsLibName(billsLibId);
         billsAjax.getBills(billsLibId, function(bills){
-            showBillsSheet(bills, jobsSpread.getActiveSheet(), billsLibSetting)
+            showBillsSheet(bills, jobsSpread.getActiveSheet(), itemsSpread.getActiveSheet(), billsLibSetting)
         });
         buildJobs(jobsSpread);
-        buildItems();
+        buildItems(itemsSpread);
     });
     //test
     //test
@@ -256,28 +257,29 @@
             dbController.delete(controller);
         });
         $('#upLevel').click(function(){
-            //controller.upLevel();
+          //   controller.upLevel();
             dbController.upLevel(controller);
         });
         $('#downLevel').click(function(){
-            //controller.downLevel();
+           // controller.downLevel();
            dbController.downLevel(controller);
         });
         $('#upMove').click(function(){
-            //controller.upMove();
+           // controller.upMove();
             dbController.upMove(controller);
         });
         $('#downMove').click(function(){
-            //controller.downMove();
+          //  controller.downMove();
             dbController.downMove(controller);
         });
     }
 
-    function showBillsSheet(datas, jobsSheet, setting){
+
+    function showBillsSheet(datas, jobsSheet, itemsSheet, 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(), setting);
+        var controller = TREE_SHEET_CONTROLLER.createInit(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)));
@@ -298,42 +300,118 @@
         });
         controller.setTreeSelected(controller.tree.findNode(controller.sheet.getTag(0,0)));
         nodeOpration(controller);
-        bindSheet(controller, jobsSheet, jobsSetting);
-        jobsController(controller, jobsSheet, jobsSetting);
+
+        /*var totalJobs = new TotalJobs(controller.tree);
+        totalJobs.loadJobs(controller.tree.items);
+
+        bindSheet(controller, jobsSheet, 'jobs', jobsSetting);
+        jobsController(controller, jobsSheet, totalJobs, jobsSetting);*/
+
+        mainAjax.getMaxNumber(billsLibId, 'jobs', function(maxNumber){
+            var totalJobs = createObj.newJobs();
+            totalJobs.loadJobs(controller.tree.items);
+            bindSheet(controller, jobsSheet, 'jobs', jobsSetting);
+            jobsController.editData(controller, jobsSheet, totalJobs, maxNumber, jobsSetting);
+        });
+
+
+        /*var totalItems = createObj.newItems();
+        totalItems.loadItems(controller.tree.items);
+        bindSheet(controller, itemsSheet, 'items', itemsSetting);
+        itemsController.editData(controller, itemsSheet, totalItems, itemsSetting);*/
+
+
         //testNodeID:
-        console.log('newNodeID: '+controller.tree.newNodeID());
+        /*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());
+        console.log('newNodeID: '+controller.tree.newNodeID());*/
         //test
     }
 
-
-    var Job = function(node, data){
-        this.node = node;
+    /*var Job = function(data){
         this.data = data;
     }
 
     var TotalJobs = function(tree){
         this.tree = tree;
         this.jobs = {};
+        this.jobsArr = [];
         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);
+        jobsAjax.getJobContent(billsLibId, function(reslut){
+            reslut.forEach(function(jobData){
+                var job = new Job(jobData);
                 me.jobs[me.prefix + jobData.id] = job;
-                node.jobs.push(job);
+                me.jobsArr.push(job);
+            });
+            nodes.forEach(function(node){
+                node.data.jobs.forEach(function(data){
+                    node.jobs.push(me.jobs[me.prefix + data.id]);
+                });
+            });
+       });
+    }
+
+    TotalJobs.prototype.getUpdateIds = function(nodes, repeatId){
+        var ids = [];
+        nodes.forEach(function(node){
+            node.jobs.forEach(function(job){
+                if(job.data.id === repeatId){
+                    ids.push(node.getID());
+                }
             });
         });
+        return ids;
+    }
+
+    //items
+    var Item = function(data){
+        this.data = data;
     }
+
+    var TotalItems = function(tree){
+        this.tree = tree;
+        this.items = {};
+        this.itemsArr = [];
+        this.prefix = '_id';
+    }
+
+    TotalItems.prototype.loaditems = function (nodes){
+        var me = this;
+        itemsAjax.getItemCharacter(billsLibId, function(reslut){
+            reslut.forEach(function(itemData){
+                var item = new Item(itemData);
+                me.items[me.prefix + itemData.id] = item;
+                me.itemsArr.push(item);
+            });
+            nodes.forEach(function(node){
+                node.data.items.forEach(function(data){
+                    node.items.push(me.items[me.prefix + data.id]);
+                });
+            });
+        });
+    }
+
+    TotalItems.prototype.getUpdateIds = function(nodes, repeatId){
+        var ids = [];
+        nodes.forEach(function(node){
+            node.items.forEach(function(item){
+                if(item.data.id === repeatId){
+                    ids.push(node.getID());
+                }
+            });
+        });
+        return ids;
+    }*/
+
     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){
+            if(controller.tree.selected && args.oldSelections[0].row !== args.newSelections[0].row|| controller.tree.selected && 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'){
@@ -353,13 +431,13 @@
                     }
                 }
                 if(field === 'items'){
-                    var items = controller.tree.selected.data.items;
+                    var items = controller.tree.selected.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]);
+                                sheet.setTag(i, cidx, items[i].data.id, GC.Spread.Sheets.SheetArea.viewport);
+                                if(items[i].data[col.data.field]){
+                                    sheet.getCell(i, cidx, GC.Spread.Sheets.SheetArea.viewport).value(items[i].data[col.data.field]);
                                 }
                                 else {
                                     sheet.getCell(i, cidx, GC.Spread.Sheets.SheetArea.viewport).value('');
@@ -372,11 +450,11 @@
         });
     }
 
-    function jobsController(controller, sheet, setting){
-   //     jobsAjax.getJobContent(billsLibId, function(jobsArr){
-        var totalJobs = new TotalJobs(controller.tree);
-        totalJobs.loadJobs(controller.tree.items);
-
+/*    function jobsController(controller, sheet, totalJobs, setting){
+        var orgData;
+        sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
+            orgData = sheet.getCell(args.row, args.col).value();
+        });
         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){
@@ -387,34 +465,46 @@
             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;
-                    }
-                });
+                //isRepeat?
+                if(controller.tree.selected.jobs){
+                    controller.tree.selected.jobs.forEach(function(job){
+                        if(job.data[field] === newData && id !== job.data.id){
+                            isRepeat = true;
+                        }
+                    });
+                }
                 //create
                 if(!id && newData && !isRepeat){
-                    if(totalJobs.jobs){
-                        totalJobs.jobs.forEach(function(job){
+                    if(totalJobs.jobsArr.length > 0){
+                        totalJobs.jobsArr.forEach(function(job){
                             //todo:整合代码
                             if(field === 'content'&& newData === job.data.content){
+                                console.log('ECreate1');
                                 isExist = true;
-                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job );
+                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
+                                if(!controller.tree.selected.jobs){
+                                    controller.tree.selected.jobs = new Array();
+                                }
                                 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){
+                                console.log('ECreate2');
                                 isExist = true;
-                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job);
-                                controller.tree.selected.data.jobs.push(job);
+                                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
+                                if(!controller.tree.selected.jobs){
+                                    controller.tree.selected.jobs = new Array();
+                                }
+                                controller.tree.selected.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){
+                            console.log('notEcreate');
                             jobsAjax.createJobContent(billsLibId, field, newData, function(id){
                                 var newJobData, newJob;
                                 if(field === 'code'){
@@ -423,9 +513,13 @@
                                 else {
                                     newJobData = {id: id, content: newData, code: ''};
                                 }
-                                newJob = new Job(controller.tree.selected, newJobData);
+                                newJob = new Job(newJobData);
                                 totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                                totalJobs.jobsArr.push(newJob);
                                 billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                                if(!controller.tree.selected.jobs){
+                                    controller.tree.selected.jobs = new Array();
+                                }
                                 controller.tree.selected.jobs.push(newJob);
                                 sheet.setTag(args.row, 0, id);
                                 sheet.setTag(args.row, 1, id);
@@ -433,6 +527,7 @@
                         }
                     }
                     else {
+                        console.log('0create '+totalJobs.jobsArr.length);
                         jobsAjax.createJobContent(billsLibId, field, newData, function(id){
                             var newJobData, newJob;
                             if(field === 'code'){
@@ -441,9 +536,13 @@
                             else {
                                 newJobData = {id: id, content: newData, code: ''};
                             }
-                            newJob = new Job(controller.tree.selected, newJobData);
+                            newJob = new Job(newJobData);
                             totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                            totalJobs.jobsArr.push(newJob);
                             billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                            if(!controller.tree.selected.jobs){
+                                controller.tree.selected.jobs = new Array();
+                            }
                             controller.tree.selected.jobs.push(newJob);
                             sheet.setTag(args.row, 0, id);
                             sheet.setTag(args.row, 1, id);
@@ -451,27 +550,38 @@
                     }
                 }
                 //update
-                if(id && newData && !isRepeat){
+                else if(id && newData !== orgData && !isRepeat){
+                    console.log('update');
+                    var ids = totalJobs.getUpdateIds(controller.tree.items, id);
                     totalJobs.jobs[totalJobs.prefix + id].data[field] = newData;
                     jobsAjax.updateJobContent(id, field, newData);
-                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), field, id, newData);
+                    billsAjax.updateBillsArr(billsLibId, ids, field, id, newData);
                 }
                 if(isRepeat){
-                    sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
+                    //todo:redirect focus
+                    if(id && newData){
+                        console.log('isRepeat1 orgData:'+orgData);
+                        sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
+                    }
+                    else {
+                        console.log('isRepeat2');
+                        sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
+                    }
                 }
+                //delete
+
+
             }
         });
-     //   });
 
-    }
+    }*/
 
     function buildJobs(jobsSpread){
         initSheet(jobsSpread);
         TREE_SHEET_HELPER.loadSheetHeader(jobsSetting, jobsSpread.getActiveSheet());
     }
 
-    function buildItems(){
-        var itemsSpread = new GC.Spread.Sheets.Workbook($("#spreadItems")[0], {sheetCount: 1});
+    function buildItems(itemsSpread){
         initSheet(itemsSpread);
         TREE_SHEET_HELPER.loadSheetHeader(itemsSetting, itemsSpread.getActiveSheet());
     }

+ 7 - 4
web/billsLib/html/test.html

@@ -10,10 +10,13 @@
 </body>
 <script>
     $(document).ready(function(){
-       var test = {a: 1}
-        if(!test.b){
-            alert(1);
-        }
+        var test = ['a', 'b', 'c', 'd'];
+        var index = test.indexOf('b');
+        console.log(test);
+        console.log('index: '+index);
+        //test.splice(index, 1);
+        test.splice(index, 0, 'vvvvv');
+        console.log(test);
     });
 </script>
 </html>

+ 87 - 7
web/billsLib/scripts/billsLibAjax.js

@@ -2,6 +2,21 @@
  * Created by vian on 2017/3/27.
  */
 var mainAjax = {
+    getMaxNumber: function(billsLibId, field, callback){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/getMaxNumber',
+            data: {data: JSON.stringify({billsLibId: billsLibId, field: field})},
+            dataType: 'json',
+            success: function(result){
+                if(!result.error){
+                    if(callback){
+                        callback(result.data);
+                    }
+                }
+            }
+        });
+    },
     getStdBillsLib: function(userId){
         $.ajax({
             type: "post",
@@ -132,7 +147,6 @@ var billsAjax = {
             data: {data: JSON.stringify({billsLibId: billsLibId, updateId: updateId, ParentID: pid, NextSiblingID: nid})},
             dataType: 'json',
             success: function(result){
-
             }
         });
     },
@@ -158,14 +172,13 @@ var billsAjax = {
             }
         });
     },
-    updateBillsArr: function(billsLibId, updateId, field, id, data){
+    updateBillsArr: function(billsLibId, updateId, id, data, classify){
         $.ajax({
             type: 'post',
             url: 'stdBillsEditor/updateBillsArr',
-            data: {data: JSON.stringify({billsLibId: billsLibId, updateId: updateId, field: field, id: id, data: data})},
+            data: {data: JSON.stringify({billsLibId: billsLibId, updateId: updateId, id: id, data: data, classify: classify})},
             dataType: 'json',
             success: function(result){
-
             }
         });
     }
@@ -198,11 +211,11 @@ var jobsAjax = {
             }
         });
     },
-    createJobContent: function(billsLibId, field, data, callback){
+    createJobContent: function(billsLibId, field, data, serialNo, callback){
         $.ajax({
             type: 'post',
             url: 'stdBillsEditor/createJobContent',
-            data: {data: JSON.stringify({billsLibId: billsLibId, field: field, data: data})},
+            data: {data: JSON.stringify({billsLibId: billsLibId, field: field, data: data, serialNo: serialNo })},
             dataType: 'json',
             success: function(result){
                 if(!result.error){
@@ -218,7 +231,73 @@ var jobsAjax = {
             type: 'post',
             url: 'stdBillsEditor/updateJobContent',
             data: {data: JSON.stringify({updateId: id, field: field, data: data })},
-            dataTypea: 'json',
+            dataType: 'json',
+            success: function(result){
+
+            }
+        });
+    },
+    deleteJobContent: function(id){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/deleteJobContent',
+            data: {data: JSON.stringify({id: id})},
+            dataType: 'json',
+            success: function(result){
+
+            }
+        });
+    }
+}
+
+var itemsAjax = {
+    getItemCharacter: function(billsLibId, callback){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/getItemCharacter',
+            data: {data: JSON.stringify({billsLibId: billsLibId})},
+            dataType: 'json',
+            success: function(result){
+                if(!result.error){
+                    if(callback){
+                        callback(result.data);
+                    }
+                }
+            }
+        });
+    },
+    createItemCharacter: function(billsLibId, field, data, callback){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/createItemCharacter',
+            data: {data: JSON.stringify({billsLibId: billsLibId, field: field, data: data})},
+            dataType: 'json',
+            success: function(result){
+                if(!result.error){
+                    if(callback){
+                        callback(result.data);
+                    }
+                }
+            }
+        });
+    },
+    updateItemCharacter: function(id, field, data){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/updateItemCharacter',
+            data: {data: JSON.stringify({updateId: id, field: field, data: data })},
+            dataType: 'json',
+            success: function(result){
+
+            }
+        });
+    },
+    deleteItemCharacter: function(id){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/deleteItemCharacter',
+            data: {data: JSON.stringify({id: id})},
+            dataType: 'json',
             success: function(result){
 
             }
@@ -226,3 +305,4 @@ var jobsAjax = {
     }
 }
 
+

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

@@ -150,7 +150,7 @@ var itemsSetting = {
                 font: '16px Arial'
             },
             data: {
-                field: 'character',
+                field: 'content',
                 vAlign: 1,
                 hAlign: 0,
                 font: '14px Arial'

+ 2 - 2
web/billsLib/scripts/billsLibTree.js

@@ -23,12 +23,12 @@ var billsLibTree = {
         billsTree.prototype.loadDatas = function(datas){
             if(datas){
                 this.datas = datas;
-                this.tree = idTree.createNew(billsLibTree.setting);
+                this.tree = idTree.createInit(billsLibTree.setting);
                 this.tree.loadDatas(this.datas);
            }
            else {
                 this.datas = [];
-                this.tree = idTree.createNew(billsLibTree.setting);
+                this.tree = idTree.createInit(billsLibTree.setting);
                 this.tree.loadDatas(this.datas);
             }
         };

+ 593 - 5
web/billsLib/scripts/dbController.js

@@ -48,22 +48,40 @@ var dbController = {
 
     upLevel: function(controller){
         var node = controller.tree.selected;
+        var ids = [];
+        var getNextSibling = function(node){
+            if(node.nextSibling){
+                ids.push(node.getNextSiblingID());
+                getNextSibling(node.nextSibling);
+            }
+        }
+        //node
+        //todo:整合代码:updataPNId;
+        //------------------------todo
+      /*  var updateData = [
+            {
+                billsLibId: null,
+                updateIds: [],
+                updatePid: null,
+                updateNid: null
+            }
+        ];*/
+        //--------------------------todo
         if(node){
             if(node.parent){
-                //node
                 billsAjax.updatePNId(billsLibId, node.getID(), node.parent.getParentID(), node.parent.getNextSiblingID());
                 //parent
                 billsAjax.updatePNId(billsLibId, node.getParentID(), null, node.getID());
                 if(node.nextSibling){
-                    billsAjax.updatePNId(billsLibId, node.getNextSiblingID(), node.getID(), null);
+                    getNextSibling(node);
+                    billsAjax.updatePNId(billsLibId, ids, node.getID(), null);
                 }
                 if(node.preSibling){
                     billsAjax.updatePNId(billsLibId, node.preSibling.getID(), null, -1);
                 }
+                controller.upLevel();
             }
-            controller.upLevel();
         }
-
     },
 
     downLevel: function(controller){
@@ -127,4 +145,574 @@ var dbController = {
         });
     }
 
-}
+};
+//todo: 总表不存在则自动生成code并对应到分表
+var createObj = {
+    newJob: function(data){
+        var Job = function(data){
+            this.data = data;
+        };
+        return new Job(data);
+    },
+    newJobs: function(){
+        var TotalJobs = function(){
+            this.jobs = {};
+            this.jobsArr = [];
+            this.prefix = '_id';
+        };
+
+        TotalJobs.prototype.loadJobs = function (nodes){
+            var me = this;
+            jobsAjax.getJobContent(billsLibId, function(reslut){
+                reslut.forEach(function(jobData){
+                    var job = createObj.newJob(jobData);
+                    me.jobs[me.prefix + jobData.id] = job;
+                    me.jobsArr.push(job);
+                });
+                nodes.forEach(function(node){
+                    node.data.jobs.forEach(function(data){
+                        node.jobs.push(me.jobs[me.prefix + data.id]);
+                    });
+                });
+            });
+        };
+
+        TotalJobs.prototype.getUpdateIds = function(nodes, repeatId){
+            var ids = [];
+            nodes.forEach(function(node){
+                node.jobs.forEach(function(job){
+                    if(job.data.id === repeatId){
+                        ids.push(node.getID());
+                    }
+                });
+            });
+            return ids;
+        };
+
+        return new TotalJobs();
+    },
+
+    newItem: function(data){
+        var Item = function(data){
+            this.data = data;
+        };
+        return new Item(data);
+    },
+
+    newItems: function(){
+        var TotalItems = function(){
+            this.items = {};
+            this.itemsArr = [];
+            this.prefix = '_id';
+        };
+
+        TotalItems.prototype.loadItems = function (nodes){
+            var me = this;
+            itemsAjax.getItemCharacter(billsLibId, function(reslut){
+                reslut.forEach(function(itemData){
+                    var item = createObj.newItem(itemData);
+                    me.items[me.prefix + itemData.id] = item;
+                    me.itemsArr.push(item);
+                });
+                nodes.forEach(function(node){
+                    node.data.items.forEach(function(data){
+                        node.items.push(me.items[me.prefix + data.id]);
+                    });
+                });
+            });
+        };
+
+        TotalItems.prototype.getUpdateIds = function(nodes, repeatId){
+            var ids = [];
+            nodes.forEach(function(node){
+                node.items.forEach(function(item){
+                    if(item.data.id === repeatId){
+                        ids.push(node.getID());
+                    }
+                });
+            });
+            return ids;
+        };
+        return new TotalItems();
+    }
+};
+
+var jobsController = {
+    editData: function(controller, sheet, totalJobs, maxNumber, setting){
+        var orgData;
+        sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
+            orgData = sheet.getCell(args.row, args.col).value();
+        });
+        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;
+                //isExist?
+                if(totalJobs.jobsArr.length > 0){
+                    totalJobs.jobsArr.forEach(function(job){
+                        if(job.data[field] === newData && newData !== orgData){
+                            isExist = true;
+                        }
+                    });
+                }
+                //isRepeat?
+                if (controller.tree.selected.jobs) {
+                    controller.tree.selected.jobs.forEach(function (job) {
+                        if (job.data[field] === newData && id !== job.data.id) {
+                            isRepeat = true;
+                        }
+                    });
+                }
+                //create
+                if(!id && newData && !isRepeat){
+                    if(totalJobs.jobsArr.length > 0){
+                        if(isExist){
+                            jobsController.createExist(sheet, controller, totalJobs, field, newData, isExist, args);
+                        }
+                        else {
+                            jobsController.createNew(maxNumber, sheet, controller, totalJobs, field, newData, args);
+                        }
+                    }
+                    else {
+                        jobsController.createInit(sheet, controller, totalJobs, field, newData, args);
+                    }
+                }
+                //update
+                else if(id && newData !== orgData && !isRepeat){
+                    jobsController.update(maxNumber, sheet, controller, totalJobs, field, newData, id);
+                }
+                //处理重复
+                if(isRepeat){
+                    //todo:redirect focus
+                    if(id && newData){
+                        console.log('isRepeat1 orgData:'+orgData);
+                        sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
+                    }
+                    else {
+                        console.log('isRepeat2');
+                        sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
+                    }
+                }
+            }
+        });
+    },
+
+    createExist: function(sheet, controller, totalJobs, field, newData, args){
+        totalJobs.jobsArr.forEach(function(job){
+            //todo:整合代码
+            if(field === 'content'&& newData === job.data.content){
+                console.log('ECreate1');
+                //isExist = true;
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
+                if(!controller.tree.selected.jobs){
+                    controller.tree.selected.jobs = new Array();
+                }
+                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){
+                console.log('ECreate2');
+                //isExist = true;
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
+                if(!controller.tree.selected.jobs){
+                    controller.tree.selected.jobs = new Array();
+                }
+                controller.tree.selected.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);
+            }
+        });
+    },
+
+    createNew: function(maxNumber, sheet, controller, totalJobs, field, newData, args){
+        console.log('notEcreate');
+        if(field === 'content'){
+            maxNumber++;
+            jobsAjax.createJobContent(billsLibId, field, newData, maxNumber, function(id){
+                var newJobData, newJob;
+                newJobData = {id: id, content: newData, code: maxNumber};
+                newJob = createObj.newJob(newJobData);
+                totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                totalJobs.jobsArr.push(newJob);
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                if(!controller.tree.selected.jobs){
+                    controller.tree.selected.jobs = new Array();
+                }
+                controller.tree.selected.jobs.push(newJob);
+                sheet.setTag(args.row, 0, id);
+                sheet.setTag(args.row, 1, id);
+            });
+        }
+        else {
+            sheet.getCell(args.row, args.col).value('');
+        }
+    },
+
+    createInit: function(sheet, controller, totalJobs, field, newData, args){
+        console.log('0create '+totalJobs.jobsArr.length);
+        //new----------------
+        if(field === 'content'){
+            jobsAjax.createJobContent(billsLibId, field, newData, 1, function(id){
+                var newJobData, newJob;
+                newJobData = {id: id, content: newData, code: 1};
+                newJob = createObj.newJob(newJobData);
+                totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                totalJobs.jobsArr.push(newJob);
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                if(!controller.tree.selected.jobs){
+                    controller.tree.selected.jobs = new Array();
+                }
+                controller.tree.selected.jobs.push(newJob);
+                sheet.setTag(args.row, 0, id);
+                sheet.setTag(args.row, 1, id);
+            });
+        }
+        else {
+            sheet.getCell(args.row, args.col).value('');
+        }
+    },
+
+    update: function(maxNumber, sheet, controller, totalJobs, field, newData, id, isExist){
+        //1.更新后的数据存在总表则引用总表,不存在则新增 2.原数据有多个引用,
+        var index;
+        controller.tree.selected.jobs.forEach(function(job){
+            if(job.data.id === id){
+                index = controller.tree.selected.jobs.indexOf(job);
+                controller.tree.selected.jobs.splice(index ,1);
+            }
+        });
+        if(isExist){
+            totalJobs.forEach(function(job){
+                if(field === 'code' && job.data[field] === newData){
+                    controller.tree.selected.jobs.splice(index, 0, job);
+                    var newJobData = {id: job.data.id, code: newData, content: job.data.content}
+                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newJobData, 'jobs');
+                    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(field === 'content' && job.data[field] === newData){
+                    controller.tree.selected.jobs.splice(index, 0, job);
+                    var newJobData = {id: job.data.id, code: job.data.code, content: newData}
+                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newJobData, 'jobs');
+                    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{
+            //jobsController.createNew(maxNumber, sheet, controller, totalJobs, field, newData, args);
+            if(field === 'content'){
+                maxNumber++;
+                jobsAjax.createJobContent(billsLibId, field, newData, maxNumber, function(newId){
+                    var newJobData, newJob;
+                    newJobData = {id: newId, content: newData, code: maxNumber};
+                    newJob = createObj.newJob(newJobData);
+                    totalJobs.jobs[totalJobs.prefix + newId] = newJob;
+                    totalJobs.jobsArr.push(newJob);
+                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newJobData, 'jobs');
+                    if(!controller.tree.selected.jobs){
+                        controller.tree.selected.jobs = new Array();
+                    }
+                    controller.tree.selected.jobs.splice(index, 0, newJob);
+                    sheet.setTag(args.row, 0, newId);
+                    sheet.setTag(args.row, 1, newId);
+                });
+            }
+            else {
+                sheet.getCell(args.row, args.col).value(orgData);
+            }
+        }
+    },
+
+    delete: function(id){
+
+    }
+
+};
+
+var itemsController = {
+    editData: function(controller, sheet, totalItems, setting){
+        var orgData;
+        sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
+            orgData = sheet.getCell(args.row, args.col).value();
+        });
+        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;
+                //isRepeat?
+                if (controller.tree.selected.items) {
+                    controller.tree.selected.items.forEach(function (item) {
+                        if (item.data[field] === newData && id !== item.data.id) {
+                            isRepeat = true;
+                        }
+                    });
+                }
+                //create
+                if(!id && newData && !isRepeat){
+                    if(totalItems.itemsArr.length > 0){
+                        itemsController.createExist(sheet, controller, totalItems, field, newData, isExist, args);
+                    }
+                    else {
+                        itemsController.createInit(sheet, controller, totalItems, field, newData, args);
+                    }
+                }
+                //update
+                else if(id && newData !== orgData && !isRepeat){
+                    itemsController.update(controller, totalItems, field, newData, id);
+                }
+                //处理重复
+                if(isRepeat){
+                    //todo:redirect focus
+                    if(id && newData){
+                        console.log('isRepeat1 orgData:'+orgData);
+                        sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
+                    }
+                    else {
+                        console.log('isRepeat2');
+                        sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
+                    }
+                }
+            }
+        });
+    },
+
+    createExist: function(sheet, controller, totalItems, field, newData, isExist, args){
+        totalItems.itemsArr.forEach(function(item){
+            //todo:整合代码
+            if(field === 'content'&& newData === item.data.content){
+                console.log('ECreate1');
+                isExist = true;
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', item.data);
+                if(!controller.tree.selected.items){
+                    controller.tree.selected.items = new Array();
+                }
+                controller.tree.selected.items.push(item);
+                sheet.getCell(args.row, 0).value(item.data.code);
+                sheet.setTag(args.row, 0, item.data.id);
+                sheet.setTag(args.row, 1, item.data.id);
+            }
+            else if(field === 'code' && newData === item.data.code){
+                console.log('ECreate2');
+                isExist = true;
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', item.data);
+                if(!controller.tree.selected.items){
+                    controller.tree.selected.items = new Array();
+                }
+                controller.tree.selected.items.push(item);
+                sheet.getCell(args.row, 1).value(item.data.content);
+                sheet.setTag(args.row, 0, item.data.id);
+                sheet.setTag(args.row, 1, item.data.id);
+            }
+        });
+        if(!isExist){
+            console.log('notEcreate');
+            itemsAjax.createItemCharacter(billsLibId, field, newData, function(id){
+                var newItemData, newItem;
+                if(field === 'code'){
+                    newItemData = {id: id, code: newData, content: ''};
+                }
+                else {
+                    newItemData = {id: id, content: newData, code: ''};
+                }
+                newItem = createObj.newItem(newItemData);
+                totalItems.items[totalItems.prefix + id] = newItem;
+                totalItems.itemsArr.push(newItem);
+                billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', newItemData);
+                if(!controller.tree.selected.items){
+                    controller.tree.selected.items = new Array();
+                }
+                controller.tree.selected.items.push(newItem);
+                sheet.setTag(args.row, 0, id);
+                sheet.setTag(args.row, 1, id);
+            });
+        }
+    },
+
+    createNew: function(sheet, controller, totalItems, field, newData, args){
+        console.log('0create '+totalItems.itemsArr.length);
+        itemsAjax.createItemCharacter(billsLibId, field, newData, function(id){
+            var newItemData, newItem;
+            if(field === 'code'){
+                newItemData = {id: id, code: newData, content: ''};
+            }
+            else {
+                newItemData = {id: id, content: newData, code: ''};
+            }
+            newItem = createObj.newItem(newItemData);
+            totalItems.items[totalItems.prefix + id] = newItem;
+            totalItems.itemsArr.push(newItem);
+            billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', newItemData);
+            if(!controller.tree.selected.items){
+                controller.tree.selected.items = new Array();
+            }
+            controller.tree.selected.items.push(newItem);
+            sheet.setTag(args.row, 0, id);
+            sheet.setTag(args.row, 1, id);
+        });
+    },
+
+    update: function(controller, totalItems, field, newData, id){
+        console.log('update');
+        var ids = totalItems.getUpdateIds(controller.tree.items, id);
+        totalItems.items[totalItems.prefix + id].data[field] = newData;
+        itemsAjax.updateItemCharacter(id, field, newData);
+        billsAjax.updateBillsArr(billsLibId, ids, field, id, newData, 'items');
+    },
+
+    delete: function(id){
+
+    }
+
+};
+
+/*function jobsController(controller, sheet, totalJobs, setting){
+    var orgData;
+    sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
+        orgData = sheet.getCell(args.row, args.col).value();
+    });
+    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;
+            //isRepeat?
+            if(controller.tree.selected.jobs){
+                controller.tree.selected.jobs.forEach(function(job){
+                    if(job.data[field] === newData && id !== job.data.id){
+                        isRepeat = true;
+                    }
+                });
+            }
+            //create
+            if(!id && newData && !isRepeat){
+                if(totalJobs.jobsArr.length > 0){
+                    //spl==========================================================
+                    totalJobs.jobsArr.forEach(function(job){
+                        //todo:整合代码
+                        if(field === 'content'&& newData === job.data.content){
+                            console.log('ECreate1');
+                            isExist = true;
+                            billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
+                            if(!controller.tree.selected.jobs){
+                                controller.tree.selected.jobs = new Array();
+                            }
+                            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){
+                            console.log('ECreate2');
+                            isExist = true;
+                            billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
+                            if(!controller.tree.selected.jobs){
+                                controller.tree.selected.jobs = new Array();
+                            }
+                            controller.tree.selected.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){
+                        console.log('notEcreate');
+                        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(newJobData);
+                            totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                            totalJobs.jobsArr.push(newJob);
+                            billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                            if(!controller.tree.selected.jobs){
+                                controller.tree.selected.jobs = new Array();
+                            }
+                            controller.tree.selected.jobs.push(newJob);
+                            sheet.setTag(args.row, 0, id);
+                            sheet.setTag(args.row, 1, id);
+                        });
+                        //spl==========================================================
+                    }
+                }
+                else {
+                    //spl==========================================================
+                    console.log('0create '+totalJobs.jobsArr.length);
+                    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(newJobData);
+                        totalJobs.jobs[totalJobs.prefix + id] = newJob;
+                        totalJobs.jobsArr.push(newJob);
+                        billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
+                        if(!controller.tree.selected.jobs){
+                            controller.tree.selected.jobs = new Array();
+                        }
+                        controller.tree.selected.jobs.push(newJob);
+                        sheet.setTag(args.row, 0, id);
+                        sheet.setTag(args.row, 1, id);
+                    });
+                    //spl==========================================================
+                }
+            }
+            //update
+            else if(id && newData !== orgData && !isRepeat){
+                //spl==========================================================
+                console.log('update');
+                var ids = totalJobs.getUpdateIds(controller.tree.items, id);
+                totalJobs.jobs[totalJobs.prefix + id].data[field] = newData;
+                jobsAjax.updateJobContent(id, field, newData);
+                billsAjax.updateBillsArr(billsLibId, ids, field, id, newData);
+                //spl==========================================================
+            }
+            if(isRepeat){
+                //todo:redirect focus
+                if(id && newData){
+                    console.log('isRepeat1 orgData:'+orgData);
+                    sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
+                }
+                else {
+                    console.log('isRepeat2');
+                    sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
+                }
+            }
+            //delete
+
+
+        }
+    });
+
+}*/
+
+

+ 3 - 3
web/main/html/main.html

@@ -628,14 +628,14 @@
             data.flags.push({fieldName: 'isPartGather', flag: false});
         });
 
-        project = PROJECT.createNew();
+        project = PROJECT.createInit();
         project.Bills.loadDatas(datas);
         project.Rations.loadDatas(drawing_data);
         project.loadMainTree();
         //project.mainTree.loadDatas(project.Bills.tree, project.Rations.datas);
 
-        controller = TREE_SHEET_CONTROLLER.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
-        //controller = TREE_SHEET_CONTROLLER.createNew(project.Bills.tree, billsSpread.getActiveSheet(), BillsGridSetting);
+        controller = TREE_SHEET_CONTROLLER.createInit(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
+        //controller = TREE_SHEET_CONTROLLER.createInit(project.Bills.tree, billsSpread.getActiveSheet(), BillsGridSetting);
         controller.showTreeData();
         controller.bind('refreshBaseActn', function (tree) {
             var showButton = function (show, btn) {

+ 5 - 5
web/main/js/models/bills.js

@@ -11,14 +11,14 @@ var Bills = {
             rootId: -1
         };
 
-        // 用户定义private方法
+        // 锟矫伙拷锟斤拷锟斤拷private锟斤拷锟斤拷
         var tools = {};
 
-        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        // ����ͨ��this���ʵ����ԣ�����Ӧ�ڴ˵�Ԫ�ⲿ����д�����
         var bills = function (proj) {
             this.project = proj;
             this.datas = null;
-            this.tree = idTree.createNew(billsTreeSetting);
+            this.tree = idTree.createInit(billsTreeSetting);
 
             var sourceType = 'bills';
             this.getSourceType = function () {
@@ -26,10 +26,10 @@ var Bills = {
             }
         };
 
-        // prototype用于定义public方法
+        // prototype锟斤拷锟节讹拷锟斤拷public锟斤拷锟斤拷
         bills.prototype.loadDatas = function (datas) {
             this.datas = datas;
-            // generate Fees & Flags IndexFor View & Calculate
+            // generate Fees & Flags Index锟斤拷For View & Calculate
             this.datas.forEach(function (data) {
                 data.FeesIndex = {};
                 data.fees.forEach(function (fee) {

+ 7 - 7
web/main/js/models/project.js

@@ -3,22 +3,22 @@
  */
 var PROJECT = {
     createNew: function () {
-        // 定义private方法
+        // 锟斤拷锟斤拷private锟斤拷锟斤拷
         var tools = {};
 
-        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        // ����ͨ��this���ʵ����ԣ�����Ӧ�ڴ˵�Ԫ�ⲿ����д�����
         var project = function () {
-            this.mainTree = cacheTree.createNew(this);
+            this.mainTree = cacheTree.createInit(this);
 
-            this.Bills = Bills.createNew(this);
-            this.Rations = Rations.createNew(this);
-            this.GLJs = GLJs.createNew(this);
+            this.Bills = Bills.createInit(this);
+            this.Rations = Rations.createInit(this);
+            this.GLJs = GLJs.createInit(this);
 
 
             this.masterField = {ration: 'BillsID'};
         };
 
-        // prototype用于定义public方法
+        // prototype锟斤拷锟节讹拷锟斤拷public锟斤拷锟斤拷
         project.prototype.modify = function (modifyDatas, callback) {
             // To Do
         };

+ 2 - 2
web/templates/js/bills.js

@@ -61,9 +61,9 @@ $(document).ready(function () {
     }
 
     var bills;
-    var tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
+    var tree = idTree.createInit({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
     var billsSpread = new GC.Spread.Sheets.Workbook($('#billsSpread')[0], { sheetCount: 1 });
-    var controller = TREE_SHEET_CONTROLLER.createNew(tree, billsSpread.getActiveSheet(), TEMPLATE_BILLS_SETTING);
+    var controller = TREE_SHEET_CONTROLLER.createInit(tree, billsSpread.getActiveSheet(), TEMPLATE_BILLS_SETTING);
 
     GC.Spread.Common.CultureManager.culture("zh-cn");