瀏覽代碼

bug fixed

zhangweicheng 7 年之前
父節點
當前提交
3620917216

+ 17 - 2
modules/main/facade/decimal_facade.js

@@ -2,10 +2,11 @@
  * Created by zhang on 2017/11/22.
  */
 let projectsModel = require("../../pm/models/project_schema");
-
+let _ = require('lodash');
 
 module.exports ={
-    getProjectDecimal:getProjectDecimal
+    getProjectDecimal:getProjectDecimal,
+    getBillsQuantityDecimal:getBillsQuantityDecimal
 }
 
 async function getProjectDecimal(projectID) {
@@ -15,4 +16,18 @@ async function getProjectDecimal(projectID) {
         decimal = project.property.decimal
     }
     return decimal;
+}
+
+async function getBillsQuantityDecimal(projectID,unit) {
+    let decimal = null;
+    let project =await projectsModel.findOne({ID:projectID});
+    if(project){
+        let billsQuantityDecimal = project.property.billsQuantityDecimal;
+        let el = _.find(billsQuantityDecimal,{'unit':unit});
+        if(!el){
+            el = billsQuantityDecimal[0];
+        }
+        decimal = el.decimal
+    }
+    return decimal;
 }

+ 13 - 0
modules/main/facade/quantity_detail_facade.js

@@ -339,17 +339,30 @@ async function summateResults (query,detailList,decimal) {
         }
     }
     if(query.hasOwnProperty('rationID')){
+        let ration = await  ration_model.findOne({'ID':query.rationID,'projectID':query.projectID,deleteInfo: null});
+        getQuantityByUnit(quantity,ration.unit);
         quantity = scMathUtil.roundTo(quantity, -decimal.ration.quantity);
         await ration_model.update({'ID':query.rationID,'projectID':query.projectID,deleteInfo: null},{quantity:quantity,isFromDetail:1});
     }else {
         let bill = await bill_model.findOne({'ID':query.billID,'projectID':query.projectID,deleteInfo: null});
         decimal = await decimal_facade.getBillsQuantityDecimal(query.projectID,bill.unit);
+        getQuantityByUnit(quantity,bill.unit);
         quantity = scMathUtil.roundTo(quantity, -decimal);
         await bill_model.update({'ID':query.billID,'projectID':query.projectID,deleteInfo: null},{quantity:quantity,isFromDetail:1});
     }
     return quantity
 }
 
+function getQuantityByUnit(quantity,unit) {
+    if(unit){
+        let times = parseInt(unit);
+        if(isNaN(times)){
+            times = 1
+        }
+        quantity = quantity/times;
+    }
+    return quantity;
+}
 
 
  function  getEvalResult(referenceIndexs,detailList,regex,decimal={}) {

+ 1 - 1
modules/main/models/bills.js

@@ -11,7 +11,7 @@ let counter = require("../../../public/counter/counter.js");
 let consts = require('./project_consts');
 let projectConsts = consts.projectConst;
 let commonConsts = consts.commonConst;
-let quantity_detial = require('../../ration_glj/facade/quantity_detail_facade');
+let quantity_detial = require('../facade/quantity_detail_facade');
 
 
 let billsSchema = new Schema({

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

@@ -7,7 +7,7 @@ var GLJData = require('./glj');
 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');
-var quantity_detail_data = require('../../ration_glj/facade/quantity_detail_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');
 let projSetting = require('./proj_setting_model');

+ 0 - 642
modules/ration_glj/facade/quantity_detail_facade.js

@@ -1,642 +0,0 @@
-/**
- * Created by chen on 2017/7/20.
- */
-
-/**
- * Created by chen on 2017/7/10.
- */
-let mongoose = require('mongoose');
-let consts = require('../../main/models/project_consts');
-let commonConsts = consts.commonConst;
-let _=require("lodash");
-let async_n = require("async");
-let quantity_detail_model = mongoose.model('quantity_detail');
-const uuidV1 = require('uuid/v1');
-let ration_model = mongoose.model('ration');
-let bill_model=mongoose.model("bills");
-const scMathUtil = require('../../../public/scMathUtil').getUtil();
-
-module.exports={
-    save:save,
-    getData:getData,
-    deleteByRation:deleteByRation,
-    deleteByBill:deleteByBill,
-    quantityEditChecking:quantityEditChecking,
-};
-
-let operationMap={
-    'ut_create':create_quantity_detail,
-    'ut_update':update_quantity_detail,
-    'ut_delete':delete_quantity_detail
-};
-
-let updateFunctionMap = {
-    'normalUpdate':normalUpdate,
-    'updateQuantityRegex':updateQuantityRegex,
-    'insertRecode':insertRecode
-}
-
-function create_quantity_detail(user_id,datas) {
-    return function (callback) {
-        let doc = datas.doc;
-        doc.ID = uuidV1();
-        if(doc.hasOwnProperty('regex')){
-            insertRecodeWithReg(doc).then(function (resultObject) {
-                if(resultObject.err){
-                    callback(null,{
-                        moduleName:consts.projectConst.QUANTITY_DETAIL,
-                        err:{
-                            message:result.err.message
-                        }
-                    });
-                } else {
-                    callback(null,resultObject.return_list);
-                }
-            })
-        }else {
-            createNormalRecode(doc,callback)
-        }
-
-    }
-}
-
-function insertRecode(user_id,datas) {
-    return function (callback) {
-        let doc = datas.doc;
-        doc.ID = uuidV1();
-        doInsertRecode(doc).then(function (result) {
-            //console.log(result);
-            if(result.err){
-                callback(result.err,'')
-            }else {
-                callback(null,result.returndata)
-            }
-
-        })
-    }
-}
-
-async function doInsertRecode(doc) {
-    let result={
-        err:null
-    }
-    try{
-        let query = {
-            projectID:doc.projectID,
-            seq : { $gte: doc.seq }
-        }
-        if(doc.hasOwnProperty('rationID')){
-            query.rationID = doc.rationID;
-        }else {
-            query.billID = doc.billID;
-        }
-        let quantity_detail_List = await getDatailList(doc,{data:{}});
-        let update_task = getUpdateReferenceTask(quantity_detail_List,doc.seq,1);
-        await quantity_detail_model.update(query,{$inc:{seq:1}},{multi: true});
-        if(update_task.length>0){
-            await quantity_detail_model.bulkWrite(generateUpdateTaks(update_task));
-        }
-        let newrecode = await quantity_detail_model.create(doc);
-        let returndata ={
-            updateTpye:commonConsts.UT_CREATE,
-            moduleName:consts.projectConst.QUANTITY_DETAIL,
-            data:{
-                doc:newrecode,
-                resort:true,
-                update_task:update_task
-            }
-        };
-        result.returndata =returndata
-        return result;
-    }catch (error){
-        console.log(error)
-        result.err;
-        return result
-    }
-}
-
-function getUpdateReferenceTask(quantity_detail_List,seq,re) {
-    let update_task=[];
-    for(let q of quantity_detail_List){
-        let need_update =false;
-        let newReg = q.regex;
-        let newReferenceIndex;
-        if(q.referenceIndexs.length>0){
-            for (let i =0;i< q.referenceIndexs.length;i++){
-                if(q.referenceIndexs[i]>seq){
-                    newReg = replaceAll('C'+q.referenceIndexs[i],'C'+(q.referenceIndexs[i]+re),newReg);
-                    newReg = replaceAll('c'+q.referenceIndexs[i],'c'+(q.referenceIndexs[i]+re),newReg);
-                    q.referenceIndexs[i] +=re;
-                    need_update = true;
-                }
-            }
-        }
-        if(need_update){
-            newReferenceIndex = q.referenceIndexs;
-            let task ={
-                query:{
-                    ID:q.ID,
-                    projectID:q.projectID
-                },
-                doc:{
-                    regex:newReg,
-                    referenceIndexs:newReferenceIndex
-                }
-            }
-            update_task.push(task);
-        }
-    }
-    return update_task;
-}
-
-
-function createNormalRecode(doc,callback) {
-    quantity_detail_model.create(doc,(err,result)=>{
-        if(err){
-            callback(err,null);
-        }else {
-            console.log(result);
-            let returndata ={
-                updateTpye:commonConsts.UT_CREATE,
-                moduleName:consts.projectConst.QUANTITY_DETAIL,
-                data:result
-            }
-            callback(null,returndata)
-        }
-    });
-}
-
-
-async function insertRecodeWithReg (doc) {
-    let returnObjec={
-        err:null,
-        return_list:[]
-    }
-    try {
-        let returnData={
-            moduleName:'',
-            data:{
-                updateTpye:commonConsts.UT_UPDATE,
-            }
-        }
-        let regex = doc.regex.toUpperCase();
-        let referenceIndexs = doc.referenceIndexs;
-        let detailList = await getDatailList(doc,returnData);
-        doc.result =getEvalResult(referenceIndexs,detailList,regex);
-        let refreshQuantity =false;
-        if(doc.refreshQuantity==true){
-            refreshQuantity = true;
-        }
-        delete doc.refreshQuantity;
-        let newRecode = await quantity_detail_model.create(doc) ;
-        detailList.push(newRecode);
-        if(refreshQuantity==true){
-            returnData.data.quantity = await summateResuts(doc,detailList);
-            returnData.data.quantityRefresh = true;
-            returnObjec.return_list.push(returnData);
-        }
-        returnObjec.return_list.push({
-            updateTpye:commonConsts.UT_CREATE,
-            moduleName:consts.projectConst.QUANTITY_DETAIL,
-            data:newRecode
-        });
-        return returnObjec;
-    }catch (error){
-        returnObjec.err = new Error('输入的表达式有误,请重新输入!');
-        console.log(error)
-        return returnObjec;
-    }
-
-
-}
-
-
-
-function normalUpdate(user_id,datas) {
-    return function(callback) {
-        if(datas.doc.hasOwnProperty('isSummation')){
-            doIsSummationUpdate(datas.query,datas.doc).then(function (sresult) {
-                let returndata ={
-                    moduleName:consts.projectConst.QUANTITY_DETAIL,
-                    data:{
-                        updateTpye:commonConsts.UT_UPDATE,
-                        query:datas.query,
-                        doc:datas.doc
-                    }
-                }
-                let retrunArr = [];
-                retrunArr.push(returndata);
-                if(sresult){
-                    retrunArr.push(sresult);
-                }
-                callback(null,retrunArr);
-            })
-        }else {
-            updateRecored(datas.query,datas.doc,callback);
-        }
-    }
-}
-function updateQuantityRegex(user_id,datas) {
-    return function(callback){
-        doRegexUpdate(datas).then(function (result) {
-            if(result.err){
-                callback(null,{
-                    moduleName:consts.projectConst.QUANTITY_DETAIL,
-                    err:{
-                        message:result.err.message
-                    }
-                });
-            }else {
-                callback(null,result.rList);
-            }
-
-        })
-    }
-}
-
-async function doIsSummationUpdate(query,doc) {
-    try {
-        let returnData={
-            moduleName:'',
-            data:{
-                updateTpye:commonConsts.UT_UPDATE,
-            }
-        }
-        let  refreshQuantity=false;
-        if(query.refreshQuantity==true){
-            refreshQuantity=true;
-        }
-        delete query.refreshQuantity;
-        let updateDoc = await quantity_detail_model.update(query,doc);
-        let detailList = await getDatailList(query,returnData);
-        if(refreshQuantity==true){
-            let quantity = await summateResuts(query,detailList);
-            returnData.data.quantity = quantity;
-            returnData.data.quantityRefresh = true;
-            return returnData;
-        }else {
-            return null;
-        }
-    }catch (error){
-        console.log(error)
-    }
-}
-
-async function getDatailList(query,resultObject) {
-    let detailList = [];
-    if(query.hasOwnProperty('rationID')){
-        detailList = await quantity_detail_model.find({'projectID':query.projectID,'rationID':query.rationID}).sort('seq').exec();
-        resultObject.moduleName = consts.projectConst.RATION;
-        resultObject.data.rationID=query.rationID;
-
-    }else {
-        detailList = await quantity_detail_model.find({'projectID':query.projectID,'billID':query.billID}).sort('seq').exec();
-        resultObject.moduleName = consts.projectConst.BILLS;
-        resultObject.data.billID=query.billID;
-    }
-    return detailList;
-}
-
-
-async function doRegexUpdate(datas) {
-    let resultObjec ={
-        err:null,
-        rList:[]
-    }
-    try {
-        let detailList = [];
-        let quantityResult ={
-            moduleName:'',
-            data:{
-                updateTpye:commonConsts.UT_UPDATE,
-                quantityRefresh:true
-            }
-        }
-        if(datas.query.hasOwnProperty('rationID')){
-            detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'rationID':datas.query.rationID}).sort('seq').exec();
-            quantityResult.moduleName = consts.projectConst.RATION;
-            quantityResult.data.rationID = datas.query.rationID;
-        }else {
-            detailList = await quantity_detail_model.find({'projectID':datas.query.projectID,'billID':datas.query.billID}).sort('seq').exec();
-            quantityResult.data.billID = datas.query.billID;
-            quantityResult.moduleName = consts.projectConst.BILLS;
-        }
-        let regex;
-        let result;
-        if(datas.doc.regex==null){
-            result=0
-            datas.doc.referenceIndexs=[];
-        }else {
-            regex = datas.doc.regex.toUpperCase();
-            let referenceIndexs = datas.doc.referenceIndexs;
-            result =getEvalResult(referenceIndexs,detailList,regex);
-        }
-        detailList[datas.query.index].result =result;
-        detailList[datas.query.index].regex=datas.doc.regex;
-        detailList[datas.query.index].referenceIndexs =datas.doc.referenceIndexs;
-        let updateTasks =[];
-        datas.doc.result=result;
-        updateTasks.push({
-            query:{
-                ID:datas.query.ID,
-                projectID:datas.query.projectID
-            },
-            doc:datas.doc
-        })
-        updateReferenceRecode(datas.query.index+1,detailList,updateTasks);
-        let updateEdit = await quantity_detail_model.bulkWrite(generateUpdateTaks(updateTasks));
-        resultObjec.rList.push(gernerateResultList(updateTasks));
-        if(datas.query.refreshQuantity==true){
-            quantityResult.data.quantity = await summateResuts(datas.query,detailList);
-            resultObjec.rList.push(quantityResult);
-        }
-        return resultObjec;
-    }catch (error){
-        console.log(error);
-        resultObjec.err=error;
-        return resultObjec
-
-    }
-}
-
-function gernerateResultList(updateTasks) {
-    let returndata ={
-        moduleName:consts.projectConst.QUANTITY_DETAIL,
-        data:{
-            updateTpye:commonConsts.UT_UPDATE,
-            refreshList:updateTasks
-        }
-    }
-    return returndata;
-
-}
-
-
-
-function updateReferenceRecode(index,detailList,updateTasks) {
-    for(let d of detailList){
-        if(_.includes(d.referenceIndexs,index)){
-            let tResult = getEvalResult(d.referenceIndexs,detailList,d.regex);
-            let t = {
-                query:{
-                    ID:d.ID,
-                    projectID:d.projectID
-                },
-                doc:{
-                    result:tResult
-                }
-            };
-            d.result = tResult;
-            updateTasks.push(t);
-            updateReferenceRecode(d.seq+1,detailList,updateTasks);
-        }
-    }
-}
-
-
-async function summateResuts (query,detailList) {
-    let quantity = 0;
-    for(let d of detailList){
-        if(d.isSummation==1){
-            let result = d.result==null||d.result==undefined?0:d.result
-            quantity+=result;
-        }
-    }
-    quantity = quantity.toFixed(4);
-    if(query.hasOwnProperty('rationID')){
-        await ration_model.update({'ID':query.rationID,'projectID':query.projectID,deleteInfo: null},{quantity:quantity,isFromDetail:1});
-    }else {
-        await bill_model.update({'ID':query.billID,'projectID':query.projectID,deleteInfo: null},{quantity:quantity,isFromDetail:1});
-    }
-    return quantity
-}
-
-
-
-function  getEvalResult(referenceIndexs,detailList,regex) {
-    try {
-        for(let i of referenceIndexs){
-            regex = replaceReference(i,detailList,regex)
-        }
-        console.log('replace all C reference -----'+regex);
-        regex =replaceSqr(regex);
-        console.log('replace all sqar reference -----'+regex);
-        return scMathUtil.roundTo(eval(regex), -4);
-    }catch (error){
-        console.log(error);
-        throw new Error('输入的表达式有误,请重新输入!');
-    }
-
-}
-
-function  generateUpdateTaks(updateTasks) {
-    var tasks=[];
-    for(let u of updateTasks){
-        let t ={
-            updateOne:{
-                filter:u.query,
-                update: u.doc
-            }
-        }
-        tasks.push(t);
-    }
-    return tasks;
-}
-
-function replaceReference(index,detailList,str) {
-    str=str.toUpperCase();
-    let rstr= detailList[index-1].regex==null?'0':'('+detailList[index-1].regex+')';
-    str=replaceAll('C'+index,rstr,str);
-    if(detailList[index-1].referenceIndexs.length>0){
-        for (let i of detailList[index-1].referenceIndexs){
-            str =replaceReference(i,detailList,str);
-        }
-    }
-    return str;
-}
-
-
-function replaceAll (FindText, RepText,str) {
-    let regExp = new RegExp(FindText, "g");
-    return str.replace(regExp, RepText);
-}
-
-
-function replaceSqr(text) {
-    var squarRegex = /\([^\^]+\)\^\d+/g;
-    var sqararr = text.match(squarRegex);
-
-    var squarRegex2 = /C[0-9]+\^\d+|[0-9]+([.]{1}[0-9]+){0,1}\^\d+/g; //匹配没有括号的
-    var sqararr2=text.match(squarRegex2);
-    if(sqararr){
-        text=converSqrByArr(sqararr,text);
-    }
-    if(sqararr2){
-        text=converSqrByArr(sqararr2,text);
-    }
-    return text;
-}
-
-function converSqrByArr (sqararr,text) {
-    var temp = text;
-    sqararr.forEach(function (item) {
-        var arr = item.split('\^');
-        var y = parseInt(arr[1]);
-        var x_arr = [];
-        for (var i = 0; i < y; i++) {
-            x_arr.push(arr[0]);
-        }
-        var temStr = x_arr.join('*');
-        temp = temp.replace(item, temStr);
-    });
-    return temp;
-};
-
-
-function updateRecored(query,doc,callback) {
-    quantity_detail_model.update(query,doc,(err,result)=>{
-        if(err){
-            callback(err,'');
-        }else {
-            let returndata ={
-                moduleName:consts.projectConst.QUANTITY_DETAIL,
-                data:{
-                    updateTpye:commonConsts.UT_UPDATE,
-                    query:query,
-                    doc:doc
-                }
-            }
-            callback(null,returndata);
-        }
-    })
-}
-
-
-function update_quantity_detail(user_id,datas) {
-    if(datas.updateFunction){
-        return updateFunctionMap[datas.updateFunction](user_id,datas);
-    }else {
-        return normalUpdate(user_id,datas);
-    }
-}
-
-function delete_quantity_detail(user_id,datas) {
-    return function (callback) {
-        doQuantityDelete(datas.doc).then(function (result) {
-            if(result.err){
-                callback(result.err,'')
-            }else {
-                callback(null,result.returndata)
-            }
-        });
-    }
-}
-
-async function doQuantityDelete(doc) {;
-    let result={
-        err:null
-    }
-    try{
-        let query = {
-            projectID:doc.projectID,
-            seq : { $gt: doc.seq }
-        }
-        if(doc.hasOwnProperty('rationID')){
-            query.rationID = doc.rationID;
-        }else {
-            query.billID = doc.billID;
-        }
-        let quantity_detail_List = await getDatailList(doc,{data:{}});
-        let update_task = getUpdateReferenceTask(quantity_detail_List,doc.seq,-1);
-        await quantity_detail_model.update(query,{$inc:{seq:-1}},{multi: true});
-        if(update_task.length>0){
-            await quantity_detail_model.bulkWrite(generateUpdateTaks(update_task));
-        }
-        await quantity_detail_model.deleteOne({ID:doc.ID,projectID:doc.projectID});
-        let returndata ={
-            moduleName:consts.projectConst.QUANTITY_DETAIL,
-            data:{
-                doc:doc,
-                resort:true,
-                update_task:update_task,
-                updateTpye:commonConsts.UT_DELETE
-            }
-        };
-        result.returndata =returndata
-        return result;
-    }catch (error){
-        console.log(error)
-        result.err;
-        return result
-    }
-
-
-}
-
-
-function getData(projectID, callback) {
-    quantity_detail_model.find({'projectID':projectID}).sort('seq').exec((err,datas)=>{
-        if(err){
-            callback(1, '', null);
-        }else {
-            callback(0, consts.projectConst.QUANTITY_DETAIL, datas);
-        }
-    })
-}
-
-function save (user_id, datas, callback) {
-    let operations=[];
-    if(_.isArray(datas)){
-        for(let i=0;i<datas.length;i++){
-            operations.push(operationMap[datas[i].updateType](user_id,datas[i]));
-        }
-    }else {
-        operations.push(operationMap[datas.updateType](user_id,datas));
-    }
-    async_n.parallel(operations,function (err,results) {
-        if(err){
-            callback(err,'');
-        }else {
-            if(results.length==1){
-                callback(null,results[0])
-            }else {
-                callback(null,results)
-            }
-        }
-    })
-}
-
-function deleteByRation(data) {
-    return function (callback) {
-        quantity_detail_model.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
-            commonCallback(callback,result,err);
-        });
-    }
-}
-function deleteByBill(data) {
-    return function (callback) {
-        console.log({projectID: data.projectID, billID: data.ID});
-        quantity_detail_model.deleteMany({projectID: data.projectID, billID: data.ID},(err,result)=>{
-            commonCallback(callback,result,err);
-        });
-    }
-}
-
-function quantityEditChecking(doc,type,functions) {
-    if(doc.updateType == commonConsts.UT_UPDATE&&doc.updateData.hasOwnProperty('isFromDetail')&&doc.updateData.isFromDetail==0) {
-        if(type=='bills'){
-            functions.push(deleteByBill(doc.updateData));
-        }else if(type=='ration'){
-            functions.push(deleteByRation(doc.updateData));
-        }
-    }
-}
-
-
-function commonCallback(callback,result,err) {
-    if(err){
-        callback(err,'');
-    }else {
-        callback(null,result);
-    }
-}

+ 1 - 1
modules/ration_glj/facade/ration_glj_facade.js

@@ -16,7 +16,7 @@ let ration_coe_facade = require('./ration_coe_facade');
 let ration_coe = mongoose.model('ration_coe');
 let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
 let glj_calculate_facade = require('./glj_calculate_facade');
-let quantity_detail_facade = require('./quantity_detail_facade');
+let quantity_detail_facade = require('../../main/facade/quantity_detail_facade');
 let logger = require("../../../logs/log_helper").logger;
 import stdgljutil  from "../../../public/cache/std_glj_type_util";
 import EngineeringLibModel from "../../users/models/engineering_lib_model";

+ 31 - 24
web/building_saas/glj/js/project_glj.js

@@ -22,6 +22,7 @@ let mixRatioConnectData = [];
 let mixRatioMap={};
 // 单价文件相关
 let usedUnitPriceInfo = {};
+let usedTenderList = [];
 let otherFileData = {};
 let currentTag = '';
 let isChanging = false;
@@ -162,12 +163,15 @@ $(document).ready(function () {
             // 从其他项目中复制
             changeUnitPriceId = $("#other-file").val();
         }
+        $('#change-dj').modal("hide");
+        $.bootstrapLoading.start();
         $.ajax({
             url: '/glj/change-file',
             type: 'post',
             data: {project_id: scUrlUtil.GetQueryString('project'), change_id: changeUnitPriceId, type: type},
             error: function() {
                 isChanging = false;
+                $.bootstrapLoading.end();
             },
             beforeSend: function() {
                 isChanging = true;
@@ -177,20 +181,16 @@ $(document).ready(function () {
                 if (response.err === 1) {
                     let msg = response.msg !== undefined ? response.msg : '未知错误';
                     alert(msg);
+                    $.bootstrapLoading.end();
                     return false;
                 }
                 projectObj.project.projectGLJ.loadData(function () {
                     let projectGLJ = projectObj.project.projectGLJ;
-                    let data = projectGLJ.datas;
                     projectGLJ.loadCacheData();
-                    let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
-                    let  usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
-                        data.constData.usedUnitPriceInfo : {};
-
-                    unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
-
+                    unitPriceFileInit();
+                    gljOprObj.refreshView();
+                    $.bootstrapLoading.end();
                 });
-                $('#change-dj').modal("hide");
             }
         });
     });
@@ -204,6 +204,14 @@ $(document).ready(function () {
             $("#notify").slideUp('fast');
         });
     });
+
+    $('#pop-dj').popover({
+            placement:"bottom",
+            html:true,
+            trigger:"hover | focus",
+            content: getUsedTenderInfo
+        }
+    );
 });
 
 /**
@@ -226,14 +234,10 @@ function init() {
                 data.constData.ownCompositionTypes : canNotChangeTypeId;
             GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
 
-            let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
-            usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
-                data.constData.usedUnitPriceInfo : {};
-
             // 连接socket服务器
             socketInit();
 
-            unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
+            unitPriceFileInit();
 
             setTimeout(spreadInit, 1);
         } else {
@@ -290,17 +294,19 @@ function spreadInit() {
  * @param {Array} data
  * @return {void}
  */
-function unitPriceFileInit(name, data) {
-    $("#used-name").text(name);
-    let usedCount = data.length <= 0 ? 1 : data.length;
+function unitPriceFileInit() {
+    let projectGLJ = projectObj.project.projectGLJ;
+    let data = projectGLJ.datas;
+     usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
+    usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
+        data.constData.usedUnitPriceInfo : {};
+    $("#used-name").text(usedUnitPriceInfo.name);
+    let usedCount = usedTenderList.length <= 0 ? 1 : usedTenderList.length;
     $("#used-count").text(usedCount);
-    $('#pop-dj').popover({
-            placement:"bottom",
-            html:true,
-            trigger:"hover | focus",
-            content: data.join('<br>')
-        }
-    );
+}
+
+function getUsedTenderInfo() {
+   return usedTenderList.join("<br>");
 }
 
 /**
@@ -371,4 +377,5 @@ function filterProjectGLJ(jsonData) {
         jsonData = tmpData;
     }
     return jsonData;
-}
+}
+

+ 1 - 1
web/building_saas/main/js/calc/calc_fees.js

@@ -70,7 +70,7 @@ let calcFees = {
     getFee: function (data, fullField) {
         let fields = fullField.split('.'), value = data;
         for (let field of fields) {
-            if (value[field]) {
+            if (value[field]!=undefined||value[field]!=null) {
                 value = value[field];
             } else {
                 return 0;

+ 84 - 62
web/building_saas/main/js/models/quantity_detail.js

@@ -48,13 +48,10 @@ var quantity_detail = {
                 _.forEach(data.update_task,function (item) {
                     me.refreshEachItme(item.query,item.doc);
                 })
-                gljOprObj.detailData.push(data.doc);
                 this.datas.push(data.doc);
             }else {
                 this.datas.push(data);
-                gljOprObj.detailData.push(data);
             }
-            gljOprObj.detailData=_.sortBy(gljOprObj.detailData,'seq');
             this.refreshSheetData();
         };
         quantity_detail.prototype.resortData=function(data,req){
@@ -106,28 +103,13 @@ var quantity_detail = {
                 me.refreshEachItme(item.query,item.doc);
             });
             _.remove(this.datas,{ID:data.doc.ID});
-            _.remove(gljOprObj.detailData,{ID:data.doc.ID});
             this.refreshSheetData();
         };
         quantity_detail.prototype.refreshSheetData=function () {
-            sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,gljOprObj.detailData);
-        };
-        quantity_detail.prototype.getUpdateData=function(type,query,doc,callfunction){
-            var updateData = [];
-            var newobj = {
-                'updateType': type,
-                'query': query,
-            }
-            if(doc){
-                newobj['doc']=doc;
-            }
-            if(callfunction){
-                newobj['updateFunction']=callfunction;
-            }
-            updateData.push(newobj);
-            return updateData;
+            gljOprObj.showQuantityDetailData();
         };
         quantity_detail.prototype.saveQuantityDetail=function (args,dataCode) {
+            var me = this;
             var doc={};
             var selected = projectObj.project.mainTree.selected;
             if(selected.sourceType==ModuleNames.ration){
@@ -152,13 +134,25 @@ var quantity_detail = {
                 }
 
             }
-            var updateData
-            if(args.hasOwnProperty("insertRecode")){
-                updateData = this.getUpdateData('ut_update',null,doc,'insertRecode');
+            var url="";
+            $.bootstrapLoading.start();
+            if(args.hasOwnProperty("insertRecode")){//右键插入或者是通过直接编辑保存
+                url = "/quantity_detail/insertRecode";
             }else{
-                updateData = this.getUpdateData('ut_create',null,doc);
+                url = "/quantity_detail/save";
+            }
+            var callback = function (data) {
+                if(doc.refreshQuantity==false){//清空数据
+                    me.cleanQuantityDetail();
+                }else {
+                    data.newRecord?me.refreshAfterSave(data.newRecord):me.refreshAfterSave(data);
+                    data.node?gljOprObj.refreshTreeNode(data.node):"";
+                }
+                $.bootstrapLoading.end();
             }
-            project.pushNow('saveQuantityDetail',[this.getSourceType()],updateData);
+            CommonAjax.post(url,doc,callback,function () {
+                $.bootstrapLoading.end();
+            });
         };
         quantity_detail.prototype.insertQuantityDetail = function (row) {
             var args = {
@@ -169,20 +163,27 @@ var quantity_detail = {
                 args.insertRecode = true;
             }
             this.saveQuantityDetail(args,'isSummation');
-
         };
 
         quantity_detail.prototype.deleteQuantityDetail = function (row) {
+           var me = this;
            var deleteable = this.checkReference(row);
            if(deleteable){
                var recode = gljOprObj.detailData[row];
-               var updateData = this.getUpdateData('ut_delete',null,recode);
-               project.pushNow('deleteQuantityDetail',[this.getSourceType()],updateData);
+               $.bootstrapLoading.start();
+               var callback=function (result) {
+                   me.refreshAfterDelete(result.data);
+                   result.node?gljOprObj.refreshTreeNode(result.node):"";
+                   $.bootstrapLoading.end();
+               }
+               CommonAjax.post("/quantity_detail/deleteRecode",recode,callback,function () {
+                   $.bootstrapLoading.end();
+               });
            }else {
                alert("当前行已被引用,不可删除。");
            }
-
         };
+
         quantity_detail.prototype.checkReference = function (row) {
             var deleteable = true;
            for(var i =0;i<gljOprObj.detailData.length;i++){
@@ -231,13 +232,7 @@ var quantity_detail = {
                     update_task.push({query:{ID:item.ID,projectID:item.projectID},doc:{regex:regex,referenceIndexs:item.referenceIndexs}});
                 }
             })
-
-            var updateData=[];
-            update_task.forEach(function (task) {
-                updateData.push({'updateType': 'ut_update', 'query': task.query,'doc':task.doc});
-            })
-            project.pushNow('updateQuantityDetail',[this.getSourceType()],[updateData]);
-
+            me.commonUpdate("/quantity_detail/swapRow",update_task);
         };
         quantity_detail.prototype.replaceAll=function(FindText, RepText,str) {
             let regExp = new RegExp(FindText, "g");
@@ -281,8 +276,7 @@ var quantity_detail = {
                 }
             }
             if(needupdate){
-                var updateData = this.getUpdateData('ut_update',query,doc,'updateQuantityRegex');
-                project.pushNow('updateQuantityDetail',[this.getSourceType()],updateData);
+                this.commonUpdate("/quantity_detail/updateRegex",{query:query,doc:doc});
             }else {
                 var sheet = subSpread.getActiveSheet();
                 sheet.getCell(args.row,args.col).value(gljOprObj.detailData[args.row].regex);
@@ -312,9 +306,21 @@ var quantity_detail = {
             };
             this.normalUpdate(query,doc);
         };
+        quantity_detail.prototype.commonUpdate = function (url,postData) {
+            var me = this;
+            $.bootstrapLoading.start();
+            var callback = function (data) {
+                me.refreshAfterUpdate(data);
+                data.node?gljOprObj.refreshTreeNode(data.node):"";
+                $.bootstrapLoading.end();
+            }
+            CommonAjax.post(url,postData,callback,function () {
+                $.bootstrapLoading.end();
+            });
+        };
         quantity_detail.prototype.normalUpdate=function(query,doc){
-            var updateData = this.getUpdateData('ut_update',query,doc);
-            project.pushNow('updateQuantityDetail',[this.getSourceType()],updateData);
+            var url = "/quantity_detail/update";
+            this.commonUpdate(url,{query:query,doc:doc});
         };
         quantity_detail.prototype.regexChecking=function(text){
             var regex=/^[0-9Cc\+\-\*\^/\(\)\.]*$/g;
@@ -447,32 +453,48 @@ var quantity_detail = {
                 this.datas = newList;
             }
         };
+        quantity_detail.prototype.cleanQuantityDetail = function (node,needSave) {
+           node =node?node:projectObj.project.mainTree.selected;
+           var query={projectID:node.data.projectID};
+            if(node.sourceType === project.Bills.getSourceType()){
+                query.billID = node.data.ID;
+                this.deleteByBills([{type:'delete',data:node.data}]);
+            }else if(node.sourceType === project.Ration.getSourceType()){
+                this.deleteByRation(node.data);
+                query.rationID = node.data.ID;
+            }
+            if(needSave===true){
+                query.refreshQuantity=false;
+                CommonAjax.post("/quantity_detail/save",query);
+            }
+            gljOprObj.detailData=[];
+            sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,[]);
+
+        };
+
         quantity_detail.prototype.quantityEditChecking = function(value,node,fieldName){
             var validate = true;
-            if (value && value != calcFees.getFee(node.data, fieldName)){
-                if(fieldName=='quantity'){
-                   if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
-                       var c = confirm('已有工程量明细,是否清空明细表,采用手工输入的表达式?')
-                        if(c){
-                            node.data.isFromDetail=0;
-                            if(node.sourceType === project.Bills.getSourceType()){
-                                this.deleteByBills([{type:'delete',data:node.data}]);
-                            }else if(node.sourceType === project.Ration.getSourceType()){
-                                this.deleteByRation(node.data);
-                            }
-                            gljOprObj.detailData=[];
-                            sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,[]);
-
-                            validate = true;
-                        }else {
-                            validate = false;
-                        }
-                   }
-                }
+            if(fieldName=='quantity'){
+               if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
+                   var c = confirm('已有工程量明细,是否清空明细表,采用手工输入的表达式?')
+                    if(c){
+                        validate = true;
+                    }else {
+                        validate = false;
+                    }
+               }
             }
             return validate;
-
-        }
+        };
+        quantity_detail.prototype.getDecimal=function (node) {
+            var decimal = 3;
+            if(node.sourceType === project.Bills.getSourceType()){
+                decimal = billsQuanDecimal.decimal(node.data.unit);
+            }else {
+                decimal = decimalObj.ration.quantity
+            }
+            return;
+        };
         return new quantity_detail(project);
     }
 

+ 28 - 0
web/building_saas/main/js/views/glj_view.js

@@ -671,6 +671,7 @@ var gljOprObj = {
     },
     showQuantityDetailData:function (node) {
         var details=[];
+        node =node?node:projectObj.project.mainTree.selected;
         var quantity_detail =projectObj.project.quantity_detail;
         if(node.sourceType==ModuleNames.ration){
             details=_.filter(quantity_detail.datas,{'rationID':node.data.ID});
@@ -996,6 +997,33 @@ var gljOprObj = {
     refreshView:function () {
         this.showRationGLJData();
     },
+    //
+    refreshTreeNode:function (obj) {
+    if(!obj){
+        return;
+    }
+    var objectArray =[];
+    var nodes =[];
+    if(obj instanceof Array){
+        objectArray.concat(obj);
+    }else {
+        objectArray.push(obj);
+    }
+    for(let o of objectArray ){
+        var node = _.find(projectObj.project.mainTree.items,function (n) {
+            return n.sourceType==o.type&&n.data.ID==o.ID;
+        })
+        if(node){
+            for (var k in o.data){
+                node.data[k] = o.data[k];
+            }
+            nodes.push(node);
+        }
+    }
+
+    projectObj.mainController.refreshTreeNode(nodes);
+
+    },
     getTreeNodeCellType:function (data) {
         var ns = GC.Spread.Sheets;
         var rectW = 10;

+ 11 - 5
web/building_saas/main/js/views/project_view.js

@@ -108,7 +108,7 @@ var projectObj = {
                 value = null;
             }
         }
-        if (value) {
+        if (value!=undefined||value!=null) {
             if (colSetting.data.decimal) {
                 value = value.toDecimal(colSetting.data.decimal);   
             }
@@ -268,12 +268,18 @@ var projectObj = {
                 project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
             }
             else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'programID' || fieldName === 'type'){
-                if (fieldName === 'quantity' && project.quantity_detail.quantityEditChecking(value,node,fieldName)) {
-                    if (value) {value = value.toDecimal(projectObj.project.Decimal.common.quantity)};
+                if (fieldName === 'quantity') {
+                    if (value) {value = value.toDecimal(project.quantity_detail.getDecimal(node))};
+                   if(project.quantity_detail.quantityEditChecking(value,node,fieldName)){
+                       node.data.isFromDetail=0;
+                       project.quantity_detail.cleanQuantityDetail(node,true);
+                   }else {
+                       projectObj.mainController.refreshTreeNode([node]);
+                       return;
+                   }
                 } else if (fieldName === 'marketUnitFee') {
                     if (value) {value = parseFloat(value).toDecimal(projectObj.project.Decimal.common.unitFee)};
-                };
-
+                }
                 node.changed = true;
                 node.data[fieldName] = value;
                 project.calcProgram.calculate(node);