Sfoglia il codice sorgente

新加材料替换功能

zhangweicheng 6 anni fa
parent
commit
213b759deb

+ 24 - 0
public/web/sheet/sheet_common.js

@@ -181,6 +181,10 @@ var sheetCommonObj = {
             if(setting.header[col].cellType === "selectButton"){
                 this.setSelectButton(row,col,sheet,setting.header[col]);
             }
+            if(setting.header[col].cellType === "replaceButton"){
+                this.setReplaceButton(row,col,sheet,setting.header[col]);
+            }
+
             if(setting.header[col].cellType === "tipsCell"){
                 this.setTipsCell(row,col,sheet,setting.header[col]);
             }
@@ -425,6 +429,26 @@ var sheetCommonObj = {
         };
         sheet.setCellType(row, col,getSelectButton(header.headerWidth),GC.Spread.Sheets.SheetArea.viewport);
     },
+    setReplaceButton(row,col,sheet){
+        let replaceButton = function(){
+
+        };
+        replaceButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
+        replaceButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
+            GC.Spread.Sheets.CellTypes.Button.prototype.paint.apply(this,arguments);
+            if(value){
+                ctx.save();
+                ctx.fillStyle = "white";
+                let fh = options.fontInfo&&options.fontInfo.fontSize?options.fontInfo.fontSize:h-6;
+                ctx.fillText(value,x+(w+ctx.measureText(value).width)/2,y+(h+fh)/2-2);
+                ctx.restore();
+            }
+        };
+        let cellType = new replaceButton();
+        cellType.buttonBackColor("#07A0FF");
+        sheet.setCellType(row, col,cellType,GC.Spread.Sheets.SheetArea.viewport);
+    },
+
     setTipsCell(row,col,sheet,header){
         let TipCellType = function () {};
         TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();

+ 4 - 0
web/building_saas/css/custom.css

@@ -248,4 +248,8 @@ legend.legend{
     font-size:13px;
     color: black;
 }
+.ration_glj_spread{
+    width: 75%;
+    float: left;
+}
 

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

@@ -164,8 +164,8 @@
                               <!-- Tab panes -->
                               <div class="tab-content" id="tabCon">
                                   <div class="tab-pane active" id="subItems" role="tabpanel">
-                                      <div class="main-data-bottom ovf-hidden" id="subSpread" style="display: none" tabindex="0">
-                                      </div>
+                                      <div class="main-data-bottom ovf-hidden" id="subSpread" style="display: none" tabindex="0"></div>
+                                      <div class="main-data-bottom ovf-hidden" id="replaceM" style="float: left;width: 25%;display: none" ></div>
                                       <div class="main-data-bottom ovf-hidden" id="tabZMHS" style="display: none">
                                           <div class=" main-data-bottom ovf-hidden" style="width: 50%; float: left; margin: 0; padding:0;" id="coeSpread"></div>
                                           <div class=" main-data-bottom ovf-hidden" style="width: 50%; float: left; margin: 0; padding:0;" id="assSpread"></div>

+ 90 - 10
web/building_saas/main/js/controllers/material_controller.js

@@ -31,7 +31,6 @@ let MaterialController = {
             }
         });
     },
-
     startReplace:function (nodes,result) {//其实应该是批量修改工料机属性,与替换工料机不同
         let me = this,updateData = [];
         for(let n of nodes){
@@ -41,6 +40,10 @@ let MaterialController = {
                 if(r_list.length > 0) updateData.push(...r_list);
             }
         }
+        me.postReplace(updateData);
+    },
+    postReplace:function (updateData) {
+        let me = this;
         if(updateData.length == 0) return;
         $.bootstrapLoading.start();
         CommonAjax.post("/material/replace",updateData,function(result){
@@ -48,7 +51,6 @@ let MaterialController = {
             me.updateCacheAfterReplace(result)
         })
     },
-
     updateCacheAfterReplace:function (result){
         let nodes = [];
         for(let data of result){
@@ -72,7 +74,6 @@ let MaterialController = {
             ration_glj_model.refreshTreeNodeIfNeeded(glj);//刷新造价书上的树节点(如果需要)
         }
     },
-
     eachNode:function (node,item) {
         let replaceDatas =[];
         if(item && item.bills.rule){
@@ -83,7 +84,6 @@ let MaterialController = {
         }
         return replaceDatas;
     },
-
     getReplaceData:function (billsItemID,materialMap,replace_property) {
         let list = [];
         let replace_glj_list = this.findMatchRationGLJ(billsItemID,materialMap);//取出需要替换的工料机和对替换的材料内容
@@ -93,8 +93,6 @@ let MaterialController = {
         }
         return list;
     },
-
-
     getDoc:function (glj,material,replace_property) {//取定额工料机中需要修改的内容
         let doc = {},keyList = ['name','specs','type','unit'];
         for(let key of keyList){
@@ -106,8 +104,6 @@ let MaterialController = {
         return doc;
 
     },
-
-
     findMatchRationGLJ:function (billsItemID,materialMap) {//查找清单下匹配的需要替换的定额工料机
         let replaceList=[];
         for(let g of projectObj.project.ration_glj.datas){
@@ -136,7 +132,6 @@ let MaterialController = {
             callback(null);
         }
     },
-
     getKeyString:function (itemText,matchStr) {//截取关键数据
         itemText = itemText.replace(/:/g, ":");//中文字符转换为英文字符
         itemText = itemText.replace(matchStr,"@$@");//用特殊符号取代关键字,方便截取
@@ -149,6 +144,91 @@ let MaterialController = {
     },
     trim:function (str) {
         return str.replace(/(^\s*)|(\s*$)/g, "");
+    },
+    //--------------2018-10-08新加替换表格-----------------
+    setting:{
+        header:[
+            {headerName: "项目特征", headerWidth: 100, dataCode: "character", dataType: "String"},
+            {headerName: "内容", headerWidth: 225, dataCode: "context", dataType: "String"},
+            {headerName: "名称", headerWidth: 50, dataCode: "name", dataType: "String",hAlign: "center",cellType:"replaceButton"},
+            {headerName: "规格", headerWidth: 50, dataCode: "specs", dataType: "String",hAlign: "center",cellType:"replaceButton"},
+        ],
+        view: {
+            lockColumns: [0,1,2,3],
+            rowHeaderWidth:25
+        }
+    },
+    spread:null,
+    sheet:null,
+    datas:[],
+    showReplaceDiv:function (node) {
+        $("#subSpread").addClass("ration_glj_spread");
+        $("#replaceM").show();
+        this.showReplaceSpread(node);
+        refreshSubSpread();
+    },
+    hideReplaceDiv:function(){
+        $("#subSpread").removeClass("ration_glj_spread");
+        $("#replaceM").hide();
+        refreshSubSpread();
+    },
+    showReplaceSpread:function(node){
+        this.initSpread();
+        this.showData(node);
+    },
+    initSpread:function () {
+        if(!this.spread){
+            this.spread = SheetDataHelper.createNewSpread($("#replaceM")[0]);
+            this.initSheet();
+        }else {
+            this.spread.refresh();
+        }
+    },
+    initSheet:function(){
+        this.sheet = this.spread .getSheet(0);
+        sheetCommonObj.initSheet( this.sheet, this.setting);
+        this.spread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onReplaceButtonClick);
+        this.sheet.name('materialReplace');
+    },
+    showData:function(node){
+        this.datas = [];
+        let parent = node.parent;
+        if(parent){
+            this.getItems(parent.data.itemCharacterText);
+        }
+        sheetCommonObj.showData(this.sheet, this.setting,this.datas);
+        this.sheet.setRowCount(this.datas.length);
+    },
+    getItems:function(characterText){
+        if(!characterText) return;
+        let strArray =  characterText.split(/\n/);
+        for(let tem of strArray){
+            tem = tem.replace(/:/g, ":");//中文字符转换为英文字符
+            if(tem.indexOf(":") != -1){//有:号才提取
+                let proArr = tem.split(":");
+                //如果内容为空的话也不提取
+                let context = this.trim(proArr[1]);
+                if(context!="") this.datas.push({character:proArr[0],context:context,name:"换",specs:"换"})
+            }
+        }
+    },
+    onReplaceButtonClick:function(e, args){
+        let me = MaterialController;
+        let sheet = args.sheet, row = args.row, col = args.col;
+        let dataCode = me.setting.header[col].dataCode, item = me.datas[row], doc = {};
+        if(dataCode && item){
+            doc[dataCode] = item.context;
+            me.replaceByClick(doc);
+        }
+    },
+    replaceByClick:function (tem) {
+        let ration_glj = gljOprObj.getSelectedRationGlj();
+        let doc = {};
+        if(ration_glj && !ration_glj.isMixRatio){//有选中并且不是组成物
+            for(let key in tem){//检查属性是否做了改变,如果没有改变不用提交替换
+                if(ration_glj[key] != tem[key]) doc[key] = tem[key]
+            }
+            if(!_.isEmpty(doc)) this.postReplace([{glj:ration_glj,doc:doc}])
+        }
     }
-
 };

+ 13 - 1
web/building_saas/main/js/views/glj_view.js

@@ -510,13 +510,17 @@ var gljOprObj = {
                 if(node.data.type==rationType.gljRation){
                     if($('#linkGLJ').hasClass('active'))  this.showMixRatio(node);
                 }else {
-                    if($('#linkGLJ').hasClass('active')) this.showRationGLJData(node);
+                    if($('#linkGLJ').hasClass('active')){
+                        this.showRationGLJData(node);
+                        MaterialController.showReplaceDiv(node);
+                    }
                     if($('#linkAZZJF').hasClass('active')) installationFeeObj.showRationInstallationData(node);
                 }
                 isShow = true;
             }
             if(node.sourceType == ModuleNames.ration_glj){
                 if($('#linkGLJ').hasClass('active')) this.showMixRatio(node);
+                MaterialController.hideReplaceDiv();
                 isShow = true;
             }
             if($('#linkGCLMX').hasClass('active')) this.showQuantityDetailData(node);
@@ -526,6 +530,7 @@ var gljOprObj = {
         }
         if (!isShow) {
             this.clearSheetData();
+            MaterialController.hideReplaceDiv();
         }
         //子目换算
         zmhs_obj.showZMHSData(node);
@@ -595,6 +600,13 @@ var gljOprObj = {
         this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: this.sheet.getActiveColumnIndex()});
 
     },
+    getSelectedRationGlj:function () {
+        let selected = this.sheet.getSelections()[0];
+        let ration_glj = this.sheetData[selected.row];
+        return ration_glj;
+    },
+
+
     getUnitPriceCodeMap : function () {//取单价文件中,编码前缀一样的映射表
         let codeMap = {};
         let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;

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

@@ -64,20 +64,21 @@ let subObj = {
 
 $("#linkGLJ").click(function(){
     $("#subItems").children().hide();//控制显示subSpread,隐藏特征及内容spread
+    //show
+    MaterialController.showReplaceDiv();
     $("#subSpread").show();
     pageCCOprObj.active = false;
     subSpread.options.allowUserDragFill = false;
     refreshSubSpread();
     subSpread.setActiveSheetIndex(0);
     gljOprObj.activeTab='#linkGLJ';
-    // for test
-    //subSpread.getActiveSheet().setValue(0, 0, "工料机");
 });
 
 
 
 $("#linkAZZJF").click(function(){
     $("#subItems").children().hide();
+    MaterialController.hideReplaceDiv();
     $("#subSpread").show();
     pageCCOprObj.active = false;
     refreshSubSpread();
@@ -87,6 +88,7 @@ $("#linkAZZJF").click(function(){
 
 $("#linkGCLMX").click(function(){
     $("#subItems").children().hide();
+    MaterialController.hideReplaceDiv();
     $("#subSpread").show();
     subSpread.options.allowUserDragFill = true;
     pageCCOprObj.active = false;
@@ -97,6 +99,7 @@ $("#linkGCLMX").click(function(){
 
 $("#linkJSCX").click(function(){        // 计算程序
     $("#subItems").children().hide();
+    MaterialController.hideReplaceDiv();
     $("#subSpread").show();
     pageCCOprObj.active = false;
     refreshSubSpread();