Przeglądaj źródła

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionOperation

TonyKang 7 lat temu
rodzic
commit
49373fc54f

+ 44 - 10
modules/ration_repository/models/ration_item.js

@@ -7,14 +7,48 @@ let moment = require('moment');
 let counter = require('../../../public/counter/counter');
 let gljDao = require('./glj_repository');
 let rationRepositoryDao = require('./repository_map');
+const scMathUtil = require('../../../public/scMathUtil').getUtil();
 import {rationItemModel} from './schemas';
 
 var rationItemDAO = function(){};
 
+rationItemDAO.prototype.sortToNumber = function (datas) {
+    for(let i = 0, len = datas.length; i < len; i++){
+        let data = datas[i]._doc;
+        if(_exist(data, 'labourPrice')){
+            data['labourPrice'] = parseFloat(data['labourPrice']);
+        }
+        if(_exist(data, 'materialPrice')){
+            data['materialPrice'] = parseFloat(data['materialPrice']);
+        }
+        if(_exist(data, 'machinePrice')){
+            data['machinePrice'] = parseFloat(data['machinePrice']);
+        }
+        if(_exist(data, 'basePrice')){
+            data['basePrice'] = parseFloat(data['basePrice']);
+        }
+        if(_exist(data, 'rationGljList')){
+            for(let j = 0, jLen = data['rationGljList'].length; j < jLen; j++){
+                let raGljObj = data['rationGljList'][j]._doc;
+                if(_exist(raGljObj, 'consumeAmt')){
+                    raGljObj['consumeAmt'] = parseFloat(raGljObj['consumeAmt']);
+                }
+            }
+        }
+    }
+    function _exist(data, attr){
+        return data && data[attr] !== undefined && data[attr];
+    }
+};
+
 rationItemDAO.prototype.getRationItemsBySection = function(sectionId,callback){
+    let me = this;
     rationItemModel.find({"sectionId": sectionId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
-        if(err) callback(true, "Fail to get items", "")
-        else callback(false,"Get items successfully", data);
+        if(err) callback(true, "Fail to get items", "");
+        else {
+            me.sortToNumber(data);
+            callback(false,"Get items successfully", data);
+        }
     })
 };
 rationItemDAO.prototype.mixUpdateRationItems = function(rationLibId, lastOpr, sectionId, updateItems, addItems, rIds, callback){
@@ -252,13 +286,13 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                     gljArr.push({gljId: gljItems[i].ID, basePrice: adjBasePrice, gljParentType: gljParentType});
                                 }
                                 else {
-                                    gljArr.push({gljId: gljItems[i].ID, basePrice: gljItems[i].basePrice, gljParentType: gljParentType});
+                                    gljArr.push({gljId: gljItems[i].ID, basePrice: parseFloat(gljItems[i].basePrice), gljParentType: gljParentType});
                                 }
                             }
                             gljArr.forEach(function (gljItem) {
                                 rationGljList.forEach(function (rationGlj) {
                                     if(gljItem.gljId === rationGlj.gljId){
-                                        gljItem.consumeAmt = rationGlj.consumeAmt;
+                                        gljItem.consumeAmt = parseFloat(rationGlj.consumeAmt);
                                     }
                                 })
                             });
@@ -266,7 +300,7 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                             let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
                             gljArr.forEach(function (gljItem) {
                                 if(gljItem.gljParentType !== -1){
-                                    singlePrc = round(gljItem.basePrice * gljItem.consumeAmt, 3);
+                                    singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
                                     if(gljItem.gljParentType === 1){
                                         labourPrc.push(singlePrc);
                                     }
@@ -283,26 +317,26 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                 for(let i=0; i<labourPrc.length; i++){
                                     sumLaP += labourPrc[i];
                                 }
-                                updatePrc.labourPrice = round(sumLaP, 2);
+                                updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
                             }
                             if(materialPrc.length > 0){
                                 let sumMtP = 0;
                                 for(let i= 0; i<materialPrc.length; i++){
                                     sumMtP += materialPrc[i];
                                 }
-                                updatePrc.materialPrice = round(sumMtP, 2);
+                                updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
                             }
                             if(machinePrc.length > 0){
                                 let sumMaP = 0;
                                 for(let i =0; i< machinePrc.length; i++){
                                     sumMaP += machinePrc[i];
                                 }
-                                updatePrc.machinePrice = round(sumMaP, 2);
+                                updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
                             }
                             updatePrc.basePrice = updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice;
                             //updateDataBase
-                            rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice, materialPrice: updatePrc.materialPrice,
-                                    machinePrice: updatePrc.machinePrice, basePrice: updatePrc.basePrice}},
+                            rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
+                                    machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
                                 function (err, result) {
                                     if(err){
                                         ecb(err);

+ 5 - 5
modules/ration_repository/models/schemas.js

@@ -65,7 +65,7 @@ let rationChapterTreeSchema = new Schema({
 //定额工料机
 let rationGljItemSchema = new Schema({
     gljId: Number,
-    consumeAmt: Number,
+    consumeAmt: String,
     proportion: Number //配合比,暂时无需使用,默认0
 }, { _id: false });
 
@@ -88,10 +88,10 @@ var rationItemSchema = new Schema({
     code: String,
     name: String,
     unit: String,
-    labourPrice: Number,
-    materialPrice: Number,
-    machinePrice: Number,
-    basePrice: Number,
+    labourPrice: String,
+    materialPrice: String,
+    machinePrice: String,
+    basePrice: String,
     sectionId: Number,
     rationRepId: Number,
     caption: String,

+ 11 - 9
modules/ration_repository/routes/ration_rep_routes.js

@@ -11,6 +11,7 @@ import RationController from "../controllers/ration_controller";
 import RepositoryGljController from "../controllers/repository_glj_controller";
 import CoeListController from "../controllers/coe_controller";
 import SearchController from "../controllers/search_controller";
+import GljController from "../../std_glj_lib/controllers/gljController";
 let viewsController = new ViewsController();
 let rationRepositoryController = new RationRepositoryController();
 let rationChapterTreeController = new RationChapterTreeController();
@@ -18,6 +19,7 @@ let rationController = new RationController();
 let coeListController = new CoeListController();
 let searchController = new SearchController();
 let repositoryGljController = new RepositoryGljController();
+let gljController = new GljController();
 
 module.exports =  function (app) {
     app.get('/rationRepository/main', viewsController.auth, viewsController.init, viewsController.redirectMain);
@@ -52,15 +54,15 @@ module.exports =  function (app) {
     apiRouter.post("/updateJobContent",rationController.auth, rationController.init, rationController.updateJobContent);
     apiRouter.post("/updateAnnotation",rationController.auth, rationController.init, rationController.updateAnnotation);
 
-    apiRouter.post("/createNewGljTypeNode",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.createNewGljTypeNode);
-    apiRouter.post("/updateGljNodes",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.updateGljNodes);
-    apiRouter.post("/deleteGljNodes",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.deleteGljNodes);
-    apiRouter.post("/getGljDistType",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.getGljDistType);
-    apiRouter.post("/getGljTree",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.getGljTree);
-    apiRouter.post("/getGljItems",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.getGljItems);
-    apiRouter.post("/mixUpdateGljItems",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.mixUpdateGljItems);
-    apiRouter.post("/getGljItemsByIds",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.getGljItemsByIds);
-    apiRouter.post("/getGljItemsByCodes",repositoryGljController.auth, repositoryGljController.init, repositoryGljController.getGljItemsByCodes);
+    apiRouter.post("/createNewGljTypeNode",repositoryGljController.auth, gljController.init, gljController.createNewGljTypeNode);
+    apiRouter.post("/updateGljNodes",repositoryGljController.auth, gljController.init, gljController.updateGljNodes);
+    apiRouter.post("/deleteGljNodes",repositoryGljController.auth, gljController.init, gljController.deleteGljNodes);
+    apiRouter.post("/getGljDistType",repositoryGljController.auth, gljController.init, gljController.getGljDistType);
+    apiRouter.post("/getGljTree",repositoryGljController.auth, gljController.init, gljController.getGljTree);
+    apiRouter.post("/getGljItems",repositoryGljController.auth, gljController.init, gljController.getGljItems);
+    apiRouter.post("/mixUpdateGljItems",repositoryGljController.auth, gljController.init, gljController.mixUpdateGljItems);
+    apiRouter.post("/getGljItemsByIds",repositoryGljController.auth, gljController.init, gljController.getGljItemsByIds);
+    apiRouter.post("/getGljItemsByCodes",repositoryGljController.auth, gljController.init, gljController.getGljItemsByCodes);
 
     apiRouter.post("/getCoeList",coeListController.auth, coeListController.init, coeListController.getCoeList);
     apiRouter.post("/saveCoeList",coeListController.auth, coeListController.init, coeListController.saveCoeList);

+ 48 - 7
modules/std_glj_lib/models/gljModel.js

@@ -46,38 +46,79 @@ class GljDao  extends OprDao{
         })
     }
 
+    _exist(data, attr){
+        return data && data[attr] !== 'undefined' && data[attr];
+    }
+
+     sortToNumber(datas){
+        for(let i = 0, len = datas.length; i < len; i++){
+            let data = datas[i]._doc;
+            if(this._exist(data, 'basePrice')){
+                data['basePrice'] = parseFloat(data['basePrice']);
+            }
+            if(this._exist(data, 'component')){
+                for(let j = 0, jLen = data['component'].length; j < jLen; j++){
+                    let comGljObj = data['component'][j]._doc;
+                    if(this._exist(comGljObj, 'consumeAmt')){
+                        comGljObj['consumeAmt'] = parseFloat(comGljObj['consumeAmt']);
+                    }
+                }
+            }
+        }
+    }
+
     getGljItemsByRep(repositoryId,callback){
+        let me = this;
         gljModel.find({"repositoryId": repositoryId},function(err,data){
             if(err) callback(true, "")
-            else callback(false,data);
+            else {
+                me.sortToNumber(data);
+                callback(false,data);
+            }
         })
     }
 
     getGljItemByType (repositoryId, type, callback){
+        let me = this;
         gljModel.find({"repositoryId": repositoryId, "gljType": type},function(err,data){
-            if(err) callback(true, "")
-            else callback(false, data);
+            if(err) callback(true, "");
+            else {
+                me.sortToNumber(data);
+                callback(false, data);
+            }
         })
     };
 
     getGljItem (repositoryId, code, callback){
+        let me = this;
         gljModel.find({"repositoryId": repositoryId, "code": code},function(err,data){
             if(err) callback(true, "")
-            else callback(false, data);
+            else {
+                me.sortToNumber(data);
+                callback(false, data);
+            }
         })
     };
 
     getGljItems (gljIds, callback){
+        let me = this;
         gljModel.find({"ID": {"$in": gljIds}},function(err,data){
             if(err) callback(true, "")
-            else callback(false, data);
+            else {
+                me.sortToNumber(data);
+                callback(false, data);
+            }
         })
     };
 
     getGljItemsByCode (repositoryId, codes, callback){
+        let me = this;
         gljModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){
-            if(err) callback(true, "")
-            else callback(false, data);
+            if(err) callback(true, "");
+            else {
+                me.sortToNumber(data);
+                callback(false, data);
+            }
         })
     };
 

+ 2 - 2
modules/std_glj_lib/models/schemas.js

@@ -37,7 +37,7 @@ let gljMapSchema = new Schema({
 let gjlComponentSchema = mongoose.Schema(
     {
         ID: Number,
-        consumeAmt: Number
+        consumeAmt: String
     },
     {_id: false},
     {versionKey: false}
@@ -52,7 +52,7 @@ let gljSchema = new Schema({
     name: String,
     specs: String,
     unit: String,
-    basePrice: Number,
+    basePrice: String,
     gljClass: Number,
     gljType: Number,
     shortName: String,

+ 6 - 6
public/scMathUtil.js

@@ -2,16 +2,16 @@
  * Created by Tony on 2017/4/14.
  */
 const fs = require('fs');
-var scMath = null;
+let scMath = null;
 
-getScMathUtil = function() {
+let getScMathUtil = function() {
     if (!(scMath)) {
-        var data = fs.readFileSync(__dirname + '/web/scMathUtil.js', 'utf8', 'r');
+        let data = fs.readFileSync(__dirname + '/web/scMathUtil.js', 'utf8', 'r');
         //console.log(data);
-        eval(data);
-        scMath = scMathUtil;
+        eval(data + ' scMath = scMathUtil;');
+        //scMath = scMathUtil;
     }
     return scMath;
-}
+};
 
 exports.getUtil = getScMathUtil;

+ 31 - 24
public/web/scMathUtil.js

@@ -2,45 +2,45 @@
  * Created by jimiz on 2017/3/28.
  */
 
-var scMathUtil = {
+let scMathUtil = {
     innerRoundTo: function(num, digit){
-        var lFactor = Math.pow(10, digit);
-        var fOffSet = 0.5;
-        var sign = '';
+        let lFactor = Math.pow(10, digit);
+        let fOffSet = 0.5;
+        let sign = '';
         if (num < 0){
             sign = '-';
             num = Math.abs(num);
         }
-        var result = Math.floor((num / lFactor) + fOffSet).toString();
-        var iLength = result.length;
-        var r1 = result.substring(0, iLength + digit);
-        var r2 = result.substring(iLength + digit, iLength);
+        let result = Math.floor((num / lFactor) + fOffSet).toString();
+        let iLength = result.length;
+        let r1 = result.substring(0, iLength + digit);
+        let r2 = result.substring(iLength + digit, iLength);
         return Number(sign + r1 + '.' + r2);
     },
     floatToBin: function(num) {
         return num.toString(2);
     },
     binToFloat: function(bin) {
-        var result = 0;
-        var iLength = bin.length;
-        var sign = '';
+        let result = 0;
+        let iLength = bin.length;
+        let sign = '';
         if (iLength > 0 && bin[0]==='-'){
             sign = '-';
             bin = bin.substring(1, iLength);
         }
         iLength = bin.length;
-        var iDot = bin.indexOf('.');
+        let iDot = bin.indexOf('.');
         if (iDot >= 0) {
-            for (var i = 0; i < iLength; i++) {
-                var num = Number(bin[i]);
-                var idx = iDot - i;
+            for (let i = 0; i < iLength; i++) {
+                let num = Number(bin[i]);
+                let idx = iDot - i;
                 if (idx === 0) {
                     continue
                 };
                 if (idx > 0) {
                     idx -= 1
                 };
-                var r = Math.pow(2, idx);
+                let r = Math.pow(2, idx);
                 result += num * r;
             }
         }
@@ -49,17 +49,24 @@ var scMathUtil = {
         };
         return sign + result;
     },
+    zeroString: function(length){
+        let result = '';
+        for (let i = 0; i < length; i++){
+            result = result + '0';
+        };
+        return result;
+    },
     incMantissa: function(bin){
-        var result = bin;
-        var iDot = bin.indexOf('.');
+        let result = bin;
+        let iDot = bin.indexOf('.');
         if (iDot < 0){return result};
-        var iLength = bin.length;
-        for (var i = iLength - 1; i > iDot; i--){
-            var num = Number(bin[i]);
+        let iLength = bin.length;
+        for (let i = iLength - 1; i > iDot; i--){
+            let num = Number(bin[i]);
             if (num === 0){
                 num = 1;
-                var bin1 = bin.substring(0, i);
-                var bin2 = bin.substring(i + 1, iLength);
+                let bin1 = bin.substring(0, i);
+                let bin2 = this.zeroString(iLength - (i + 1));//bin.substring(i + 1, iLength);
                 result = bin1 + num.toString() + bin2;
                 break;
             }
@@ -68,7 +75,7 @@ var scMathUtil = {
         return result;
     },
     roundTo: function(num, digit){
-        var me = this;
+        let me = this;
         return me.innerRoundTo(me.binToFloat(me.incMantissa(me.floatToBin(num))), digit);
     }
 };

+ 13 - 9
web/maintain/bills_lib/scripts/db_controller.js

@@ -499,7 +499,7 @@ var tools = {
                         if(ref === 'reference' && item[classify].data[field] == newData){
                             isRepeat = true;
                         }
-                        else if(ref === 'document' && item[field] === newData){
+                        else if(ref === 'document' && item[field] == newData){
                             isRepeat = true;
                         }
                     });
@@ -511,7 +511,7 @@ var tools = {
                         if(ref === 'reference' && item.data[field] == newData){
                             isRepeat = true;
                         }
-                        else if(ref === 'document' && item[field] === newData){
+                        else if(ref === 'document' && item[field] == newData){
                             isRepeat = true;
                         }
                     });
@@ -765,6 +765,7 @@ var tools = {
     },
 
     reshowValue: function(sheet, arr, setting, isResort){
+        sheet.suspendPaint();
         tools.clearData(sheet);
         sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.viewport);
         sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.colHeader);
@@ -778,7 +779,6 @@ var tools = {
             arr.sort(myCompareCode);
         }
         if(arr.length > 0){
-            sheet.suspendPaint();
             var length = arr.length;
             for(var i=0; i<length; i++){
                 setting.cols.forEach(function(col, colIdx){
@@ -791,8 +791,8 @@ var tools = {
                     }
                 });
             }
-            sheet.resumePaint();
         }
+        sheet.resumePaint();
     },
 
     clearData: function(sheet){
@@ -2047,7 +2047,7 @@ var valueController = {
         let me = valueController;
         sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
             me.currentEditData = sheet.getValue(args.row, args.col);
-        })
+        });
         sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args){
             var newValue = args.editingText, tagId = sheet.getTag(args.row, args.col), field, isRepeat;
             setting.cols.forEach(function(col, colIdx){
@@ -2117,13 +2117,13 @@ var valueController = {
             itemsAjax.updateValue(userAccount, billsLibId, selectedId, updateData, null, 'update');
         }
         else {
-            if(typeof newData === 'number'){
+            if(isNumber(newData)){
                 if(itemVals){
                     var updateEle;
                     var index;
                     itemVals.forEach(function(val){
                         if(val.code === tagId){
-                            updateEle = {code: newData, value: val.value};
+                            updateEle = {code: parseInt(newData), value: val.value};
                             index = itemVals.indexOf(val);
                             itemVals.splice(index, 1);
                         }
@@ -2134,7 +2134,7 @@ var valueController = {
             }
             else {
                 //编号只能为数字!
-                sheet.getCell(args.row, args.col).value('');
+                args.sheet.getCell(args.row, args.col).value(args.sheet.getValue(0, args.col) ? args.sheet.getValue(0, args.col) : '');
             }
         }
     },
@@ -2152,7 +2152,7 @@ var valueController = {
         var valArr = totalItems.findItem(id).data.itemValue;
         if(valArr){
             tools.resort(valArr, 'code', true);
-            return valArr.length > 0 ? valArr[valArr.length - 1].code + 1 : 1;
+            return valArr.length > 0 ? parseInt(valArr[valArr.length - 1].code) + 1 : 1;
         }else {
             return 1;
         }
@@ -2385,6 +2385,10 @@ var rechargeController = {
     }
 };
 
+function isNumber(num){
+    return !isNaN(num) && num % 1 === 0;
+}
+
 
 
 

+ 1 - 0
web/maintain/ration_repository/dinge.html

@@ -442,6 +442,7 @@
         <script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
         <script type="text/javascript" src="/lib/ztree/jquery.ztree.exedit.js"></script>
         <script type="text/javascript" src="/web/maintain/ration_repository/js/section_tree.js"></script>
+        <script type="text/javascript" src="/public/web/scMathUtil.js"></script>
         <script type="text/javascript" src="/public/web/ztree_common.js"></script>
         <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
         <script type="text/javascript" src="/web/maintain/ration_repository/js/sheetsOpr.js"></script>

+ 3 - 3
web/maintain/ration_repository/js/coe.js

@@ -123,12 +123,12 @@ let coeOprObj = {
                             me.save([], updateArr, [], true);
                         }
                         else if(!me.isInt(inputT)){
-                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
                             alert('编号只能为整数!');
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
                         }
                         else if(me.hasTisNo(me.currentCoeList, inputT)){
-                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
                             alert('该编号已存在!');
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
                         }
                     }
                     else {
@@ -421,9 +421,9 @@ let gljAdjOprObj = {
             dataCode = me.setting.header[args.col].dataCode;
         if(args.editingText && args.editingText.toString().trim().length > 0){
             if(dataCode === 'amount' &&  isNaN(args.editingText)){
+                alert("只能输入数值!");
                 args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
                     ? me.currentGljAdjList[args.row][dataCode] + '' : '');
-                alert("只能输入数值!");
             }
             else {
                 //update

+ 32 - 1
web/maintain/ration_repository/js/ration.js

@@ -9,6 +9,11 @@ $("#gongliao").click(function(){
 $("#fuzhu").click(function(){
     $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
 });
+const digital = {
+    gljPrc: -3,//计算定额基价时单个工料机价格取三位
+    rationBasePrc: -2,
+    consumeAmt: -3
+};
 let rationOprObj = {
     workBook: null,
     currentRations: {},
@@ -444,6 +449,7 @@ let rationOprObj = {
     },
     mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
         let me = rationOprObj;
+        me.saveInString(updateArr);
         $.ajax({
             type:"POST",
             url:"api/mixUpdateRationItems",
@@ -593,5 +599,30 @@ let rationOprObj = {
             }
         }
         arr.sort(compare());
+    },
+    saveInString(datas){
+        for(let i = 0, len = datas.length; i < len; i++){
+            let data = datas[i];
+            if(data.labourPrice !== undefined && data.labourPrice){
+                data.labourPrice = data.labourPrice.toString();
+            }
+            if(data.materialPrice !== undefined && data.materialPrice){
+                data.materialPrice = data.materialPrice.toString();
+            }
+            if(data.machinePrice !== undefined && data.machinePrice){
+                data.machinePrice = data.machinePrice.toString();
+            }
+            if(data.basePrice !== undefined && data.basePrice){
+                data.basePrice = data.basePrice.toString();
+            }
+            if(data.rationGljList !== undefined && data.rationGljList && data.rationGljList.length > 0){
+                for(let j = 0, jLen = data.rationGljList.length; j < jLen; j++){
+                    let raGljObj = data.rationGljList[j];
+                    if(raGljObj.consumeAmt !== undefined && raGljObj.consumeAmt){
+                        raGljObj.consumeAmt = raGljObj.consumeAmt.toString();
+                    }
+                }
+            }
+        }
     }
-}
+}

+ 7 - 7
web/maintain/ration_repository/js/ration_glj.js

@@ -168,7 +168,7 @@ var rationGLJOprObj = {
                         let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
                         me.cache["_GLJ_" + me.currentRationItem.ID].length - info.cellRange.row : info.cellRange.rowCount;
                         for(let i = 0; i < maxCount; i++){
-                            let roundCons = me.round(tempConsumes[i].consumeAmt, 3);
+                            let roundCons = scMathUtil.roundTo(tempConsumes[i].consumeAmt, -3);
                             me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
                         }
                         me.updateRationItem(function () {
@@ -232,7 +232,7 @@ var rationGLJOprObj = {
                         }
                         else {
                             args.sheet.setValue(args.row, args.col, parseNum);
-                            let roundNum = me.round(parseNum, 3);
+                            let roundNum = scMathUtil.roundTo(parseNum, -3);
                             editGlj["consumeAmt"] = roundNum;
                             me.updateRationItem(function () {
                                 me.sheet.getParent().focus(true);
@@ -435,10 +435,10 @@ var rationGLJOprObj = {
                 if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
                     let parent = me.distTypeTree.distTypes[me.distTypeTree.prefix + gljData.gljType].parent;
                     if(parent && parent.data.ID <= 3){
-                        price['gljType' + parent.data.ID].push(me.round( gljData.basePrice * gljData.consumeAmt, 3));//取三位
+                        price['gljType' + parent.data.ID].push(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
                     }
                     if(!parent && gljData.gljType <= 3){
-                        price['gljType' + gljData.gljType].push(me.round( gljData.basePrice * gljData.consumeAmt, 3));//取三位
+                        price['gljType' + gljData.gljType].push(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
                     }
                 }
             });
@@ -447,7 +447,7 @@ var rationGLJOprObj = {
                 price.gljType1.forEach(function (singlePrc) {
                     labourPrice += singlePrc;
                 });
-                let roundPrice = me.round(labourPrice, 2);
+                let roundPrice = scMathUtil.roundTo(labourPrice, -2);
                 rst.labourPrice = roundPrice;
                 rationBasePrc += roundPrice;
             }
@@ -456,7 +456,7 @@ var rationGLJOprObj = {
                 price.gljType2.forEach(function (singlePrc) {
                     materialPrice += singlePrc;
                 });
-                let roundPrice = me.round(materialPrice, 2);
+                let roundPrice = scMathUtil.roundTo(materialPrice, -2);
                 rst.materialPrice = roundPrice;
                 rationBasePrc += roundPrice;
             }
@@ -465,7 +465,7 @@ var rationGLJOprObj = {
                 price.gljType3.forEach(function (singlePrc) {
                     machinePrice += singlePrc;
                 });
-                let roundPrice = me.round(machinePrice, 2);
+                let roundPrice = scMathUtil.roundTo(machinePrice, -2);
                 rst.machinePrice = roundPrice;
                 rationBasePrc += roundPrice;
             }

+ 1 - 2
web/maintain/ration_repository/js/repository_glj.js

@@ -144,7 +144,7 @@ repositoryGljObj = {
         $.ajax({
             type:"POST",
             url:"api/getGljItems",
-            data:{"gljLibID": gljLibID},
+            data:{"repositoryId": gljLibID},
             dataType:"json",
             cache:false,
             timeout:5000,
@@ -343,7 +343,6 @@ repositoryGljObj = {
         if(updateArr.length >0 || addArr.length >0){
             me.currentEditingGlj = null;
             //me.workBook.getSheet(0).setValue(11, 5, "人工");
-            console.log(addArr);
             me.mixUpdateRequest(updateArr, addArr, []);
         }
     },

+ 1 - 0
web/maintain/std_glj_lib/html/gongliao.html

@@ -244,6 +244,7 @@
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.exedit.js"></script>
+    <script type="text/javascript" src="/public/web/scMathUtil.js"></script>
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/web/QueryParam.js"></script>
     <script type="text/javascript" src="/web/maintain/std_glj_lib/js/glj.js"></script>

+ 41 - 5
web/maintain/std_glj_lib/js/glj.js

@@ -1,6 +1,12 @@
 /**
  * Created by Zhong on 2017/8/14.
  */
+
+const digital = {
+    basePrice: -2,
+    consumeAmt: -3
+};
+
 let pageOprObj = {
     gljLibName : null,
     gljLibId: null,
@@ -21,7 +27,7 @@ let pageOprObj = {
             });
         });
     }
-}
+};
 let repositoryGljObj = {
     treeObj : null,
     workBook: null,
@@ -435,6 +441,12 @@ let repositoryGljObj = {
                         }
                         else if(rObj.basePrice !== me.currentEditingGlj.basePrice){//修改了单价,可修改单价的必为可成为组成物的
                             //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
+                            if(isNaN(parseFloat(rObj.basePrice))){
+                                alert('单价只能输入数值!');
+                                args.sheet.setValue(args.row, args.col, me.currentEditingGlj.basePrice ? me.currentEditingGlj.basePrice : 0);
+                                return;
+                            }
+                            rObj.basePrice = !isNaN(parseFloat(rObj.basePrice))? scMathUtil.roundTo(parseFloat(rObj.basePrice), -2) : me.currentEditingGlj.basePrice;
                             let updateGljs = me.getUpdateGljs(rObj);
                             if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
                                 for(let i = 0; i < updateGljs.updateArr.length; i++){
@@ -444,7 +456,6 @@ let repositoryGljObj = {
                                     updateArr.push(updateGljs.updateBasePrcArr[i]);
                                 }
                             }
-                            rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? that.round(parseFloat(rObj.basePrice), 2) : me.currentEditingGlj.basePrice;
                         }
                         rObj.component = me.currentGlj.component;
                         updateArr.push(rObj);
@@ -504,7 +515,7 @@ let repositoryGljObj = {
                     if(me.allowComponent.indexOf(rObj.gljType) !== -1){
                         rObj.basePrice = 0;
                     }
-                    rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? parseFloat(rObj.basePrice) : 0;
+                    rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(rObj.basePrice), -2) : 0;
                     addArr.push(rObj);
                 }
             }
@@ -699,7 +710,7 @@ let repositoryGljObj = {
             }
         }
         if(typeof pasteObj.basePrice !== 'undefined'){
-            pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? that.round(parseFloat(pasteObj.basePrice), 2) :
+            pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), -2) :
                 me.currentCache[rowIdx].basePrice;
             if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
                 reCalBasePrc = true;
@@ -944,6 +955,12 @@ let repositoryGljObj = {
     },*/
     mixUpdateRequest: function(updateArr, addArr, removeIds) {
         let me = repositoryGljObj;
+        if(updateArr.length > 0){
+            me.saveInString(updateArr)
+        }
+        if(addArr.length > 0){
+            me.saveInString(addArr);
+        }
         $.ajax({
             type:"POST",
             url:"api/mixUpdateGljItems",
@@ -976,7 +993,26 @@ let repositoryGljObj = {
                 console.log(err);
                 alert("保存失败");
             }
-        })
+        });
+    },
+    saveInString: function (datas) {
+        for(let i = 0, len = datas.length; i < len; i++){
+            let data = datas[i];
+            if(_exist(data, 'basePrice')){
+                data['basePrice'] = data['basePrice'].toString();
+            }
+            if(_exist(data, 'component')){
+                for(let j = 0, jLen = data['component'].length; j < jLen; j++){
+                    let comGljObj = data['component'][j];
+                    if(_exist(comGljObj, 'consumeAmt')){
+                        comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
+                    }
+                }
+            }
+        }
+        function _exist(data, attr){
+            return data && data[attr] !== undefined && data[attr];
+        }
     },
     getParentCache: function (nodes) {
         let me = repositoryGljObj, rst = [];

+ 5 - 11
web/maintain/std_glj_lib/js/gljComponent.js

@@ -310,7 +310,7 @@ let gljComponentOprObj = {
         else if(args.col === 4 && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
             let consumeAmt = parseFloat(args.editingText);
             if(!isNaN(consumeAmt) && consumeAmt !== me.currentEditingComponent.consumeAmt){
-                let roundCons = me.round(consumeAmt, 3);
+                let roundCons = scMathUtil.roundTo(consumeAmt, -3);
                 let component = that.currentGlj.component;
                 for(let i = 0; i < component.length; i++){
                     if(component[i].ID === that.currentComponent[args.row].ID){
@@ -358,7 +358,6 @@ let gljComponentOprObj = {
         let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [] ,materialComponent = [202, 203, 204], machineComponent = [302, 303],
             component = that.currentGlj.component, newComponent = [], concatComponent = [], isChange = false, updateBasePrc = [];
         let items = sheetCommonObj.analyzePasteData(me.setting, info);
-        console.log(items);
         let gljCache = that.gljList;
         if(info.cellRange.col === 0){
             for(let i = 0; i < items.length; i++){
@@ -431,7 +430,7 @@ let gljComponentOprObj = {
                 if(row + i < that.currentComponent.length){
                     let currentObj = that.currentComponent[row + i];
                     if(items[i].consumeAmt.trim().length > 0 && items[i].consumeAmt !== currentObj.consumeAmt){
-                        let roundCons = me.round(items[i].consumeAmt, 3);
+                        let roundCons = scMathUtil.roundTo(items[i].consumeAmt, -3);
                         isChange = true;
                         currentObj.consumeAmt = roundCons;
                         for(let j = 0; j < component.length; j++){
@@ -469,6 +468,7 @@ let gljComponentOprObj = {
     },
     updateComponent: function (updateArr) {
         let me = gljComponentOprObj, that = repositoryGljObj;
+        repositoryGljObj.saveInString(updateArr);
         $.ajax({
             type: 'post',
             url: 'api/updateComponent',
@@ -486,17 +486,11 @@ let gljComponentOprObj = {
             }
         })
     },
-    round: function (v, e) {
-        let t=1;
-        for(;e>0;t*=10,e--);
-        for(;e<0;t/=10,e++);
-        return Math.round(v*t)/t;
-    },
     reCalGljBasePrc: function (component) {
         let me = gljComponentOprObj, gljBasePrc = 0;
         for(let i = 0; i < component.length; i++){
-            let roundBasePrc = me.round(component[i].basePrice, 2);
-            gljBasePrc += me.round(roundBasePrc * component[i].consumeAmt, 2);
+            let roundBasePrc = scMathUtil.roundTo(component[i].basePrice, -2);
+            gljBasePrc += scMathUtil.roundTo(roundBasePrc * component[i].consumeAmt, -2);
         }
         return gljBasePrc;
     }