zhangweicheng 7 년 전
부모
커밋
7bb597daa3

+ 3 - 8
modules/glj/controllers/glj_controller.js

@@ -237,6 +237,7 @@ class GLJController extends BaseController {
      */
     async getProjectInfo(request, response) {
         let projectId = request.body.project_id;
+        let rootProjectID = request.body.rootProjectID;
         projectId = parseInt(projectId);
         let responseData = {
             err: 0,
@@ -258,19 +259,13 @@ class GLJController extends BaseController {
                 other: []
             };
             for (let index in projectList) {
-                // 获取对应建设项目下所有的单位工程id
-                let idList = await ProjectModel.getTenderByProjectId(projectList[index].ID);
-                if (idList.length <= 0) {
-                    continue;
-                }
-
                 // 获取对应的单价文件
                 let unitPriceFileModel = new UnitPriceFileModel();
-                let unitPriceFileData = await unitPriceFileModel.getDataByTenderId(idList);
+                let unitPriceFileData = await unitPriceFileModel.getDataByRootProject(projectList[index].ID);
                 projectList[index].unitPriceList = unitPriceFileData;
 
                 // 归类
-                if (idList.indexOf(projectId) >= 0) {
+                if (rootProjectID == projectList[index].ID) {
                     result.self = unitPriceFileData;
                 } else {
                     result.other.push(projectList[index]);

+ 1 - 1
modules/pm/models/project_model.js

@@ -566,7 +566,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function (projectId) {
     }
 
     // 查找对应的单位工程id
-    let tenderData = await Projects.find({ParentID: {$in: engineeringIdList}});
+    let tenderData = await Projects.find({ParentID: {$in: engineeringIdList},deleteInfo: null});
     if (tenderData.length <= 0) {
         return result;
     }

+ 1 - 2
public/web/common_ajax.js

@@ -106,9 +106,8 @@ var CommonAjax = {
             success: function(response) {
                 // 修改失败则恢复原值
                 if (response.err !== 0) {
-                    alert('更改数据失败!');
                     if (errorCallback) {
-                        errorCallback();
+                        errorCallback(response);
                     }
                 } else {
                     if (successCallback) {

+ 5 - 5
web/building_saas/glj/html/glj_index.html

@@ -52,7 +52,7 @@
     </div>
 </div>
 <!--弹出更换-->
-<div class="modal fade" id="change-dj" data-backdrop="static">
+<!--<div class="modal fade" id="change-dj" data-backdrop="static">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
@@ -74,12 +74,12 @@
                         <span class="custom-control-description">从其他建设项目中复制</span>
                     </label>
                 </div>
-                <!--从本建设项目中选择-->
+                &lt;!&ndash;从本建设项目中选择&ndash;&gt;
                 <div class="form-group select option">
                     <label id="current-project-name"></label>
                     <select class="form-control" id="self-file"></select>
                 </div>
-                <!--从其他建设项目中复制-->
+                &lt;!&ndash;从其他建设项目中复制&ndash;&gt;
                 <div class="form-group copy option">
                     <label>选择建设项目</label>
                     <select class="form-control" id="other-project"></select>
@@ -96,7 +96,7 @@
         </div>
     </div>
 </div>
-<!--弹出 另存新文件-->
+&lt;!&ndash;弹出 另存新文件&ndash;&gt;
 <div class="modal fade" id="file-save-as-dialog" data-backdrop="static">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
@@ -119,4 +119,4 @@
             </div>
         </div>
     </div>
-</div>
+</div>-->

+ 10 - 11
web/building_saas/glj/html/project_glj.html

@@ -5,9 +5,9 @@
 </style>
 <div class="toolsbar px-1">
     <div class="form-inline py-1">
-        <label class="mx-2">当前使用:<span id="used-name"></span>(<a href="#" id="pop-dj_2" data-original-title="" title=""><span id="used-count_2">0</span> 单位工程使用</a>)
-            <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#change-dj_2"><i class="fa fa-exchange"></i> 选择其他</a>
-            <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#file-save-as-dialog_2"><i class="fa fa-files-o"></i> 另存单独用</a></label>
+        <label class="mx-2">当前使用:<span id="current-name"></span>(<a href="#" id="pop-used-list" data-original-title="" title=""><span id="used-project-count">0</span> 单位工程使用</a>)
+            <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#change-unitFile"><i class="fa fa-exchange"></i> 选择其他</a>
+            <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#unitFile-save-as"><i class="fa fa-files-o"></i> 另存单独用</a></label>
     </div>
 </div>
 <div class="container-fluid">
@@ -39,7 +39,6 @@
                     </div>
                     <div class="tab-pane" id="ph_div" role="tabpanel">
                         <div class="main-data-bottom" id="mix_ratio_sheet">
-                            test
                         </div>
                     </div>
              <!--       <div class="tab-pane" id="jx_div" role="tabpanel">
@@ -52,7 +51,7 @@
     </div>
 </div>
 <!--弹出更换-->
-<!--<div class="modal fade" id="change-dj" data-backdrop="static">
+<div class="modal fade" id="change-unitFile" data-backdrop="static">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
@@ -74,12 +73,12 @@
                         <span class="custom-control-description">从其他建设项目中复制</span>
                     </label>
                 </div>
-                &lt;!&ndash;从本建设项目中选择&ndash;&gt;
+                <!--从本建设项目中选择-->
                 <div class="form-group select option">
                     <label id="current-project-name"></label>
                     <select class="form-control" id="self-file"></select>
                 </div>
-                &lt;!&ndash;从其他建设项目中复制&ndash;&gt;
+                <!--从其他建设项目中复制-->
                 <div class="form-group copy option">
                     <label>选择建设项目</label>
                     <select class="form-control" id="other-project"></select>
@@ -96,12 +95,12 @@
         </div>
     </div>
 </div>
-&lt;!&ndash;弹出 另存新文件&ndash;&gt;
-<div class="modal fade" id="file-save-as-dialog" data-backdrop="static">
+<!--弹出 另存新文件-->
+<div class="modal fade" id="unitFile-save-as" data-backdrop="static">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
-                <h5 class="modal-title">另存新费率文件</h5>
+                <h5 class="modal-title">另存新单价文件</h5>
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                 </button>
@@ -119,4 +118,4 @@
             </div>
         </div>
     </div>
-</div>-->
+</div>

+ 8 - 83
web/building_saas/glj/js/project_glj.js

@@ -89,92 +89,17 @@ $(document).ready(function () {
         });
     });
 
-    // 单价文件另存为弹框
+  /*  // 单价文件另存为弹框
     $("#file-save-as-dialog").on('shown.bs.modal', function () {
         // 获取当前建设项数据
         $("#save-as-name").val(usedUnitPriceInfo.name + '(复件)');
-    });
-
-    // 单价文件另存为操作
-    $("#save-as-confirm").click(function () {
-        let name = $("#save-as-name").val();
-        if (name === '') {
-            $("#save-as-tips").text('请填写单价文件名称').show();
-            return false;
-        }
-        if (isChanging) {
-            return false;
-        }
-
-        $.ajax({
-            url: '/glj/save-as',
-            type: 'post',
-            data: {name: name, project_id: scUrlUtil.GetQueryString('project')},
-            dataType: 'json',
-            error: function () {
-                isChanging = false;
-            },
-            beforeSend: function () {
-                isChanging = true;
-            },
-            success: function (response) {
-                isChanging = false;
-                if (response.err === 1) {
-                    let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
-                    $("#save-as-tips").text(msg).show();
-                    return false;
-                }
-                projectObj.project.projectGLJ.loadData(function () {
-                    let projectGLJ = projectObj.project.projectGLJ;
-                    projectGLJ.loadCacheData();
-                    unitPriceFileInit();
-                    projectObj.project.calcProgram.calcAllNodesAndSave();
-                    gljOprObj.refreshView();
-                    if(socketObject.roomInfo){
-                        let data ={
-                            projectID:projectObj.project.ID(),
-                            oldRoom:socketObject.roomInfo.unitFile,
-                            newRoom:socketObject.getUnitFileRoomID(),
-                            name:'unitFile'
-                        }
-                        socket.emit('changeNewRoom',data);
-                        socketObject.roomInfo.unitFile = socketObject.getUnitFileRoomID();
-                    }
-                    $.bootstrapLoading.end();
-                });
-                $("#file-save-as-dialog").modal("hide");
-            }
-        });
+    });*/
 
-    });
 
-    // 从其他建设项目中复制 选择建设项目
-    $("#other-project").change(function () {
-        let projectId = $(this).val();
-        if (otherFileData[projectId] === undefined) {
-            return false;
-        }
-        let otherFileHtml = '';
-        for (let unitPrice of otherFileData[projectId]) {
-            otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
-        }
-        $("#other-file").html(otherFileHtml);
-    });
 
-    // 单价文件选项切换
-    $("input[name='change-type']").change(function () {
-        let type = $(this).val();
-        type = parseInt(type);
-        $("#change-dj .option").hide();
-        if (type === 0) {
-            $(".option.select").show();
-        } else {
-            $(".option.copy").show();
-        }
-    });
 
     // 单价文件切换确认
-    $("#change-file-confirm").click(function () {
+    /*$("#change-file-confirm").click(function () {
         if (isChanging) {
             return false;
         }
@@ -229,9 +154,9 @@ $(document).ready(function () {
                 });
             }
         });
-    });
+    });*/
 
-    // 是否主动更改数据
+/*    // 是否主动更改数据
     $("#message").on('click', '#load-data', function () {
         $("#message").html('正在加载...');
         // 重新加载数据到缓存
@@ -239,15 +164,15 @@ $(document).ready(function () {
             projectObj.project.projectGLJ.loadCacheData();
             $("#notify").slideUp('fast');
         });
-    });
+    });*/
 
-    $('#pop-dj').popover({
+    /*$('#pop-dj').popover({
             placement: "bottom",
             html: true,
             trigger: "hover | focus",
             content: getUsedTenderInfo
         }
-    );
+    );*/
 });
 
 /**

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

@@ -42,7 +42,6 @@
         <div class="main-nav">
             <ul class="nav nav-tabs flex-column" role="tablist">
                 <li class="nav-item"><a class="active" data-toggle="tab" href="#zaojiashu" id="tab_zaojiashu" role="tab">造价书</a></li>
-                <li class="nav-item"><a data-toggle="tab" href="#gongliaoji" id="tab_gongliaoji" data-name="tab_gongliaoji" role="tab">工料机</a></li>
                 <li class="nav-item"><a data-toggle="tab" href="#project_glj" id="tab_project_glj" data-name="tab_project_glj" role="tab">工料机新</a></li>
                 <li class="nav-item"><a data-toggle="tab" href="#fee_rates" id="tab_fee_rate" role="tab" >费率</a></li>
                 <li class="nav-item"><a data-toggle="tab" href="#calc_program_manage" id="tab_calc_program_manage" role="tab">计算程序</a></li>
@@ -270,9 +269,7 @@
                   </div>
               </div>
             </div>
-            <div class="tab-pane" id="gongliaoji" role="tabpanel">
-                <%include ../../glj/html/glj_index.html %>
-            </div>
+
             <div class="tab-pane" id="project_glj" role="tabpanel">
               <%include ../../glj/html/project_glj.html %>
             </div>

+ 65 - 1
web/building_saas/main/js/models/composition.js

@@ -85,4 +85,68 @@ Composition.prototype.getCompositionByGLJ = function (glj) {
         gljList =  gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
     }
     return gljList;
-}
+};
+
+Composition.prototype.deleteComposition = function (updateData,recode,pid,callback) {
+    let me = this;
+    $.bootstrapLoading.start();
+    CommonAjax.specialPost( '/glj/delete-ratio',{id: updateData.id},function (result){
+        me.updateConsumptionInCache(pid,recode,updateData,"delete");
+        if(callback){
+            callback();
+        }
+        $.bootstrapLoading.end();
+    })
+};
+
+Composition.prototype.updateConsumptionInCache = function (pid,recode,updateData,operation='modify') {
+    let decimal = getDecimal("glj.quantity");
+    let parentGlj = projectObj.project.projectGLJ.getByID(pid);//得到父工料机的数据
+    let ratioData = recode;
+    let con_key = gljOprObj.getIndex(ratioData,gljKeyArray);
+    let mglj = projectObj.project.projectGLJ.getByConKey(con_key);//取组成物对应的工料机;
+    if(mglj && parentGlj){
+        let newValue = scMathUtil.roundForObj(updateData.value,decimal);
+        let oldValue = scMathUtil.roundForObj(ratioData.consumption,decimal);
+        let changValue = scMathUtil.roundForObj(newValue-oldValue,decimal);
+        //乘以父工料机的消耗量得到该组成物总消耗量的改变量
+        changValue = operationWithRound(parentGlj.quantity,changValue,"glj.quantity","*");
+        let oldQuantity =  scMathUtil.roundForObj(mglj.quantity,decimal);
+        mglj.quantity = scMathUtil.roundToString(oldQuantity+changValue,decimal);
+        let p_key = gljOprObj.getIndex(parentGlj,gljKeyArray);
+        let m_list = projectObj.project.projectGLJ.datas.mixRatioMap[p_key];
+        if(operation == 'delete'){//如果是删除
+            _.remove(parentGlj.ratio_data,{"id":updateData.id});
+            _.remove(m_list,{"id":updateData.id});
+        }else {
+            let subData = _.find(parentGlj.ratio_data,{"id":updateData.id});
+            if(subData){
+                subData.consumption = updateData.value;
+            }
+            //更新组成物map里的数据
+            let m_ratioData = _.find(m_list,{"id":updateData.id});
+            if(m_ratioData){
+                m_ratioData.consumption = updateData.value;
+            }
+        }
+        // 设置父级3个价格
+        parentGlj.unit_price.market_price =  updateData.market_price;
+        parentGlj.unit_price.base_price =  updateData.base_price;
+    }
+}
+
+
+Composition.prototype.updateConsumption = function (updateData,recode,pid,callback){
+    console.log(updateData);
+    let me = this;
+    $.bootstrapLoading.start();
+    CommonAjax.specialPost( '/glj/update',updateData,function (result) {
+        //更新缓存
+        me.updateConsumptionInCache(pid,recode,updateData);
+        if(callback){
+            callback();
+        }
+        $.bootstrapLoading.end();
+    })
+
+};

+ 53 - 0
web/building_saas/main/js/models/project_glj.js

@@ -314,6 +314,51 @@ ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
     });
 };
 
+ProjectGLJ.prototype.getRatioData=function(id,callback){
+    if(id){
+        CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
+            let ratios = JSON.parse(response.data);
+            if(callback){
+                callback(ratios);
+            }
+        })
+    }else {
+        if(callback){
+            callback([]);
+        }
+    }
+};
+
+ProjectGLJ.prototype.changeFile = function (changeData,callback) {
+    $.bootstrapLoading.start();
+    CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
+        projectObj.project.projectGLJ.loadData(function () {
+            if(callback){
+                callback();
+            }
+            $.bootstrapLoading.end();
+        });
+    });
+};
+
+ProjectGLJ.prototype.saveAs = function (saveData,callback) {
+    $.bootstrapLoading.start();
+    CommonAjax.specialPost('/glj/save-as',saveData,function () {
+        projectObj.project.projectGLJ.loadData(function () {
+            if(callback){
+                callback();
+            }
+            $.bootstrapLoading.end();
+        });
+    },function (response) {
+        let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
+        $("#save-as-tips").text(msg).show();
+        $.bootstrapLoading.end();
+    });
+
+
+};
+
 //更新是否暂估
 ProjectGLJ.prototype.changeIsEvaluate=function (id){
     let projectGLJ = projectObj.project.projectGLJ;
@@ -348,6 +393,14 @@ ProjectGLJ.prototype.getByID = function (ID) {
     return _.find(this.datas.gljList,{'id':ID});
 };
 
+ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
+    return _.find(this.datas.gljList,function (item) {
+        let tem_key = gljOprObj.getIndex(item,gljKeyArray);
+        return tem_key == conkey
+    })
+};
+
+
 ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
     if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
         var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {

+ 375 - 22
web/building_saas/main/js/views/project_glj_view.js

@@ -2,6 +2,9 @@
  * Created by zhang on 2018/3/13.
  */
 projectGljObject={
+    showTag:'ration',//mixRatio/machine
+    mixRatioType: [gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO,gljType.MAIN_MATERIAL],
+    machineType: [gljType.GENERAL_MACHINE],
     projectGljSetting:{
         header: [
             {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String"},
@@ -10,7 +13,7 @@ projectGljObject={
             {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
             {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
             {headerName: "总消耗量", headerWidth: 100, dataCode: "quantity", hAlign: "right", dataType: "Number",decimalField:'glj.quantity'},
-            {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",decimalField:'glj.quantity',validator:"number"},
+            {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",decimalField:'glj.unitPrice',validator:"number"},
             {headerName: "调整价", headerWidth: 70, dataCode: "adjustPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice"},
             {headerName: "市场价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice",validator:"number"},
             {headerName: "是否暂估", headerWidth: 60, dataCode: "is_evaluate", hAlign: "center", dataType: "String",cellType:'checkBox'},
@@ -29,21 +32,24 @@ projectGljObject={
     projectGljSheetData:[],
     mixRatioSetting:{
         header:[
-            {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String"},
-            {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
-            {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
-            {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
-            {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",decimalField:'glj.quantity',validator:"number"},
-            {headerName: "调整价", headerWidth: 70, dataCode: "adjustPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice"},
-            {headerName: "市场价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice",validator:"number"}
+            {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
+            {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String"},
+            {headerName: "单位", headerWidth: 120, dataCode: "unit", hAlign: "center", dataType: "String"},
+            {headerName: "类型", headerWidth: 120, dataCode: "short_name", hAlign: "center", dataType: "String"},
+            {headerName: "定额价", headerWidth: 120, dataCode: "basePrice", hAlign: "right", dataType: "Number",decimalField:'glj.unitPrice',validator:"number"},
+            {headerName: "调整价", headerWidth: 120, dataCode: "adjustPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice"},
+            {headerName: "市场价", headerWidth: 120, dataCode: "marketPrice", hAlign: "right", dataType: "Number",decimalField:"glj.unitPrice",validator:"number"},
+            {headerName: "用量", headerWidth: 120, dataCode: "consumption", hAlign: "right", dataType: "Number",decimalField:"glj.quantity",validator:"number"}
         ],
         view: {
-            lockColumns: [0,1]
+            lockColumns: [0,1,2,3,4,5,6]
         }
     },
     mixRatioSpread:null,
     mixRatioSheet:null,
     mixRatioData:[],
+    usedTenderList:[],
+    usedUnitPriceInfo:null,
     initProjectGljSpread:function () {
         this.projectGljSpread = SheetDataHelper.createNewSpread($("#project_glj_sheet")[0]);
         this.projectGljSheet = this.projectGljSpread .getSheet(0);
@@ -52,6 +58,77 @@ projectGljObject={
         this.projectGljSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onProjectGljEditStarting);
         this.projectGljSheet.name('projectGljSheet');
     },
+    initMixRatio:function () {
+        let me = projectGljObject;
+        if(me.mixRatioSpread==null){
+            me.initMixRatioSpread();
+            me.initRightClick();
+        }
+        me.showMixRatioData();
+    },
+    initMixRatioSpread:function () {
+        this.mixRatioSpread = SheetDataHelper.createNewSpread($("#mix_ratio_sheet")[0]);
+        this.mixRatioSheet = this.mixRatioSpread .getSheet(0);
+        this.initSheet(this.mixRatioSheet,this.mixRatioSetting);
+        this.mixRatioSheet.name('mixRatioSheet');
+    },
+    unitPriceFileInit:function() {
+        let me = this;
+        let projectGLJ = projectObj.project.projectGLJ;
+        let data = projectGLJ.datas;
+        me.usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
+        me.usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
+            data.constData.usedUnitPriceInfo : {};
+        $("#current-name").text(me.usedUnitPriceInfo.name);
+        let usedCount = me.usedTenderList.length <= 0 ? 1 : me.usedTenderList.length;
+        $("#used-project-count").text(usedCount);
+    },
+    getUsedTenderInfo:function() {
+        return projectGljObject.usedTenderList.join("<br>");
+    },
+    showMixRatioData:function () {
+        let me = this,gljId = null;
+        let consumptionCol =  _.findIndex(me.mixRatioSetting.header, { 'dataCode': 'consumption'});
+        if(me.showTag == 'ration'){
+            return;
+        }else if(me.showTag == 'mixRatio'){
+            me.mixRatioSheet.setValue(0, consumptionCol, '用量', GC.Spread.Sheets.SheetArea.colHeader);
+        }else if(me.showTag == 'machine'){
+            me.mixRatioSheet.setValue(0, consumptionCol, '消耗量', GC.Spread.Sheets.SheetArea.colHeader);
+        }
+        let sel = me.projectGljSheet.getSelections()[0];
+        if(me.projectGljSheetData.length>sel.row){
+            gljId = me.projectGljSheetData[sel.row].id;
+        }
+        projectObj.project.projectGLJ.getRatioData(gljId,function (data) {
+            let rationList =[];
+            console.log(data);
+            for(let glj of data){
+                rationList.push(me.getMixRatioSheetData(glj)) ;
+            }
+            me.mixRatioData = rationList;
+            me.mixRatioSheet.setRowCount(0);
+            sheetCommonObj.showData(me.mixRatioSheet, me.mixRatioSetting,me.mixRatioData);
+            me.mixRatioSheet.setRowCount(me.mixRatioData.length);
+        })
+    },
+    getMixRatioSheetData:function (glj) {
+        let data ={
+            id:glj.id,
+            mix_ratio_id:glj.ratio_data.id,
+            code:glj.code,
+            name:glj.name,
+            specs:glj.specs,
+            unit:glj.unit,
+            type:glj.type,
+            short_name:projectObj.project.projectGLJ.getShortNameByID(glj.type),
+            consumption:glj.ratio_data.consumption,
+            unit_price:glj.unit_price
+        };
+        gljOprObj.setGLJPrice(data,glj);
+        return data;
+    },
+
     onProjectGljEditStarting:function (sender, args) {
         let me = projectGljObject;
         let row = args.row;
@@ -84,14 +161,13 @@ projectGljObject={
                 me.projectGljSheet.getCell(row, col,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
             }
         }
+        me.showMixRatioData();
         me.projectGljSheet.repaint();
     },
-
-
     showProjectGljData:function () {
         let projectGljSheetData = [];
         let gljList = projectObj.project.projectGLJ.datas.gljList;
-        gljList = filterProjectGLJ(gljList);
+        gljList = this.filterProjectGLJ(gljList);
         gljList = sortProjectGLJ(gljList);
         for(let glj of gljList){
             projectGljSheetData.push(this.getSheetDataByGLJ(glj));
@@ -101,6 +177,25 @@ projectGljObject={
         sheetCommonObj.showData(this.projectGljSheet, this.projectGljSetting,this.projectGljSheetData);
         this.projectGljSheet.setRowCount(this.projectGljSheetData.length);
     },
+    filterProjectGLJ:function (gljList) {
+        let me = projectGljObject;
+        if(gljList.length>0){
+            gljList = _.filter(gljList,function (item) {
+                if(item.quantity !== 0 && item.quantity !== '0'){//过滤掉消耗量为0的工料机
+                    //showTag:'ration',//mixRatio/machine
+                    if(me.showTag == 'ration'){
+                        return true;
+                    }else if(me.showTag == 'mixRatio'){
+                        return _.includes(me.mixRatioType,item.type)
+                    }else if(me.showTag == 'machine'){
+                        return _.includes(me.machineType,item.type)
+                    }
+                }
+                return false;
+            });
+        }
+        return gljList;
+    },
     getSheetDataByGLJ:function (glj) {
         let projectGLJ = projectObj.project.projectGLJ;
         let materialIdList = projectGLJ.datas.constData.materialIdList;
@@ -162,7 +257,90 @@ projectGljObject={
         let me = projectGljObject;
         if(info.sheetName=='projectGljSheet'){
             me.onProjectGLJValueChange(e,info);
+        }if(info.sheetName == 'mixRatioSheet'){
+            me.onMixRatioValueChange(e,info);
+        }
+    },
+    onMixRatioValueChange:function (e,info){
+        let composition = projectObj.project.composition;
+        let me = projectGljObject,row = info.row, col = info.col;
+        let dataCode = me.mixRatioSetting.header[col].dataCode;
+        let recode = me.mixRatioData[row];
+        let value = info.newValue;
+        if (!me.checkData(col,me.mixRatioSetting,value)) {
+            alert('输入的数据类型不对,请重新输入!');
+            me.mixRatioSheet.setValue(row, col, info.oldValue);
+            return false;
         }
+        value = scMathUtil.roundToString(value,getDecimal("glj.quantity"));
+        let [parentMarketPrice, parentBasePrice] = me.getCompositionSumPrice('modify', row, value);
+        let updateData ={id: recode.mix_ratio_id, field: 'mix_ratio.' + dataCode, value: value, market_price: parentMarketPrice, base_price: parentBasePrice};
+        let prow= projectGljObject.projectGljSheet.getActiveRowIndex();//取父机械或组成物的下标
+        let prowData = projectGljObject.projectGljSheetData[prow];
+        composition.updateConsumption(updateData,recode,prowData.id,function () {
+           me.refreshParentData(prow,prowData.id);
+        });
+    },
+    refreshParentData:function (row,pid) {
+        let me = this;
+        me.refreshProjectGljRow(row);
+        // 更新组成物缓存
+        projectObj.project.composition.loadData();
+        //选查找使用了父项目工料机的定额工料机
+        let updateNodes=[];
+        let ration_gljs = _.filter(projectObj.project.ration_glj.datas,{'projectGLJID':pid});
+        for(let rg of ration_gljs){
+            let node = projectObj.project.mainTree.getNodeByID(rg.rationID);
+            if(node){
+                updateNodes.push(node);
+            }
+        }
+        //或者是使用了父项目工料机的工料机类型的定额
+        let rations = _.filter(projectObj.project.Ration.datas,{'type':3,'projectGLJID':pid});
+        for(let r of rations){
+            let r_node = projectObj.project.mainTree.getNodeByID(r.ID);
+            if(r_node){
+                r_node.data.marketUnitFee =  projectGljObject.projectGljSheetData[row].marketPrice;//parentMarketPrice;//这里用显示的价格
+                updateNodes.push(r_node);
+            }
+        }
+        if(updateNodes.length>0){
+            projectObj.project.calcProgram.calcRationsAndSave(updateNodes);
+        }
+        gljOprObj.refreshView();
+    },
+
+    deleteMixRatio:function (row) {
+        let me = this, deleteRecode = me.mixRatioData[row];
+        let consumption = deleteRecode.consumption;
+        let [parentMarketPrice, parentBasePrice] = me.getCompositionSumPrice('delete', row);
+        let prow= projectGljObject.projectGljSheet.getActiveRowIndex();//取父机械或组成物的下标
+        let prowData = projectGljObject.projectGljSheetData[prow];
+        let updateData = {id: deleteRecode.mix_ratio_id, field: 'mix_ratio.consumption' , value: 0, market_price: parentMarketPrice, base_price: parentBasePrice};
+        projectObj.project.composition.deleteComposition(updateData,deleteRecode,prowData.id,function () {
+            me.refreshParentData(prow,prowData.id);
+            me.mixRatioSheet.deleteRows(row,1);
+        });
+    },
+    getCompositionSumPrice : function(scene, affectRow, newValue = 0) {
+        let me = this;
+        let parentMarketPrice = 0;
+        let parentBasePrice = 0;
+        for(let i = 0;i < me.mixRatioData.length;i++){
+            let ratio = me.mixRatioData[i];
+            let marketPrice = ratio.unit_price.marketPrice;
+            let basePrice = ratio.unit_price.base_price;
+            // 如果是删除则忽略即将被删除的行数据
+            if (scene === 'delete' && affectRow === i) {
+                continue;
+            }
+            let consumption = i === affectRow ? newValue : ratio.consumption;
+            parentMarketPrice += operationWithRound(consumption,marketPrice,"glj.unitPrice","*");
+            parentBasePrice += operationWithRound(consumption,basePrice,"glj.unitPrice","*");
+        }
+        parentMarketPrice = parentMarketPrice.toDecimal(getDecimal("glj.unitPrice"));
+        parentBasePrice = parentBasePrice.toDecimal(getDecimal("glj.unitPrice"));
+        return [parentMarketPrice, parentBasePrice];
     },
     onProjectGLJValueChange:function (e,info) {
         let projectGLJ = projectObj.project.projectGLJ;
@@ -236,27 +414,202 @@ projectGljObject={
                 break;
         }
         return result;
+    },
+    initRightClick : function() {
+        let activeSheet = this.mixRatioSheet;
+        let me = this;
+        $.contextMenu({
+            selector: '#mix_ratio_sheet',
+            build: function ($trigger, e) {
+                me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.mixRatioSpread);
+                return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
+                    me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
+            },
+            items: {
+                "deleteMixRatio": {
+                    name: "删除",
+                    icon: 'fa-trash-o',
+                    disabled: function () {
+                        return me.rightClickTarget.row === undefined;
+                    },
+                    callback: function (key, opt) {
+                        let row = me.rightClickTarget.row;
+                        me.deleteMixRatio(row);
+                    }
+                },
+            }
+        });
+    },
+    changeFileCallback:function(){
+        projectGljObject.unitPriceFileInit();
+        projectGljObject.showProjectGljData();
+        gljOprObj.refreshView();
+        projectObj.project.calcProgram.calcAllNodesAndSave();
+        if(socketObject.roomInfo){
+            let data ={
+                projectID:projectObj.project.ID(),
+                oldRoom:socketObject.roomInfo.unitFile,
+                newRoom:socketObject.getUnitFileRoomID(),
+                name:'unitFile'
+            };
+            socket.emit('changeNewRoom',data);
+            socketObject.roomInfo.unitFile = socketObject.getUnitFileRoomID();
+        }
     }
 };
 
 
 $(function () {
-    $('#tab_project_glj').on('show.bs.tab', function (e) {
+    $('#tab_project_glj').on('shown.bs.tab', function (e) {
         let me = projectGljObject;
         $(e.relatedTarget.hash).removeClass('active');
-        setTimeout(function () {
-            if(me.projectGljSpread==null){
-                me.initProjectGljSpread();
-            }
-            me.showProjectGljData();
-            loadSize("project-glj-main", function () {
-                me.projectGljSpread.refresh();
-            });
-        },1)
+        if(me.projectGljSpread==null){
+            me.initProjectGljSpread();
+        }
+        me.unitPriceFileInit();
+        me.showProjectGljData();
+        loadSize("project-glj-main", function () {
+            me.projectGljSpread.refresh();
+        });
+    });
+    $('#ration_link').on('shown.bs.tab', function (e) {
+        let me = projectGljObject;
+        me.showTag='ration';
+        me.showProjectGljData();
+    });
+    $('#mix_ratio_link').on('shown.bs.tab', function (e) {
+        let me = projectGljObject;
+        me.showTag='mixRatio';
+        me.showProjectGljData();
+        me.initMixRatio();
+    });
+    $('#machine_ratio_link').on('shown.bs.tab', function (e) {
+        let me = projectGljObject;
+        me.showTag='machine';
+        me.showProjectGljData();
+        me.initMixRatio();
     });
     slideResize($("#project-glj-main"), function () {
         projectGljObject.projectGljSpread.refresh();
     });
+    $('#pop-used-list').popover({
+            placement: "bottom",
+            html: true,
+            trigger: "hover | focus",
+            content: projectGljObject.getUsedTenderInfo
+        }
+    );
+    // 单价文件切换弹框
+    $('#change-unitFile').on('shown.bs.modal', function () {
+        // 获取当前建设项数据
+        let projectName = projectInfoObj.projectInfo.fullFolder !== undefined &&
+        projectInfoObj.projectInfo.fullFolder.length > 0 ? projectInfoObj.projectInfo.fullFolder[0] : '';
+        $("#current-project-name").text(projectName);
+        let rootProjectID = projectInfoObj.projectInfo.property.rootProjectID;
+        // 获取切换单价文件相关数据
+        $.ajax({
+            url: '/glj/get-project-info',
+            type: 'post',
+            data: {project_id: scUrlUtil.GetQueryString('project'),rootProjectID:rootProjectID},
+            dataType: 'json',
+            success: function (response) {
+                if (response.err === 1) {
+                    alert('数据传输错误!');
+                    return false;
+                }
+                let data = response.data;
+                // 本项目中的单价文件
+                if (data.self.length > 0) {
+                    let selfFileHtml = '';
+                    for (let tmp of data.self) {
+                        let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
+                        selfFileHtml += '<option' + select + ' value="' + tmp.id + '">' + tmp.name + '</option>';
+                    }
+                    $("#self-file").html(selfFileHtml);
+                }
+
+                // 其他建设项目数据
+                if (data.other.length > 0) {
+                    let otherProjectHtml = '';
+                    let otherFileHtml = '';
+                    for (let tmp of data.other) {
+                        otherProjectHtml += '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
+                        otherFileData[tmp.ID] = tmp.unitPriceList;
+                        if (otherFileHtml !== '') {
+                            continue;
+                        }
+                        for (let unitPrice of tmp.unitPriceList) {
+                            otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
+                        }
+                    }
+                    $("#other-project").html(otherProjectHtml);
+                    $("#other-file").html(otherFileHtml);
+                }
+            }
+        });
+    });
+    // 单价文件切换确认
+    $("#change-file-confirm").click(function () {
+        let type = $("input[name='change-type']:checked").val();
+        type = parseInt(type);
+        let changeUnitPriceId = 0;
+        if (type === 0) {
+            // 从本项目中选择
+            changeUnitPriceId = $("#self-file").val();
+        } else {
+            // 从其他项目中复制
+            changeUnitPriceId = $("#other-file").val();
+        }
+        $('#change-unitFile').modal("hide");
+        let data = {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId, type: type};
+        projectObj.project.projectGLJ.changeFile(data,function () {
+            projectGljObject.changeFileCallback();
+        })
+    });
+    // 单价文件选项切换
+    $("input[name='change-type']").change(function () {
+        let type = $(this).val();
+        type = parseInt(type);
+        $("#change-unitFile .option").hide();
+        if (type === 0) {
+            $(".option.select").show();
+        } else {
+            $(".option.copy").show();
+        }
+    });
+
+
+    $("#unitFile-save-as").on('shown.bs.modal', function () {
+        // 获取当前建设项数据
+        $("#save-as-name").val(projectGljObject.usedUnitPriceInfo.name + '(复件)');
+    });
+
+    // 从其他建设项目中复制 选择建设项目
+    $("#other-project").change(function () {
+        let projectId = $(this).val();
+        if (otherFileData[projectId] === undefined) {
+            return false;
+        }
+        let otherFileHtml = '';
+        for (let unitPrice of otherFileData[projectId]) {
+            otherFileHtml += '<option value="' + unitPrice.id + '">' + unitPrice.name + '</option>';
+        }
+        $("#other-file").html(otherFileHtml);
+    });
+
+    // 单价文件另存为操作
+    $("#save-as-confirm").click(function () {
+        let name = $("#save-as-name").val();
+        if (name === '') {
+            $("#save-as-tips").text('请填写单价文件名称').show();
+            return false;
+        }
+        let saveData = {name: name, project_id: scUrlUtil.GetQueryString('project')};
+        projectObj.project.projectGLJ.saveAs(saveData,function () {
+             projectGljObject.changeFileCallback();
+            $("#unitFile-save-as").modal("hide");
+        });
+    });
 });
 
 

+ 4 - 3
web/building_saas/main/js/views/project_view.js

@@ -579,6 +579,9 @@ var projectObj = {
                 that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.beforeTreeSelectedChange, that.beforeMainTreeSelectedChange);
                 that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, that.treeSelectedChanged);
 
+                that.mainSpread.getActiveSheet().startEdit();
+                that.mainSpread.getActiveSheet().endEdit();
+
                 that.mainSpread.bind(GC.Spread.Sheets.Events.LeaveCell, that.mainSpreadLeaveCell);
                 that.mainSpread.bind(GC.Spread.Sheets.Events.EnterCell, that.mainSpreadEnterCell);
                 that.mainSpread.bind(GC.Spread.Sheets.Events.EditStarting, that.mainSpreadEditStarting);
@@ -596,8 +599,7 @@ var projectObj = {
                 that.project.projectMarkChecking();//是否需要重新进行造价计算
                 installationFeeObj.engineeringTypeChecking();//检查是否安装工程
                 //初始需要触发一次点击表格事件,sheet.getAutoFitWidth值(获取单元格文本长度)才正确
-                that.mainSpread.getActiveSheet().startEdit();
-                that.mainSpread.getActiveSheet().endEdit();
+
             }
             else {
 
@@ -842,7 +844,6 @@ var projectObj = {
                 "calculateAll_RationContent": {
                     name: '造价计算',
                     callback: function () {
-                        $.bootstrapLoading.start();
                         project.calcProgram.calcAllNodesAndSave();
                     }
                 }