zhangweicheng 8 years ago
parent
commit
fb661b7c74

+ 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_coe_data = require('../../ration_glj/facade/ration_coe_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');
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
@@ -20,6 +21,7 @@ moduleMap[projectConsts.RATION] = rationData;
 moduleMap[projectConsts.RATION_GLJ] = ration_glj_data;
 moduleMap[projectConsts.RATION_COE] = ration_coe_data;
 moduleMap[projectConsts.RATION_ASS] = ration_ass_data;
+moduleMap[projectConsts.QUANTITY_DETAIL] = quantity_detail_data;
 moduleMap[projCounter.collectionName] = projCounter;
 
 

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

@@ -8,6 +8,7 @@ var projectConst = {
     RATION_GLJ:'ration_glj',
     RATION_COE:'ration_coe',
     RATION_ASS:'ration_ass',
+    QUANTITY_DETAIL:'quantity_detail',
     PROJECTGLJ: 'projectGLJ',
     GLJLIST: 'GLJList',
     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');
-const uuidV1 = require('uuid/v1')
+const uuidV1 = require('uuid/v1');
 let consts = require('../../main/models/project_consts')
 let commonConsts = consts.commonConst;
 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;
 
 var ration_glj = new Schema({
-    ID:{ type:String,unique:true},
+    ID:String,
     GLJID:Number,
     projectID: Number,
     rationID:Number,

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

@@ -509,6 +509,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/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/models/quantity_detail.js"></script>
     <!-- reports -->
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/web/ztree_common.js"></script>

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

@@ -9,5 +9,6 @@ const ModuleNames = {
     projectGLJ: 'projectGLJ',
     ration_glj:'ration_glj',
     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_coe = ration_coe.createNew(this);
             this.ration_ass = ration_ass.createNew(this);
+            this.quantity_detail = quantity_detail.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
 
             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);
+    }
+
+};

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

@@ -12,6 +12,8 @@ var gljOprObj = {
     coeSheet:null,
     assSheet:null,
     assSheetData:[],
+    detailSheet:null,
+    detailData:[],
     setting: {
         header: [
             {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
@@ -55,7 +57,17 @@ var gljOprObj = {
             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) {
         var me = this;
         me.sheet = sheet;
@@ -81,6 +93,13 @@ var gljOprObj = {
         sheet.name('ration_ass');
         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){
         sheet.floatingObjects.remove("customerCoe");
         sheetCommonObj.showData(sheet,setting,datas);
@@ -118,15 +137,33 @@ var gljOprObj = {
 
     onEditEnded: function(sender,args){
         var me = gljOprObj;
-        if(subSpread.getActiveSheetIndex()==0){
+        if(args.sheetName=='ration_glj'){
             me.onEditGLJSheet(args)
         }
-        if(subSpread.getActiveSheetIndex()==1){
+        if(args.sheetName=='ration_ass'){
             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;
         if(args.row>=me.sheetData.length){
             me.sheet.getCell(args.row, args.col).value(null);
@@ -142,7 +179,7 @@ var gljOprObj = {
         }
         me.updateRationGLJ(args,updateFunction);
     },
-    onEditAssSheet(args){
+    onEditAssSheet:function(args){
         var me = gljOprObj;
         if(args.row>=me.assSheetData.length){
             me.assSheet.getCell(args.row, args.col).value(null);
@@ -159,21 +196,26 @@ var gljOprObj = {
         if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
             me.onCusButtonClick(sender,args);
         }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)
+        }else {
+            projectObj.project.quantity_detail.isSummationUpdate(args,gljOprObj.detailData,newval);
         }
     },
     onCusButtonClick:function (sender,args){
@@ -396,6 +438,7 @@ var gljOprObj = {
                this.showRationAssData(node);
                 isShow=true;
             }
+            this.showQuantityDetailData(node);
         }else {
             this.selectedNodeId=null;
         }
@@ -420,9 +463,9 @@ var gljOprObj = {
         this.sheetData=gljList;
     },
     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){
             coeList = _.filter(ration_coe.datas,{'projectID':ration.projectID,'rationID':ration.ID})
         }
@@ -430,17 +473,31 @@ var gljOprObj = {
         this.coeSheetData=coeList;
     },
     showRationAssData:function (node) {
-        let assList = node.data.rationAssList;
+        var assList = node.data.rationAssList;
         sheetCommonObj.showData(this.assSheet,this.assSetting,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 () {
         sheetCommonObj.showData(this.sheet,this.setting,[]);
         sheetCommonObj.showData(this.coeSheet,this.coeSetting,[]);
         sheetCommonObj.showData(this.assSheet,this.assSetting,[]);
+        sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
         this.sheetData = [];
         this.coeSheetData = [];
         this.assSheetData = [];
+        this.detailData=[];
     },
  /*   lockRationGLJCell:function(){
         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));
 SheetDataHelper.protectdSheet(subSpread.getSheet(2));
-//辅助定额
 
+//辅助定额
 gljOprObj.initAssSheet(subSpread.getSheet(1));
 SheetDataHelper.protectdSheet(subSpread.getSheet(1));
+
+//工程量明细
+gljOprObj.initDetailSheet(subSpread.getSheet(3));
+SheetDataHelper.protectdSheet(subSpread.getSheet(3));
+
+
 $("#linkGLJ").click(function(){
     subSpread.setActiveSheetIndex(0);
 
@@ -41,7 +47,7 @@ $("#linkFZTJ").click(function(){
 $("#linkGCLMX").click(function(){
     subSpread.setActiveSheetIndex(3);
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "工程量明细");
+    //subSpread.getActiveSheet().setValue(0, 0, "工程量明细");
 });
 
 $("#linkJSCX").click(function(){