瀏覽代碼

模板子目关联

zhangweicheng 6 年之前
父節點
當前提交
df01099af7

+ 1 - 0
config/gulpConfig.js

@@ -97,6 +97,7 @@ module.exports = {
         'web/building_saas/main/js/models/ration_coe.js',
         'web/building_saas/main/js/models/ration_ass.js',
         'web/building_saas/main/js/models/ration_installation.js',
+        'web/building_saas/main/js/models/ration_template.js',
         // 'web/building_saas/main/js/models/volume_price.js',
         'web/building_saas/main/js/models/labour_coe.js',
         'web/building_saas/main/js/models/installation_fee.js',

+ 7 - 0
modules/all_models/compleRation_ration.js

@@ -55,6 +55,13 @@ const compleRationSchema = new Schema({
     rationCoeList: Array,
     rationAssList: [compleRationAssItemSchema],
     rationInstList: [rationInstSchema],
+    rationTemplateList : [new Schema({
+        type: String,
+        code: String,
+        name: String,
+        billsLocation: String,
+        unit:String
+    }, { _id: false })],
     deleteInfo: deleteSchema
 }, {versionKey: false});
 

+ 1 - 0
modules/all_models/ration.js

@@ -66,6 +66,7 @@ let rationSchema = new Schema({
     annotation: String,                         //附注
     ruleText: String,                            // 计算规则
     prefix: {type: String, default: ''},                              //定额是补充、借用时用  补 借
+    referenceRationID:String,//如果是通过模板关联子目生成的定额,这里记录对应的主定额ID
 
     //工料机特有属性
     projectGLJID:Number,  //项目工料机ID

+ 26 - 0
modules/all_models/ration_template.js

@@ -0,0 +1,26 @@
+/**
+ * Created by zhang on 2018/11/26.
+ */
+
+var mongoose = require('mongoose'),
+    Schema = mongoose.Schema;
+
+let ration_template =  new Schema({
+    ID:String,
+    projectID: Number,
+    rationID:String,
+    createLocation:Number,//提取位置
+    templateList:[new Schema({
+        code:String,
+        name:String,
+        type:String,
+        billsLocation:String,//这个是清单编号
+        fxID:String,//这个是分项对应的ID
+        unit:String,
+        quantity:String,
+        coe:String,
+        billID:String//记取位置对应的清单ID
+    },{ _id: false })]
+},{versionKey:false});
+
+mongoose.model('ration_template', ration_template);

+ 9 - 2
modules/all_models/stdRation_ration.js

@@ -46,7 +46,14 @@ const rationItemSchema = new Schema({
     rationGljList: [rationGljItemSchema],
     rationCoeList: Array,
     rationAssList: [rationAssItemSchema],
-    rationInstList: [rationInstSchema]
-});
+    rationInstList: [rationInstSchema],
+    rationTemplateList : [new Schema({
+        type: String,
+        code: String,
+        name: String,
+        billsLocation: String,
+        unit:String
+    }, { _id: false })]
 
+});
 mongoose.model('std_ration_lib_ration_items', rationItemSchema, 'std_ration_lib_ration_items');

+ 2 - 6
modules/main/controllers/bills_controller.js

@@ -8,9 +8,7 @@ let ProjectsData = require('../../pm/models/project_model').project;
 let logger = require("../../../logs/log_helper").logger;
 let quantity_detail = require("../facade/quantity_detail_facade");
 let bill_facade = require("../facade/bill_facade");
-let ration_glj = mongoose.model('ration_glj');
-let ration_coe = mongoose.model('ration_coe');
-let rationInstallationModel = mongoose.model('ration_installation');
+let raiton_facade = require("../facade/ration_facade");
 let stdBillsModel = mongoose.model('std_bills_lib_bills');
 let stdBillJobsModel = mongoose.model('std_bills_lib_jobContent');
 let stdBillCharacterModel = mongoose.model('std_bills_lib_itemCharacter');
@@ -425,9 +423,7 @@ async function doBillsOrRationsDelete(data) {
         await quantity_detail.deleteByQuery(qd_query) ;
     }
     if(sub_query!=null){
-        await ration_coe.deleteMany(sub_query);//删除附注条件
-        await ration_glj.deleteMany(sub_query);//删除定额工料机
-        await rationInstallationModel.deleteMany(sub_query);//删除安装增加费
+        await raiton_facade.deleteSubListByQuery(sub_query);
     }
     if(rationTask.length>0){
         await ration_model.model.bulkWrite(rationTask);//删除定额

+ 4 - 1
modules/main/facade/bill_facade.js

@@ -14,6 +14,7 @@ let ration_Model = mongoose.model('ration');
 let ration_glj_Model = mongoose.model('ration_glj');
 let ration_coe_Model = mongoose.model('ration_coe');
 let ration_installation_Model = mongoose.model('ration_installation');
+let ration_template_Model = mongoose.model('ration_template');
 let bill_Model = require('../models/bills').model;
 import GLJController from "../../glj/controllers/glj_controller";
 
@@ -89,6 +90,7 @@ async function pasteOtherData(data) {
     let quantity_details = data.quantity_details;
     let ration_coes = data.ration_coes;
     let ration_installations = data.ration_installations;
+    let ration_templates = data.ration_templates;
     let updateData = data.updateData;
     let uModel = null;
     let tasks = [];
@@ -113,9 +115,10 @@ async function pasteOtherData(data) {
     quantity_details.length > 0 ? await insertMany(quantity_details,quantity_detail_model):'';
     ration_coes.length > 0 ? await insertMany(ration_coes,ration_coe_Model):'';
     ration_installations.length > 0 ? await insertMany(ration_installations,ration_installation_Model):'';
+    ration_templates.length > 0? await insertMany(ration_templates,ration_template_Model):'';
     tasks.length>0?await uModel.bulkWrite(tasks):'';
 
-    return {bills:bills,quantity_details:quantity_details,ration_coes:ration_coes,ration_installations:ration_installations,updateData:updateData}
+    return {bills:bills,quantity_details:quantity_details,ration_coes:ration_coes,ration_installations:ration_installations,ration_templates:ration_templates,updateData:updateData}
 }
 
 async function pasteRationsAndRationGLJ (rations,ration_gljs) {

+ 47 - 5
modules/main/facade/ration_facade.js

@@ -13,6 +13,7 @@ let bill_model = require('../models/bills');
 let decimal_facade = require('./decimal_facade');
 let installationFeeModel = mongoose.model("installation_fee");
 let rationInstallationModel = mongoose.model('ration_installation');
+let rationTemplateModel = mongoose.model('ration_template');
 const uuidV1 = require('uuid/v1');
 let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
 let complementary_glj_model =  mongoose.model('complementary_glj_lib');
@@ -32,7 +33,8 @@ module.exports = {
     addMultiRation: addMultiRation,
     getSameSectionRations:getSameSectionRations,
     getExtendData:getExtendData,
-    getDefaultProgramID:getDefaultProgramID
+    getDefaultProgramID:getDefaultProgramID,
+    deleteSubListByQuery:deleteSubListByQuery
 };
 async function addNewRation(data,compilation) {
     let query = data.itemQuery;
@@ -201,13 +203,15 @@ async function addRationSubList(stdRation,newRation,needInstall,compilation) {
     let ration_coes = await addRationCoe(stdRation,newRation,compilation);
     let addRationCoeTime = +new Date();
     console.log("添加定额coe时间-----"+(addRationCoeTime - addRationGLJTime));
-    let ration_installs = [];
+    let ration_installations = [];
     if(needInstall && stdRation.type == 'std'){//只有标准的定额才有安装增加费,补充的定额没有安装增加费
-        ration_installs =  await addRationInstallFee(stdRation,newRation);
+        ration_installations =  await addRationInstallFee(stdRation,newRation);
     }
     let addRationInstallFeeTime = +new Date();
     console.log("添加定额install时间-----"+(addRationInstallFeeTime - addRationCoeTime));
-    return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installs:ration_installs};
+    //添加定额模板子目
+    let ration_template = await addRationTemplate(stdRation,newRation);
+    return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installations:ration_installations,ration_templates:[ration_template]};
 }
 
 async function addRationInstallFee(std,newRation) {
@@ -249,6 +253,38 @@ async function addRationInstallFee(std,newRation) {
     return install_fee_list;
 }
 
+async function addRationTemplate(std,newRation) {
+    let templateList = [];
+    if(std.hasOwnProperty('rationTemplateList') && std.rationTemplateList.length > 0){
+        for(let tem of std.rationTemplateList){
+            let template = {
+                billID:"",
+                fxID:"",
+                quantity:'',
+                coe:""
+            }
+            template.code = tem.code;
+            template.name = tem.name;
+            template.type = tem.type;
+            template.unit = tem.unit &&_.isString(tem.unit) ?tem.unit.replace(/^\d+/,""):"";
+            template.billsLocation = template.billsLocation
+            templateList.push(tem)
+        }
+    }
+    if(templateList.length > 0){
+        let ration_template = {};
+        ration_template.ID = uuidV1();
+        ration_template.projectID = newRation.projectID;
+        ration_template.rationID = newRation.ID;
+        ration_template.createLocation = 1; //默认模板子目分别放在措施项目下
+        ration_template.templateList = templateList;
+        await  rationTemplateModel.create(ration_template);
+        return ration_template;
+    }
+    return null;
+}
+
+
 async function addRationCoe(std,newRation,compilation) {
     let ration_coe_list = [];
     let seq = 0;
@@ -423,12 +459,18 @@ async function addRationGLJ(std,newRation,compilation) {
 async function deleRationSubRecode(projectID,rationID) {//删除挂在定额下的数据,如工程量明细,定额工料机等
     let delete_query={projectID: projectID, rationID: rationID};
     //删除工程量明细
-    await quantity_detail.deleteByQuery(delete_query) ;
+    await deleteSubListByQuery(delete_query) ;
+}
+
+async function deleteSubListByQuery(delete_query) {
+    await quantity_detail.deleteByQuery(delete_query) ;//删除工程量明细
     await ration_coe.deleteMany(delete_query);//删除附注条件
     await ration_glj.deleteMany(delete_query);//删除定额工料机
     await rationInstallationModel.deleteMany(delete_query);//删除安装增加费
+    await rationTemplateModel.deleteMany(delete_query);//删除模板关联子目
 }
 
+
 async function  updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity) {
     // insertNewRation
     let ration ={};

+ 21 - 0
modules/main/facade/ration_template_facade.js

@@ -0,0 +1,21 @@
+/**
+ * Created by zhang on 2018/11/26.
+ */
+
+let mongoose = require('mongoose');
+let rationTemplateModel = mongoose.model('ration_template');
+let consts = require('../models/project_consts');
+
+module.exports={
+    getData:getData,
+};
+
+function getData(projectID, callback) {
+    rationTemplateModel.find({'projectID': projectID}, (err, datas) => {
+        if (err) {
+            callback(1, '', null);
+        } else {
+            callback(0, consts.projectConst.RATION_TEMPLATE, datas);
+        }
+    })
+}

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

@@ -7,6 +7,7 @@ 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');
 let ration_installation = require('../facade/ration_installation_facade');
+let ration_template = require('../facade/ration_template_facade');
 var quantity_detail_data = require('../facade/quantity_detail_facade');
 var fee_rate_data = require('../../fee_rates/facade/fee_rates_facade');
 let projCounter = require('./proj_counter_model');
@@ -41,7 +42,7 @@ moduleMap[projectConsts.LABOUR_COE] = labour_coe_facade;
 moduleMap[projectConsts.CALC_PROGRAM] = calc_program_facade;
 moduleMap[projectConsts.PROJECTGLJ] = new GLJController();
 moduleMap[projectConsts.INSTALLATION_FEE] = installation_facade;
-
+moduleMap[projectConsts.RATION_TEMPLATE] = ration_template;
 
 var Project = function (){};
 

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

@@ -10,6 +10,7 @@ let projectConst = {
     RATION_COE:'ration_coe',
     RATION_ASS:'ration_ass',
     RATION_INSTALLATION:'ration_installation',
+    RATION_TEMPLATE:'ration_template',
     QUANTITY_DETAIL:'quantity_detail',
     PROJECTGLJ: 'projectGLJ',
     GLJLIST: 'GLJList',

+ 4 - 2
modules/ration_glj/facade/ration_glj_facade.js

@@ -316,13 +316,15 @@ async function doCustomQuantityUpdate(datas) {
 
 function delete_ration_glj(user_id, datas) {
     return function (callback) {
-        if (datas.deleteType == "RATION") {
+        callback(new Error("删除子数据失败!"),null)
+        //这个方法已经不用,先注释,稳定后再删除
+       /* if (datas.deleteType == "RATION") {
             deleteByRation(datas, callback);
         } else if (datas.deleteType == "BILL") {
             deleteByBill(user_id, datas, callback);
         } else {
             deleteByID(datas, callback);
-        }
+        }*/
     }
 }
 

+ 2 - 2
public/web/sheet/sheet_common.js

@@ -264,9 +264,9 @@ var sheetCommonObj = {
             for (var i = 0; i < setting.view.lockColumns.length; i++) {
                 let col = setting.view.lockColumns[i];
                 if(_.isString(col)){//如果是dataCode 进行转换
-                    col = _.findIndex(setting.header,{dataCode:tem})
+                    col = _.findIndex(setting.header,{dataCode:col})
                 }
-                sheet.getRange(-1,setting.view.lockColumns[i], -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
+                sheet.getRange(-1,col, -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
             }
         }
     },

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

@@ -187,7 +187,7 @@
                                   <li class="nav-item" id = "TZJNR_div">
                                       <a class="nav-link sub-item" id="linkTZJNR" data-toggle="tab" href="#subSpread" role="tab">特征及内容</a>
                                   </li>
-                                  <!--<li class="nav-item" id="MBZM_div">
+                                 <!-- <li class="nav-item" id="MBZM_div">
                                       <a class="nav-link sub-item" id="linkMBZM" data-toggle="tab" href="#subSpread" role="tab">模板子目</a>
                                   </li>-->
                               </ul>
@@ -216,7 +216,7 @@
                                                   <div class="row" style="border-bottom:1px solid #ccc">
                                                       <label class="col-auto col-form-label col-form-label-sm">提取位置</label>
                                                       <div class="col-2">
-                                                          <select class="form-control  form-control-sm" id="">
+                                                          <select class="form-control  form-control-sm" id="createLocation">
                                                               <option value="1">模板子目分别放在措施项目下</option>
                                                               <option value="2">模板子目分别放在分部分项下</option>
                                                               <option value="3">模板子目分别放在对应混凝土子目下</option>
@@ -1818,6 +1818,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_coe.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_ass.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_installation.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/ration_template.js"></script>
     <!--<script type="text/javascript" src="/web/building_saas/main/js/models/volume_price.js"></script>-->
     <script type="text/javascript" src="/web/building_saas/main/js/models/labour_coe.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/calc_program.js"></script>

+ 19 - 4
web/building_saas/main/js/controllers/block_controller.js

@@ -127,6 +127,7 @@ let BlockController = {
             data.ration_coes = projectObj.project.ration_coe.getCoeByRationID(data.ID);
             data.ration_installations =  projectObj.project.ration_installation.getInstallationByRationID(data.ID);
             data.quantity_details = projectObj.project.quantity_detail.getDetailByRationID(data.ID);
+            data.ration_template = projectObj.project.ration_template.getTemplateByRationID(data.ID);
         }else if(node.children.length>0){
             let children = [];
             for(let c of node.children){
@@ -290,10 +291,11 @@ let BlockController = {
         let mainTree = project.mainTree;
         Bills.addDatasToList(result.bills);
         Ration.addDatasToList(result.rations);
-        project.quantity_detail.addDatasToList(result.quantity_details);
+        Ration.addSubListOfRation(result);//这里是新插入定额时
+      /*  project.quantity_detail.addDatasToList(result.quantity_details);
         project.ration_glj.addDatasToList(result.ration_gljs);
         project.ration_coe.addDatasToList(result.ration_coes);
-        project.ration_installation.addDatasToList(result.ration_installations);
+        project.ration_installation.addDatasToList(result.ration_installations);*/
         for(let u of  result.updateData){
             let unode = mainTree.findNode(u.query.ID);
             if(unode){
@@ -390,7 +392,7 @@ let BlockController = {
     preparePasteData : function (datas,billsIDMap,firstParentID,lastNextID) {
         let me = this;
         me.datas = _.cloneDeep(projectObj.project.Bills.datas);
-        let bills = [],rations=[],ration_gljs = [],ration_coes = [],quantity_details = [],ration_installations = [];
+        let bills = [],rations=[],ration_gljs = [],ration_coes = [],quantity_details = [],ration_installations = [],ration_templates=[];
         let firstBillIDs = [],lastBillID = null;//记录第一层清单的ID,和第一层的最后一个清单ID
         let firstIDMap = {};
         for(let i = 0 ;i< datas.length ;i++){
@@ -420,7 +422,7 @@ let BlockController = {
         }
 
 
-        return {bills:bills,rations:rations,ration_gljs:ration_gljs,ration_coes:ration_coes,quantity_details:quantity_details,ration_installations:ration_installations};
+        return {bills:bills,rations:rations,ration_gljs:ration_gljs,ration_coes:ration_coes,quantity_details:quantity_details,ration_installations:ration_installations,ration_templates:ration_templates};
 
         function eachData(data) {
             if(data.sourceType == 'bills'){
@@ -453,10 +455,22 @@ let BlockController = {
                 for(let ri of data.ration_installations){
                     ration_installations.push(createSubList(ri,tem_r));
                 }
+                if(data.ration_template){
+                    ration_templates.push(createRationTemplate(data.ration_template,tem_r))
+                }
             }
 
         }
 
+        function createRationTemplate(oldTem,rationData) {
+            let template = _.cloneDeep(oldTem);
+            delete template._id;
+            template.ID = uuid.v1();
+            template.projectID = projectObj.project.ID();
+            template.rationID = rationData.ID;
+            return template;
+        }
+        
         function createSubList(subData,rationData) {
             let tem_sub = _.cloneDeep(subData);
             delete tem_sub._id;
@@ -490,6 +504,7 @@ let BlockController = {
             delete tem_ration.ration_coes;
             delete tem_ration.ration_installations;
             delete tem_ration.quantity_details;
+            delete tem_ration.referenceRationID;//删除关联的主定额信息
             delete tem_ration.__v;
             delete tem_ration.sourceType;
 

+ 1 - 7
web/building_saas/main/js/models/bills.js

@@ -756,9 +756,6 @@ var Bills = {
             CommonAjax.post("/bills/multiDelete", updateData, function () {
                 let quantity_detail_datas = project.quantity_detail.datas;
                 let ration_datas = project.Ration.datas;
-                let ration_glj_datas = project.ration_glj.datas;
-                let ration_coe_datas = project.ration_coe.datas;
-                let ration_install_datas = project.ration_installation.datas;
                 let nodes = controller.tree.nodes;
                 let prefix = controller.tree.prefix;
                 //更新缓存
@@ -777,10 +774,7 @@ var Bills = {
                 if(updateData['ration']){
                     for(let r_key in updateData['ration']){//定额只有删除,没有更新
                         _.remove(ration_datas,{'ID':r_key});
-                        _.remove(quantity_detail_datas,{'rationID':r_key});
-                        _.remove(ration_glj_datas,{'rationID':r_key});
-                        _.remove(ration_coe_datas,{'rationID':r_key});
-                        _.remove(ration_install_datas,{'rationID':r_key});
+                        project.Ration.deleteSubListOfRation({ID:r_key});
                     }
                 }
                 controller.m_delete(mainNodes);//删除树节点

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

@@ -12,6 +12,7 @@ const ModuleNames = {
     ration_coe:'ration_coe',
     ration_ass:'ration_ass',
     ration_installation:'ration_installation',
+    ration_template:'ration_template',
     quantity_detail:'quantity_detail',
     labour_coe: 'labour_coe',
     calc_program: 'calc_program',

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

@@ -80,6 +80,7 @@ var PROJECT = {
             this.ration_coe = ration_coe.createNew(this);
             this.ration_ass = ration_ass.createNew(this);
             this.ration_installation = ration_installation.createNew(this);
+            this.ration_template = ration_template.createNew(this);
             this.quantity_detail = quantity_detail.createNew(this);
             this.installation_fee = installation_fee.createNew(this);
             this.FeeRate = FeeRate.createNew(this);

+ 16 - 15
web/building_saas/main/js/models/ration.js

@@ -269,11 +269,7 @@ var Ration = {
         ration.prototype.delete = function (ration) {
             var ration_glj =projectObj.project.ration_glj;
             this.project.pushNow('deleteRation', [this.getSourceType(),ration_glj.getSourceType()], [this.getDeleteData(ration),ration_glj.getDeleteDataByRation(ration)]);
-
-            project.ration_glj.deleteByRation(ration);
-            project.ration_coe.deleteByRation(ration);
-            project.quantity_detail.deleteByRation(ration);
-            project.ration_installation.deleteByRation(ration);
+            this.deleteSubListOfRation(ration);
             this.datas.splice(this.datas.indexOf(ration), 1);
         };
         ration.prototype.removeByID = function(ID){
@@ -420,9 +416,8 @@ var Ration = {
                        project.ration_glj.removeNodeByRation(recode.ration,projectObj.mainController);
                        project.Ration.deleteSubListOfRation(recode.ration);//删除旧定额下的相关记录
                        //添加新的记录
-                       project.ration_glj.addDatasToList(recode.ration_gljs);
-                       project.ration_coe.addDatasToList(recode.ration_coes);
-                       project.ration_installation.addDatasToList(recode.ration_installs);
+                       project.Ration.addSubListOfRation(recode);
+
 
                        project.ration_glj.addToMainTree(recode.ration_gljs);
                    }
@@ -507,10 +502,7 @@ var Ration = {
                     //更新缓存
                     for(let data of rstData){
                         me.datas.push(data.ration);
-                        project.ration_glj.addDatasToList(data.ration_gljs);
-                        project.ration_coe.addDatasToList(data.ration_coes);
-                        project.ration_installation.addDatasToList(data.ration_installs);
-
+                        me.addSubListOfRation(data);
                         //插入树节点
                         newSource = data.ration;
                         newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
@@ -605,9 +597,8 @@ var Ration = {
                 CommonAjax.post("/ration/addNewRation",{itemQuery:itemQuery,newData:newData,defaultLibID: rationLibObj.getDefaultStdRationLibID(),calQuantity:calQuantity,brUpdate:brUpdate,needInstall:needInstall},function (data) {
                     //更新缓存
                     me.datas.push(data.ration);
-                    project.ration_glj.addDatasToList(data.ration_gljs);
-                    project.ration_coe.addDatasToList(data.ration_coes);
-                    project.ration_installation.addDatasToList(data.ration_installs);
+
+                    me.addSubListOfRation(data);
 
                     //插入树节点
                     newSource = data.ration;
@@ -686,6 +677,7 @@ var Ration = {
                 CommonAjax.post("/ration/addNewRation",{itemQuery:null,newData:newData,defaultLibID: rationLibObj.getDefaultStdRationLibID(),calQuantity:false,brUpdate:brUpdate,needInstall:false},function (data) {
                     //更新缓存
                     me.datas.push(data.ration);
+                    me.addSubListOfRation(data);
                     //插入树节点
                     newSource = data.ration;
                     newNode.source = newSource;
@@ -705,7 +697,16 @@ var Ration = {
             projectObj.project.ration_coe.deleteByRation(ration);
             projectObj.project.quantity_detail.deleteByRation(ration);
             projectObj.project.ration_installation.deleteByRation(ration);
+            projectObj.project.ration_template.deleteByRation(ration);
+        };
+        ration.prototype.addSubListOfRation = function (data) {
+             project.ration_glj.addDatasToList(data.ration_gljs);
+             project.ration_coe.addDatasToList(data.ration_coes);
+             project.ration_installation.addDatasToList(data.ration_installations);
+             project.ration_template.addDatasToList(data.ration_templates);
+             project.quantity_detail.addDatasToList(data.quantity_details);
         };
+
         ration.prototype.replaceRation = function (ration, std) {
             this.project.beginUpdate('replaceRation');
             

+ 38 - 0
web/building_saas/main/js/models/ration_template.js

@@ -0,0 +1,38 @@
+/**
+ * Created by zhang on 2018/11/26.
+ */
+let ration_template = {
+    createNew: function (project) {
+        let ration_template = function (proj){
+            this.datas = [];
+
+            var sourceType = ModuleNames.ration_template;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.ration_template, this);
+
+        };
+        // prototype用于定义public方法
+        ration_template.prototype.loadData = function (datas) {
+            this.datas = datas;
+        };
+        ration_template.prototype.addDatasToList = function (datas) {
+            let  me = this;
+            if(datas&&datas.length>0){
+                if (me.datas && Array.isArray(me.datas)) {
+                    me.datas = me.datas.concat(datas);
+                } else {
+                    me.datas = datas;
+                }
+            }
+        };
+        ration_template.prototype.getTemplateByRationID = function (rationID) {
+            return _.find(this.datas, {'rationID': rationID});
+        };
+        ration_template.prototype.deleteByRation = function(ration){
+            _.remove(this.datas,{'rationID':ration.ID});
+        };
+        return new ration_template(project);
+    }
+}

+ 41 - 10
web/building_saas/main/js/views/mbzm_view.js

@@ -4,35 +4,66 @@
 
 let mbzm_obj={
     spread:null,
+    datas:[],
     setting:{
         header: [
             {headerName: "编码", headerWidth: 130, dataCode: "code", dataType: "String", formatter: "@"},
-            {headerName: "模板类别", headerWidth: 260, dataCode: "templateType", dataType: "String", hAlign: "left"},
+            {headerName: "模板类别", headerWidth: 260, dataCode: "name", dataType: "String", hAlign: "left"},
             {headerName: "系数", headerWidth: 65, dataCode: "coe", dataType: "Number"},
             {headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center"},
             {headerName: "工程量", headerWidth: 65, dataCode: "quantity", dataType: "Number",decimalField: "ration.quantity"},
             {headerName: "关联类别", headerWidth: 100, dataCode: "type", dataType: "String"},
-            {headerName: "清单位置", headerWidth: 200, dataCode: "billsPosition", hAlign: "left", dataType: "String",cellType:'selectButton',getText:'forPosition'},
-            {headerName: "清单位置", headerWidth: 200, dataCode: "fxPosition", hAlign: "left", dataType: "String",cellType:'selectButton',getText:'forPosition',visible:false}
+            {headerName: "清单位置", headerWidth: 200, dataCode: "position", hAlign: "left", dataType: "String",cellType:'selectButton',getText:'forPosition'},
         ],
         view: {
-            lockColumns:["code","content","unit","type","billsPosition","fxPosition"],
+            lockColumns:["code","name","unit","type","fxID"],
             rowHeaderWidth:25
         },
-
+        getText:{
+            forPosition:function (item) {
+                return ""
+            }
+        }
     },
+    //当点击应用的时候才保存数据
     initSpread:function () {
         this.spread = SheetDataHelper.createNewSpread($("#mbzmSpread")[0]);
         sheetCommonObj.spreadDefaultStyle(this.spread);
         this.sheet = this.spread.getSheet(0);
         sheetCommonObj.initSheet(this.sheet, this.setting);
-        this.sheet.setRowCount(0);
-
     },
     refresh:function () {
-        this.spread?this.spread.refresh():'';
+        let total = $('#mbzmSpread').parent().height();
+        let b_height = $('#mbzmSpread').prev('.col-12').height();
+        $('#mbzmSpread').css('height',total- b_height);
+        this.spread?this.spread.refresh():this.initSpread();
     },
     showMBZMData:function(node){
-       let selected = node?node:projectObj.project.mainTree.selected;
+        let selected = node?node:projectObj.project.mainTree.selected;
+        let datas = [];
+        $("#createLocation").val(1);//初始化
+        if(selected&&selected.sourceType == "ration"){
+            let ration = selected.data;
+            let  template = projectObj.project.ration_template.getTemplateByRationID(ration.ID);
+            if(template) {
+                $("#createLocation").val(template.createLocation);
+                let pcol = _.findIndex(this.setting.header,{dataCode:"position"});
+                this.setting.header[pcol].visible = template.createLocation == 3?false:true;
+                datas = _.cloneDeep(template.templateList);
+            }
+        }
+        this.datas = datas;
+        sheetCommonObj.showData(this.sheet, this.setting,this.datas);
+        this.sheet.setRowCount(this.datas.length);
     }
-}
+};
+
+$('#createLocation').change(function(){
+    let me = mbzm_obj;
+    let pcol = _.findIndex(me.setting.header,{dataCode:"position"});
+    me.setting.header[pcol].visible = template.createLocation == 3?false:true;
+
+    $(this).val();
+
+    mbzm_obj.showMBZMData();
+});

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

@@ -601,12 +601,6 @@ $('#linkZMHS').on('shown.bs.tab', function (e) {
 
 
 $('#linkMBZM').on('shown.bs.tab', function (e) {
-    let total = $('#mbzmSpread').parent().height();
-    let b_height = $('#mbzmSpread').prev('.col-12').height();
-    $('#mbzmSpread').css('height',total- b_height);
-    if(mbzm_obj.spread == null){
-        mbzm_obj.initSpread();
-    }
     mbzm_obj.refresh();
     mbzm_obj.showMBZMData();
 });