浏览代码

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

zhongzewei 8 年之前
父节点
当前提交
996ccac8e2

+ 7 - 7
modules/main/models/bills.js

@@ -8,18 +8,18 @@ var Schema = mongoose.Schema;
 var counter = require("../../../public/counter/counter.js");
 var counter = require("../../../public/counter/counter.js");
 
 
 var billsSchema = new Schema({
 var billsSchema = new Schema({
-    id: Number,
-    parentId: Number,
-    nextSiblingId: Number,
-    projectId: Number,
+    ID: Number,
+    ParentID: Number,
+    NextSiblingID: Number,
+    projectID: Number,
     serialNo: Number,
     serialNo: Number,
-    chapterId: Number,
+    chapterID: Number,
     code: String,
     code: String,
     fullCode: String,
     fullCode: String,
     name: String,
     name: String,
     unit: String,
     unit: String,
     quantity: String, // Decimal
     quantity: String, // Decimal
-    programId: Number,
+    programID: Number,
     comments: String,
     comments: String,
     // 调价
     // 调价
     xs_Labour: String, // Decimal
     xs_Labour: String, // Decimal
@@ -96,7 +96,7 @@ billsDAO.prototype.allocIDs = function(callback){
     var lowID, highID;
     var lowID, highID;
     counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
     counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
     lowID = highID - IDStep + 1;
     lowID = highID - IDStep + 1;
-    callback(0, '', {lowID, highID});
+    callback(0, '', {lowID: lowID, highID: highID});
 };
 };
 
 
 module.exports = new billsDAO();
 module.exports = new billsDAO();

+ 1 - 1
modules/main/models/billsSubSchemas.js

@@ -19,4 +19,4 @@ var flagsSchema = new Schema({
     flag: Boolean
     flag: Boolean
 });
 });
 
 
-module.exports = {feesSchema, flagsSchema};
+module.exports = {feesSchema: feesSchema, flagsSchema: flagsSchema};

+ 1 - 1
modules/main/models/gljs.js

@@ -6,7 +6,7 @@ var db = require("../db/project_db");
 var Schema = mongoose.Schema;
 var Schema = mongoose.Schema;
 
 
 var gljSchema = new Schema({
 var gljSchema = new Schema({
-    id: Number,
+    ID: Number,
     projectID: Number,
     projectID: Number,
     orgRQuantity: String, //Decimal
     orgRQuantity: String, //Decimal
     rQuantity: String, //Decimal
     rQuantity: String, //Decimal

+ 1 - 1
modules/main/models/projectGLJ.js

@@ -6,7 +6,7 @@ var db = require("../db/project_db");
 var Schema = mongoose.Schema;
 var Schema = mongoose.Schema;
 
 
 var projectGLJSchema = new Schema({
 var projectGLJSchema = new Schema({
-    id: Number,
+    ID: Number,
     projectId: Number,
     projectId: Number,
     code: Number,
     code: Number,
     name: String,
     name: String,

+ 3 - 3
modules/main/models/rationPrograms.js

@@ -6,11 +6,11 @@ var db = require("../db/project_db");
 var Schema = mongoose.Schema;
 var Schema = mongoose.Schema;
 
 
 var rationProgramSchema = new Schema({
 var rationProgramSchema = new Schema({
-    id: Number,
-    projectId: Number,
+    ID: Number,
+    projectID: Number,
     name: String,
     name: String,
     programs: [{
     programs: [{
-        id: Number,
+        ID: Number,
         serialNo: Number,
         serialNo: Number,
         code: String,
         code: String,
         name: String,
         name: String,

+ 4 - 4
modules/main/models/rations.js

@@ -7,9 +7,9 @@ var subSchema = require("./billsSubSchemas");
 var Schema = mongoose.Schema;
 var Schema = mongoose.Schema;
 
 
 var rationsSchema = new Schema({
 var rationsSchema = new Schema({
-    id: Number,
-    projectId: Number,
-    billsItemId: Number,
+    ID: Number,
+    ProjectID: Number,
+    billsItemID: Number,
     serialNo: Number,
     serialNo: Number,
     libID: Number,
     libID: Number,
     code: String,
     code: String,
@@ -83,7 +83,7 @@ rationsDAO.prototype.allocIDs = function(callback){
     var lowID, highID;
     var lowID, highID;
     counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
     counter.getIDAfterCount(IDModule, IDStep, function(highID, err){});
     lowID = highID - IDStep + 1;
     lowID = highID - IDStep + 1;
-    callback(0, '', {lowID, highID});
+    callback(0, '', {lowID: lowID, highID: highID});
 };
 };
 
 
 module.exports = new rationsDAO();
 module.exports = new rationsDAO();

+ 93 - 19
modules/reports/util/rpt_excel_util.js

@@ -3,6 +3,7 @@
  */
  */
 var JV = require('../rpt_component/Jpc_ValueDefine');
 var JV = require('../rpt_component/Jpc_ValueDefine');
 var fs = require('fs');
 var fs = require('fs');
+var JSZip = require("jszip");
 var strUtil = require('../../../public/stringUtil');
 var strUtil = require('../../../public/stringUtil');
 var jpcCmnHelper = require('../rpt_component/helper/Jpc_Helper_Common');
 var jpcCmnHelper = require('../rpt_component/helper/Jpc_Helper_Common');
 var DPI = jpcCmnHelper.getScreenDPI()[0];
 var DPI = jpcCmnHelper.getScreenDPI()[0];
@@ -21,7 +22,7 @@ function writeContentTypes(sheets) {
     rst.push('<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>');
     rst.push('<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>');
     rst.push('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>');
     rst.push('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>');
     for (var i = 0; i < sheets.length; i++) {
     for (var i = 0; i < sheets.length; i++) {
-        rst.push('<Override PartName="/xl/worksheets/' + sheets[i].sheetName + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>')
+        rst.push('<Override PartName="/xl/worksheets/sheet' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>')
     }
     }
     rst.push('<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>');
     rst.push('<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>');
     rst.push('</Types>');
     rst.push('</Types>');
@@ -46,7 +47,7 @@ function writeApp(sheets) {
     rst.push('<ScaleCrop>false</ScaleCrop>');
     rst.push('<ScaleCrop>false</ScaleCrop>');
     rst.push('<HeadingPairs>');
     rst.push('<HeadingPairs>');
     rst.push('<vt:vector size="2" baseType="variant">');
     rst.push('<vt:vector size="2" baseType="variant">');
-    rst.push('<vt:variant><vt:lpstr>工作�?</vt:lpstr></vt:variant>');
+    rst.push('<vt:variant><vt:lpstr>工作</vt:lpstr></vt:variant>');
     rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
     rst.push('<vt:variant><vt:i4>' + sheets.length + '</vt:i4></vt:variant>');
     rst.push('</vt:vector>');
     rst.push('</vt:vector>');
     rst.push('</HeadingPairs>');
     rst.push('</HeadingPairs>');
@@ -96,7 +97,7 @@ function writeXlWorkBook(sheets){
     rst.push('<bookViews><workbookView xWindow="360" yWindow="345" windowWidth="14655" windowHeight="4305"/></bookViews>');
     rst.push('<bookViews><workbookView xWindow="360" yWindow="345" windowWidth="14655" windowHeight="4305"/></bookViews>');
     rst.push('<sheets>');
     rst.push('<sheets>');
     for (var i = 0; i < sheets.length; i++) {
     for (var i = 0; i < sheets.length; i++) {
-        rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + 'r:id="rId' + (i + 1) + '1"/>')
+        rst.push('<sheet name="' + sheets[i].sheetName + '" sheetId="' + (i + 1) + '" r:id="rId' + (i + 1) + '"/>')
     }
     }
     rst.push('</sheets>');
     rst.push('</sheets>');
     rst.push('<calcPr calcId="124519"/>');
     rst.push('<calcPr calcId="124519"/>');
@@ -109,7 +110,7 @@ function writeXlRels(sheets){
     rst.push(dftHeadXml + '\r\n');
     rst.push(dftHeadXml + '\r\n');
     rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
     rst.push('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
     for (var i = 0; i < sheets.length; i++) {
     for (var i = 0; i < sheets.length; i++) {
-        rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/' + sheets[i].sheetName + '.xml/>"')
+        rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet' + (i + 1) + '.xml"/>')
         idx++;
         idx++;
     }
     }
     rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>');
     rst.push('<Relationship Id="rId' + idx + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>');
@@ -143,7 +144,7 @@ function writeStyles(stylesObj){
         rst.push('<charset val="' + font.charset + '"/>');
         rst.push('<charset val="' + font.charset + '"/>');
         rst.push('</font>');
         rst.push('</font>');
     }
     }
-    rst.push('<fonts>');
+    rst.push('</fonts>');
     //2. push default fills
     //2. push default fills
     rst.push('<fills count="2"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill></fills>');
     rst.push('<fills count="2"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill></fills>');
     //3. push borders
     //3. push borders
@@ -160,10 +161,13 @@ function writeStyles(stylesObj){
     };
     };
     for (var i = 0; i < stylesObj.borders.length; i++) {
     for (var i = 0; i < stylesObj.borders.length; i++) {
         var border = stylesObj.borders[i];
         var border = stylesObj.borders[i];
+        rst.push('<border>');
         private_setBorder(border, JV.PROP_LEFT);
         private_setBorder(border, JV.PROP_LEFT);
         private_setBorder(border, JV.PROP_RIGHT);
         private_setBorder(border, JV.PROP_RIGHT);
         private_setBorder(border, JV.PROP_TOP);
         private_setBorder(border, JV.PROP_TOP);
         private_setBorder(border, JV.PROP_BOTTOM);
         private_setBorder(border, JV.PROP_BOTTOM);
+        rst.push('<diagonal />');
+        rst.push('</border>');
     }
     }
     rst.push('</borders>');
     rst.push('</borders>');
     //4. push cellStyleXfs
     //4. push cellStyleXfs
@@ -186,7 +190,9 @@ function writeStyles(stylesObj){
     }
     }
     rst.push('</cellXfs>');
     rst.push('</cellXfs>');
     //6. others (xfl style / dxfs / tableStyles)
     //6. others (xfl style / dxfs / tableStyles)
-    //..
+    rst.push('<cellStyles count="1"><cellStyle name="常规" xfId="0" builtinId="0"/></cellStyles>');
+    rst.push('<dxfs count="0"/>');
+    rst.push('<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/>');
     rst.push('</styleSheet>');
     rst.push('</styleSheet>');
     return rst;
     return rst;
 }
 }
@@ -204,12 +210,24 @@ function writeSharedString(sharedStrList){
 }
 }
 function writeSheets(pageData, sharedStrList, stylesObj){
 function writeSheets(pageData, sharedStrList, stylesObj){
     var rst = [];
     var rst = [];
+    private_pushDftFont = function(){
+        var font = {};
+        if (!(stylesObj.fonts)) {
+            stylesObj.fonts = [];
+        }
+        font[JV.FONT_PROPS[0]] = "宋体"; //font name
+        font.size = 11;
+        font.charset = 134;
+        font.colorIdx = "8";
+        stylesObj.fonts.push(font);
+    };
+    private_pushDftFont();
     for (var i = 0; i < pageData.items.length; i++) {
     for (var i = 0; i < pageData.items.length; i++) {
-        rst.push(writeSheet(pageData.items[i], sharedStrList, stylesObj));
+        rst.push(writeSheet(pageData, pageData.items[i], sharedStrList, stylesObj));
     }
     }
     return rst;
     return rst;
 }
 }
-function writeSheet(sheetData, sharedStrList, stylesObj){
+function writeSheet(pageData, sheetData, sharedStrList, stylesObj){
     var rst = [], xPos = [], yPos = [], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     var rst = [], xPos = [], yPos = [], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     xPos.push(0);
     xPos.push(0);
     yPos.push(0);
     yPos.push(0);
@@ -277,7 +295,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
             stylesObj.fonts = [];
             stylesObj.fonts = [];
             //for (var i = 0; i < sheetData.font_collection)
             //for (var i = 0; i < sheetData.font_collection)
         }
         }
-        var sheetFont = sheetData.font_collection[cell.font];
+        var sheetFont = pageData.font_collection[cell.font];
         for (var i = 0; i < stylesObj.fonts.length; i++) {
         for (var i = 0; i < stylesObj.fonts.length; i++) {
             var font = stylesObj.fonts[i];
             var font = stylesObj.fonts[i];
             if (sheetFont) {
             if (sheetFont) {
@@ -341,7 +359,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
         if (!(stylesObj.borders)) {
         if (!(stylesObj.borders)) {
             stylesObj.borders = [];
             stylesObj.borders = [];
         }
         }
-        var sheetBorder = sheetData.style_collection[cell.style];
+        var sheetBorder = pageData.style_collection[cell.style];
         for (var i = 0; i < stylesObj.borders.length; i++) {
         for (var i = 0; i < stylesObj.borders.length; i++) {
             var border = stylesObj.borders[i];
             var border = stylesObj.borders[i];
             if (private_checkBorder(border, sheetBorder)) {
             if (private_checkBorder(border, sheetBorder)) {
@@ -392,7 +410,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
         if (!(stylesObj.cellXfs)) stylesObj.cellXfs = [];
         if (!(stylesObj.cellXfs)) stylesObj.cellXfs = [];
         var fontId = private_getFontId(cell);
         var fontId = private_getFontId(cell);
         var borderId = private_getBorderId(cell);
         var borderId = private_getBorderId(cell);
-        var cellControl = sheetData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
+        var cellControl = pageData[JV.NODE_CONTROL_COLLECTION][cell[JV.PROP_CONTROL]];
         for (var i = 0; i < stylesObj.cellXfs.length; i++) {
         for (var i = 0; i < stylesObj.cellXfs.length; i++) {
             var sheetControl = stylesObj.cellXfs[i];
             var sheetControl = stylesObj.cellXfs[i];
             if (sheetControl.fontId == fontId && sheetControl.borderId == borderId) {
             if (sheetControl.fontId == fontId && sheetControl.borderId == borderId) {
@@ -451,11 +469,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
             hasMoreCols = true, nextColIdx = -1,
             hasMoreCols = true, nextColIdx = -1,
             nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
             nextRowIdx = yPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_TOP]);
         for (var i = 1; i < yPos.length - 1; i++) {
         for (var i = 1; i < yPos.length - 1; i++) {
-            if (i === 0) {
-                h = 1.0 * (yPos[i]) / DPI * 25.4 / 0.3612;
-            } else {
-                h = 1.0 * (yPos[i] - yPos[i - 1]) / DPI * 25.4 / 0.3612;
-            }
+            h = 1.0 * (yPos[i+1] - yPos[i]) / DPI * 25.4 / 0.3612;
             h = Math.round(h * 1000) / 1000;
             h = Math.round(h * 1000) / 1000;
             rst.push('<row r="' + i + '" spans="1:' + spanX + '" ht="' + h + '" customHeight="1">');
             rst.push('<row r="' + i + '" spans="1:' + spanX + '" ht="' + h + '" customHeight="1">');
             //then put the cells of this row
             //then put the cells of this row
@@ -473,8 +487,8 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
                 hasMoreCols = false;
                 hasMoreCols = false;
             }
             }
             nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
             nextColIdx = xPos.indexOf(sheetData.cells[cellIdx][JV.PROP_AREA][JV.PROP_LEFT]);
-            for (var j = 0; j < xPos.length; j++) {
-                colIdxStr = private_getCellIdxStr(j);
+            for (var j = 1; j < xPos.length; j++) {
+                colIdxStr = private_getCellIdxStr(j - 1);
                 if (hasMoreCols) {
                 if (hasMoreCols) {
                     if (nextColIdx == j) {
                     if (nextColIdx == j) {
                         var styleIdx = private_getStyleId(sheetData.cells[cellIdx]);
                         var styleIdx = private_getStyleId(sheetData.cells[cellIdx]);
@@ -483,7 +497,7 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
                             //should setup the right style instead!
                             //should setup the right style instead!
                         } else {
                         } else {
                             var valIdx = private_getSharedStrIdx(sheetData.cells[cellIdx][JV.PROP_VALUE]);
                             var valIdx = private_getSharedStrIdx(sheetData.cells[cellIdx][JV.PROP_VALUE]);
-                            rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '">');
+                            rst.push('<c r="' + colIdxStr + i + '" s="' + styleIdx + '" t="s">');
                             rst.push('<v>' + valIdx + '</v>');
                             rst.push('<v>' + valIdx + '</v>');
                             rst.push('</c>');
                             rst.push('</c>');
                         }
                         }
@@ -538,6 +552,66 @@ function writeSheet(sheetData, sharedStrList, stylesObj){
 module.exports = {
 module.exports = {
     exportExcel: function (pageData, options) {
     exportExcel: function (pageData, options) {
         var rptOptions = (options || {singlePage: false, fileName: 'report'});
         var rptOptions = (options || {singlePage: false, fileName: 'report'});
+        var sheets = [];
+        for (var i = 0; i < pageData.items.length; i++) {
+            sheets.push({sheetName: '第' + (i + 1) + '页'});
+        }
+        //1.
+        var file = '[Content_Types].xml';
+        var data = writeContentTypes(sheets);
+        var zip = new JSZip();
+        zip.file(file, data.join(''), {compression: 'DEFLATE'});
+        //2.
+        var zip_rels = zip.folder('_rels');
+        file = '.rels';
+        data = writeRootRels();
+        zip_rels.file(file, data.join(''), {compression: 'DEFLATE'});
+        //3.
+        var zip_docProps = zip.folder('docProps');
+        file = 'app.xml';
+        data = writeApp(sheets);
+        zip_docProps.file(file, data.join(''), {compression: 'DEFLATE'});
+        file = 'core.xml';
+        data = writeCore();
+        zip_docProps.file(file, data.join(''), {compression: 'DEFLATE'});
+        //4.
+        var zip_xl = zip.folder('xl');
+        file = 'workbook.xml';
+        data = writeXlWorkBook(sheets);
+        zip_xl.file(file, data.join(''), {compression: 'DEFLATE'});
+        var zip_rels2 = zip_xl.folder('_rels');
+        file = 'workbook.xml.rels';
+        data = writeXlRels(sheets);
+        zip_rels2.file(file, data.join(''), {compression: 'DEFLATE'});
+        //5.
+        var zip_theme = zip_xl.folder('theme');
+        file = 'theme1.xml';
+        data = writeTheme();
+        zip_theme.file(file, data, {compression: 'DEFLATE'});
+        //6.
+        var zip_worksheets = zip_xl.folder('worksheets');
+        var sharedStrList = [], stylesObj = {};
+        data = writeSheets(pageData, sharedStrList, stylesObj);
+        for (var i = 0; i < data.length; i++) {
+            file = 'sheet' + (i + 1) + '.xml';
+            zip_worksheets.file(file, data[i].join(''), {compression: 'DEFLATE'});
+        }
+        file = 'sharedStrings.xml';
+        data = writeSharedString(sharedStrList);
+        zip_xl.file(file, data.join(''), {compression: 'DEFLATE'});
+        file = 'styles.xml';
+        data = writeStyles(stylesObj);
+        zip_xl.file(file, data.join(''), {compression: 'DEFLATE'});
+
+        zip.generateNodeStream({type:'nodebuffer',streamFiles:true})
+            //.pipe(fs.createWriteStream('../../../tmp/outExcel.xlsx'))
+            .pipe(fs.createWriteStream('../../../tmp/outExcel.zip'))
+            .on('finish', function () {
+                // JSZip generates a readable stream with a "end" event,
+                // but is piped here in a writable stream which emits a "finish" event.
+                console.log("outExcel.xlsx was written.");
+            }
+        );
     }
     }
     ,testWriteContentTypes: function(sheets) {
     ,testWriteContentTypes: function(sheets) {
         return writeContentTypes(sheets);
         return writeContentTypes(sheets);

+ 30 - 2
public/web/tree_sheet_helper.js

@@ -67,11 +67,39 @@ var TREE_SHEET_HELPER = {
             setting.cols.forEach(function (colSetting, iCol) {
             setting.cols.forEach(function (colSetting, iCol) {
                 var iRow = node.serialNo();
                 var iRow = node.serialNo();
                 var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
                 var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
-                if (node.data[colSetting.data.field]) {
+
+                var getFieldText = function () {
+                    var fields = colSetting.data.field.split('.');
+                    var validField = fields.reduce(function (field1, field2) {
+                        if (eval('node.data.' + field1)) {
+                            return field1 + '.' + field2
+                        } else {
+                            return field1;
+                        }
+                    });
+                    if (eval('node.data.' + validField)) {
+                        return eval('node.data.' + validField);
+                    } else {
+                        return '';
+                    }
+                };
+                var getFieldText2 = function () {
+                    var fields = colSetting.data.field.split('.'), iField, data = node.data;
+                    for (iField = 0; iField < fields.length; iField++) {
+                        if (data[fields[iField]]) {
+                            data = data[fields[iField]];
+                        } else {
+                            return '';
+                        }
+                    }
+                    return data;
+                };
+                cell.value(getFieldText2());
+                /*if (node.data[colSetting.data.field]) {
                     cell.value(node.data[colSetting.data.field]);
                     cell.value(node.data[colSetting.data.field]);
                 } else {
                 } else {
                     cell.text('');
                     cell.text('');
-                }
+                }*/
                 sheet.setTag(iRow, iCol, node.getID());
                 sheet.setTag(iRow, iCol, node.getID());
             });
             });
             if (recursive) {
             if (recursive) {

+ 51 - 0
test/tmp_data/bills_grid_setting.js

@@ -189,6 +189,57 @@ var BillsGridSetting = {
                 font: '9px Arial'
                 font: '9px Arial'
             },
             },
             width: 60
             width: 60
+        },
+        {
+            head: {
+                titleNames: ['人工费单价', ''],
+                spanCols: [1, 0],
+                spanRows: [2, 0],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '9px Arial'
+            },
+            data: {
+                field: 'FeesIndex.labour.unitFee',
+                vAlign: 1,
+                hAlign: 2,
+                font: '9px Arial'
+            },
+            width: 60
+        },
+        {
+            head: {
+                titleNames: ['机械费单价', ''],
+                spanCols: [1, 0],
+                spanRows: [2, 0],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '9px Arial'
+            },
+            data: {
+                field: 'FeesIndex.machine.unitFee',
+                vAlign: 1,
+                hAlign: 2,
+                font: '9px Arial'
+            },
+            width: 60
+        },
+        {
+            head: {
+                titleNames: ['局部汇总', ''],
+                spanCols: [1, 0],
+                spanRows: [2, 0],
+                vAlign: [1, 1],
+                hAlign: [1, 1],
+                font: '9px Arial'
+            },
+            data: {
+                field: 'FlagsIndex.isPartGather.flag',
+                vAlign: 1,
+                hAlign: 2,
+                font: '9px Arial'
+            },
+            width: 60
         }
         }
     ],
     ],
     headRows: 2,
     headRows: 2,

+ 55 - 46
test/unit/excel_export/rpt_excel_export_test.js

@@ -6,52 +6,61 @@ var fs = require('fs');
 var fsUtil = require('../../../public/fsUtil');
 var fsUtil = require('../../../public/fsUtil');
 var rpt_xl_util = require('../../../modules/reports/util/rpt_excel_util');
 var rpt_xl_util = require('../../../modules/reports/util/rpt_excel_util');
 
 
-test('check excel output', function(t){
-    var data = fs.readFileSync('../../../tmp/07_1.page.js', 'utf8', 'r');
+test('check real function.', function(t){
+    var data = fs.readFileSync('../../../tmp/07_1.page1.js', 'utf8', 'r');
+    //var data = fs.readFileSync('../../../tmp/08_2.page.js', 'utf8', 'r');
     eval(data);
     eval(data);
-    //console.log(testReport07_1);
-    var sheets = [];
-    for (var i = 0; i < testReport07_1.items.length; i++) {
-        sheets.push({sheetName: '第' + (i + 1) + '页'});
-    }
-    var ct = rpt_xl_util.testWriteContentTypes(sheets);
-    fsUtil.writeArrayToFile(ct, '../../../tmp/[Content_Types].xml');
-    t.pass('pass content types');
-    var rootRels = rpt_xl_util.testWriteRootRels();
-    fsUtil.writeArrayToFile(rootRels, '../../../tmp/.rels');
-    t.pass('pass root rels');
-    var app = rpt_xl_util.testWriteApp(sheets);
-    fsUtil.writeArrayToFile(app, '../../../tmp/app.xml');
-    t.pass('pass app');
-    var core = rpt_xl_util.testWriteCore(sheets);
-    fsUtil.writeArrayToFile(core, '../../../tmp/core.xml');
-    t.pass('pass core');
-    var xlWBs = rpt_xl_util.testWriteXlWorkBook(sheets);
-    fsUtil.writeArrayToFile(xlWBs, '../../../tmp/workbook.xml');
-    t.pass('pass workbook');
-    //workbook.xml.rels
-    var xlRels = rpt_xl_util.testWriteXlRels(sheets);
-    fsUtil.writeArrayToFile(xlRels, '../../../tmp/workbook.xml.rels');
-    t.pass('pass xl sheet rels');
-    var sharedStrList = [], stylesObj = {};
-    var sheetsArr = rpt_xl_util.testWriteSheets(testReport07_1, sharedStrList, stylesObj);
-    for (var i = 0; i < sheetsArr.length; i++) {
-        fsUtil.writeArrayToFile(sheetsArr[i], '../../../tmp/sheet' + (i + 1) + '.xml');
-        t.pass('pass sheet' + (i + 1));
-    }
-    var sharedStr = rpt_xl_util.testWriteSharedString(sharedStrList);
-    fsUtil.writeArrayToFile(sharedStr, '../../../tmp/sharedStrings.xml');
-    t.pass('pass shared string');
-
-    var styleStr = rpt_xl_util.testWriteStyles(stylesObj);
-    fsUtil.writeArrayToFile(sharedStr, '../../../tmp/styles.xml');
-    t.pass('pass styles');
-
-    var theme = rpt_xl_util.testWriteTheme();
-    //console.log(theme);
-    var themeArr = [];
-    themeArr.push(theme)
-    fsUtil.writeArrayToFile(themeArr, '../../../tmp/theme1.xml');
-    t.pass('pass theme');
+    rpt_xl_util.exportExcel(testReport07_1, null);
+    t.pass('pass exportExcel');
     t.end();
     t.end();
 });
 });
+
+//test('check excel output', function(t){
+//    var data = fs.readFileSync('../../../tmp/07_1.page.js', 'utf8', 'r');
+//    eval(data);
+//    //console.log(testReport07_1);
+//    var sheets = [];
+//    for (var i = 0; i < testReport07_1.items.length; i++) {
+//        sheets.push({sheetName: '第' + (i + 1) + '页'});
+//    }
+//    var ct = rpt_xl_util.testWriteContentTypes(sheets);
+//    fsUtil.writeArrayToFile(ct, '../../../tmp/[Content_Types].xml');
+//    t.pass('pass content types');
+//    var rootRels = rpt_xl_util.testWriteRootRels();
+//    fsUtil.writeArrayToFile(rootRels, '../../../tmp/.rels');
+//    t.pass('pass root rels');
+//    var app = rpt_xl_util.testWriteApp(sheets);
+//    fsUtil.writeArrayToFile(app, '../../../tmp/app.xml');
+//    t.pass('pass app');
+//    var core = rpt_xl_util.testWriteCore(sheets);
+//    fsUtil.writeArrayToFile(core, '../../../tmp/core.xml');
+//    t.pass('pass core');
+//    var xlWBs = rpt_xl_util.testWriteXlWorkBook(sheets);
+//    fsUtil.writeArrayToFile(xlWBs, '../../../tmp/workbook.xml');
+//    t.pass('pass workbook');
+//    //workbook.xml.rels
+//    var xlRels = rpt_xl_util.testWriteXlRels(sheets);
+//    fsUtil.writeArrayToFile(xlRels, '../../../tmp/workbook.xml.rels');
+//    t.pass('pass xl sheet rels');
+//    var sharedStrList = [], stylesObj = {};
+//    var sheetsArr = rpt_xl_util.testWriteSheets(testReport07_1, sharedStrList, stylesObj);
+//    for (var i = 0; i < sheetsArr.length; i++) {
+//        fsUtil.writeArrayToFile(sheetsArr[i], '../../../tmp/sheet' + (i + 1) + '.xml');
+//        t.pass('pass sheet' + (i + 1));
+//    }
+//    var sharedStr = rpt_xl_util.testWriteSharedString(sharedStrList);
+//    fsUtil.writeArrayToFile(sharedStr, '../../../tmp/sharedStrings.xml');
+//    t.pass('pass shared string');
+//
+//    var styleStr = rpt_xl_util.testWriteStyles(stylesObj);
+//    fsUtil.writeArrayToFile(styleStr, '../../../tmp/styles.xml');
+//    t.pass('pass styles');
+//
+//    var theme = rpt_xl_util.testWriteTheme();
+//    //console.log(theme);
+//    var themeArr = [];
+//    themeArr.push(theme)
+//    fsUtil.writeArrayToFile(themeArr, '../../../tmp/theme1.xml');
+//    t.pass('pass theme');
+//    t.end();
+//});

+ 2 - 1
tmp/07_1.page.js

@@ -1,4 +1,5 @@
-var testReport07_1 = {
+var
+	testReport07_1 = {
 	"control_collection": {
 	"control_collection": {
 		"Default": {
 		"Default": {
 			"Shrink": "T",
 			"Shrink": "T",

+ 1 - 3
tmp/excel_test_raw_data/08-2/xl/styles.xml

@@ -199,9 +199,7 @@
 			<protection locked="0"/>
 			<protection locked="0"/>
 		</xf>
 		</xf>
 	</cellXfs>
 	</cellXfs>
-	<cellStyles count="1">
-		<cellStyle name="常规" xfId="0" builtinId="0"/>
-	</cellStyles>
+	<cellStyles count="1"><cellStyle name="常规" xfId="0" builtinId="0"/></cellStyles>
 	<dxfs count="0"/>
 	<dxfs count="0"/>
 	<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/>
 	<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/>
 </styleSheet>
 </styleSheet>

+ 47 - 4
web/main/html/main.html

@@ -615,13 +615,27 @@
         billsSpread.options.scrollbarMaxAlign = true;
         billsSpread.options.scrollbarMaxAlign = true;
 
 
         // For Test
         // For Test
+        datas.forEach(function (data) {
+            data.fees = [];
+            data.fees.push({fieldName: 'labour', unitFee: '1', totalFee: '2', tenderUnitFee: '3', tenderTotalFee: '4'});
+            data.flags = [];
+            data.flags.push({fieldName: 'isPartGather', flag: true});
+        });
+        drawing_data.forEach(function (data) {
+            data.fees = [];
+            data.fees.push({fieldName: 'machine', unitFee: '5', totalFee: '6', tenderUnitFee: '7', tenderTotalFee: '8'});
+            data.flags = [];
+            data.flags.push({fieldName: 'isPartGather', flag: false});
+        });
+
         project = PROJECT.createNew();
         project = PROJECT.createNew();
         project.Bills.loadDatas(datas);
         project.Bills.loadDatas(datas);
         project.Rations.loadDatas(drawing_data);
         project.Rations.loadDatas(drawing_data);
-        project.mainTree.loadDatas(project.Bills.tree, project.Rations.datas);
+        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.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
+        //controller = TREE_SHEET_CONTROLLER.createNew(project.Bills.tree, billsSpread.getActiveSheet(), BillsGridSetting);
         controller.showTreeData();
         controller.showTreeData();
         controller.bind('refreshBaseActn', function (tree) {
         controller.bind('refreshBaseActn', function (tree) {
             var showButton = function (show, btn) {
             var showButton = function (show, btn) {
@@ -639,7 +653,36 @@
         });
         });
 
 
         $('#insert').click(function () {
         $('#insert').click(function () {
-            controller.insert();
+            var selected = controller.tree.selected;
+            var newSource = null, newNode = null, sels = billsSpread.getActiveSheet().getSelections();
+
+            if (!selected || selected.sourceType === project.Bills.getSourceType()) {
+                newSource = project.Bills.tree.insert(selected ? selected.source.getParentID() : -1, selected ? selected.source.getNextSiblingID() : -1);
+                newSource.data.Name = 'aaa';
+                newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
+            } else if (selected.sourceType === project.Rations.getSourceType()) {
+
+            } else if (selected.sourceType === project.GLJs.getSourceType()) {
+
+            }
+
+            if (newNode) {
+                newNode.source = newSource;
+                newNode.sourceType = selected ? selected.sourceType : project.Bills.getSourceType();
+                if (newNode.sourceType === project.Bills.getSourceType()) {
+                    newNode.data = newSource.data;
+                } else {
+                    newNode.data = newSource;
+                }
+
+                TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
+                    controller.sheet.addRows(newNode.serialNo(), 1);
+                    TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, [newNode], false);
+                    controller.setTreeSelected(newNode);
+                    controller.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
+                    controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center)
+                });
+            }
         });
         });
         $('#delete').click(function () {
         $('#delete').click(function () {
             controller.delete();
             controller.delete();

+ 18 - 2
web/main/js/models/bills.js

@@ -18,13 +18,29 @@ var Bills = {
         var bills = function (proj) {
         var bills = function (proj) {
             this.project = proj;
             this.project = proj;
             this.datas = null;
             this.datas = null;
-            this.tree = null;
+            this.tree = idTree.createNew(billsTreeSetting);
+
+            var sourceType = 'bills';
+            this.getSourceType = function () {
+                return sourceType;
+            }
         };
         };
 
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         bills.prototype.loadDatas = function (datas) {
         bills.prototype.loadDatas = function (datas) {
             this.datas = datas;
             this.datas = datas;
-            this.tree = idTree.createNew(billsTreeSetting);
+            // generate Fees & Flags Index£¬For View & Calculate
+            this.datas.forEach(function (data) {
+                data.FeesIndex = {};
+                data.fees.forEach(function (fee) {
+                    data.FeesIndex[fee.fieldName] = fee;
+                });
+                data.FlagsIndex = {};
+                data.flags.forEach(function (flag) {
+                    data.FlagsIndex[flag.fieldName] = flag;
+                });
+            });
+            // datas load to Tree
             this.tree.loadDatas(this.datas);
             this.tree.loadDatas(this.datas);
         };
         };
 
 

+ 31 - 78
web/main/js/models/cache_tree.js

@@ -3,9 +3,6 @@
  */
  */
 var cacheTree = {
 var cacheTree = {
     createNew: function (owner) {
     createNew: function (owner) {
-        var _eventType = {
-            afterSelectedChanged: 'afterSelectedChanged'
-        };
         var tools = {
         var tools = {
             findNode: function (nodes, check) {
             findNode: function (nodes, check) {
                 for (var i = 0; i < nodes.length; i++) {
                 for (var i = 0; i < nodes.length; i++) {
@@ -102,17 +99,6 @@ var cacheTree = {
                     }
                     }
                     nodes[i].parent = parent;
                     nodes[i].parent = parent;
                 }
                 }
-            },
-            sortTreeItems: function (tree) {
-                var addItems = function (items) {
-                    var i;
-                    for (i = 0; i < items.length; i++) {
-                        tree.items.push(items[i]);
-                        addItems(items[i].children);
-                    }
-                };
-                tree.items.splice(0, tree.items.length);
-                addItems(tree.roots);
             }
             }
         };
         };
 
 
@@ -129,7 +115,7 @@ var cacheTree = {
             this.expanded = true;
             this.expanded = true;
             this.visible = true;
             this.visible = true;
 
 
-            this.nodeType = null;
+            this.sourceType = null;
             this.source = null;
             this.source = null;
 
 
             this.getID = function () {
             this.getID = function () {
@@ -212,14 +198,14 @@ var cacheTree = {
         };
         };
 
 
         Node.prototype.canUpLevel = function () {
         Node.prototype.canUpLevel = function () {
-            if (this.nodeType === this.tree.nodeType.bills) {
+            if (this.sourceType === this.tree.owner.Bills.getSourceType()) {
                 return this.parent ? true : false;
                 return this.parent ? true : false;
             } else {
             } else {
                 return false;
                 return false;
             }
             }
         };
         };
         Node.prototype.canDownLevel = function () {
         Node.prototype.canDownLevel = function () {
-            return this.nodeType === this.tree.nodeType.bills ? !this.isFirst() : false;
+            return this.sourceType === this.tree.owner.Bills.getSourceType() ? !this.isFirst() : false;
         };
         };
         Node.prototype.canUpMove = function () {
         Node.prototype.canUpMove = function () {
             return !this.isFirst();
             return !this.isFirst();
@@ -268,7 +254,7 @@ var cacheTree = {
                 this.nextSibling = orgPre;
                 this.nextSibling = orgPre;
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex - 1, 0, this);
                 belongArray.splice(iIndex - 1, 0, this);
-                tools.sortTreeItems(this.tree);
+                this.tree.sortTreeItems();
                 success = true;
                 success = true;
             }
             }
             return success;
             return success;
@@ -283,22 +269,20 @@ var cacheTree = {
                 this.preSibling = orgNext;
                 this.preSibling = orgNext;
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex + 1, 0, this);
                 belongArray.splice(iIndex + 1, 0, this);
-                tools.sortTreeItems(this.tree);
+                this.tree.sortTreeItems();
                 success = true;
                 success = true;
             }
             }
             return success;
             return success;
         };
         };
 
 
         var Tree = function (owner) {
         var Tree = function (owner) {
+            this.owner = owner;
             this.nodes = {};
             this.nodes = {};
             this.roots = [];
             this.roots = [];
             this.items = [];
             this.items = [];
             this.prefix = 'id_';
             this.prefix = 'id_';
             this.selected = null;
             this.selected = null;
 
 
-            this.nodeType = {bills: 'bills', ration: 'ration', zc: 'zhuCai'};
-            this.masterField = {ration: 'BillsID'};
-
             var _MaxID = 0;
             var _MaxID = 0;
             this.newNodeID = function (id) {
             this.newNodeID = function (id) {
                 if (arguments.length === 0) {
                 if (arguments.length === 0) {
@@ -315,44 +299,29 @@ var cacheTree = {
             }
             }
         };
         };
 
 
-        Tree.prototype.createNewNode = function () {
-            var node = new Node(this, this.newNodeID());
-            this.nodes[this.prefix + node.getID()] = node;
-            return node;
+        Tree.prototype.addNode = function (parent, nextSibling) {
+            var newNode = new Node(this, this.newNodeID());
+            this.nodes[this.prefix + newNode.getID()] = newNode;
+            if (nextSibling) {
+                tools.addNodes(this, parent, [newNode], nextSibling.siblingIndex());
+            } else {
+                tools.addNodes(this, parent, [newNode]);
+            }
+            return newNode;
         };
         };
-
-        Tree.prototype.loadDatas = function (idTree, rations) {
+        Tree.prototype.sortTreeItems = function () {
             var that = this;
             var that = this;
-            var loadRationNode = function (rations, cacheNode) {
-                var newNode;
-                rations.forEach(function (ration) {
-                    if (ration[that.masterField.ration] && ration[that.masterField.ration] === cacheNode.source.getID()) {
-                        newNode = that.createNewNode();
-                        newNode.source = ration;
-                        newNode.nodeType = that.nodeType.ration;
-                        newNode.data = ration;
-                        tools.addNodes(that, cacheNode, [newNode]);
-                    }
-                });
-            };
-            var loadIdTreeNode = function (nodes, parent) {
-                var newNode, i;
+            var addItems = function (nodes) {
+                var i;
                 for (i = 0; i < nodes.length; i++) {
                 for (i = 0; i < nodes.length; i++) {
-                    newNode = that.createNewNode();
-                    newNode.source = nodes[i];
-                    newNode.nodeType = that.nodeType.bills;
-                    newNode.data = nodes[i].data;
-                    newNode.parent = parent;
-                    tools.addNodes(that, parent, [newNode]);
-                    if (nodes[i].children.length === 0) {
-                        loadRationNode(rations, newNode);
-                    };
-                    loadIdTreeNode(nodes[i].children, newNode);
+                    that.items.push(nodes[i]);
+                    addItems(nodes[i].children);
                 }
                 }
             };
             };
-            loadIdTreeNode(idTree.roots, null);
-            tools.sortTreeItems(this);
+            this.items.splice(0, this.items.length);
+            addItems(this.roots);
         };
         };
+
         Tree.prototype.firstNode = function () {
         Tree.prototype.firstNode = function () {
             return this.roots.length === 0 ? null : this.roots[0];
             return this.roots.length === 0 ? null : this.roots[0];
         };
         };
@@ -371,25 +340,13 @@ var cacheTree = {
         };
         };
 
 
         Tree.prototype.insert = function (parentID, nextSiblingID) {
         Tree.prototype.insert = function (parentID, nextSiblingID) {
-            var newID = this.newNodeID(), node = null, data = {};
-            var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
-            var nextSibling = nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
-            if (newID !== -1) {
-                data = {};
-                data[this.setting.id] = newID;
-                data[this.setting.pid] = parentID;
-                data[this.setting.nid] = nextSiblingID;
-                node = new Node(this, data);
-                if (nextSibling) {
-                    tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
-                } else {
-                    tools.addNodes(this, parent, [node]);
-                }
-                this.nodes[this.prefix + newID] = node;
-                tools.sortTreeItems(this);
-                this.maxNodeID(newID);
-            }
-            return node;
+            var parent = !parentID || parentID === -1 ? null : this.nodes[this.prefix + parentID];
+            var nextSibling = !nextSiblingID || nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
+
+            var newNode = this.addNode(parent, nextSibling);
+            this.sortTreeItems();
+
+            return newNode;
         };
         };
         Tree.prototype.delete = function (node) {
         Tree.prototype.delete = function (node) {
             var success = false;
             var success = false;
@@ -406,16 +363,12 @@ var cacheTree = {
                 } else {
                 } else {
                     this.roots.splice(node.siblingIndex(), 1);
                     this.roots.splice(node.siblingIndex(), 1);
                 }
                 }
-                tools.sortTreeItems(this);
+                this.sortTreeItems();
                 success = true;
                 success = true;
             }
             }
             return success;
             return success;
         };
         };
 
 
-        Tree.prototype.editedData = function (field, id, newText) {
-            var node = this.findNode(id);
-        }
-
         return new Tree(owner);
         return new Tree(owner);
     }
     }
 };
 };

+ 5 - 0
web/main/js/models/gljs.js

@@ -10,6 +10,11 @@ var GLJs = {
         var gljs = function (proj) {
         var gljs = function (proj) {
             this.project = proj;
             this.project = proj;
             this.datas = null;
             this.datas = null;
+
+            var sourceType = 'glj';
+            this.getSourceType = function () {
+                return sourceType;
+            }
         };
         };
 
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨

+ 35 - 0
web/main/js/models/project.js

@@ -13,6 +13,9 @@ var PROJECT = {
             this.Bills = Bills.createNew(this);
             this.Bills = Bills.createNew(this);
             this.Rations = Rations.createNew(this);
             this.Rations = Rations.createNew(this);
             this.GLJ = GLJs.createNew(this);
             this.GLJ = GLJs.createNew(this);
+
+
+            this.masterField = {ration: 'BillsID'};
         };
         };
 
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
@@ -20,6 +23,38 @@ var PROJECT = {
             // To Do
             // To Do
         };
         };
 
 
+        project.prototype.loadMainTree = function () {
+            var that = this;
+            var loadRationNode = function (rations, cacheNode) {
+                var newNode;
+                rations.forEach(function (ration) {
+                    if (ration[that.masterField.ration] && ration[that.masterField.ration] === cacheNode.source.getID()) {
+                        newNode = that.mainTree.addNode(cacheNode);
+                        newNode.source = ration;
+                        newNode.sourceType = that.Rations.getSourceType();
+                        newNode.data = ration;
+                    }
+                });
+            };
+            var loadIdTreeNode = function (nodes, parent) {
+                var newNode, i;
+                for (i = 0; i < nodes.length; i++) {
+                    newNode = that.mainTree.addNode(parent);
+                    newNode.source = nodes[i];
+                    newNode.sourceType = that.Bills.getSourceType();
+                    newNode.data = nodes[i].data;
+
+                    if (nodes[i].children.length === 0) {
+                        loadRationNode(that.Rations.datas, newNode);
+                    } else {
+                        loadIdTreeNode(nodes[i].children, newNode);
+                    }
+                }
+            };
+            loadIdTreeNode(this.Bills.tree.roots, null);
+            this.mainTree.sortTreeItems();
+        }
+
         return new project();
         return new project();
     }
     }
 };
 };

+ 16 - 0
web/main/js/models/rations.js

@@ -11,11 +11,27 @@ var Rations = {
         var rations = function (proj) {
         var rations = function (proj) {
             this.project = proj;
             this.project = proj;
             this.datas = null;
             this.datas = null;
+
+            var sourceType = 'ration';
+            this.getSourceType = function () {
+                return sourceType;
+            }
         };
         };
 
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         rations.prototype.loadDatas = function (datas) {
         rations.prototype.loadDatas = function (datas) {
             this.datas = datas;
             this.datas = datas;
+            // generate Fees & Flags Index£¬For View & Calculate
+            this.datas.forEach(function (data) {
+                data.FeesIndex = {};
+                data.fees.forEach(function (fee) {
+                    data.FeesIndex[fee.fieldName] = fee;
+                });
+                data.FlagsIndex = {};
+                data.flags.forEach(function (flag) {
+                    data.FlagsIndex[flag.fieldName] = flag;
+                });
+            });
         };
         };
 
 
         return new rations(project);
         return new rations(project);