zhangweicheng 8 years ago
parent
commit
957960d3f5

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

@@ -4,7 +4,8 @@
 var billsData = require('./bills');
 var rationData = require('./ration');
 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');
 let projCounter = require('./proj_counter');
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
@@ -14,10 +15,12 @@ var moduleMap = {};
 
 moduleMap[projectConsts.BILLS] = billsData;
 moduleMap[projectConsts.RATION] = rationData;
-moduleMap[projectConsts.GLJ] = GLJData;
+//moduleMap[projectConsts.GLJ] = GLJData;
 moduleMap[projectConsts.RATION_GLJ] = ration_glj_data;
+moduleMap[projectConsts.RATION_COE] = ration_coe_data;
 moduleMap[projCounter.collectionName] = projCounter;
 
+
 var Project = function (){};
 
 Project.prototype.datas = [];

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

@@ -6,6 +6,7 @@ var projectConst = {
     RATION: 'ration',
     GLJ: 'GLJ',
     RATION_GLJ:'ration_glj',
+    RATION_COE:'ration_coe',
     PROJECTGLJ: 'projectGLJ',
     GLJLIST: 'GLJList',
     UNITPRICEFILE: 'unitPriceFile',

+ 133 - 0
modules/ration_glj/facade/ration_coe_facade.js

@@ -0,0 +1,133 @@
+/**
+ * Created by chen on 2017/7/6.
+ */
+
+let mongoose = require('mongoose');
+const uuidV1 = require('uuid/v1')
+let consts = require('../../main/models/project_consts');
+let commonConsts = consts.commonConst;
+let _=require("lodash");
+let async_n = require("async");
+let coeMolde = mongoose.model('std_ration_lib_coe_list');
+let ration_coe = mongoose.model('ration_coe');
+
+module.exports={
+    save:save,
+    getData:getData,
+    delete_ration_coe:delete_ration_coe
+}
+let operationMap={
+    'ut_create':create_ration_coe,
+    'ut_update':update_ration_coe,
+    'ut_delete':delete_ration_coe
+};
+
+function create_ration_coe(user_id,datas) {
+    return function (callback) {
+        let ration_coe_list=datas.ration_coe_list;
+        var tasks=[];
+        for(let i=0;i<ration_coe_list.length;i++){
+            ration_coe_list[i].ID = uuidV1();
+            ration_coe_list[i].seq = i;
+            tasks.push(get_lib_coe_info(ration_coe_list[i]));
+        }
+        async_n.parallel(tasks,(err,results)=>{
+            if(err){
+                callback(err,results)
+            }else {
+                ration_coe.insertMany(results,(err,doc)=>{
+                    if(err){
+                        callback(err,null);
+                    }else {
+                        let returndata ={
+                            updateTpye:commonConsts.UT_CREATE,
+                            moduleName:'ration_coe',
+                            data:results
+                        }
+                        callback(null,returndata)
+                    }
+                });
+            }
+        })
+
+    }
+}
+function update_ration_coe() {
+    
+}
+function delete_ration_coe(data) {
+    return function (callback) {
+        ration_coe.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
+            commonCallback(callback,result,err)
+        });
+    }
+}
+
+
+function get_lib_coe_info(ration_coe) {
+    return function (cb) {
+        if(ration_coe.coeID == -1){//自定义系数
+            cb(null,ration_coe);
+        }else {
+           let query ={
+                "libID": ration_coe.libID,
+                "ID": ration_coe.coeID,
+                "$or": [{"isDeleted": null}, {"isDeleted": false}]
+            };
+            coeMolde.findOne(query,(err,coe)=>{
+                if(err){
+                    cb(err,'')
+                }else {
+                    ration_coe.name = coe.name;
+                    ration_coe.content = coe.content;
+                    ration_coe.isAdjust=0;
+                    ration_coe.coes = coe.coes;
+                    cb(null,ration_coe);
+                }
+            })
+        }
+    }
+}
+
+
+
+function getData(projectID, callback) {
+    ration_coe.find({'projectID':projectID}).sort('seq').exec((err,datas)=>{
+        if(err){
+            callback(1, '', null);
+        }else {
+            callback(0, consts.projectConst.RATION_COE, 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)
+            }
+        }
+    })
+}
+
+function commonCallback(callback,result,err) {
+    if(err){
+        callback(err,'');
+    }else {
+        callback(null,result);
+    }
+}

+ 107 - 23
modules/ration_glj/facade/ration_glj_facade.js

@@ -8,18 +8,23 @@ let consts = require('../../main/models/project_consts')
 let commonConsts = consts.commonConst;
 let _=require("lodash");
 let ration_glj = mongoose.model('ration_glj');
+import GLJListModel from '../../glj/models/glj_list_model';
 //let std_ration_lib_glj_list_model = require('../../ration_repository/models/glj_repository');
 let std_ration_lib_glj_list_model = mongoose.model('std_ration_lib_glj_list');
-let async = require("async");
+let async_n = require("async");
 let ration = mongoose.model('ration');
+let ration_coe_facade = require('./ration_coe_facade');
 
 let operationMap={
     'ut_create':create_ration_glj,
     'ut_update':update_ration_glj,
     'ut_delete':delete_ration_glj
+};
+let updateFunctionMap = {
+    'normalUpdate':normalUpdate,
+    'marketPriceAdjustUpdate':marketPriceAdjustUpdate
 }
 
-
 module.exports={
     save:save,
     getData:getData,
@@ -28,22 +33,59 @@ module.exports={
 
 function get_lib_glj_info(ration_glj) {
     return function (cb) {
-        std_ration_lib_glj_list_model.findOne({'ID':ration_glj.GLJID},(err,glj)=>{
+        std_ration_lib_glj_list_model.findOne({'ID':ration_glj.GLJID,'repositoryId':ration_glj.glj_repository_id},(err,glj)=>{
             if(err){
                 cb(err,'')
-            }else {
+            }else if(glj){
                 ration_glj.name = glj.name;
                 ration_glj.code = glj.code;
                 ration_glj.unit = glj.unit;
                 ration_glj.specs = glj.specs;
                 ration_glj.basePrice = glj.basePrice;
                 ration_glj.gljDistType = glj.gljDistType;
-                cb(null,ration_glj)
+                ration_glj.type = glj.gljType;
+                getInfoFromProjectGLJ(ration_glj).then(function (result) {
+                    if(result){
+                        cb(null,result);
+                    }else {
+                        cb(new Error('get project glj error'),null);
+                    }
+                });
+            }else {
+                cb(null,null);
             }
         })
     }
 }
 
+async function getInfoFromProjectGLJ(ration_glj) {
+     let data = {
+         glj_repository_id: ration_glj.glj_repository_id,
+         project_id: ration_glj.projectID,
+         code: ration_glj.code,
+         name: ration_glj.name,
+         specs: ration_glj.specs,
+         unit: ration_glj.unit,
+         type: ration_glj.type,
+         type_of_work: ration_glj.type,
+         base_price: ration_glj.basePrice,
+         market_price: ration_glj.basePrice
+     };
+     try {
+         let projectGljModel = new GLJListModel();
+         let result = await projectGljModel.addList(data);
+         ration_glj.marketPrice=result.unit_price.market_price;
+         ration_glj.adjustPrice=result.adjust_price;
+         ration_glj.projectGLJID=result.id;
+         ration_glj.isEstimate=result.is_evaluate;
+         return ration_glj;
+     } catch (err) {
+         console.log(err);
+         return null;
+     }
+
+ }
+
 function create_ration_glj(user_id,datas) {
     return function (callback) {
         let ration_glj_list=datas.ration_glj_list;
@@ -52,7 +94,7 @@ function create_ration_glj(user_id,datas) {
             ration_glj_list[i].ID = uuidV1();
             tasks.push(get_lib_glj_info(ration_glj_list[i]))
         }
-        async.parallel(tasks,(err,results)=>{
+        async_n.parallel(tasks,(err,results)=>{
             if(err){
                 callback(err,results)
             }else {
@@ -75,7 +117,16 @@ function create_ration_glj(user_id,datas) {
 }
 
 function update_ration_glj(user_id,datas) {
-    return function (callback) {
+    if(datas.updateFunction){
+        return updateFunctionMap[datas.updateFunction](user_id,datas);
+    }else {
+        return normalUpdate(user_id,datas);
+    }
+
+}
+
+function normalUpdate(user_id,datas){
+    return function(callback) {
         ration_glj.update(datas.query,datas.doc,(err,result)=>{
             if(err){
                 callback(err,'');
@@ -90,11 +141,28 @@ function update_ration_glj(user_id,datas) {
                 }
                 callback(null,returndata)
             }
-
         })
     }
 }
 
+
+function marketPriceAdjustUpdate(user_id,datas) {
+    return function (callback) {
+
+
+        console.log(datas.query);
+        console.log(datas.doc);
+        callback(null,'')
+    }
+}
+
+async function updateprojectGljAndRationGLJ(query,doc) {
+
+
+
+}
+
+
 function delete_ration_glj(user_id,datas) {
     return function (callback) {
         if(datas.deleteType=="RATION"){
@@ -109,16 +177,30 @@ function delete_ration_glj(user_id,datas) {
 
 function deleteByRation(datas,callback) {
     let data = datas.updateData;
-    ration_glj.deleteMany({projectID: data.projectID, rationID: data.ID},callback);
+    let tasks=[];
+    tasks.push(deleteGLJList(data));
+    tasks.push(ration_coe_facade.delete_ration_coe(data))
+    async_n.parallel(tasks,function (err,result) {
+        commonCallback(callback,result,err)
+    })
 }
 
+function  deleteGLJList(data) {
+    return function (callback) {
+        ration_glj.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
+            commonCallback(callback,result,err)
+        });
+    }
+}
+
+
 function deleteByBill(user_id,datas,callback) {
     let tasks = [];
     tasks.push(startingTask("deleteByBill"));
     tasks.push(getRationsByBill(datas));
     tasks.push(deleteRationsbyBill(user_id,datas));
     tasks.push(deleteByMultiRations(datas));
-    async.waterfall(tasks,function (err,results) {
+    async_n.waterfall(tasks,function (err,results) {
         if(err){
             callback(err,'');
         }else {
@@ -189,19 +271,16 @@ function deleteByMultiRations(datas) {
         var deleteOne=function (ration) {
             return function (callback) {
                 ration_glj.deleteMany({projectID: ration.projectID, rationID: ration.ID},function (err,result) {
-                    if(err){
-                        callback(err,'');
-                    }else {
-                        callback(null,result);
-                    }
+                    commonCallback(callback,result,err)
                 });
             }
         }
         let rations = results.rations;
         for(let i=0;i<rations.length;i++){
             delete_tasks.push(deleteOne(rations[i]._doc));
+            delete_tasks.push(ration_coe_facade.delete_ration_coe(rations[i]._doc));
         }
-        async.parallel(delete_tasks,(err,results)=>{
+        async_n.parallel(delete_tasks,(err,results)=>{
             if (err){
                 deleteCallBack(err,'')
             }else {
@@ -221,15 +300,15 @@ function  deleteByRation(doc) {
 */
 
 function save (user_id, datas, callback) {
-    let perations=[];
+    let operations=[];
     if(_.isArray(datas)){
         for(let i=0;i<datas.length;i++){
-            perations.push(operationMap[datas[i].updateType](user_id,datas[i]));
+            operations.push(operationMap[datas[i].updateType](user_id,datas[i]));
         }
     }else {
-        perations.push(operationMap[datas.updateType](user_id,datas));
+        operations.push(operationMap[datas.updateType](user_id,datas));
     }
-    async.parallel(perations,function (err,results) {
+    async_n.parallel(operations,function (err,results) {
         if(err){
             callback(err,'');
         }else {
@@ -243,7 +322,6 @@ function save (user_id, datas, callback) {
 }
 
 function getData(projectID, callback) {
-    console.log("ration_glj getData function");
     ration_glj.find({'projectID':projectID},(err,datas)=>{
         if(err){
             callback(1, '', null);
@@ -251,6 +329,12 @@ function getData(projectID, callback) {
             callback(0, consts.projectConst.RATION_GLJ, datas);
         }
     })
+}
 
-
-}
+function commonCallback(callback,result,err) {
+    if(err){
+        callback(err,'');
+    }else {
+        callback(null,result);
+    }
+}

+ 28 - 0
modules/ration_glj/models/ration_coe.js

@@ -0,0 +1,28 @@
+/**
+ * Created by chen on 2017/6/29.
+ */
+var mongoose = require('mongoose'),
+    Schema = mongoose.Schema;
+
+var coeSchema = mongoose.Schema({
+    coeType: String,                // 系数类型,指作用范围:// 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
+    gljID: Number,                  // 要调整的工料机ID(当coeType=0时有效)
+    operator: String,               // 运算符(*、+、-、=)
+    amount: String,                 // 调整的量
+    _id: false
+});
+
+var coeListSchema = mongoose.Schema({
+    libID: Number,                      // 所属定额库ID
+    ID: String,                         // 系数ID(流水号ID)
+    name: String,                       // 名称
+    content: String,                    // 说明
+    rationID:Number,
+    projectID:Number,
+    coeID:Number,
+    isAdjust:Number, //0不调整,1调整
+    seq:Number,//序数,排序用
+    coes: [coeSchema]
+}, {versionKey: false});
+
+mongoose.model('ration_coe', coeListSchema);

+ 4 - 3
modules/ration_glj/models/ration_glj.js

@@ -9,20 +9,21 @@ var ration_glj = new Schema({
     GLJID:Number,
     projectID: Number,
     rationID:Number,
+    projectGLJID:Number,
     name:String,
     code:String,
     specs:String,
     unit:String,
     basePrice:Number,
     gljDistType:String,
-    gljType:Number,
+    type:Number,
     quantity:Number,
     customQuantity:Number,
     rationItemQuantity:Number,
     marketPrice:Number,
     adjustPrice:Number,
-    marketPriceAdjest:Number,
-    isEstimate:Boolean
+    marketPriceAdjust:Number,
+    isEstimate:Number
 },{versionKey:false});
 
 mongoose.model('ration_glj', ration_glj);

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

@@ -46,4 +46,23 @@ let rationSchema = new Schema({
     deleteInfo: deleteSchema
 });
 
-mongoose.model("ration", rationSchema, "ration");
+mongoose.model("ration", rationSchema, "ration");
+
+var coeSchema = mongoose.Schema({
+    coeType: String,                // 系数类型,指作用范围:
+                                    // 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
+    gljID: Number,                  // 要调整的工料机ID(当coeType=0时有效)
+    operator: String,               // 运算符(*、+、-、=)
+    amount: String,                 // 调整的量
+    _id: false
+});
+
+var coeListSchema = mongoose.Schema({
+    libID: Number,                      // 所属定额定ID
+    ID: Number,                         // 系数ID(流水号ID)
+    name: String,                       // 名称
+    content: String,                    // 说明
+    coes: [coeSchema]
+}, {versionKey: false});
+
+ mongoose.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list");

+ 1 - 1
public/common_util.js

@@ -17,4 +17,4 @@ function deleteEmptyObject(arr) {
             i = i - 1;
         };
     };
-};
+};

+ 10 - 0
public/web/number_util.js

@@ -0,0 +1,10 @@
+/**
+ * Created by chen on 2017/7/5.
+ */
+var  number_util = {
+    isNumber : function (obj) {
+        return obj === +obj;
+    },
+
+
+}

+ 25 - 1
public/web/sheet/sheet_common.js

@@ -92,6 +92,8 @@ var sheetCommonObj = {
         var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
         sheet.suspendPaint();
         sheet.suspendEvent();
+        //sheet.addRows(row, 1);
+
         sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
         for (var col = 0; col < setting.header.length; col++) {
             var hAlign = "left", vAlign = "center";
@@ -108,9 +110,23 @@ var sheetCommonObj = {
                 //sheet.setStyle(row,col,style,GC.Spread.Sheets.SheetArea.viewport);
                 sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
             }
+            if(setting.header[col].cellType === "checkBox"){//clear and reset
+                var me = this, header = GC.Spread.Sheets.SheetArea.colHeader;
+                sheet.deleteColumns(col,1);
+                sheet.addColumns(col, 1);
+                sheet.setValue(0, col, setting.header[col].headerName, header);
+                sheet.setColumnWidth(col, setting.header[col].headerWidth?setting.header[col].headerWidth:100);
+            }
             for (var row = 0; row < data.length; row++) {
                 //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
-                sheet.setValue(row, col, data[row][setting.header[col].dataCode], ch);
+                var val = data[row][setting.header[col].dataCode];
+                if(val&&setting.header[col].dataType === "Number"){
+                    val =parseFloat(val).toFixed(2);
+                }
+                if(val!=null&&setting.header[col].cellType === "checkBox"){
+                    this.setCheckBoxCell(row,col,sheet,val)
+                 }
+                sheet.setValue(row, col, val, ch);
             }
         }
         sheet.resumeEvent();
@@ -165,6 +181,14 @@ var sheetCommonObj = {
             }
         }
     },
+    setCheckBoxCell(row,col,sheet,val){
+        var c = new GC.Spread.Sheets.CellTypes.CheckBox();
+        c.isThreeState(false);
+        sheet.setCellType(row, col,c,GC.Spread.Sheets.SheetArea.viewport);
+        sheet.getCell(row, col).value(val);
+        sheet.getCell(row, col).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
+
+    },
     chkIfEmpty: function(rObj, setting) {
         var rst = true;
         if (rObj) {

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

@@ -469,6 +469,7 @@
     <!-- Common -->
     <script type="text/javascript" src="/public/web/common_ajax.js"></script>
     <script type="text/javascript" src="/public/web/url_util.js"></script>
+    <script type="text/javascript" src="/public/web/number_util.js"></script>
     <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
     <!--报表 zTree -->
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
@@ -484,6 +485,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/fee_rate.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_glj.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/ration_coe.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>

+ 12 - 2
web/building_saas/main/js/models/bills.js

@@ -147,12 +147,22 @@ var Bills = {
             //project.endUpdate();
             var moudles =[ModuleNames.bills,ModuleNames.ration_glj];
             var deleteDatas=[tools.coverseTreeUpdateData(deleteData, this.project.ID()),ration_glj.getDeleteDataByBills(deleteData)];
-           // project.ration.getDeleteDataByBill(node);
+            project.ration_glj.deleteByBills(deleteData);
             project.pushNow('deleteBILL', moudles, deleteDatas);
-
+            this.delete(deleteData);
 
            // return this.tree.delete(node);
         };
+        bills.prototype.delete=function(deleteData){
+            for(var i=0;i<deleteData.length;i++){
+                var billID = deleteData[i].data.ID;
+                 this.datas =_.filter(this.datas,(bill)=>{
+                    return bill.ID!=billID;
+                });
+            }
+        }
+
+
         bills.prototype.upMoveBills = function (node) {
             var upMoveData = node.getUpMoveData();
             project.pushNow('upMoveBills', this.getSourceType(), tools.coverseTreeUpdateData(upMoveData, this.project.ID()));

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

@@ -7,5 +7,6 @@ const ModuleNames = {
     GLJ: 'GLJ',
     feeRate: 'feeRate',
     projectGLJ: 'projectGLJ',
-    ration_glj:'ration_glj'
+    ration_glj:'ration_glj',
+    ration_coe:'ration_coe'
 };

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

@@ -58,7 +58,8 @@ var PROJECT = {
             this.Bills = Bills.createNew(this);
             this.Ration = Ration.createNew(this);
             this.GLJ = GLJ.createNew(this);
-            this.ration_glj = ration_glj.createNew(this)
+            this.ration_glj = ration_glj.createNew(this);
+            this.ration_coe = ration_coe.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
 
             this.masterField = {ration: 'billsItemID'};

+ 108 - 0
web/building_saas/main/js/models/ration_coe.js

@@ -0,0 +1,108 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+var ration_coe = {
+    createNew: function (project) {
+        // 用户定义private方法
+        var tools = {};
+
+        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        var ration_coe = function (proj) {
+            this.gljTree = cacheTree.createNew(this);
+           // this.project = proj;
+            this.datas = [];
+
+            var sourceType = ModuleNames.ration_coe;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.ration_coe, this);
+        };
+
+        // prototype用于定义public方法
+        ration_coe.prototype.loadData = function (datas) {
+            this.datas = datas;
+        };
+
+        // 提交数据后返回数据处理
+        ration_coe.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);
+                }
+            }
+        };
+        ration_coe.prototype.refreshAfterSave=function(data){
+            if(projectObj.project.ration_coe.datas&&Array.isArray(projectObj.project.ration_coe.datas)){
+                projectObj.project.ration_coe.datas = projectObj.project.ration_coe.datas.concat(data);
+            }else {
+                projectObj.project.ration_coe.datas = data;
+            }
+            sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,data);
+            // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
+        };
+        ration_coe.prototype.refreshAfterUpdate=function(data){
+            var glj_list = projectObj.project.ration_coe.datas;
+            var glj_index= _.findIndex(glj_list,(glj)=>{
+                return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
+            })
+            _.forEach(data.doc, function(n, key) {
+                glj_list[glj_index][key] = n;
+            });
+
+            var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
+            gljOprObj.sheetData=showList;
+           sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,showList);
+        };
+        ration_coe.prototype.refreshAfterDelete=function(data){
+            var glj_list = projectObj.project.ration_coe.datas;
+            _.remove(glj_list,data.query);
+            _.remove(gljOprObj.sheetData,data.query);
+            sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,gljOprObj.sheetData);
+        };
+
+        ration_coe.prototype.getRationCoedata=function(newRation,data){
+            var criteria= {};
+            criteria.ration_coe_list = [];
+            var dataLength = 0;
+            if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
+                dataLength = data.rationCoeList.length
+            }
+            for(var i=0;i<=dataLength;i++){;
+                var newCoe = {
+                    libID :data.rationRepId,
+                    rationID:newRation.ID,
+                    projectID :  newRation.projectID
+                }
+                if(i==dataLength){
+                    newCoe.coeID=-1;
+                    newCoe.name = '自定义系数';
+                    newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
+                    newCoe.isAdjust=0;
+                }else {
+                    newCoe.coeID= data.rationCoeList[i];
+                }
+                criteria.ration_coe_list.push(newCoe);
+            }
+            criteria.updateType = 'ut_create';
+            return criteria;
+        };
+        ration_coe.prototype.deleteByRation = function(ration){
+            var coe_list = projectObj.project.ration_coe.datas;
+            var newList =_.filter(coe_list,(coe)=>{
+                return coe.rationID!=ration.ID;
+            });
+            if(newList!=undefined){
+                projectObj.project.ration_coe.datas = newList;
+            }
+        };
+        return new ration_coe(project);
+    }
+
+
+
+};

+ 84 - 9
web/building_saas/main/js/models/ration_glj.js

@@ -67,8 +67,9 @@ var ration_glj = {
             var glj_index= _.findIndex(glj_list,(glj)=>{
                 return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
             })
-            glj_list[glj_index].customQuantity=data.doc.customQuantity;
-            glj_list[glj_index].quantity=data.doc.quantity;
+            _.forEach(data.doc, function(n, key) {
+                glj_list[glj_index][key] = n;
+            });
 
             var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
             gljOprObj.sheetData=showList;
@@ -117,6 +118,8 @@ var ration_glj = {
         };
 
         ration_glj.prototype.addRationGLJ = function (newRation,data) {
+            var souceTypeList=[];
+            var criteriaDataList = [];
             if(data.hasOwnProperty('rationGljList')&&data.rationGljList.length>0){
                 let criteria= {};
                 criteria.ration_glj_list = [];
@@ -128,12 +131,21 @@ var ration_glj = {
                     newGLJ.rationID = newRation.ID;
                     newGLJ.rationItemQuantity= temdata.consumeAmt;
                     newGLJ.quantity=temdata.consumeAmt;
-                    criteria.ration_glj_list.push(newGLJ)
+                    newGLJ.glj_repository_id=data.rationRepId;
+                    criteria.ration_glj_list.push(newGLJ);
                 }
                 criteria.updateType = 'ut_create';
-                project.pushNow('addRationGLJ',[this.getSourceType()],[criteria]);
+                souceTypeList.push(this.getSourceType());
+                criteriaDataList.push(criteria);
             }
+            var ration_coe = projectObj.project.ration_coe;
+            var rationCoeData = ration_coe.getRationCoedata(newRation,data);
+            souceTypeList.push(ration_coe.getSourceType());
+            criteriaDataList.push(rationCoeData);
+            project.pushNow('addRationGLJAndRationCoe',souceTypeList,criteriaDataList);
+
         };
+
         ration_glj.prototype.getDeleteDataByRation=function(rationData){
             var updateData = [];
             updateData.push({'deleteType':'RATION','updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}});
@@ -156,16 +168,79 @@ var ration_glj = {
                 projectObj.project.ration_glj.datas = newList;
             }
         };
+        ration_glj.prototype.deleteByBills=function(deleteData){
+            var rationList = projectObj.project.Ration.datas;
+            var deleteRationList = [];
+            for(var i=0;i<deleteData.length;i++){
+                var billID = deleteData[i].data.ID;
+                var raList =_.filter(rationList,(ration)=>{
+                    return ration.billsItemID==billID;
+                });
+                deleteRationList = deleteRationList.concat(raList);
+            }
+            for(var i=0;i<deleteRationList.length;i++){
+                this.deleteByRation(deleteRationList[i]);
+                projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
+                projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
+            }
+        }
+
+
         ration_glj.prototype.updataOrdelete=function(row){
-            var updateData = [];
+            var updateData = null;
             if(row.rationItemQuantity==0){
-                updateData.push({'updateType': 'ut_delete', 'query': {'ID': row.ID, 'projectID': row.projectID}});
+                updateData=this.getUpdateData('ut_delete',{'ID': row.ID, 'projectID': row.projectID});
             }else {
-                updateData.push({'updateType': 'ut_update','query': {'ID': row.ID, 'projectID': row.projectID},'doc':{'quantity':0,'customQuantity':0}});
+                updateData= this.getUpdateData('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
             }
-            project.pushNow('addRationGLJ',[this.getSourceType()],updateData)
-        }
+            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData)
+        };
+        ration_glj.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;
+        };
+        ration_glj.prototype.customQuantityUpdate = function(recode,newVal){
+            var query = {
+                'ID':recode.ID,
+                'projectID': recode.projectID
+            };
+            var doc ={
+                customQuantity:newVal,
+                quantity:newVal
+            };
+            var updateData = this.getUpdateData('ut_update',query,doc);
+            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
 
+        };
+        ration_glj.prototype.marketPriceAdjustUpdate = function (recode,newVal) {
+            var query = {
+                'ID':recode.ID,
+                'projectID': recode.projectID
+            };
+            var doc ={
+                market_price:newVal,
+                code:recode.code,
+                name:recode.name,
+                project_id:recode.projectID
+            };
+         /*   code: '01010101',
+                market_price: '40',
+                name: '水泥',
+                project_id: projectId*/
+            var updateData = this.getUpdateData('ut_update',query,doc,'marketPriceAdjustUpdate');
+            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
+        };
 
         return new ration_glj(project);
     }

+ 110 - 25
web/building_saas/main/js/views/glj_view.js

@@ -6,42 +6,63 @@ var gljOprObj = {
     sheet: null,
     libID: null,
     ration: null,
-    sheetData:null,
+    sheetData:[],
+    coeSheetData:[],
+    checkb:null,
+    coeSheet:null,
     setting: {
         header: [
-            {headerName: "编码", headerWidth: 60, dataCode: "code", dataType: "String", formatter: "@"},
-            {headerName: "名称", headerWidth: 80, dataCode: "name", dataType: "String"},
+            {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
+            {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String"},
             {headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center"},
             {headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String", hAlign: "center"},
             {headerName: "类别", headerWidth: 50, dataCode: "gljDistType", dataType: "String", hAlign: "center"},
-            {headerName: "定额消耗量", headerWidth: 80, dataCode: "rationItemQuantity", dataType: "String", hAlign: "right"},    // dataType: "Number", formatter: "0.00"
-            {headerName: "自定义消耗量", headerWidth: 80, dataCode: "customQuantity", dataType: "String", hAlign: "right"},
-            {headerName: "消耗量", headerWidth: 80, dataCode: "quantity", dataType: "String", hAlign: "right"},
-            {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "String", hAlign: "right"},
+            {headerName: "定额消耗量", headerWidth: 80, dataCode: "rationItemQuantity", dataType: "Number", hAlign: "right"},    // dataType: "Number", formatter: "0.00"
+            {headerName: "自定义消耗量", headerWidth: 80, dataCode: "customQuantity", dataType: "Number", hAlign: "right"},
+            {headerName: "消耗量", headerWidth: 80, dataCode: "quantity", dataType: "Number", hAlign: "right"},
+            {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", hAlign: "right"},
             {headerName: "调整基价", headerWidth: 80, dataCode: "adjustPrice", dataType: "String", hAlign: "right"},
             {headerName: "市场单价", headerWidth: 80, dataCode: "marketPrice", dataType: "String", hAlign: "right"},
-            {headerName: "市场单价调整", headerWidth: 80, dataCode: "price", dataType: "String", hAlign: "right"},
-            {headerName: "是否暂估", headerWidth: 80, dataCode: "isEstimate", dataType: "String", hAlign: "right"}
+            {headerName: "市场单价调整", headerWidth: 80, dataCode: "marketPriceAdjust", dataType: "String", hAlign: "right"},
+            {headerName: "是否暂估", headerWidth: 80, dataCode: "isEstimate", dataType: "String", hAlign: "center",vAlign:"center",cellType:"checkBox"}
         ],
         view: {
             comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
-            lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}]
+            lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
+            lockColumns:[0,1,2,3,4,5,7,8,9,10,12]
         }
     },
+    coeSetting:{
+        header:[
+            {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String",cellType:"checkBox"},
+            {headerName: "条件", headerWidth: 120, dataCode: "name", dataType: "String"},
+            {headerName: "内容", headerWidth: 260, dataCode: "content", dataType: "String", hAlign: "center"}
+        ]
+    },
 
     initSheet: function(sheet) {
         var me = this;
         me.sheet = sheet;
         sheetCommonObj.initSheet(me.sheet, me.setting, 30);
-
        // var unit = new GC.Spread.Sheets.CellTypes.ComboBox();
         //unit.items(["米","千克"]);
        // me.sheet.getRange(-1, 3, -1, 1).cellType(unit);
+        me.bindSheetEvent(sheet);
+        this.loadGLJSpreadContextMenu();
+    },
+    initCoeSheet:function (sheet) {
+        var me = this;
+        me.coeSheet = sheet;
+        sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
+        me.bindSheetEvent(sheet);
+    },
+
+    bindSheetEvent:function (sheet) {
+        var me = this;
         sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
         sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
         sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
-        this.loadGLJSpreadContextMenu();
     },
 
     onClipboardPasting: function(sender, args) {
@@ -57,12 +78,21 @@ var gljOprObj = {
         // your code...
     },
 
-    onEditEnded: function(sender, args){
+    onEditEnded: function(sender,args){
         var me = gljOprObj;
-        if (!me.ration) {return;};
-        // your code...
+        if(args.row>=me.sheetData.length){
+            return;
+        }
+        var ration_glj = projectObj.project.ration_glj;
+        var updateFunction =null;
+        if(me.setting.header[args.col].dataCode=='marketPriceAdjust'){//市场单价调整
+            updateFunction = ration_glj.marketPriceAdjustUpdate;
+        }
+        if(me.setting.header[args.col].dataCode=='customQuantity'){//自定义消耗量
+            updateFunction = ration_glj.customQuantityUpdate;
+        }
+        me.updateRationGLJ(args,updateFunction);
     },
-
     onRangeChanged: function(sender, args) {
         if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
             if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
@@ -70,7 +100,7 @@ var gljOprObj = {
         };
     },
     showDataIfRationSelect:function (node) {
-        let gljList = [];
+        var isShow = false;
         if(node){
             if(this.selectedNodeId&&this.selectedNodeId==node.getID()){
                 return;
@@ -78,18 +108,49 @@ var gljOprObj = {
                 this.selectedNodeId=node.getID();
             }
             if(node.sourceType=="ration"){
-                let ration_glj = projectObj.project.ration_glj;
-                let ration = node.data;
-                if(ration_glj.datas&&ration_glj.datas.length>0){
-                    gljList = _.filter(ration_glj.datas,{'projectID':ration.projectID,'rationID':ration.ID})
-                }
-                sheetCommonObj.showData(this.sheet,this.setting,gljList);
+               this.showRationGLJData(node);
+               this.showRationCoeData(node);
+                isShow=true;
             }
+        }else {
+            this.selectedNodeId=null;
+        }
+        if(!isShow){
+            this.clearSheetData();
+        }
+      //  var activitySheet = subSpread.getActiveSheet();
+
+        //activitySheet.clear(0, 0, activitySheet.getRowCount(), activitySheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
+       // ------sheetCommonObj.showData(this.sheet,this.setting,gljList);
+       // sheetCommonObj.lockCells(this.sheet,this.setting);
+    },
+    showRationGLJData:function (node) {
+        let gljList = [];
+        let ration_glj = projectObj.project.ration_glj;
+        let ration = node.data;
+        if(ration_glj.datas&&ration_glj.datas.length>0){
+            gljList = _.filter(ration_glj.datas,{'projectID':ration.projectID,'rationID':ration.ID})
         }
-        this.selectedNodeId=null;
         sheetCommonObj.showData(this.sheet,this.setting,gljList);
         this.sheetData=gljList;
     },
+    showRationCoeData:function (node) {
+        let coeList = [];
+        let ration_coe= projectObj.project.ration_coe;
+        let ration = node.data;
+        if(ration_coe.datas&&ration_coe.datas.length>0){
+            coeList = _.filter(ration_coe.datas,{'projectID':ration.projectID,'rationID':ration.ID})
+        }
+        sheetCommonObj.showData(this.coeSheet,this.coeSetting,coeList);
+        this.coeSheetData=coeList;
+    },
+    clearSheetData:function () {
+        sheetCommonObj.showData(this.sheet,this.setting,[]);
+        sheetCommonObj.showData(this.coeSheet,this.coeSetting,[]);
+        this.sheetData = [];
+        this.coeSheetData = [];
+    },
+
     loadGLJSpreadContextMenu: function () {
         var project =projectObj.project, spread =subSpread;
         var selectedRow =null;
@@ -108,7 +169,7 @@ var gljOprObj = {
                     disabled: function () {
                         //var selected = project.mainTree.selected;
                         var disable = true;
-                        if(gljOprObj.sheetData!=null&&gljOprObj.sheetData.length>0&&selectedRow<gljOprObj.sheetData.length){
+                        if(subSpread.getActiveSheetIndex()==0&&gljOprObj.sheetData!=null&&gljOprObj.sheetData.length>0&&selectedRow<gljOprObj.sheetData.length){
                             disable=false
                         }
                         return disable;
@@ -120,7 +181,31 @@ var gljOprObj = {
                 }
             }
         });
+    },
+    updateRationGLJ:function (args,updateFunction) {
+        var me = gljOprObj;
+        var newval = this.numberValueChecking(args.editingText);
+        var recode = me.sheetData[args.row];
+        if(newval){
+            updateFunction.apply(projectObj.project.ration_glj,[recode,newval]);
+        }else {
+            newval = parseFloat(recode.customQuantity).toFixed(2);
+            me.sheet.getCell(args.row, args.col).value(newval);
+        }
+    },
+    numberValueChecking:function (val) {
+        var newval = Number(val);
+        if(number_util.isNumber(newval)){
+            newval = newval.toFixed(2);
+        }else {
+            if(val){
+                alert('您输入的数据类型不正确,请重新输入。');
+            }
+            newval = null;
+        }
+        return newval;
     }
 
+
 }
 

+ 1 - 0
web/building_saas/main/js/views/project_view.js

@@ -158,6 +158,7 @@ $('#delete').click(function () {
         } else if (selected.sourceType === project.Ration.getSourceType()) {
             project.Ration.delete(selected.source);
             project.ration_glj.deleteByRation(selected.source);
+            project.ration_coe.deleteByRation(selected.source);
             controller.delete();
         };
     }

+ 6 - 5
web/building_saas/main/js/views/sub_view.js

@@ -8,17 +8,18 @@ var subSpread = sheetCommonObj.createSpread($("#subSpread")[0], 7);
 
 // 工料机
 gljOprObj.initSheet(subSpread.getSheet(0));
-sheetCommonObj.shieldAllCells(subSpread.getSheet(0), gljOprObj.setting);
+//sheetCommonObj.shieldAllCells(subSpread.getSheet(0), gljOprObj.setting);
 
 // assistOprObj.initSheet(subSpread.getSheet(1));
 // sheetCommonObj.shieldAllCells(subSpread.getSheet(1), assistOprObj.setting);
-
-
+//附注条件
+gljOprObj.initCoeSheet(subSpread.getSheet(2));
 
 $("#linkGLJ").click(function(){
     subSpread.setActiveSheetIndex(0);
+
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "工料机");
+    //subSpread.getActiveSheet().setValue(0, 0, "工料机");
 });
 
 $("#linkFZDE").click(function(){
@@ -30,7 +31,7 @@ $("#linkFZDE").click(function(){
 $("#linkFZTJ").click(function(){
     subSpread.setActiveSheetIndex(2);
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "附注条件");
+    //subSpread.getActiveSheet().setValue(0, 0, "附注条件");
 });
 
 $("#linkGCLMX").click(function(){