Просмотр исходного кода

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

Conflicts:
	web/building_saas/main/html/main.html
Chenshilong 8 лет назад
Родитель
Сommit
7da8f69981

+ 2 - 0
modules/main/models/project.js

@@ -7,6 +7,7 @@ var GLJData = require('./glj');
 var ration_glj_data = require('../../ration_glj/facade/ration_glj_facade');
 var ration_glj_data = require('../../ration_glj/facade/ration_glj_facade');
 var ration_coe_data = require('../../ration_glj/facade/ration_coe_facade');
 var ration_coe_data = require('../../ration_glj/facade/ration_coe_facade');
 var ration_ass_data = require('../../ration_glj/facade/ration_ass_facade');
 var ration_ass_data = require('../../ration_glj/facade/ration_ass_facade');
+var quantity_detail_data = require('../../ration_glj/facade/quantity_detail_facade');
 let projCounter = require('./proj_counter');
 let projCounter = require('./proj_counter');
 var consts = require('./project_consts');
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
 var projectConsts = consts.projectConst;
@@ -20,6 +21,7 @@ moduleMap[projectConsts.RATION] = rationData;
 moduleMap[projectConsts.RATION_GLJ] = ration_glj_data;
 moduleMap[projectConsts.RATION_GLJ] = ration_glj_data;
 moduleMap[projectConsts.RATION_COE] = ration_coe_data;
 moduleMap[projectConsts.RATION_COE] = ration_coe_data;
 moduleMap[projectConsts.RATION_ASS] = ration_ass_data;
 moduleMap[projectConsts.RATION_ASS] = ration_ass_data;
+moduleMap[projectConsts.QUANTITY_DETAIL] = quantity_detail_data;
 moduleMap[projCounter.collectionName] = projCounter;
 moduleMap[projCounter.collectionName] = projCounter;
 
 
 
 

+ 1 - 0
modules/main/models/project_consts.js

@@ -8,6 +8,7 @@ var projectConst = {
     RATION_GLJ:'ration_glj',
     RATION_GLJ:'ration_glj',
     RATION_COE:'ration_coe',
     RATION_COE:'ration_coe',
     RATION_ASS:'ration_ass',
     RATION_ASS:'ration_ass',
+    QUANTITY_DETAIL:'quantity_detail',
     PROJECTGLJ: 'projectGLJ',
     PROJECTGLJ: 'projectGLJ',
     GLJLIST: 'GLJList',
     GLJLIST: 'GLJList',
     UNITPRICEFILE: 'unitPriceFile',
     UNITPRICEFILE: 'unitPriceFile',

+ 275 - 0
modules/ration_glj/facade/quantity_detail_facade.js

@@ -0,0 +1,275 @@
+/**
+ * Created by chen on 2017/7/20.
+ */
+
+/**
+ * Created by chen on 2017/7/10.
+ */
+let mongoose = require('mongoose');
+let consts = require('../../main/models/project_consts');
+let commonConsts = consts.commonConst;
+let _=require("lodash");
+let async_n = require("async");
+let quantity_detail_model = mongoose.model('quantity_detail');
+const uuidV1 = require('uuid/v1');
+
+module.exports={
+    save:save,
+    getData:getData
+};
+
+let operationMap={
+    'ut_create':create_quantity_detail,
+    'ut_update':update_quantity_detail,
+    'ut_delete':delete_quantity_detail
+};
+
+let updateFunctionMap = {
+    'normalUpdate':normalUpdate,
+    'updateQuantityRegex':updateQuantityRegex
+}
+
+function create_quantity_detail(user_id,datas) {
+    return function (callback) {
+        let doc = datas.doc;
+        doc.ID = uuidV1();
+        quantity_detail_model.create(doc,(err,result)=>{
+            if(err){
+                callback(err,null);
+            }else {
+                console.log(result);
+                let returndata ={
+                    updateTpye:commonConsts.UT_CREATE,
+                    moduleName:consts.projectConst.QUANTITY_DETAIL,
+                    data:result
+                }
+                callback(null,returndata)
+            }
+        });
+    }
+}
+function normalUpdate(user_id,datas) {
+    return function(callback) {
+        updateRecored(datas.query,datas.doc,callback);
+    }
+}
+function updateQuantityRegex(user_id,datas) {
+    return function(callback){
+        console.log(datas);
+        doRegexUpdate(datas).then(function (result) {
+
+            console.log("update");
+            callback(null,'');
+        })
+
+       /* let checkResult =checkingRegex(datas);
+        if(checkResult!=null){
+            callback(null,{
+                moduleName:consts.projectConst.QUANTITY_DETAIL,
+                err:{
+                    message:checkResult.message
+                }
+            });
+        }else {
+            updateRecored(datas.query,datas.doc,callback)
+        }*/
+    }
+}
+
+async function doRegexUpdate(datas) {
+    if(datas.doc.regex==null){
+        //update result and bill/ration  records to null and refresh
+    }else {
+        try {
+            let regex = datas.doc.regex.toUpperCase();
+            let referenceIndexs = datas.doc.referenceIndexs;
+            let detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'rationID':datas.query.rationID}).sort('seq').exec();
+            let result =getEvalResult(referenceIndexs,detailList,regex);
+            detailList[datas.query.index].result =result;
+            detailList[datas.query.index].regex=datas.doc.regex;
+            let updateTasks =[];
+            datas.doc.result=result;
+            updateTasks.push({
+                query:{
+                    ID:datas.query.ID,
+                    projectID:datas.query.projectID
+                },
+                doc:datas.doc
+            })
+            for(let d of detailList){
+                if(_.includes(d.referenceIndexs,datas.query.index+1)){
+                    let tResult = getEvalResult(d.referenceIndexs,detailList,d.regex);
+                    let t = {
+                        query:{
+                            ID:d.ID,
+                            projectID:d.projectID
+                        },
+                        doc:{
+                            result:tResult
+                        }
+                    };
+                    updateTasks.push(t);
+
+                }
+            }
+            let updateEdit = await quantity_detail_model.bulkWrite(generateUpdateTaks(updateTasks));
+            console.log(updateEdit);
+            return regex;
+        }catch (error){
+            console.log(error);
+        }
+
+    }
+}
+
+function  getEvalResult(referenceIndexs,detailList,regex) {
+    for(let i of referenceIndexs){
+        regex = replaceReference(i,detailList,regex)
+    }
+    console.log('replace all C reference -----'+regex);
+    regex =replaceSqr(regex);
+    console.log('replace all sqar reference -----'+regex);
+    return eval(regex);
+}
+
+function  generateUpdateTaks(updateTasks) {
+    var tasks=[];
+    for(let u of updateTasks){
+        let t ={
+            updateOne:{
+                filter:u.query,
+                update: u.doc
+            }
+        }
+        tasks.push(t);
+    }
+    return tasks;
+}
+
+function replaceReference(index,detailList,str) {
+    str=str.toUpperCase();
+    str=replaceAll('C'+index,'('+detailList[index-1].regex+')',str);
+    if(detailList[index-1].referenceIndexs.length>0){
+        for (let i of detailList[index-1].referenceIndexs){
+            str =replaceReference(i,detailList,str);
+        }
+    }
+    return str;
+}
+
+
+function replaceAll (FindText, RepText,str) {
+    let regExp = new RegExp(FindText, "g");
+    return str.replace(regExp, RepText);
+}
+
+
+function replaceSqr(text) {
+    var squarRegex = /\([^\^]+\)\^\d+/g;
+    var sqararr = text.match(squarRegex);
+
+    var squarRegex2 = /C[0-9]+\^\d+|[0-9]+([.]{1}[0-9]+){0,1}\^\d+/g; //匹配没有括号的
+    var sqararr2=text.match(squarRegex2);
+    if(sqararr){
+        text=converSqrByArr(sqararr,text);
+    }
+    if(sqararr2){
+        text=converSqrByArr(sqararr2,text);
+    }
+    return text;
+}
+
+function converSqrByArr (sqararr,text) {
+    var temp = text;
+    sqararr.forEach(function (item) {
+        var arr = item.split('\^');
+        var y = parseInt(arr[1]);
+        var x_arr = [];
+        for (var i = 0; i < y; i++) {
+            x_arr.push(arr[0]);
+        }
+        var temStr = x_arr.join('*');
+        temp = temp.replace(item, temStr);
+    });
+    return temp;
+};
+
+
+function updateRecored(query,doc,callback) {
+    quantity_detail_model.update(query,doc,(err,result)=>{
+        if(err){
+            callback(err,'');
+        }else {
+            let returndata ={
+                moduleName:consts.projectConst.QUANTITY_DETAIL,
+                data:{
+                    updateTpye:commonConsts.UT_UPDATE,
+                    query:query,
+                    doc:doc
+                }
+            }
+            callback(null,returndata);
+        }
+    })
+}
+
+function checkingRegex(datas) {
+    try{
+        if(datas.doc.hasOwnProperty('regex')){
+           // datas.doc.result=eval(datas.doc.regex);
+        }
+        return null;
+    }catch (error){
+        console.log(error.message);
+        return error
+    }
+
+}
+
+function update_quantity_detail(user_id,datas) {
+    if(datas.updateFunction){
+        return updateFunctionMap[datas.updateFunction](user_id,datas);
+    }else {
+        return normalUpdate(user_id,datas);
+    }
+}
+
+function delete_quantity_detail(user_id,datas) {
+    return function (callback) {
+        callback(null,'');
+    }
+}
+
+
+
+function getData(projectID, callback) {
+    quantity_detail_model.find({'projectID':projectID}).sort('seq').exec((err,datas)=>{
+        if(err){
+            callback(1, '', null);
+        }else {
+            callback(0, consts.projectConst.QUANTITY_DETAIL, datas);
+        }
+    })
+}
+
+function save (user_id, datas, callback) {
+    let operations=[];
+    if(_.isArray(datas)){
+        for(let i=0;i<datas.length;i++){
+            operations.push(operationMap[datas[i].updateType](user_id,datas[i]));
+        }
+    }else {
+        operations.push(operationMap[datas.updateType](user_id,datas));
+    }
+    async_n.parallel(operations,function (err,results) {
+        if(err){
+            callback(err,'');
+        }else {
+            if(results.length==1){
+                callback(null,results[0])
+            }else {
+                callback(null,results)
+            }
+        }
+    })
+}

+ 1 - 1
modules/ration_glj/facade/ration_glj_facade.js

@@ -3,7 +3,7 @@
  */
  */
 
 
 let mongoose = require('mongoose');
 let mongoose = require('mongoose');
-const uuidV1 = require('uuid/v1')
+const uuidV1 = require('uuid/v1');
 let consts = require('../../main/models/project_consts')
 let consts = require('../../main/models/project_consts')
 let commonConsts = consts.commonConst;
 let commonConsts = consts.commonConst;
 let _=require("lodash");
 let _=require("lodash");

+ 21 - 0
modules/ration_glj/models/quantity_detail.js

@@ -0,0 +1,21 @@
+/**
+ * Created by chen on 2017/7/20.
+ */
+
+var mongoose = require('mongoose'),
+    Schema = mongoose.Schema;
+
+var quantity_detail = new Schema({
+    ID:String,
+    projectID: Number,
+    rationID:Number,
+    billID:Number,
+    name:String,
+    regex:String,
+    result:String,
+    isSummation: {type: Number,default:1},//0:false 1:true
+    referenceIndexs:[Number],
+    seq:Number
+},{versionKey:false});
+
+mongoose.model('quantity_detail', quantity_detail);

+ 1 - 1
modules/ration_glj/models/ration_glj.js

@@ -5,7 +5,7 @@ var mongoose = require('mongoose'),
     Schema = mongoose.Schema;
     Schema = mongoose.Schema;
 
 
 var ration_glj = new Schema({
 var ration_glj = new Schema({
-    ID:{ type:String,unique:true},
+    ID:String,
     GLJID:Number,
     GLJID:Number,
     projectID: Number,
     projectID: Number,
     rationID:Number,
     rationID:Number,

+ 2 - 62
test/tmp_data/bills_grid_setting.js

@@ -4,72 +4,12 @@
 var BillsGridSetting ={
 var BillsGridSetting ={
     "emptyRows":3,
     "emptyRows":3,
     "headRows":1,
     "headRows":1,
-    "treeCol": 2,
+    "treeCol": 0,
     "headRowHeight":[
     "headRowHeight":[
         47
         47
     ],
     ],
     "cols":[
     "cols":[
         {
         {
-            "width":50,
-            "readOnly":false,
-            "head":{
-                "titleNames":[
-                    "ID"
-                ],
-                "spanCols":[
-                    1
-                ],
-                "spanRows":[
-                    1
-                ],
-                "vAlign":[
-                    1
-                ],
-                "hAlign":[
-                    1
-                ],
-                "font":[
-                    "Comic Sans MS"
-                ]
-            },
-            "data":{
-                "field":"ID",
-                "vAlign":1,
-                "hAlign":0,
-                "font":"Arial"
-            }
-        },
-        {
-            "width":50,
-            "readOnly":false,
-            "head":{
-                "titleNames":[
-                    "serialNo"
-                ],
-                "spanCols":[
-                    1
-                ],
-                "spanRows":[
-                    1
-                ],
-                "vAlign":[
-                    1
-                ],
-                "hAlign":[
-                    1
-                ],
-                "font":[
-                    "Comic Sans MS"
-                ]
-            },
-            "data":{
-                "field":"serialNo",
-                "vAlign":1,
-                "hAlign":0,
-                "font":"Arial"
-            }
-        },
-        {
             "width":150,
             "width":150,
             "readOnly":false,
             "readOnly":false,
             "head":{
             "head":{
@@ -643,4 +583,4 @@ var BillsGridSetting ={
             }
             }
         }
         }
     ]
     ]
-};
+};

+ 209 - 0
test/tmp_data/test_bills_calc/bills_calc_base.js

@@ -0,0 +1,209 @@
+let BillsCalcBase = [
+    {
+        'classKey': 'FBFX',
+        'className': '分部分项',
+        'type': 'bills',
+        'subBase': [
+            {
+                'subKey': 'GCF',
+                'subName': '工程费',
+                'dispName': '分部分项--工程费'
+            },{
+                'subKey': 'DEJJRGF',
+                'subName': '定额基价人工费',
+                'dispName': '分部分项--定额基价人工费'
+            },{
+                'subKey': 'DEJJCLF',
+                'subName': '定额基价材料费',
+                'dispName': '分部分项--定额基价材料费'
+            },{
+                'subKey': 'DEJJJXF',
+                'dispName': '分部分项--定额基价机械费'
+            },{
+                'subKey': 'TZRGF',
+                'dispName': '分部分项--调整人工费'
+            },{
+                'subKey': 'TZJSRGF',
+                'dispName': '分部分项--调整机上人工费'
+            },{
+                'subKey': 'ZCF',
+                'dispName': '分部分项--主材费'
+            },{
+                'subKey': 'SBF',
+                'dispName': '分部分项--定额基价设备费'
+            },{
+                'subKey': 'WJJCLF',
+                'dispName': '分部分项--未计价材料费'
+            },{
+                'subKey': 'RGGR',
+                'dispName': '分部分项--人工工日'
+            },{
+                'subKey': 'GCLQDZDJJZJGCF',
+                'dispName': '分部分项--工程量清单中的基价直接工程费'
+            },{
+                'subKey': 'GCLQDZDJJRGF',
+                'dispName': '分部分项--工程量清单中的基价人工费'
+            }
+        ]
+    },{
+        'className': 'CSXM',
+        'type': 'bills',
+        'className': '措施项目',
+        'subBase': [
+            {
+                'subKey': 'CSXMF',
+                'dispName': '措施项目费'
+            },{
+                'subKey': 'ZZCSXMF',
+                'dispName': '组织措施项目费'
+            },{
+                'subKey': 'ZZCSXMDEJJZJGCF',
+                'dispName': '组织措施项目定额基价直接工程费'
+            },{
+                'subKey': 'ZZCSXMDEJJRGF',
+                'dispName': '组织措施项目定额基价人工费'
+            },{
+                'subKey': 'ZZCSXMDEJJCLF',
+                'dispName': '组织措施项目定额基价材料费'
+            },{
+                'subKey': 'ZZCSXMDEJJJXF',
+                'dispName': '组织措施项目定额基价机械费'
+            },{
+                'subKey': 'JSCSXMF',
+                'dispName': '技术措施项目费'
+            },{
+                'subKey': 'JSCSXMDEJJZJGCF',
+                'dispName': '技术措施项目定额基价直接工程费'
+            },{
+                'subKey': 'JSCSXMDEJJRGF',
+                'dispName': '技术措施项目定额基价人工费'
+            },{
+                'subKey': 'JSCSXMDEJJCLF',
+                'dispName': '技术措施项目定额基价材料费'
+            },{
+                'subKey': 'JSCSXMDEJJJXF',
+                'dispName': '技术措施项目定额基价机械费'
+            },{
+                'subKey': 'JSCSXMTZRGF',
+                'dispName': '技术措施项目调整人工费'
+            },{
+                'subKey': 'JSCSXMTZJSRGF',
+                'dispName': '技术措施项目调整机上人工费'
+            },{
+                'subKey': 'JSCSXMZCF',
+                'dispName': '技术措施项目主材费'
+            },{
+                'subKey': 'JSCSXMSBF',
+                'dispName': '技术措施项目设备费'
+            },{
+                'subKey': 'JSCSXMWJJCLF',
+                'dispName': '技术措施项目未计价材料费'
+            },{
+                'subKey': 'JSCSXMQDZDDEJJZJGCF',
+                'dispName': '技术措施项目清单中的定额基价直接工程费'
+            },{
+                'subKey': 'JSCSXMQDZDDEJJRGF',
+                'dispName': '技术措施项目清单中的定额基价人工费'
+            }
+        ]
+    },{
+        'classKey': 'QTXM',
+        'className': '其他项目',
+        'subBase': [
+            {
+                'subKey': 'QTXMF',
+                'dispName': '其他项目费'
+            },{
+                'subKey': 'GF',
+                'dispName': '规费'
+            },{
+                'subKey': 'SJ',
+                'dispName': '税金'
+            },{
+                'subKey': 'SQGCZJ',
+                'dispName': '税前工程造价'
+            }
+        ]
+    },{
+        'classKey': 'FBF',
+        'className': '分包费',
+        'subBase': [
+            {
+                'subKey': 'FBF',
+                'dispName': '分包费'
+            },{
+                'subKey': 'FBJJZJGCF',
+                'dispName': '分包基价直接工程费'
+            },{
+                'subKey': 'FBJJRGF',
+                'dispName': '分包基价人工费'
+            },{
+                'subKey': 'FBJJCLF',
+                'dispName': '分包基价材料费'
+            },{
+                'subKey': 'FBJJJXF',
+                'dispName': '分包基价机械费'
+            },{
+                'subKey': 'FBJJZCF',
+                'dispName': '分包基价主材费'
+            },{
+                'subKey': 'FBJJSBF',
+                'dispName': '分包基价设备费'
+            },{
+                'subKey': 'FBJJRGGR',
+                'dispName': '分包基价人工工日'
+            }
+        ]
+    },{
+
+        'classKey': 'RCJ',
+        'type': 'projectGLJ',
+        'className': '人材机',
+        'subBase': [
+            {
+                'subKey': 'RGJC',
+                'dispName': '人工价差'
+            },{
+                'subKey': 'CLJC',
+                'dispName': '材料价差'
+            },{
+                'subKey': 'JXJC',
+                'dispName': '机械价差'
+            },{
+                'subKey': 'JGRGF',
+                'dispName': '甲供人工费'
+            },{
+                'subKey': 'JGCLF',
+                'dispName': '甲供材料费'
+            },{
+                'ubKey': 'JGJXF',
+                'dispName': '甲供机械费'
+            },{
+                'ubKey': 'JGZCF',
+                'dispName': '甲供主材费'
+            },{
+                'ubKey': 'JGSBF',
+                'dispName': '甲供设备费'
+            },{
+                'subKey': 'JDRGF',
+                'dispName': '甲定人工费'
+            },{
+                'subKey': 'JDCLF',
+                'dispName': '甲供材料费'
+            },{
+                'ubKey': 'JDJXF',
+                'dispName': '甲供机械费'
+            },{
+                'ubKey': 'JDZCF',
+                'dispName': '甲供主材费'
+            },{
+                'ubKey': 'JDSBF',
+                'dispName': '甲供设备费'
+            }
+        ]
+    },{
+        'className': '结算价'
+    },{
+        'className': '变量表'
+    }
+];

+ 93 - 0
test/tmp_data/test_ration_calc/ration_calc_base.js

@@ -0,0 +1,93 @@
+/**
+ * Created by Mai on 2017/7/21.
+ */
+
+const baseCalc = 0, adjustCalc = 1, budgetCalc = 2, offerCalc = 3;
+
+const gljType = {
+    // 人工
+    LABOUR: 1,
+    // ==============材料类型=================
+    // 普通材料
+    GENERAL_MATERIAL: 201,
+    // 混凝土
+    CONCRETE: 202,
+    // 砂浆
+    MORTAR: 203,
+    // 配合比
+    MIX_RATIO: 204,
+    // 商品混凝土
+    COMMERCIAL_CONCRETE: 205,
+    // 商品砂浆
+    COMMERCIAL_MORTAR: 206,
+    // ==============材料类型=================
+    // ==============机械类型=================
+    // 普通机械
+    GENERAL_MACHINE: 301,
+    // 机械组成物
+    MACHINE_COMPOSITION: 302,
+    // ==============机械类型=================
+    // 主材
+    MAIN_MATERIAL: 4,
+    // 设备
+    EQUIPMENT: 5
+};
+
+let rationCalcBase = [
+    {
+        'dispName': '定额基价人工费',
+        'calcFun': 'base',
+        'calcType': baseCalc,
+        'gljTypes': [gljType.LABOUR]
+    },{
+        'dispName': '定额基价材料费',
+        'calcFun': 'base',
+        'calcType': baseCalc,
+        'gljTypes': [gljType.GENERAL_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]
+    },{
+        'dispName': '定额基价机械费',
+        'calcFun': 'base',
+        'calcType': baseCalc,
+        'gljTypes': [gljType.GENERAL_MACHINE]
+    },{
+        'dispName': '定额基价机上人工费',
+        'calcFun': 'base',
+        'calcType': baseCalc,
+        'gljTypes': [gljType.MACHINE_COMPOSITION]
+    },{
+        'dispName': '定额基价人工费(调整后)',
+        'calcFun': 'adjust',
+        'calcType': adjustCalc,
+        'gljTypes': [gljType.LABOUR]
+    },{
+        'dispName': '定额基价机上人工费(调整后)',
+        'calcFun': 'adjust',
+        'calcType': adjustCalc,
+        'gljTypes': [gljType.MACHINE_COMPOSITION]
+    },{
+        'dispName': '市场价格人工费',
+        'calcFun': 'budget',
+        'calcType': budgetCalc,
+        'gljTypes': [gljType.LABOUR]
+    },{
+        'dispName': '市场价格材料费',
+        'calcFun': 'budget',
+        'calcType': budgetCalc,
+        'gljTypes': [gljType.GENERAL_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]
+    },{
+        'dispName': '市场价格机械费',
+        'calcFun': 'budget',
+        'calcType': budgetCalc,
+        'gljTypes': [gljType.GENERAL_MACHINE]
+    },{
+        'dispName': '主材费',
+        'calcFun': 'budget',
+        'calcType': budgetCalc,
+        'gljTypes': [gljType.MAIN_MATERIAL]
+    },{
+        'dispName': '设备费',
+        'calcFun': 'budget',
+        'calcType': budgetCalc,
+        'gljTypes': [gljType.EQUIPMENT]
+    }
+];

+ 2 - 1
web/building_saas/main/html/main.html

@@ -490,7 +490,7 @@
 
 
     <script type="text/javascript" src="/public/web/id_tree.js"></script>
     <script type="text/javascript" src="/public/web/id_tree.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/cache_tree.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/cache_tree.js"></script>
-    <script type="text/javascript" src="/web/building_saas/main/js/models/bills_calc.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/calc/bills_calc.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_calc.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_calc.js"></script>
     <!-- Controller -->
     <!-- Controller -->
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
@@ -510,6 +510,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/views/side_tools.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/side_tools.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/std_bills_lib.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/std_bills_lib.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/std_ration_lib.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/std_ration_lib.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/quantity_detail.js"></script>
     <!-- reports -->
     <!-- reports -->
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/web/ztree_common.js"></script>
     <script type="text/javascript" src="/public/web/ztree_common.js"></script>

+ 0 - 10
web/building_saas/main/js/models/bills_calc.js

@@ -32,10 +32,6 @@ let billsPriceCalcFields = [
     {'type': 'machine', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
     {'type': 'machine', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
 ];
 ];
 
 
-Number.prototype.toDecimal = function (ADigit) {
-    return parseFloat(this.toFixed(ADigit));
-};
-
 let nodeCalcObj = {
 let nodeCalcObj = {
     node: null,
     node: null,
     digit: 2,
     digit: 2,
@@ -95,8 +91,6 @@ let nodeCalcObj = {
         let result = 0, child;
         let result = 0, child;
         for (child of this.node.children) {
         for (child of this.node.children) {
             result += this.getFee(child.data, this.field.totalFee);
             result += this.getFee(child.data, this.field.totalFee);
-            //result += child.data.feesIndex[this.field.type].totalFee;
-            //result += this.getFeeSplit(child.data, this.field.totalFeeSplit);
         }
         }
         return result;
         return result;
     },
     },
@@ -111,8 +105,6 @@ let nodeCalcObj = {
     },
     },
     totalFee: function () {
     totalFee: function () {
         return this.getFee(this.node.data, this.field.unitFee) * this.getFee(this.node.data, 'quantity');
         return this.getFee(this.node.data, this.field.unitFee) * this.getFee(this.node.data, 'quantity');
-        //return this.node.data.feesIndex[this.field.type].unitFee * this.node.data.quantity;
-        //return this.getFeeSplit(this.node.data, this.field.unitFeeSplit) * this.getFee(this.node.data, 'quantity');
     },
     },
     rationContentUnitFee: function () {
     rationContentUnitFee: function () {
         let result = 0, child, qty = this.getFee(this.node.data, 'quantity');
         let result = 0, child, qty = this.getFee(this.node.data, 'quantity');
@@ -121,8 +113,6 @@ let nodeCalcObj = {
         }
         }
         for (child of this.node.children) {
         for (child of this.node.children) {
             result += (this.getFee(child.data, this.field.unitFee) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
             result += (this.getFee(child.data, this.field.unitFee) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
-            //result += (child.data.feesIndex[this.field.type].unitFee * child.data.quantity / qty).toDecimal(this.digit);
-            //result += (this.getFeeSplit(child.data, this.field.unitFeeSplit) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
         }
         }
         return result;
         return result;
     }
     }

+ 57 - 0
web/building_saas/main/js/calc/calc_fees.js

@@ -0,0 +1,57 @@
+/**
+ * Created by Mai on 2017/7/21.
+ */
+
+let calcFees = {
+    findFee: function (data, fieldName) {
+        if (!data.fees) {
+            data.fees = [];
+        }
+        for (let fee of data.fees) {
+            if (fee.fieldName === fieldName) {
+                return fee;
+            }
+        }
+        return null;
+    },
+    AddFee: function (data, fieldName) {
+        let fee = {
+            'fieldName': fieldName,
+            'unitFee': 0,
+            'totalFee': 0,
+            'tenderUnitFee': 0,
+            'tenderTotalFee': 0
+        };
+        data.fees.push(fee);
+        data.feesIndex[fieldName] = fee;
+    },
+    checkFields: function (data, fields) {
+        for (let field of fields) {
+            if (!this.findFee(data, field.type)) {
+                this.AddFee(data, field.type);
+            }
+        }
+    },
+    getFee: function (data, fullField) {
+        let fields = fullField.split('.'), value = data;
+        for (let field of fields) {
+            if (value[field]) {
+                value = value[field];
+            } else {
+                return 0;
+            }
+        }
+        return value;
+    },
+    getFeeSplit: function (data, fullFields) {
+        let value = data;
+        for (let field of fullFields) {
+            if (value[field]) {
+                value = value[field];
+            } else {
+                return 0;
+            }
+        }
+        return value;
+    }
+}

+ 120 - 0
web/building_saas/main/js/calc/ration_calc.js

@@ -0,0 +1,120 @@
+/**
+ * Created by Mai on 2017/7/13.
+ */
+
+let rationCalcFields = [
+    {
+        type: 'baseDirect', code: "1", name: "基价直接工程费",
+        dispExpr: "1.1+1.2+1.3+1.4", expression: "@('1.1') + @('1.2') + @('1.3') + @('1.4')", compiledExpr: "",
+        statement: "基价人工费+基价材料费+基价机械费+未计价材料费"
+    },{
+        type: 'baseLabour', code: "1.1", name: "基价人工费",
+        dispExpr: "1.1.1+1.1.2", expression: "@('1.1.1') + @('1.1.2')", compiledExpr: "",
+        statement: "定额基价人工费+定额人工单价(基价)调整"
+    },{
+        type: 'rationBaseLabour', code: "1.1.1", name: "定额基价人工费",
+        dispExpr: "定额基价人工费", expression: "base('定额基价人工费').toFixed(2)", compiledExpr: "",
+        statement: "定额基价人工费"
+    },{
+        type: 'rationAdjustLabour', code: "1.1.2", name: "定额人工单价(基价)调整",
+        dispExpr: "1.1.1*[1.89-1]", expression: "@('1.1.1') * fee('3')", compiledExpr: "",
+        statement: "定额基价人工费*[定额人工单价(基价)调整系数-1]"
+    },{
+        type: 'baseMaterial', code: "1.2", name: "基价材料费",
+        dispExpr: "定额基价材料费", expression: "base('定额基价材料费')", compiledExpr: "",
+        statement: "定额基价材料费"
+    },{
+        type: 'baseMachine', code: "1.3", name: "基价机械费",
+        dispExpr: "1.3.1+1.3.2", expression: "@('1.3.1') + @('1.3.2')", compiledExpr: "",
+        statement: "定额基价机械费+定额机上人工单价(基价)调整"
+    },{
+        type: 'rationBaseMachine', code: "1.3.1", name: "定额基价机械费",
+        dispExpr: "定额基价机械费", expression: "base('定额基价机械费')", compiledExpr: "",
+        statement: "定额基价机械费"
+    },{
+        type: 'rationBaseMachineLabour', code: "1.3.1.1", name: "其中:定额基价机上人工费",
+        dispExpr: "定额基价机上人工费", expression: "base('定额基价机上人工费')", compiledExpr: "",
+        statement: "定额基价机上人工费"
+    },{
+        type: 'rationBaseMachineLabourFixed', code: "1.3.2", name: "定额机上人工单价(基价)调整",
+        dispExpr: "1.3.1.1*[1.89-1]", expression: "@('1.3.1.1') * fee('30')", compiledExpr: "",
+        statement: "定额基价机上人工费*[定额人工单价(基价)调整系数-1]"
+    },{
+        type: 'unPriceMaterial', code: "1.4", name: "未计价材料费",
+        dispExpr: "主材费+设备费", expression: "base('主材费') + base('设备费')", compiledExpr: "",
+        statement: "主材费+设备费"
+    },{
+        type: 'management', code: "2", name: "企业管理费",
+        dispExpr: "1.1.1", expression: "@('1.1.1')", compiledExpr: "",
+        statement: "定额基价人工费"
+    },{
+        type: 'profit', code: "3", name: "利润",
+        dispExpr: "1.1.1", expression: "@('1.1.1')", compiledExpr: "",
+        statement: "定额基价人工费"
+    },{
+        type: 'risk', code: "4", name: "风险因素",
+        dispExpr: "", expression: "0", compiledExpr: "",
+        statement: ""
+    },{
+        type: 'gljDiff', code: "5", name: "人材机价差",
+        dispExpr: "5.1+5.2+5.3", expression: "@('5.1') + @('5.2') + @('5.3')", compiledExpr: "",
+        statement: "人工费价差+材料费价差+机械费价差"
+    },{
+        type: 'labourDiff', code: "5.1", name: "人工费价差",
+        dispExpr: "信息价或市场价格-调整后的定额人工费(基价)", expression: "base('市场价格人工费') - base('定额基价人工费(调整后)')", compiledExpr: "",
+        statement: "市场价格人工费-调整后的定额人工费(基价)"
+    },{
+        type: 'materialDiff', code: "5.2", name: "材料费价差",
+        dispExpr: "信息价或市场价格-定额基价材料费", expression: "base('市场价格材料费') - base('定额基价材料费(调整后)')", compiledExpr: "",
+        statement: "市场价格材料费-定额基价材料费"
+    },{
+        type: 'machineDiff', code: "5.3", name: "机械费价差",
+        dispExpr: "信息价或市场价格-调整后的定额基价机械费(基价)", expression: "base('市场价格机械费') - base('定额基价机械费(调整后)')", compiledExpr: "",
+        statement: "市场价格机械费-调整后的定额基价机械费(基价)"
+    },{
+        type: 'common', code: "6", name: "综合单价",
+        dispExpr: "1+2+3+4+5", expression: "@('1') + @('2') + @('3') + @('4') + @('5')", compiledExpr: "",
+        statement: "基价直接工程费+企业管理费+利润+风险因素+人材机价差"
+    }
+];
+
+let rationCalcObj = {
+    calcGljs: [],
+    calcFields: null,
+    base: function () {
+
+    },
+    adjust: function () {
+        
+    },
+    budget: function () {
+
+    },
+    calculate () {
+        let result = {};
+
+    }
+};
+
+class RationCalc {
+    constructor (project) {
+        this.project = project;
+    };
+
+    calculate (ration) {
+        rationCalcObj.calcGljs = this.project.ration_glj.getGljArrByRation(ration.ID);
+        rationCalcObj.calcFields = rationCalcFields;
+        let virData = rationCalcObj.calculate();
+        calcFees.checkFields(ration, rationCalcFields);
+        for (let field of rationCalcFields) {
+            ration.feesIndex[field.type].unitFee = virData[field.type].unitFee;
+            ration.feesIndex[field.type].totalFee = virData[field.type].totalFee;
+        }
+    }
+
+    calculateAll () {
+        for (let rationData of project.ration.data) {
+            this.calculate(rationData);
+        }
+    };
+}

+ 2 - 1
web/building_saas/main/js/models/main_consts.js

@@ -9,5 +9,6 @@ const ModuleNames = {
     projectGLJ: 'projectGLJ',
     projectGLJ: 'projectGLJ',
     ration_glj:'ration_glj',
     ration_glj:'ration_glj',
     ration_coe:'ration_coe',
     ration_coe:'ration_coe',
-    ration_ass:'ration_ass'
+    ration_ass:'ration_ass',
+    quantity_detail:'quantity_detail'
 };
 };

+ 1 - 0
web/building_saas/main/js/models/project.js

@@ -71,6 +71,7 @@ var PROJECT = {
             this.ration_glj = ration_glj.createNew(this);
             this.ration_glj = ration_glj.createNew(this);
             this.ration_coe = ration_coe.createNew(this);
             this.ration_coe = ration_coe.createNew(this);
             this.ration_ass = ration_ass.createNew(this);
             this.ration_ass = ration_ass.createNew(this);
+            this.quantity_detail = quantity_detail.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
 
 
             this.masterField = {ration: 'billsItemID'};
             this.masterField = {ration: 'billsItemID'};

+ 265 - 0
web/building_saas/main/js/models/quantity_detail.js

@@ -0,0 +1,265 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+var quantity_detail = {
+    createNew: function (project) {
+        // 用户定义private方法
+        var tools = {};
+
+        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        var quantity_detail = function (proj) {
+            this.gljTree = cacheTree.createNew(this);
+           // this.project = proj;
+            this.datas = [];
+
+            var sourceType = ModuleNames.quantity_detail;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.quantity_detail, this);
+            this.temList=[];
+        };
+
+        // prototype用于定义public方法
+        quantity_detail.prototype.loadData = function (datas) {
+            this.datas = datas;
+        };
+
+        // 提交数据后返回数据处理
+        quantity_detail.prototype.doAfterUpdate = function(err, data){
+            if(!err){
+                if(data.updateTpye=='ut_update'){
+                    this.refreshAfterUpdate(data);
+                }else if(data.updateTpye=='ut_delete'){
+                    this.refreshAfterDelete(data);
+                } else {
+                    this.refreshAfterSave(data);
+                }
+            }else {
+                alert("输入的表达式有误,请重新输入");
+                this.refreshSheetData();
+            }
+        };
+        quantity_detail.prototype.refreshAfterSave=function(data){
+            this.datas.push(data);
+            gljOprObj.detailData.push(data);
+            gljOprObj.detailData=_.sortBy(gljOprObj.detailData,'seq');
+            this.refreshSheetData();
+        };
+        quantity_detail.prototype.refreshAfterUpdate=function(data){
+            var detail_list = this.datas;
+            var detail_index= _.findIndex(detail_list,(detail)=>{
+                return detail.ID==data.query.ID;
+            })
+            _.forEach(data.doc, function(n, key) {
+                detail_list[detail_index][key] = n;
+            });
+            var filter_object;
+            if(detail_list[detail_index].hasOwnProperty('rationID')){
+                filter_object={'rationID':detail_list[detail_index].rationID};
+            }else {
+                filter_object={'billID':detail_list[detail_index].billID};
+            }
+            var showList = _.filter(this.datas,filter_object);
+            gljOprObj.detailData=showList;
+            this.refreshSheetData();
+        };
+        quantity_detail.prototype.refreshAfterDelete=function(data){
+            var glj_list = projectObj.project.ration_coe.datas;
+            _.remove(glj_list,data.query);
+            _.remove(gljOprObj.sheetData,data.query);
+            this.refreshSheetData();
+        };
+        quantity_detail.prototype.refreshSheetData=function () {
+            sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,gljOprObj.detailData);
+        };
+        quantity_detail.prototype.getUpdateData=function(type,query,doc,callfunction){
+            var updateData = [];
+            var newobj = {
+                'updateType': type,
+                'query': query,
+            }
+            if(doc){
+                newobj['doc']=doc;
+            }
+            if(callfunction){
+                newobj['updateFunction']=callfunction;
+            }
+            updateData.push(newobj);
+            return updateData;
+        };
+        quantity_detail.prototype.saveQuantityDetail=function (args,dataCode) {
+            var doc={};
+            var selected = projectObj.project.mainTree.selected;
+            if(selected.sourceType==ModuleNames.ration){
+                doc.rationID=selected.data.ID;
+            }
+            if(selected.sourceType==ModuleNames.bills){
+                doc.billID=selected.data.ID;
+            }
+            doc.projectID = selected.data.projectID;
+            doc[dataCode]=args.editingText;
+            doc.seq=args.row;
+            var updateData = this.getUpdateData('ut_create',null,doc);
+            project.pushNow('saveQuantityDetail',[this.getSourceType()],updateData);
+        };
+        quantity_detail.prototype.updateQuantityDetail=function (args,dataCode,recode) {
+            var doc ={};
+            var query={
+                ID:recode.ID,
+                projectID:recode.projectID
+            };
+            doc[dataCode]=args.editingText;
+            if (dataCode == 'regex') {
+                if(recode.hasOwnProperty('rationID')){
+                    query.rationID=recode.rationID;
+                }else {
+                    query.billID = recode.billID
+                }
+                query.index = args.row;
+                this.updateQuantityRegex(query,doc,args)
+            }else {
+                this.normalUpdate(query,doc);
+            }
+        };
+        quantity_detail.prototype.updateQuantityRegex=function(query,doc,args){
+            var needupdate = false;
+            if(args.editingText==null){
+                needupdate =true;
+            }else {
+                args.editingText = _.trim(args.editingText,/\r\n/);
+                if(this.regexChecking(args.editingText)&&this.referenceChecking(args.editingText,args.row,doc)){
+                    needupdate = true;
+                }
+            }
+            if(needupdate){
+                var updateData = this.getUpdateData('ut_update',query,doc,'updateQuantityRegex');
+                project.pushNow('updateQuantityDetail',[this.getSourceType()],updateData);
+            }
+        };
+
+        quantity_detail.prototype.isSummationUpdate=function (args,detailList,newval) {
+            var query={
+                ID:detailList[args.row].ID,
+                projectID:detailList[args.row].projectID
+            };
+            var doc={
+                isSummation:newval
+            };
+            this.normalUpdate(query,doc);
+        };
+        quantity_detail.prototype.normalUpdate=function(query,doc){
+            var updateData = this.getUpdateData('ut_update',query,doc);
+            project.pushNow('updateQuantityDetail',[this.getSourceType()],updateData);
+        };
+        quantity_detail.prototype.regexChecking=function(text){
+            var regex=/^[0-9Cc\+\-\*\^/\(\)\.]*$/g;
+            if(!regex.test(text)){
+                alert("输入了非法字符,请重新输入!")
+                return false;
+            }else {
+                return true;
+            }
+        };
+        quantity_detail.prototype.referenceChecking=function (text,row,doc) {
+            text = text.toUpperCase();
+            //text= this.replaceSqr(text);
+            var me = this;
+            var refReg = /C\d+/g;
+            var self ='C'+(row+1);
+
+            var refList = text.match(refReg);
+            var invalidate = _.includes(refList,self);
+            var referenceIndexs = [];
+            var indexOut = false;
+            _.forEach(refList,function (item) {
+                var ref_index = parseInt(item.substring(1));
+                if(ref_index>me.datas.length){
+                    indexOut=true;
+                    return;
+                }else {
+                    referenceIndexs.push(ref_index);
+                }
+            });
+            if(indexOut){
+                alert("引用有误,请重新输入!");
+                return false;
+            }
+            referenceIndexs=_.uniq(referenceIndexs);
+            doc.referenceIndexs = referenceIndexs;
+
+            this.temList = referenceIndexs;
+
+            invalidate=this.getAllReferenceList((row+1),referenceIndexs);
+
+            if(invalidate){
+                alert("计算式中产生了循环引用,请重新输入!");
+                return false;
+            }
+            return true;
+        };
+
+        quantity_detail.prototype.getAllReferenceList=function(original,refList){
+            var me =this;
+            var invalidate=false;
+            _.forEach(refList,function (item) {
+                if(me.getReferenceList(item,original)){
+                    invalidate=true;
+                }
+            })
+            return invalidate;
+
+        };
+
+        quantity_detail.prototype.getReferenceList=function(item,original) {
+            var invalidate =false;
+            var recode = this.datas[item - 1];
+            if (recode.referenceIndexs.length > 0) {
+                if(_.includes(recode.referenceIndexs,original)){
+                    invalidate = true;
+                    return invalidate;
+                }
+                this.temList = this.temList.concat(recode.referenceIndexs);
+                _.forEach(recode.referenceIndex, function (item) {
+                    if(this.getReferenceList(item,original)){
+                        invalidate = true;
+                    }
+                })
+            }
+            return invalidate;
+        }
+
+        quantity_detail.prototype.replaceSqr = function(text) {
+            var squarRegex = /\([^\^]+\)\^\d+/g;
+            var sqararr = text.match(squarRegex);
+
+            var squarRegex2 = /C[0-9]+\^\d+|[0-9]+([.]{1}[0-9]+){0,1}\^\d+/g; //匹配没有括号的
+            var sqararr2=text.match(squarRegex2);
+            if(sqararr){
+                text=converSqrByArr(sqararr,text);
+            }
+            if(sqararr2){
+                text=converSqrByArr(sqararr2,text);
+            }
+            return text;
+        };
+        quantity_detail.prototype.converSqrByArr = function (sqararr,text) {
+            var temp = text;
+            sqararr.forEach(function (item) {
+                var arr = item.split('\^');
+                var y = parseInt(arr[1]);
+                var x_arr = [];
+                for (var i = 0; i < y; i++) {
+                    x_arr.push(arr[0]);
+                }
+                var temStr = x_arr.join('*');
+                temp = temp.replace(item, temStr);
+            });
+            console.log(temp);
+            return temp;
+        };
+
+        return new quantity_detail(project);
+    }
+
+};

+ 6 - 1
web/building_saas/main/js/models/ration_glj.js

@@ -41,6 +41,12 @@ var ration_glj = {
             this.datas = datas;
             this.datas = datas;
         };
         };
 
 
+        ration_glj.prototype.getGljArrByRation = function (rationID) {
+            return this.datas.filter(function (data) {
+                return data.rationID = rationID;
+            })
+        }
+
         // 提交数据后返回数据处理
         // 提交数据后返回数据处理
         ration_glj.prototype.doAfterUpdate = function(err, data){
         ration_glj.prototype.doAfterUpdate = function(err, data){
             if(!err){
             if(!err){
@@ -202,7 +208,6 @@ var ration_glj = {
             }
             }
         }
         }
 
 
-
         ration_glj.prototype.updataOrdelete=function(row){
         ration_glj.prototype.updataOrdelete=function(row){
             var updateData = null;
             var updateData = null;
             if(row.rationItemQuantity==0){
             if(row.rationItemQuantity==0){

+ 78 - 21
web/building_saas/main/js/views/glj_view.js

@@ -12,6 +12,8 @@ var gljOprObj = {
     coeSheet:null,
     coeSheet:null,
     assSheet:null,
     assSheet:null,
     assSheetData:[],
     assSheetData:[],
+    detailSheet:null,
+    detailData:[],
     setting: {
     setting: {
         header: [
         header: [
             {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
             {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
@@ -55,7 +57,17 @@ var gljOprObj = {
             lockColumns:[0,1]
             lockColumns:[0,1]
         }
         }
     },
     },
-
+    detailSetting:{
+        header:[
+            {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
+            {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
+            {headerName: "结果(C)", headerWidth: 120, dataCode: "result", dataType: "Number",formatter:"0.0000",tofix:4},
+            {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String",cellType:"checkBox"}
+        ],
+        view:{
+            lockColumns:[2,3]
+        }
+    },
     initSheet: function(sheet) {
     initSheet: function(sheet) {
         var me = this;
         var me = this;
         me.sheet = sheet;
         me.sheet = sheet;
@@ -81,6 +93,13 @@ var gljOprObj = {
         sheet.name('ration_ass');
         sheet.name('ration_ass');
         me.bindSheetEvent(sheet);
         me.bindSheetEvent(sheet);
     },
     },
+    initDetailSheet: function(sheet) {
+        var me = this;
+        me.detailSheet = sheet;
+        sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
+        sheet.name('quantity_detail');
+        me.bindSheetEvent(sheet);
+    },
     showCoeData:function(sheet,setting,datas){
     showCoeData:function(sheet,setting,datas){
         sheet.floatingObjects.remove("customerCoe");
         sheet.floatingObjects.remove("customerCoe");
         sheetCommonObj.showData(sheet,setting,datas);
         sheetCommonObj.showData(sheet,setting,datas);
@@ -118,15 +137,33 @@ var gljOprObj = {
 
 
     onEditEnded: function(sender,args){
     onEditEnded: function(sender,args){
         var me = gljOprObj;
         var me = gljOprObj;
-        if(subSpread.getActiveSheetIndex()==0){
+        if(args.sheetName=='ration_glj'){
             me.onEditGLJSheet(args)
             me.onEditGLJSheet(args)
         }
         }
-        if(subSpread.getActiveSheetIndex()==1){
+        if(args.sheetName=='ration_ass'){
             me.onEditAssSheet(args);
             me.onEditAssSheet(args);
         }
         }
+        if(args.sheetName=='quantity_detail'){
+            me.onEditDetailSheet(args);
+        }
+    },
+    onEditDetailSheet:function(args){
+        var me = gljOprObj;
+        if(args.row>me.detailData.length){
+            return;
+        }
+        if(args.row==me.detailData.length&&args.editingText==null){
+            return;
+        }
+       if(args.row==me.detailData.length){
+           projectObj.project.quantity_detail.saveQuantityDetail(args,me.detailSetting.header[args.col].dataCode);
+       }
+        if(args.row<me.detailData.length){
+            projectObj.project.quantity_detail.updateQuantityDetail(args,me.detailSetting.header[args.col].dataCode,me.detailData[args.row]);
+        }
 
 
     },
     },
-    onEditGLJSheet(args){
+    onEditGLJSheet:function(args){
         var me = gljOprObj;
         var me = gljOprObj;
         if(args.row>=me.sheetData.length){
         if(args.row>=me.sheetData.length){
             me.sheet.getCell(args.row, args.col).value(null);
             me.sheet.getCell(args.row, args.col).value(null);
@@ -142,7 +179,7 @@ var gljOprObj = {
         }
         }
         me.updateRationGLJ(args,updateFunction);
         me.updateRationGLJ(args,updateFunction);
     },
     },
-    onEditAssSheet(args){
+    onEditAssSheet:function(args){
         var me = gljOprObj;
         var me = gljOprObj;
         if(args.row>=me.assSheetData.length){
         if(args.row>=me.assSheetData.length){
             me.assSheet.getCell(args.row, args.col).value(null);
             me.assSheet.getCell(args.row, args.col).value(null);
@@ -159,21 +196,26 @@ var gljOprObj = {
         if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
         if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
             me.onCusButtonClick(sender,args);
             me.onCusButtonClick(sender,args);
         }else {
         }else {
-           me.onCoeCheckBoxClick(sender,args)
+           me.onCheckBoxClick(sender,args)
         }
         }
     },
     },
-    onCoeCheckBoxClick:function(sender,args){
-        if(subSpread.getActiveSheetIndex()==2){
-            var checkboxValue = gljOprObj.coeSheet.getCell(args.row, args.col).value();
-            var newval = 0;
-            if(checkboxValue){
-                newval = 0;
-                gljOprObj.coeSheet.getCell(args.row, args.col).value(newval);
-            }else {
-                newval=1
-                gljOprObj.coeSheet.getCell(args.row, args.col).value(newval);
-            }
+    onCheckBoxClick:function(sender,args){
+        if(args.sheetName=='ration_glj'){
+            return;
+        }
+        var checkboxValue = args.sheet.getCell(args.row, args.col).value();
+        var newval = 0;
+        if(checkboxValue){
+            newval = 0;
+            args.sheet.getCell(args.row, args.col).value(newval);
+        }else {
+            newval=1
+            args.sheet.getCell(args.row, args.col).value(newval);
+        }
+        if(args.sheetName=='ration_coe'){
             gljOprObj.updateRationCoe(args,newval)
             gljOprObj.updateRationCoe(args,newval)
+        }else {
+            projectObj.project.quantity_detail.isSummationUpdate(args,gljOprObj.detailData,newval);
         }
         }
     },
     },
     onCusButtonClick:function (sender,args){
     onCusButtonClick:function (sender,args){
@@ -396,6 +438,7 @@ var gljOprObj = {
                this.showRationAssData(node);
                this.showRationAssData(node);
                 isShow=true;
                 isShow=true;
             }
             }
+            this.showQuantityDetailData(node);
         }else {
         }else {
             this.selectedNodeId=null;
             this.selectedNodeId=null;
         }
         }
@@ -420,9 +463,9 @@ var gljOprObj = {
         this.sheetData=gljList;
         this.sheetData=gljList;
     },
     },
     showRationCoeData:function (node) {
     showRationCoeData:function (node) {
-        let coeList = [];
-        let ration_coe= projectObj.project.ration_coe;
-        let ration = node.data;
+        var coeList = [];
+        var ration_coe= projectObj.project.ration_coe;
+        var ration = node.data;
         if(ration_coe.datas&&ration_coe.datas.length>0){
         if(ration_coe.datas&&ration_coe.datas.length>0){
             coeList = _.filter(ration_coe.datas,{'projectID':ration.projectID,'rationID':ration.ID})
             coeList = _.filter(ration_coe.datas,{'projectID':ration.projectID,'rationID':ration.ID})
         }
         }
@@ -430,17 +473,31 @@ var gljOprObj = {
         this.coeSheetData=coeList;
         this.coeSheetData=coeList;
     },
     },
     showRationAssData:function (node) {
     showRationAssData:function (node) {
-        let assList = node.data.rationAssList;
+        var assList = node.data.rationAssList;
         sheetCommonObj.showData(this.assSheet,this.assSetting,assList);
         sheetCommonObj.showData(this.assSheet,this.assSetting,assList);
         this.assSheetData =assList;
         this.assSheetData =assList;
     },
     },
+    showQuantityDetailData:function (node) {
+        var details=[];
+        var quantity_detail =projectObj.project.quantity_detail;
+        if(node.sourceType==ModuleNames.ration){
+            details=_.filter(quantity_detail.datas,{'rationID':node.data.ID});
+        }else if(node.sourceType==ModuleNames.bills){
+            details=_.filter(quantity_detail.datas,{'billID':node.data.ID});
+        }
+        details=_.sortBy(details,'seq');
+        sheetCommonObj.showData(this.detailSheet,this.detailSetting,details);
+        this.detailData = details;
+    },
     clearSheetData:function () {
     clearSheetData:function () {
         sheetCommonObj.showData(this.sheet,this.setting,[]);
         sheetCommonObj.showData(this.sheet,this.setting,[]);
         sheetCommonObj.showData(this.coeSheet,this.coeSetting,[]);
         sheetCommonObj.showData(this.coeSheet,this.coeSetting,[]);
         sheetCommonObj.showData(this.assSheet,this.assSetting,[]);
         sheetCommonObj.showData(this.assSheet,this.assSetting,[]);
+        sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
         this.sheetData = [];
         this.sheetData = [];
         this.coeSheetData = [];
         this.coeSheetData = [];
         this.assSheetData = [];
         this.assSheetData = [];
+        this.detailData=[];
     },
     },
  /*   lockRationGLJCell:function(){
  /*   lockRationGLJCell:function(){
         sheetCommonObj.lockCells(this.sheet,this.setting);
         sheetCommonObj.lockCells(this.sheet,this.setting);

+ 8 - 2
web/building_saas/main/js/views/sub_view.js

@@ -15,10 +15,16 @@ SheetDataHelper.protectdSheet(subSpread.getSheet(0));
 //附注条件
 //附注条件
 gljOprObj.initCoeSheet(subSpread.getSheet(2));
 gljOprObj.initCoeSheet(subSpread.getSheet(2));
 SheetDataHelper.protectdSheet(subSpread.getSheet(2));
 SheetDataHelper.protectdSheet(subSpread.getSheet(2));
-//辅助定额
 
 
+//辅助定额
 gljOprObj.initAssSheet(subSpread.getSheet(1));
 gljOprObj.initAssSheet(subSpread.getSheet(1));
 SheetDataHelper.protectdSheet(subSpread.getSheet(1));
 SheetDataHelper.protectdSheet(subSpread.getSheet(1));
+
+//工程量明细
+gljOprObj.initDetailSheet(subSpread.getSheet(3));
+SheetDataHelper.protectdSheet(subSpread.getSheet(3));
+
+
 $("#linkGLJ").click(function(){
 $("#linkGLJ").click(function(){
     subSpread.setActiveSheetIndex(0);
     subSpread.setActiveSheetIndex(0);
 
 
@@ -41,7 +47,7 @@ $("#linkFZTJ").click(function(){
 $("#linkGCLMX").click(function(){
 $("#linkGCLMX").click(function(){
     subSpread.setActiveSheetIndex(3);
     subSpread.setActiveSheetIndex(3);
     // for test
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "工程量明细");
+    //subSpread.getActiveSheet().setValue(0, 0, "工程量明细");
 });
 });
 
 
 $("#linkJSCX").click(function(){
 $("#linkJSCX").click(function(){