Browse Source

Merge branch '1.0.0_online' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost into 1.0.0_online

zhongzewei 6 years ago
parent
commit
9ee52b5ce5

+ 35 - 0
modules/all_models/block_lib_model.js

@@ -0,0 +1,35 @@
+/**
+ * Created by CSL on 2018-12-17.
+ */
+let mongoose = require('mongoose');
+let Schema = mongoose.Schema;
+
+let dataSchema = new Schema({
+    ID: String,
+    NextSiblingID: String,
+    ParentID: String,
+    children: [],
+    code: String,
+    compilationID: String,
+    copyTime: Number,
+    firstNodeType: Number,
+    isFBFX: {type: Boolean, default: true},
+    itemCharacterText: String,
+    name: String,
+    nodeName: String,
+    type: Number,
+    unit: String,
+    unitFee: String,
+    _id: false
+},{versionKey:false});
+
+let blockLibsSchema = new Schema({
+    userID: String,
+    compilationID: String,
+    libID: Number,
+    libName: String,
+    datas: [dataSchema],
+    share: {}
+},{versionKey:false});
+
+mongoose.model('blockLibsModel', blockLibsSchema, 'block_libs');

+ 3 - 0
modules/all_models/ration_coe.js

@@ -20,6 +20,9 @@ var coeListSchema = mongoose.Schema({
     ID: String,                         // 系数ID(流水号ID)
     name: String,                       // 名称
     content: String,                    // 说明
+    original_code:String,               //原人材机编码
+    option_codes:String,                //可选人材机编码
+    select_code:String,
     rationID:String,
     projectID:Number,
     coeID:Number,

+ 2 - 0
modules/all_models/stdRation_coe.js

@@ -23,6 +23,8 @@ const coeListSchema = new Schema({
     serialNo: Number,                  //编号
     name: String,                       // 名称
     content: String,                    // 说明
+    original_code:String,               //原人材机编码
+    option_codes:String,                //可选人材机编码
     coes: [coeSchema]
 }, {versionKey: false});
 

+ 23 - 0
modules/main/controllers/block_lib_controller.js

@@ -0,0 +1,23 @@
+/**
+ * Created by CSL on 2018-12-17.
+ */
+
+let mongoose = require('mongoose');
+let blFacade = require('../facade/block_lib_facade');
+
+module.exports = {
+    doController: async function (req, res) {
+        let result = {error: 0, message: '', data: null};
+        try {
+            let funcName = req.url.replace(/\//g, "");
+            let dataObj = JSON.parse(req.body.data);
+            result.data = await blFacade[funcName](dataObj);
+        } catch (err) {
+            console.log(err);
+            result.error = 1;
+            result.message = err.message;
+        }
+        res.json(result);
+    }
+};
+

+ 38 - 0
modules/main/facade/block_lib_facade.js

@@ -0,0 +1,38 @@
+/**
+ * Created by CSL on 2018-12-17.
+ */
+
+let mongoose = require('mongoose');
+let blModel = mongoose.model('blockLibsModel');
+
+module.exports = {
+    getLibNames: getLibNames,
+    getLib: getLib,
+    getLibNamesAndFirstLib: getLibNamesAndFirstLib,
+    saveBlock: saveBlock
+};
+
+// userID、compilationID
+async function getLibNames(data) {
+    let libNames = await blModel.find({userID: data.userID, compilation: data.compilationID}, ["libID","libName","-_id"]);
+    return libNames;
+};
+
+// libID
+async function getLib(data) {
+    let lib = await blModel.findOne({libID: data.libID});
+    return lib;
+};
+
+// userID、compilationID
+async function getLibNamesAndFirstLib(data) {
+    let libNames = await getLibNames(data);
+    let firstLib = await getLib(libNames[0]);
+    return {libNames: libNames, firstLib: firstLib};
+};
+
+// libID
+async function saveBlock(data) {
+    await blModel.update({libID: data.libID}, {"$addToSet": {"datas": data}});
+    return 'saveBlock.OK';
+};

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

@@ -310,6 +310,8 @@ async function addRationCoe(std,newRation,compilation) {
                 newCoe.seq = seq;
                 newCoe.name = libCoe.name;
                 newCoe.content = libCoe.content;
+                newCoe.original_code = libCoe.original_code;
+                newCoe.option_codes = libCoe.option_codes;
                 newCoe.isAdjust=0;
                 newCoe.coes = libCoe.coes;
                 newCoe.rationID = newRation.ID;
@@ -488,7 +490,7 @@ async function updateCoeAdjust(data,compilation) {
         }
     }
 
-    let cal_result = await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID});
+    let cal_result = await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID},null,true);
     let coe = {
         query:{ID:data.ID,projectID:data.projectID},
         doc:data.doc
@@ -499,16 +501,13 @@ async function updateCoeAdjust(data,compilation) {
     };
     let ration = {
         ID:cal_result.rationID,
-        adjustState:cal_result.adjustState
+        adjustState:cal_result.adjustState,
+        name:cal_result.rationName
     };
     return {coe:coe,ration_glj:ration_glj,ration:ration,add:data.add,delete:data.delete,replace:replace}
 
 }
 
-function addGLJByCoe(code,engineerID,rationID,projectID) {//通过单个工料机类型编号添加
-
-}
-
 
 
 async function  updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity) {

+ 19 - 0
modules/main/routes/block_lib_route.js

@@ -0,0 +1,19 @@
+/**
+ * Created by CSL on 2018-12-14.
+ */
+
+let express = require('express');
+let blController = require('../controllers/block_lib_controller');
+
+module.exports = function (app) {
+    let blRouter = express.Router();
+    let funcNames = ['getLibNames', 'getLib', 'getLibNamesAndFirstLib', 'saveBlock'];
+    for (let name of funcNames) {
+        blRouter.post(`/${name}`, blController.doController);
+    }
+    app.use('/blockLib', blRouter);
+}
+
+
+
+

+ 37 - 17
modules/ration_glj/facade/glj_calculate_facade.js

@@ -66,8 +66,7 @@ async function calculateQuantity(query,noNeedCal,refreshRationName = false){
          }
          gljList = sortRationGLJ(gljList);
          for(let i =0;i<gljList.length;i++ ){
-             let isLast = i == gljList.length -1;
-             let r = await calculateQuantityPerGLJ(gljList[i],isLast,coeList,assList,adjustState,noNeedCal);
+             let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,noNeedCal);
              result.glj_result.push(r);
          }
 
@@ -137,7 +136,7 @@ function sortRationGLJ(list) {
     return list;
 }
 
-async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,noNeedCal) {
+async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,noNeedCal) {
     let decimalObject =await decimal_facade.getProjectDecimal(glj.projectID);
     let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
     let quantity =  scMathUtil.roundTo(parseFloat(glj.quantity),-decimal);
@@ -155,7 +154,7 @@ async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,no
             if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""){
                 quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal);
                 quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
-                quantity = calculateQuantityByCoes(quantity,coeList,glj);
+                quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
             }else {
                 quantity = glj.customQuantity;
                 result.doc.customQuantity = glj.customQuantity;
@@ -163,11 +162,12 @@ async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,no
             let customerCoe = _.last(coeList);
             if(customerCoe&&customerCoe.isAdjust==1){
                 quantity = scMathUtil.roundToString(quantity,decimal);
-                quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj);
+                quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj,decimal);
             }
             result.doc.quantity =scMathUtil.roundToString(quantity,decimal);
+            glj.quantity = quantity;//这里保存中间过程计算出来的消耗量,后面处理“+*”操作符时要用到
         }
-        generateAdjustState(glj,coeList,adjustState,isLast,result.doc.quantity);
+        generateAdjustState(glj,coeList,adjustState,gljList,result.doc.quantity);
         return result;
     }catch (err){
         throw err;
@@ -199,7 +199,7 @@ async function calculateAss(quantity,assList,glj) {
     return scMathUtil.roundTo(quantity,-6);
 }
 
-function generateAdjustState(glj,coeList,adjustState,isLast,quantity) {
+function generateAdjustState(glj,coeList,adjustState,gljList,quantity) {
    //替换工料机 and 添加工料机
     if(glj._doc.createType=='replace'&&glj.rcode!=glj.code){
         adjustState.push({index:stateSeq.replace,content:glj.rcode+'换'+glj.code});
@@ -214,17 +214,21 @@ function generateAdjustState(glj,coeList,adjustState,isLast,quantity) {
     // to do
 
   //标准附注条件调整 + 自定义乘系数
-    if(isLast){//最后一个工料机的时候才生成,生成一次就可以了
+    if(_.last(gljList).ID == glj.ID){//最后一个工料机的时候才生成,生成一次就可以了
         for(let i=0;i<coeList.length;i++){
             if(coeList[i].isAdjust==1){
                 if(i==coeList.length-1){
                     adjustState.push({index:stateSeq.cusCoe,content:getContent(coeList[i].coes)});//自定义乘系数要去掉倍数为1的
                 }else {
+                    if(coeList[i].select_code && coeList[i].select_code!=""){
+                        _.remove(adjustState,{'content':coeList[i].original_code+'换'+coeList[i].select_code});//去掉替换工料机自动生成的调整状态
+                        adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].original_code+'换'+coeList[i].select_code});
+                    }
                     for(let c of coeList[i].coes){
                         if(c.coeType=='单个工料机') _.remove(adjustState,{'type':"添"+c.gljCode});//如果是单个工料机子目换算类型自动添加的,去掉前面手动生成的调整状态
                         if(c.coeType=='替换人材机') _.remove(adjustState,{'content':c.gljCode+'换'+c.replaceCode});//如果是替换人材机子目换算类型自动添加的,去掉前面手动生成的调整状态
                     }
-                    adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content
+                    if(coeList[i].content) adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content
                 }
             }
         }
@@ -295,28 +299,30 @@ function calculateTimes(ass){
     return scMathUtil.roundTo(times,-6);
 }
 
-function calculateQuantityByCoes(quantity,coeList,glj){
+function calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal){
     let coeQuantity = quantity;
     if(coeList.length>1){
         for(let i=0;i<coeList.length-1;i++){
-            coeQuantity = everyCoe(coeQuantity,coeList[i],glj);
+            coeQuantity = everyCoe(coeQuantity,coeList[i],glj,gljList,decimal);
         }
     }
     return scMathUtil.roundTo(coeQuantity,-6);
 }
 
-function everyCoe(quantity,coe,glj) {
+function everyCoe(quantity,coe,glj,gljList,decimal) {
     let coeQuantity = quantity;
     if(coe.isAdjust==1){
         for(let i=0;i<coe.coes.length;i++){
             if(coe.coes[i].coeType=='单个工料机' &&coe.coes[i].gljCode==glj.code){//if(coe.coes[i].coeType=='单个工料机'&&coe.coes[i].gljCode==glj.code)
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             }else if(coe.coes[i].coeType== "替换人材机" && glj.rcode == coe.coes[i].gljCode && glj.code == coe.coes[i].replaceCode){
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
+            }else if(coe.coes[i].coeType== "所选人材机" && glj.rcode == coe.original_code && glj.code == coe.select_code ){
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             } else if(coe.coes[i].coeType=='定额'){
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             }else if(coeTypeMap[coe.coes[i].coeType]==getRootGLJType(glj.type).ID){
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             }
         }
     }
@@ -338,7 +344,15 @@ function calculateQuantityByCustomerCoes(quantify,coe,glj) {
     return quantify
 }
 
-function getCalculateResult(quantify,c) {
+function getCoeSelectedGLJ(gljList,rcode,code) {
+    if(gljList&& code && code !=""){
+        let o_glj = _.find(gljList,{'rcode':rcode,'code':code});
+        return o_glj;
+    }
+    return null;
+}
+
+function getCalculateResult(quantify,c,coe,gljList,decimal) {
     let q = quantify;
     switch (c.operator){
         case '+' :
@@ -353,6 +367,12 @@ function getCalculateResult(quantify,c) {
         case '/' :
             q = q / c.amount;
             break;
+        case '+*' :
+            let o_glj = getCoeSelectedGLJ(gljList,coe.original_code,coe.select_code);
+            if(o_glj){
+              q = q +  c.amount * scMathUtil.roundForObj(o_glj.quantity,decimal);
+            }
+            break;
         case '=' :
              q = c.amount;
             break;

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

@@ -612,7 +612,7 @@
                               <div class="tab-pane" id="kmbk">
                                   <div class="tools-bar-height-d container-fluid" id="kmbkToolsBar">
                                       <div class="p-1 row">
-                                          <select class="form-control form-control-sm col-6" id="exampleSelect1">
+                                          <select class="form-control form-control-sm col-6" id="select_block_lib_names">
                                               <option>我的模板库</option>
                                           </select>
                                           <div class="col-6">

+ 43 - 10
web/building_saas/main/js/models/ration_coe.js

@@ -127,21 +127,25 @@ var ration_coe = {
             updateData.push(newobj);
             return updateData;
         };
-        ration_coe.prototype.adjustCoeClick = function(recode,newval){
+        ration_coe.prototype.adjustCoeClick = function(record,newval,ext){
             let me=this,codesList = [],add=[],replace=[];
+            let doc = ext?ext:{};
+            doc['isAdjust'] = newval;
             var updateData = {
-                'ID':recode.ID,
-                'projectID': recode.projectID,
-                'rationID':recode.rationID,
-                'doc':{
-                    isAdjust:newval
-                },
+                'ID':record.ID,
+                'projectID': record.projectID,
+                'rationID':record.rationID,
+                'doc':doc,
                 add:[],
                 delete:[],
                 replace:[]
             };
-            let gljList = project.ration_glj.getGLJListByRationID(recode.rationID);
-            for(let coe of recode.coes){//做单个、替换等检查
+            let gljList = project.ration_glj.getGLJListByRationID(record.rationID);
+            if(gljUtil.isDef(record.option_codes)&&record.option_codes!=""){ //说明编辑的是下拉选择编号的类型
+                this.prepareDataForOptionType(record,newval,gljList,updateData,replace,codesList,ext);
+            }
+
+            for(let coe of record.coes){//做单个、替换等检查
                 if(coe.coeType == "单个工料机"){ //单个工料机的情况
                     let glj = _.find(gljList,{"code":coe.gljCode});
                     if(newval == 1){ //单个工料机,选中时,如果能找到则不管,如果没找到,则需自动插入
@@ -175,7 +179,7 @@ var ration_coe = {
                 let gljMap = _.indexBy(gljList, 'code');
                 for(let a of add){
                     if(gljMap[a]){
-                        let tem = project.ration_glj.getAddDataByStd(gljMap[a],recode.rationID,project.mainTree.selected.data.billsItemID,recode.projectID);
+                        let tem = project.ration_glj.getAddDataByStd(gljMap[a],record.rationID,project.mainTree.selected.data.billsItemID,record.projectID);
                         updateData.add.push(tem);
                     }
                 }
@@ -194,6 +198,35 @@ var ration_coe = {
             });
 
         };
+        ration_coe.prototype.prepareDataForOptionType = function (record,newval,gljList,updateData,replace,codesList,ext) {
+            let select_code = record.select_code;
+            if(ext && gljUtil.isDef(ext.select_code)&&ext.select_code!=""){//是下拉框选择了人材机编号进来的
+                select_code = ext.select_code;
+            }
+            if(gljUtil.isDef(select_code) && select_code!=""){//有选中编号的情况下,才会做这些操作
+                let glj = _.find(gljList,{"rcode":record.original_code,'code':select_code});//两个条件都满足,则表示已找到对应的记录
+                if(newval == 1){
+                    if(!glj){//在没找到的情况下,要替换
+                        let r_glj = _.find(gljList,function (g) {
+                            return (g.code == record.original_code && (g.createType===undefined || g.createType == 'normal')) || g.rcode == record.original_code //这两个满足一个说明要替换
+                        });
+                        if(r_glj){
+                            replace.push({code:select_code,oldData:r_glj});
+                            codesList.push(select_code);
+                        }
+                    }
+                }else {
+                    updateData.doc['select_code'] = ""; //取消勾选,选中值要恢复为空
+                    if(glj){//如果找到工料机,还需要恢复成原来的
+                        replace.push({code:record.original_code,oldData:glj});
+                        codesList.push(record.original_code);
+                    }
+                }
+            }
+        };
+
+
+
 
         ration_coe.prototype.updateCustomerCoe = function (data) {
             var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');

+ 71 - 41
web/building_saas/main/js/views/block_lib.js

@@ -3,6 +3,8 @@
  * Created by CSL on 2018-09-19.
  */
 var blockLibObj = {
+    libs: [],
+    activeLib: null,
     mainSpread: null,
     mainSheet: null,
     mainTree: null,
@@ -67,10 +69,10 @@ var blockLibObj = {
     },
     cloneType: null,
 
-    buildSheet: function () {
+    buildSheet: async function () {
         $.bootstrapLoading.start();
         let me = this;
-        me.mainDatas = [
+       /* me.mainDatas = [
             {ID: 1, ParentID: -1, NextSiblingID: 2, nodeName: '分类1', type: 1},
             {ID: 2, ParentID: -1, NextSiblingID: 3, nodeName: '分类2', type: 1},
             {ID: 3, ParentID: -1, NextSiblingID: 4, nodeName: '分类3', type: 1},
@@ -79,9 +81,10 @@ var blockLibObj = {
             {ID: 7, ParentID: -1, NextSiblingID: 8, nodeName: '分类7', type: 1},
             {ID: 9, ParentID: -1, NextSiblingID: -1, nodeName: '分类9', type: 1}//,
             // {ID: 201, ParentID: 52, NextSiblingID: -1, nodeName: '块201', type: 2}
-        ];
+        ];*/
 
-        if (me.mainSpread) {
+       if (me.libs.length > 0) me.libs.splice(0, me.libs.length);
+       if (me.mainSpread) {
             me.mainSpread.destroy();
             me.mainSpread = null;
         };
@@ -94,6 +97,21 @@ var blockLibObj = {
             me.rationSpread = null;
         };
 
+        let namesAndLib = await ajaxPost('/blockLib/getLibNamesAndFirstLib', {userID: userID, compilationID: projectInfoObj.projectInfo.compilation});
+        me.mainDatas = namesAndLib.firstLib.datas;
+        me.libs.push(namesAndLib.firstLib);
+        me.activeLib = namesAndLib.firstLib;
+
+        function getLibNamesHtml(libsArr) {
+            let result = '';
+            for (let lib of libsArr) {
+                result += '<option value="' + lib.libID + '">' + lib.libName + '</option>';
+            };
+            return result;
+        };
+        let html = getLibNamesHtml(namesAndLib.libNames);
+        $("#select_block_lib_names").html(html);
+
         me.mainSpread = SheetDataHelper.createNewSpread($('#div_block_tree')[0]);
         // me.mainSpread = TREE_SHEET_HELPER.createNewSpread($('#div_block_tree')[0]);
         me.mainSheet = me.mainSpread.getSheet(0);
@@ -345,43 +363,45 @@ var blockLibObj = {
         };
         return new TreeCell();
     },
-    newNode: function (nodeType, nodeName, categoryID, source){     // 1 分类(只用前两个参数)  2 块文件
+    newNode: async function (nodeType, nodeName, categoryID, source){     // 1 分类(只用前两个参数)  2 块文件
         let tree = blockLibObj.mainTree;
-        let pID = -1, nID = -1;
-        let select = tree.selected;
-        if (nodeType == 1){
-            if (!select) {
-                nID = -1;
-            }
-            else if (select.data.type == 1){
-                nID = select.getNextSiblingID();
-            }
-            else if (select.data.type == 2){
-                nID = select.parent.getNextSiblingID();
-            };
-        }
-        else if (nodeType == 2) {
-            pID = categoryID;
-            nID = -1;
-        }
-
-        let newN = tree.insert(pID, nID);
-        newN.data.type = nodeType;
-        newN.data.nodeName = nodeName;
+        let ID = uuid.v1();
+        let pID = (nodeType == 2) ? categoryID : -1;
+        let nID = -1;
+
+        // 先生成临时结点数据用于提交入库,成功后才生成树结点,并在UI上刷新显示。
+        let temp = {};
+        temp.data = {
+            ID: ID,
+            ParentID: pID,
+            NextSiblingID: nID,
+            libID: blockLibObj.activeLib.libID,
+            type: nodeType,
+            nodeName: nodeName
+        };
         if (nodeType == 2)
-            blockLibObj.assignData(newN, source);
-
-        tree.selected = newN;
-        let sheet = blockLibObj.mainSheet;
-        sheet.suspendPaint();
-        sheet.suspendEvent();
-        let idx = tree.items.indexOf(newN);
-        sheet.addRows(idx, 1);
-        sheet.getRange(idx, 0, 1, 1).locked(true);
-        sheet.setValue(idx, 0, newN.data.nodeName);
-        sheet.setSelection(idx, 0, 1, 1);
-        sheet.resumeEvent();
-        sheet.resumePaint();
+            blockLibObj.assignData(temp, source);
+
+        try {
+            await ajaxPost('/blockLib/saveBlock', temp.data);
+            let newN = tree.insertByID(ID, pID, nID);
+            newN.data = temp.data;
+            tree.selected = newN;
+            let sheet = blockLibObj.mainSheet;
+            sheet.suspendPaint();
+            sheet.suspendEvent();
+            let idx = tree.items.indexOf(newN);
+            sheet.addRows(idx, 1);
+            sheet.getRange(idx, 0, 1, 1).locked(true);
+            sheet.setValue(idx, 0, newN.data.nodeName);
+            sheet.setSelection(idx, 0, 1, 1);
+            sheet.resumeEvent();
+            sheet.resumePaint();
+        }
+        catch (err) {
+            console.log(err.message);
+            return;
+        };
     },
     assignData: function (block, source){
         block.data.compilationID = source.compilationID;
@@ -576,17 +596,27 @@ var blockLibObj = {
         };
         vBlock_WC = JSON.parse(JSON.stringify(vBlock_WC));
         BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
+    },
+    checkShow: async function () {   // 这里需要处理异步:模板库装载完再弹出位置选择窗。
+        if (!$("#kmbk").is(":visible")){  // 如果还没显示
+            if (!blockLibObj.mainSpread){
+                await blockLibObj.buildSheet();
+            };
+            $('#blockLibTab').click();  // 强制显示
+        };
+        $("#div_createBlocks").modal({show: true});
     }
 };
 
-$(document).ready(function(){
+$(document).ready(function(){    // 这里不需要处理异步:因为不需要弹出位置选择窗。
     $('#blockLibTab').on('click', function (){
-        if ($("#kmbk").is(":visible")){
+        if ($("#kmbk").is(":visible")){    // 显示状态下
             if (!blockLibObj.mainSpread){
                 blockLibObj.buildSheet();
             };
         }
     });
+
     $('#btn_block_newFolder').on('click', function (){
         $('#input_block_newFolder').val('');
     });

+ 10 - 13
web/building_saas/main/js/views/project_view.js

@@ -1562,11 +1562,8 @@ var projectObj = {
                         let selected = project.mainTree.selected;
                         return selected.sourceType != ModuleNames.bills;
                     },
-                    callback:function(){
-                        if (!$("#kmbk").is(":visible")){
-                            $('#blockLibTab').click()
-                        };
-                        $("#div_createBlocks").modal({show: true});
+                    callback: function(){
+                        blockLibObj.checkShow();
                     },
                     visible: function(key, opt){
                         return G_SHOW_BLOCK_LIB;
@@ -3027,13 +3024,13 @@ $(function () {
         $('#clone_option_noCover').prop("checked", true);
     });
 
-    $("#btn_block_createBlocks").click(function () {
+    $("#btn_block_createBlocks").click(async function () {
         if ($("#select_block_category")[0].options.length < 1) return;
         let cID = $("#select_block_category").val();
         let selected = projectObj.project.mainTree.selected;
         let cover = $('#ckb_block_exist_cover').prop("checked");
-        function createBlocks(aNode, categoryID){
-            function createBlock(node) {
+        async function createBlocks(aNode, categoryID){
+            async function createBlock(node) {
                 if (node.data.name == undefined || node.data.name == '') return;  // 清单名称为空,不生成块模板文件
                 if (node.children.length == 0) return;
                 // 封装成伟城的块文件格式,直接调用伟城接口(定额这里的业务太多太庞杂,不要再重做一遍,尽量共用,维护代价小)
@@ -3056,10 +3053,10 @@ $(function () {
                     if (cover) blockLibObj.assignData(extN, vBlock_WC);
                 }
                 else
-                    blockLibObj.newNode(2, fileName, categoryID, vBlock_WC);
+                    await blockLibObj.newNode(2, fileName, categoryID, vBlock_WC);
             };
 
-            function createRecursion(node){
+            async function createRecursion(node){
                 if (!node) return;
 
                 if (calcTools.isLeafBill(node)) createBlock(node);
@@ -3069,12 +3066,12 @@ $(function () {
             };
 
             if (calcTools.isLeafBill(aNode))
-                createBlock(aNode)
+               await createBlock(aNode)
             else
-                createRecursion(aNode.firstChild());
+               await createRecursion(aNode.firstChild());
         };
 
-        createBlocks(selected, cID);
+        await createBlocks(selected, cID);
         blockLibObj.loadDetailDatas(blockLibObj.mainTree.selected);
         $("#div_createBlocks").modal("hide");
     });

+ 42 - 9
web/building_saas/main/js/views/zmhs_view.js

@@ -11,12 +11,22 @@ let zmhs_obj = {
         header: [
             {headerName: "调整", headerWidth: 35, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
             {headerName: "条件", headerWidth: 250, dataCode: "name", dataType: "String", cellType: "button"},
-            {headerName: "内容", headerWidth: 160, dataCode: "content", dataType: "String", hAlign: "left"}
+            {headerName: "内容", headerWidth: 160, dataCode: "content", dataType: "String", hAlign: "left",getText:'forContent'}
         ],
         view: {
             lockColumns:[0,1,2],
             rowHeaderWidth:25
         },
+        getText:{
+            forContent:function (item) {
+               if(gljUtil.isDef(item.select_code)&&item.select_code!=""){
+                   return item.select_code;
+               }else {
+                   return item.content;
+               }
+
+            }
+        },
         autoFit:true,
         fitRow:['name']
     },
@@ -45,9 +55,12 @@ let zmhs_obj = {
         this.coeSheet.name('ration_coe');
         this.coeSheet.bind(GC.Spread.Sheets.Events.CellClick, this.onCoeCellClick);
         this.coeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onButtonClick);
-        this.coeSheet.bind(GC.Spread.Sheets.Events.EditStarting, function (e,args) {
-            //args.cancel = true;
+        this.coeSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onCoeValueChange);
+        this.coeSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e,args) {
+            args.sheet.repaint();
         });
+
+
         this.assSheet = this.assSpread.getSheet(0);
         sheetCommonObj.initSheet(this.assSheet, this.assSetting, 30);
         this.assSheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onAssEditEnded);
@@ -68,17 +81,29 @@ let zmhs_obj = {
         }
         sheetCommonObj.showData(this.coeSheet, this.coeSetting,coeList);
         if (coeList.length > 0) {
-            var cus_index = _.findIndex(coeList, function (item) {
-                return item.coeID == -1;
-            })
-            if (cus_index != -1) {
-                this.coeSheet.getCell(cus_index, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
-                this.coeSheet.setCellType(cus_index, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
+            for(let i =0;i<coeList.length;i++ ){
+                if(gljUtil.isDef(coeList[i].option_codes)&&coeList[i].option_codes!=""){
+                    this.getComboBoxForCodes(coeList[i],i);//设置可选类型的下拉框
+                    //  sheet.setValue(row, col, val, ch);
+                } else if(coeList[i].coeID == -1){ //自定义系数列
+                    this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+                    this.coeSheet.setCellType(i, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
+                }
             }
         }
         this.coeSheetData = coeList;
+    },
+    getComboBoxForCodes:function (coe,i) {
+        this.coeSheet.getCell(i, 2, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+        let options = coe.option_codes.split("|");
+        let combo = sheetCommonObj.getDynamicCombo(true);
+        combo.itemHeight(options.length).items(options);
+        this.coeSheet.setCellType(i, 2, combo, GC.Spread.Sheets.SheetArea.viewport);
+        this.coeSheet.setValue(i, 2, coe.select_code);
 
     },
+
+
     showAssData:function (node) {
         this.assSheet.suspendPaint();
         this.assSheet.suspendEvent();
@@ -302,6 +327,14 @@ let zmhs_obj = {
             zmhs_obj.coeSheet.startEdit();
         }
     },
+    onCoeValueChange:function (e,args) {
+        let fieldID =  zmhs_obj.coeSetting.header[args.col].dataCode;
+        let recode = zmhs_obj.coeSheetData[args.row];
+        if(gljUtil.isDef(recode.option_codes)&&recode.option_codes!=""&& fieldID == 'content'){//说明是选择了下拉框
+            projectObj.project.ration_coe.adjustCoeClick(recode, 1,{'select_code':args.newValue});
+        }
+    },
+
     onAssEditEnded:function (e,args) {
         var me = zmhs_obj;
         if (args.row >= me.assSheetData.length) {