Pārlūkot izejas kodu

工料机库修改重新计算定额基价的方法等等

zhongzewei 7 gadi atpakaļ
vecāks
revīzija
cc036b595d
27 mainītis faili ar 924 papildinājumiem un 428 dzēšanām
  1. 23 0
      modules/bills_lib/controllers/stdBillsLib_permissionController.js
  2. 4 3
      modules/bills_lib/models/bills_lib_interfaces.js
  3. 26 4
      modules/bills_lib/models/bills_lib_schemas.js
  4. 1 0
      modules/bills_lib/routes/bills_lib_routes.js
  5. 54 19
      modules/ration_repository/controllers/ration_repository_controller.js
  6. 3 3
      modules/ration_repository/controllers/repository_glj_controller.js
  7. 8 7
      modules/ration_repository/models/glj_repository.js
  8. 34 147
      modules/ration_repository/models/ration_item.js
  9. 94 61
      modules/ration_repository/models/repository_map.js
  10. 1 0
      modules/ration_repository/routes/ration_rep_routes.js
  11. 31 12
      modules/std_glj_lib/controllers/gljController.js
  12. 10 1
      modules/std_glj_lib/models/gljMapModel.js
  13. 51 18
      modules/std_glj_lib/models/gljModel.js
  14. 24 5
      modules/std_glj_lib/models/schemas.js
  15. 2 1
      modules/std_glj_lib/routes/routes.js
  16. 15 1
      public/web/sheet/sheet_common.js
  17. 17 7
      web/maintain/bills_lib/html/main.html
  18. 21 2
      web/maintain/bills_lib/scripts/bills_lib_ajax.js
  19. 8 8
      web/maintain/ration_repository/gongliao.html
  20. 273 11
      web/maintain/ration_repository/js/main.js
  21. 18 3
      web/maintain/ration_repository/js/ration.js
  22. 33 29
      web/maintain/ration_repository/js/ration_glj.js
  23. 18 16
      web/maintain/ration_repository/js/repository_glj.js
  24. 14 10
      web/maintain/ration_repository/main.html
  25. 92 45
      web/maintain/std_glj_lib/js/glj.js
  26. 42 13
      web/maintain/std_glj_lib/js/gljComponent.js
  27. 7 2
      web/maintain/std_glj_lib/js/main.js

+ 23 - 0
modules/bills_lib/controllers/stdBillsLib_permissionController.js

@@ -3,8 +3,31 @@
  */
 let billsController = require("./bills_lib_controllers");
 import baseController from "../../common/base/base_controller";
+import CompilationModel from "../../users/models/compilation_model";
 
+let callback = function(req, res, err, message, data){
+    res.json({error: err, message: message, data: data});
+}
 class billsLibPermContr extends baseController{
+    async getCompilationList(req, res){
+        try{
+            let compilationModel = new CompilationModel(), rst = [];
+            let compilationList = await compilationModel.getCompilationList();
+            if(compilationList.length <= 0){
+                throw '没有数据';
+            }
+            else{
+
+                compilationList.forEach(function (compilation) {
+                    rst.push({_id: compilation._id, name: compilation.name});
+                })
+                callback(req, res, false, '', rst);
+            }
+        }
+        catch(err) {
+            callback(req, res, err, '没有数据', null);
+        }
+    }
     getMaxNumber(req, res){
         billsController.getMaxNumber(req, res);
     }

+ 4 - 3
modules/bills_lib/models/bills_lib_interfaces.js

@@ -66,10 +66,10 @@ billsLibDao.prototype.getStdBillsLib = function(callback){
 billsLibDao.prototype.createStdBillsLib = function(clibData, callback){
     counter.counterDAO.getIDAfterCount(counter.moduleName.billsLib, 1, function(err, result){
         let billsLibId = result.value.sequence_value;
-        let userId = clibData.userId;
         let userAccount = clibData.userAccount;
         let billsLibName = clibData.name;
-        let createDate = Date.now();
+        let compilationId = clibData.compilationId;
+        let compilationName = clibData.compilationName;
         let dateStr = moment().format('YYYY-MM-DD HH:mm:ss');
         let newStdBillsLib = {
             creator: userAccount,
@@ -77,7 +77,8 @@ billsLibDao.prototype.createStdBillsLib = function(clibData, callback){
             recentOpr: [{operator: userAccount, operateDate: dateStr}],
             billsLibId: billsLibId,
             billsLibName: billsLibName,
-            localeType: -1,
+            compilationId: compilationId,
+            compilationName: compilationName,
             deleted: false
         };
         StdBillsLib.create(newStdBillsLib, function(err){

+ 26 - 4
modules/bills_lib/models/bills_lib_schemas.js

@@ -1,19 +1,41 @@
 let mongoose = require('mongoose');
 
+let oprSchema = mongoose.Schema({
+    operateDate: String,
+    operator: String
+},
+    {_id: false},
+    {versionKey: false});
+
 let stdBillsLibSchema =mongoose.Schema({
         creator: String,
         createDate: String,
-        recentOpr: [],
+        recentOpr: [oprSchema],
        /* lastOperator: String,
         lastOperateDate: Date,*/
         billsLibId: Number,
         billsLibName: String,
-        localeType: Number,
+        compilationId: String,
+        compilationName: String,
         deleted: Boolean
     },
     {versionKey: false}
 );
 
+let jobsSchema = mongoose.Schema({
+    id: Number,
+    serialNo: Number
+},
+    {_id: false},
+    {versionKey: false});
+
+let itemsSchema = mongoose.Schema({
+    id: Number,
+    serialNo: Number
+},
+    {_id: false},
+    {versionKey: false});
+
 let billsSchema = mongoose.Schema({
     ID: Number,
     ParentID: Number,
@@ -23,8 +45,8 @@ let billsSchema = mongoose.Schema({
     unit: String,
     ruleText: String,
     Expression: String,
-    jobs: Array,
-    items: Array,
+    jobs: [jobsSchema],
+    items: [itemsSchema],
     recharge:String,
     billsLibId: Number,
     deleted: Boolean

+ 1 - 0
modules/bills_lib/routes/bills_lib_routes.js

@@ -21,6 +21,7 @@ module.exports =function (app) {
      app.get('/stdJobs', viewsContr.auth, viewsContr.init, viewsContr.redirectStdJobs);
      app.get('/stdItems', viewsContr.auth, viewsContr.init, viewsContr.redirectStdItems);
 
+     billsRouter.post('/getCompilationList', billsLibContr.auth, billsLibContr.init, billsLibContr.getCompilationList);
      billsRouter.post('/getMaxNumber', billsLibContr.auth, billsLibContr.init, billsLibContr.getMaxNumber);
      billsRouter.post('/getABillsLib', billsLibContr.auth, billsLibContr.init, billsLibContr.getABillsLib);
      billsRouter.post("/getStdBillsLib", billsLibContr.auth, billsLibContr.init, billsLibContr.getStdBillsLib);

+ 54 - 19
modules/ration_repository/controllers/ration_repository_controller.js

@@ -4,6 +4,8 @@
 var rationRepository = require("../models/repository_map");
 import baseController from "../../common/base/base_controller";
 import CompilationModel from "../../users/models/compilation_model";
+import {gljMapModel} from "../../std_glj_lib/models/schemas";
+import async from "async";
 var callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
 };
@@ -20,8 +22,37 @@ class RationRepositoryController extends baseController{
 
                compilationList.forEach(function (compilation) {
                    rst.push({_id: compilation._id, name: compilation.name});
+               });
+               //获得相关编办下的工料机库
+               let parallelFucs = [];
+               for(let i = 0; i < rst.length; i++){
+                   parallelFucs.push((function (obj) {
+                       return function (cb) {
+                           gljMapModel.find({compilationId: obj._id, deleted: false}, function (err, result) {
+                               if(err){
+                                   cb(err);
+                               }
+                               else{
+                                   cb(null, result);
+                               }
+                           })
+                       }
+                   })(rst[i]));
+               }
+               async.parallel(parallelFucs, function (err, result) {
+                   if(err){
+                       callback(req, res, err, '没有数据', null);
+                   }
+                   else{
+                       let gljLibsRst = [];
+                       for(let i = 0; i < result.length; i++){
+                           for(let j = 0; j < result[i].length; j++){
+                               gljLibsRst.push(result[i][j]);
+                           }
+                       }
+                       callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
+                   }
                })
-               callback(req, res, false, '', rst);
            }
        }
         catch(err) {
@@ -38,6 +69,16 @@ class RationRepositoryController extends baseController{
             }
         })
     }
+    getRationLib(req, res){
+        let libId = req.body.libId;
+        rationRepository.getRationLib(libId, function(err, data){
+            if (data) {
+                callback(req, res, err, "has data",data);
+            } else {
+                callback(req, res, err, "no data", null);
+            }
+        });
+    }
     getDisPlayRationLibs(req, res){
         rationRepository.getDisplayRationLibs(function(err, data){
             if (data) {
@@ -66,27 +107,21 @@ class RationRepositoryController extends baseController{
             }
         })
     }
+
     deleteRationLib(req,res){
-        var rationName = req.body.rationName, lastOperator = req.body.lastOperator;
-        rationRepository.deleteRationLib(rationName, lastOperator, function(err,data){
-            if (data) {
-                callback(req, res, err, "has data", data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        })
+        let oprtor = req.body.oprtor,
+            libId = req.body.libId;
+        rationRepository.deleteRationLib(oprtor, libId, function (err, message) {
+            callback(req, res, err, message, null);
+        });
     }
+
     updateRationRepositoryName(req, res) {
-        var orgName = req.body.rationName;
-        var newName = req.body.newName;
-        var lastOperator = req.body.lastOperator;
-        rationRepository.updateName(orgName, newName, lastOperator, function(err, data){
-            if (data) {
-                callback(req, res, err, "has data", data);
-            } else {
-                callback(req, res, err, "no data", null);
-            }
-        });
+        let oprtor = req.body.oprtor,
+            renameObj = JSON.parse(req.body.renameObj);
+        rationRepository.updateName(oprtor, renameObj, function (err, message) {
+            callback(req, res, err, message, null);
+        })
     }
 }
 

+ 3 - 3
modules/ration_repository/controllers/repository_glj_controller.js

@@ -20,8 +20,8 @@ class RepositoryGljController extends BaseController{
         }
     }
     getGljTree(req,res){
-        var rationLibId = req.body.rationLibId;
-        gljRepository.getGljTypes(rationLibId,function(err,data){
+        var gljLibID = req.body.gljLibID;
+        gljRepository.getGljTypes(gljLibID,function(err,data){
             callback(req,res,err, 'Get Tree', data)
         });
     }
@@ -52,7 +52,7 @@ class RepositoryGljController extends BaseController{
         });
     }
     getGljItems(req, res) {
-        var repId = req.body.repositoryId,
+        var repId = req.body.gljLibID,
             gljType = req.body.type,
             gljCode = req.body.code;
         if (gljCode) {

+ 8 - 7
modules/ration_repository/models/glj_repository.js

@@ -36,10 +36,11 @@ var gljItemModel = db.model("std_ration_lib_glj_list",gljSchema, "std_ration_lib
 var repositoryMap = require('./repository_map');
 var counter = require('../../../public/counter/counter');
 let moment = require('moment');
+import {gljModel, gljClassModel} from "../../std_glj_lib/models/schemas";
 
 var gljItemDAO = function(){};
-gljItemDAO.prototype.getGljTypes = function(rationLibId, callback){
-    gljTypeModel.find({"repositoryId": rationLibId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
+gljItemDAO.prototype.getGljTypes = function(gljLibID, callback){
+    gljClassModel.find({"repositoryId": gljLibID, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
         if(data.length) callback(false,data);
         else  if(err) callback("获取工料机类型错误!",false)
         else callback(false,false);
@@ -47,35 +48,35 @@ gljItemDAO.prototype.getGljTypes = function(rationLibId, callback){
 };
 
 gljItemDAO.prototype.getGljItemsByRep = function(repositoryId,callback){
-    gljItemModel.find({"repositoryId": repositoryId},function(err,data){
+    gljModel.find({"repositoryId": repositoryId},function(err,data){
         if(err) callback(true, "")
         else callback(false,data);
     })
 };
 
 gljItemDAO.prototype.getGljItemByType = function(repositoryId, type, callback){
-    gljItemModel.find({"repositoryId": repositoryId, "gljType": type},function(err,data){
+    gljModel.find({"repositoryId": repositoryId, "gljType": type},function(err,data){
         if(err) callback(true, "")
         else callback(false, data);
     })
 };
 
 gljItemDAO.prototype.getGljItem = function(repositoryId, code, callback){
-    gljItemModel.find({"repositoryId": repositoryId, "code": code},function(err,data){
+    gljModel.find({"repositoryId": repositoryId, "code": code},function(err,data){
         if(err) callback(true, "")
         else callback(false, data);
     })
 };
 
 gljItemDAO.prototype.getGljItems = function(gljIds, callback){
-    gljItemModel.find({"ID": {"$in": gljIds}},function(err,data){
+    gljModel.find({"ID": {"$in": gljIds}},function(err,data){
         if(err) callback(true, "")
         else callback(false, data);
     })
 };
 
 gljItemDAO.prototype.getGljItemsByCode = function(repositoryId, codes, callback){
-    gljItemModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){
+    gljModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){
         if(err) callback(true, "")
         else callback(false, data);
     })

+ 34 - 147
modules/ration_repository/models/ration_item.js

@@ -212,24 +212,52 @@ function round(v,e){
     return Math.round(v*t)/t;
 }
 
-rationItemDAO.prototype.updateRationBasePrc = function (data, callback) {
-    let basePrcArr = data.basePrcArr,
+rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
+   // let basePrcArr = data.basePrcArr;
        // adjGljId = data.gljId, adjBasePrice = data.basePrice, adjGljType = data.gljType,
-        repId = data.repId, lastOpr = data.lastOpr;
+      //  repId = data.repId, lastOpr = data.lastOpr;
     //
-    let updateArr;
+   // let updateArr;
     async.each(basePrcArr, function (basePrcObj, finalCb) {
         let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
         async.waterfall([
             function (cb) {
-                rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
+                if(typeof basePrcObj.delete !== 'undefined' && basePrcObj.delete === 1){
+                    rationItemModel.find({'rationGljList.gljId': adjGljId},{ID: 1, rationGljList: 1}, function (err, result) {
+                        if(err){
+                            cb(err);
+                        }
+                        else{
+                            //删除
+                            rationItemModel.update({'rationGljList.gljId': adjGljId}, {$pull: {rationGljList: {gljId: adjGljId}}}, {multi: true}, function (err) {
+                                if(err){
+                                    cb(err);
+                                }
+                                else{
+                                    cb(null, result);
+                                }
+                            });
+                        }
+                    });
+                }
+                else{
+                    rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
+                        if(err){
+                            cb(err);
+                        }
+                        else{
+                            cb(null, result);
+                        }
+                    });
+                }
+               /* rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
                     if(err){
                         cb(err);
                     }
                     else{
                         cb(null, result);
                     }
-                });
+                });*/
             },
             function (result, cb) {
                 async.each(result, function (rationItem, ecb) {
@@ -332,16 +360,6 @@ rationItemDAO.prototype.updateRationBasePrc = function (data, callback) {
                     }
                 });
             },
-            function (cb) {
-                rationRepositoryDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
-                    if(err){
-                        cb(err);
-                    }
-                    else{
-                        cb(null);
-                    }
-                })
-            }
         ], function (err) {
             if(err){
                 finalCb(err);
@@ -358,137 +376,6 @@ rationItemDAO.prototype.updateRationBasePrc = function (data, callback) {
             callback(null, '');
         }
     });
-    //
-    /*async.waterfall([
-        function (cb) {
-            rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
-                if(err){
-                    cb(err);
-                }
-                else{
-                    cb(null, result);
-                }
-            });
-        },
-        function (result, cb) {
-            async.each(result, function (rationItem, ecb) {
-                let rationGljList = rationItem.rationGljList,
-                    gljIds = [];
-                rationGljList.forEach(function (rationGlj) {
-                    gljIds.push(rationGlj.gljId);
-                });
-                gljDao.getGljItems(gljIds, function(err, gljItems){
-                    if(err){
-                        ecb(err);
-                    }
-                    else{
-                        let gljArr = [];
-                        for(let i=0; i<gljItems.length; i++){
-                            let gljParentType = -1;
-                            if(gljItems[i].ID === adjGljId){
-                                gljItems[i].gljType = adjGljType;
-                            }
-                            if(gljItems[i].gljType <= 3){
-                                gljParentType = gljItems[i].gljType;
-                            }
-                            if(gljItems[i].gljType > 200 && gljItems[i].gljType < 300){
-                                gljParentType = 2;
-                            }
-                            if(gljItems[i].gljType > 300 && gljItems[i].gljType < 400){
-                                gljParentType = 3;
-                            }
-                            if(gljItems[i].ID === adjGljId){
-                                gljArr.push({gljId: gljItems[i].ID, basePrice: adjBasePrice, gljParentType: gljParentType});
-                            }
-                            else {
-                                gljArr.push({gljId: gljItems[i].ID, basePrice: gljItems[i].basePrice, gljParentType: gljParentType});
-                            }
-                        }
-                        gljArr.forEach(function (gljItem) {
-                            rationGljList.forEach(function (rationGlj) {
-                                if(gljItem.gljId === rationGlj.gljId){
-                                    gljItem.consumeAmt = rationGlj.consumeAmt;
-                                }
-                            })
-                        });
-                        //recalculate the price of ration
-                        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);
-                                if(gljItem.gljParentType === 1){
-                                    labourPrc.push(singlePrc);
-                                }
-                                else if(gljItem.gljParentType ===2){
-                                    materialPrc.push(singlePrc);
-                                }
-                                else{
-                                    machinePrc.push(singlePrc);
-                                }
-                            }
-                        });
-                        if(labourPrc.length > 0){
-                            let sumLaP = 0;
-                            for(let i=0; i<labourPrc.length; i++){
-                                sumLaP += labourPrc[i];
-                            }
-                            updatePrc.labourPrice = round(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);
-                        }
-                        if(machinePrc.length > 0){
-                            let sumMaP = 0;
-                            for(let i =0; i< machinePrc.length; i++){
-                                sumMaP += machinePrc[i];
-                            }
-                            updatePrc.machinePrice = round(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}},
-                            function (err, result) {
-                                if(err){
-                                    ecb(err);
-                                }
-                                else {
-                                    ecb(null);
-                                }
-                            });
-                    }
-                });
-            }, function(err){
-                if(err){
-                    cb(err);
-                }
-                else {
-                    cb(null);
-                }
-            });
-        },
-        function (cb) {
-            rationRepositoryDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
-                if(err){
-                    cb(err);
-                }
-                else{
-                    cb(null);
-                }
-            })
-        }
-    ], function (err) {
-        if(err){
-            callback(err, 'Error');
-        }
-        else{
-            callback(null, '');
-        }
-    });*/
 };
 
 rationItemDAO.prototype.getRationGljIds = function (data, callback) {

+ 94 - 61
modules/ration_repository/models/repository_map.js

@@ -6,19 +6,29 @@ var mongoose = require('mongoose');
 var dbm = require("../../../config/db/db_manager");
 let async = require("async");
 let moment = require('moment');
+import {gljMapModel} from "../../std_glj_lib/models/schemas";
 //var stringUtil = require('../../../public/stringUtil');
 var rationLibdb = dbm.getCfgConnection("scConstruct");
 var Schema = mongoose.Schema;
+
+let oprSchema = new Schema({
+        operateDate: String,
+        operator: String
+    },
+    {_id: false},
+    {versionKey: false});
+
 var RepositoryMapSchema = new Schema({
     "ID": Number,
     "dispName" : String,
     "appType" : String, //如:"建筑" / "公路"
-    "compilationId": Number, //编办
+    "compilationId": String, //编办
     "compilationName": String,
+    "gljLib": Number,
     "descr" : String,
     "creator": String,
     "createDate": String,
-    "recentOpr" :[],
+    "recentOpr" :[oprSchema],
     "deleted": Boolean
 },  {versionKey: false});
 var counter = require('../../../public/counter/counter');
@@ -29,17 +39,29 @@ function createNewLibModel(rationLibObj){
     var rst = {};
     rst.dispName = rationLibObj.dispName;
     rst.appType = rationLibObj.appType?rationLibObj.appType:'construct';
-    rst.localeType = rationLibObj.localeType?rationLibObj.localeType:'';
-    rst.descr = rationLibObj.descr;
+    rst.compilationId = rationLibObj.compilationId;
+    rst.compilationName = rationLibObj.compilationName;
+    rst.gljLib = rationLibObj.gljLib;
     rst.creator = rationLibObj.creator;
     rst.createDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
-    rst.recentOpr = [{operator: rationLibObj.lastOperator, operateDate: rst.createDate}],
+    rst.recentOpr = [{operator: rationLibObj.creator, operateDate: rst.createDate}],
     rst.deleted = false;
     return rst;
 }
 
 var rationRepositoryDao = function(){};
 
+rationRepositoryDao.prototype.updateGljLib = function (gljLibId, callback) {
+    rationRepository.update({gljLib: gljLibId}, {$set: {gljLib: -1}}, {multi: true}, function (err) {
+        if(err){
+            callback(err);
+        }
+        else{
+            callback(null);
+        }
+    })
+};
+
 rationRepositoryDao.prototype.updateOprArr= function(findSet, oprtor, oprDate, cb){
     rationRepository.find(findSet, function (err, result) {
         if(err){
@@ -133,13 +155,39 @@ rationRepositoryDao.prototype.addRationRepository = function( rationLibObj,callb
         var rMap = createNewLibModel(rationLibObj);
         rMap.ID = result.value.sequence_value;
         new rationRepository(rMap).save(function(err, result) {
-            if (err) callback("Error", null)
-            else
-                callback(false, result);
+            if (err) callback("Error", null);
+            else{
+                //向引用工料机库的添加标记
+                gljMapModel.update({ID: rMap.gljLib, deleted: false}, {$addToSet: {rationLibs: {ID: rMap.ID, dispName: rMap.dispName}}}, function (err, data) {
+                    if(err){
+                        rationRepository.remove({ID: rMap.ID}, function (err) {
+                            if(err){
+                                callback("创建失败且回滚失败!", null);
+                            }
+                            else{
+                                callback("创建失败,已回滚!", null);
+                            }
+                        });
+                    }
+                    else{
+                        callback(false, result);
+                    }
+                });
+            }
         });
     });
 };
 
+rationRepositoryDao.prototype.getRationLib = function(libId, callback) {
+    rationRepository.find({ID: libId, "deleted": false}, function(err, data){
+        if (err) {
+            callback( 'Error', null);
+        } else {
+            callback( false, data);
+        }
+    });
+};
+
 rationRepositoryDao.prototype.getDisplayRationLibs = function(callback) {
     rationRepository.find({"deleted": false}, function(err, data){
         if (err) {
@@ -150,69 +198,54 @@ rationRepositoryDao.prototype.getDisplayRationLibs = function(callback) {
     });
 };
 
-rationRepositoryDao.prototype.updateName = function(orgName,newName, lastOpr, callback){
-    rationRepository.find({"dispName":newName, "deleted": false}, function(err, data){
-        if (data.length == 0) {
-            async.waterfall([
-                function (cb) {
-                    rationRepository.update({dispName:orgName},{$set:{dispName:newName}},function(err){
-                        if(err) cb(err);
-                        else cb(null)
-                    });
-                },
-                function (cb) {
-                    new rationRepositoryDao().updateOprArr({dispName: newName}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
-                        if(err){
-                            cb(err)
-                        }
-                        else{
-                            cb(null);
-                        }
-                    });
-                }
-            ], function (err) {
+rationRepositoryDao.prototype.updateName = function(oprtor, renameObj, callback){
+    rationRepository.update({ID: renameObj.ID, deleted: false}, {$set: {dispName: renameObj.newName}}, function (err) {
+        if(err){
+            callback(err, '重命名失败!');
+        }
+        else{
+            new rationRepositoryDao().updateOprArr({ID: renameObj.ID, deleted: false}, oprtor, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
                 if(err){
-                    callback('err', false);
+                    callback(err, '更新最近操作者失败!');
                 }
                 else{
-                    callback(false, 'ok');
+                    callback(null, '成功!');
                 }
             });
-        } else
-            callback("不可重名!",false);
+        }
     });
 }
 
-rationRepositoryDao.prototype.deleteRationLib = function(rationName, lastOpr,  callback){
-    rationRepository.find({"dispName":rationName, "deleted": false}, function(err, data){
-        if (data.length == 1) {
-            async.parallel([
-                function (cb) {
-                    rationRepository.update({dispName:rationName, deleted: false},{$set: {deleted: true}},function(err){
-                        if(err) cb(err);
-                        else cb(null);
-                    })
-                },
-                function (cb) {
-                    new rationRepositoryDao().updateOprArr({dispName: rationName}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
-                        if(err){
-                            cb(err);
-                        }
-                        else{
-                            cb(null);
-                        }
-                    });
-                }
-            ], function (err) {
-                if(err){
-                    callback("err", false)
-                }
+rationRepositoryDao.prototype.deleteRationLib = function(oprtor, libId, callback){
+    new rationRepositoryDao().updateOprArr({ID: libId, deleted: false}, oprtor, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
+        if(err){
+            callback(err, '失败!')
+        }
+        else{
+            rationRepository.find({ID: libId, deleted: false}, function (err, result) {
+               if(err){
+                   callback(err, "没有数据!");
+               }
                 else{
-                    callback(false, "ok");
-                }
+                   rationRepository.update({ID: libId, deleted: false}, {$set: {deleted: true}}, function (err) {
+                       if(err){
+                           callback(err, '移除工料机库失败!');
+                       }
+                       else{
+                           //移除工料机库内被引用标记
+                           gljMapModel.update({ID: result[0].gljLib, deleted: false}, {$pull: {rationLibs: {ID: libId}}}, function (err) {
+                               if(err){
+                                   callback(err, '删除引用失败!');
+                               }
+                               else{
+                                   callback(null, '成功!');
+                               }
+                           });
+                       }
+                   });
+               }
             });
-        } else
-            callback("删除失败!",false);
+        }
     });
 }
 

+ 1 - 0
modules/ration_repository/routes/ration_rep_routes.js

@@ -38,6 +38,7 @@ module.exports =  function (app) {
 
     apiRouter.post("/getCompilationList", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getCompilationList);
 
+    apiRouter.post("/getRationLib",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLib);
     apiRouter.post("/getRationDisplayNames",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getDisPlayRationLibs);
     apiRouter.post("/editRationLibs",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.updateRationRepositoryName);
     apiRouter.post("/addRationRepository",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.addRationRepository);

+ 31 - 12
modules/std_glj_lib/controllers/gljController.js

@@ -5,6 +5,7 @@
 import BaseController from "../../common/base/base_controller";
 import stdgljutil  from "../../../public/cache/std_glj_type_util";
 import GljDao from "../models/gljModel";
+import rationItemDao from "../../ration_repository/models/ration_item";
 
 let gljDao = new GljDao();
 let callback = function(req, res, err, message, data){
@@ -22,22 +23,40 @@ class GljController extends BaseController{
         }
     }
     getGljTree(req,res){
-        var gljLibId = req.body.gljLibId;
+        let gljLibId = req.body.gljLibId;
         gljDao.getGljTypes(gljLibId,function(err,data){
             callback(req,res,err, 'Get Tree', data)
         });
     }
+    updateRationBasePrc(req, res){
+        let basePrcArr = JSON.parse(req.body.basePrcArr);
+        rationItemDao.updateRationBasePrc(basePrcArr, function (err, message) {
+            if(err){
+                callback(req, res, err, message, null);
+            }
+            else{
+                callback(req, res, err, message, null);
+            }
+        });
+    }
+
+    getRationGljIds(req, res){
+        let rationLibs = req.body.rationLibs;
+        gljDao.getRationGljIds(rationLibs, function (err, msg, data) {
+            callback(req, res, err, msg, data);
+        })
+    }
     createNewGljTypeNode(req, res) {
-        var repId = req.body.repositoryId;
-        var lastNodeId = req.body.lastNodeId;
+        let repId = req.body.repositoryId;
+        let lastNodeId = req.body.lastNodeId;
         let lastOpr = req.body.lastOpr;
-        var nodeData = JSON.parse(req.body.rawNodeData);
+        let nodeData = JSON.parse(req.body.rawNodeData);
         gljDao.createNewNode(repId, lastOpr, lastNodeId, nodeData, function(err, msg, data){
             callback(req,res,err,msg, data)
         });
     }
     updateGljNodes(req, res) {
-        var nodes = JSON.parse(req.body.nodes);
+        let nodes = JSON.parse(req.body.nodes);
         let repId = req.body.repId,
             lastOpr = req.body.lastOpr;
         gljDao.updateNodes(repId, lastOpr, nodes, function(err,results){
@@ -45,16 +64,16 @@ class GljController extends BaseController{
         });
     }
     deleteGljNodes(req, res) {
-        var nodes = JSON.parse(req.body.nodes);
-        var preNodeId = req.body.preNodeId;
-        var preNodeNextId = req.body.preNodeNextId;
+        let nodes = JSON.parse(req.body.nodes);
+        let preNodeId = req.body.preNodeId;
+        let preNodeNextId = req.body.preNodeNextId;
         let repId = req.body.repId, lastOpr = req.body.lastOpr;
         gljDao.removeNodes(repId, lastOpr, nodes, preNodeId, preNodeNextId, function(err,results){
             callback(req,res, err, results)
         });
     }
     getGljItems(req, res) {
-        var repId = req.body.repositoryId,
+        let repId = req.body.repositoryId,
             gljType = req.body.type,
             gljCode = req.body.code;
         if (gljCode) {
@@ -72,13 +91,13 @@ class GljController extends BaseController{
         }
     }
     getGljItemsByIds(req, res) {
-        var gljIds = JSON.parse(req.body.gljIds);
+        let gljIds = JSON.parse(req.body.gljIds);
         gljDao.getGljItems(gljIds, function(err, data){
             callback(req,res,err,'Get Items',data)
         });
     }
     getGljItemsByCodes(req, res) {
-        var gljCodes = JSON.parse(req.body.gljCodes),
+        let gljCodes = JSON.parse(req.body.gljCodes),
             repId = req.body.repId;
         gljDao.getGljItemsByCode(repId, gljCodes, function(err, data){
             callback(req,res,err,'Get Items',data)
@@ -93,7 +112,7 @@ class GljController extends BaseController{
         })
     }
     mixUpdateGljItems(req, res){
-        var repId = req.body.repositoryId,
+        let repId = req.body.repositoryId,
             updateItems = JSON.parse(req.body.updateItems),
             addItems = JSON.parse(req.body.addItems),
             removeIds = JSON.parse(req.body.removeIds),

+ 10 - 1
modules/std_glj_lib/models/gljMapModel.js

@@ -5,6 +5,7 @@ import {gljMapModel} from "./schemas";
 import moment from "moment";
 import counter from "../../../public/counter/counter";
 import async from "async";
+let rationRepositoryDao =  require("../../ration_repository/models/repository_map");
 
 class OprDao {
     static updateOprArr(findSet, oprtor, date, cb){
@@ -139,7 +140,15 @@ class GljMapDao extends OprDao{
                         callback(err, '移除工料机库失败!');
                     }
                     else{
-                        callback(null, '成功!');
+                        //删除定额库引用标段gljLib
+                        rationRepositoryDao.updateGljLib(libId, function (err) {
+                            if(err){
+                                callback(null, "移除工料机成功,删除定额库引用字段失败!");
+                            }
+                            else{
+                                callback(null, '成功!');
+                            }
+                        })
                     }
                 });
             }

+ 51 - 18
modules/std_glj_lib/models/gljModel.js

@@ -116,34 +116,63 @@ class GljDao  extends OprDao{
                 callback(err, '更新组成物错误!', null);
             }
             else{
-                console.log(result);
                 callback(null, '成功!', result);
             }
         });
     }
 
     mixUpdateGljItems (repId, lastOpr, updateItems, addItems, rIds, callback) {
-        var me = this;
         if (updateItems.length == 0 && rIds.length == 0) {
-            me.addGljItems(repId, lastOpr, addItems, callback);
-        } else {
-            me.removeGljItems(repId, lastOpr, rIds, function(err, message, docs) {
-                me.updateGljItems(repId, lastOpr, updateItems, function(err, results){
-                    if (err) {
-                        callback(true, "Fail to update", false);
+            GljDao.addGljItems(repId, lastOpr, addItems, callback);
+        } else if (rIds.length > 0) {
+            GljDao.removeGljItems(repId, lastOpr, rIds, function(err, message, docs) {
+            });
+            gljModel.remove({ID: {$in: rIds}}, function (err) {
+                if(err){
+                    callback(err, '删除错误', null);
+                }
+                else{
+                    callback(null, '删除成功', null);
+                }
+            });
+        }
+        else if(updateItems.length > 0 || addItems.length > 0){
+            GljDao.updateGljItems(repId, lastOpr, updateItems, function(err, results){
+                if (err) {
+                    callback(true, "Fail to update", false);
+                } else {
+                    if (addItems && addItems.length > 0) {
+                        GljDao.addGljItems(repId, lastOpr, addItems, callback);
                     } else {
-                        if (addItems && addItems.length > 0) {
-                            me.addGljItems(repId, lastOpr, addItems, callback);
-                        } else {
-                            callback(false, "Save successfully", results);
-                        }
+                        callback(false, "Save successfully", results);
                     }
-                });
+                }
             });
         }
-    };
+    }
 
-    removeGljItems (repId, lastOpr, rIds, callback) {
+    /*mixUpdateGljItems (repId, lastOpr, updateItems, addItems, rIds, callback) {
+        if (updateItems.length == 0 && rIds.length == 0) {
+            GljDao.addGljItems(repId, lastOpr, addItems, callback);
+        } else if (rIds.length > 0) {
+            GljDao.removeGljItems(repId, lastOpr, rIds, function(err, message, docs) {
+            });
+        }else{
+            GljDao.updateGljItems(repId, lastOpr, updateItems, function(err, results){
+                if (err) {
+                    callback(true, "Fail to update", false);
+                } else {
+                    if (addItems && addItems.length > 0) {
+                        GljDao.addGljItems(repId, lastOpr, addItems, callback);
+                    } else {
+                        callback(false, "Save successfully", results);
+                    }
+                }
+            });
+        }
+    };*/
+
+    static removeGljItems (repId, lastOpr, rIds, callback) {
         if (rIds && rIds.length > 0) {
             gljModel.collection.remove({ID: {$in: rIds}}, null, function(err, docs){
                 if (err) {
@@ -164,7 +193,7 @@ class GljDao  extends OprDao{
         }
     }
 
-    addGljItems (repId, lastOpr, items, callback) {
+    static addGljItems (repId, lastOpr, items, callback) {
         if (items && items.length > 0) {
             counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, items.length, function(err, result){
                 var maxId = result.value.sequence_value;
@@ -195,7 +224,7 @@ class GljDao  extends OprDao{
         }
     }
 
-    updateGljItems(repId, lastOpr, items, callback) {
+    static updateGljItems(repId, lastOpr, items, callback) {
         var functions = [];
         for (var i=0; i < items.length; i++) {
             functions.push((function(doc) {
@@ -228,6 +257,10 @@ class GljDao  extends OprDao{
         });
     }
 
+    getRationGljIds(rationLibs, callback){
+
+    }
+
     updateNodes (repId, lastOpr, nodes, callback) {
         var functions = [];
         for (var i=0; i < nodes.length; i++) {

+ 24 - 5
modules/std_glj_lib/models/schemas.js

@@ -3,19 +3,37 @@
  */
 import mongoose from "mongoose";
 let Schema = mongoose.Schema;
+let gjlMapRationLibsSchema = new Schema(
+    {
+        ID: Number,
+        dispName: String
+    },
+    {_id: false},
+    {versionKey: false}
+);
+
+let oprSchema = new Schema({
+        operateDate: String,
+        operator: String
+    },
+    {_id: false},
+    {versionKey: false});
+
 let gljMapSchema = new Schema({
-    deleted: false,
+    deleted: Boolean,
     ID: Number,
     dispName: String,
     appType: String,
     creator: String,
     createDate: String,
-    recentOpr: [],
+    recentOpr: [oprSchema],
+    rationLibs: [gjlMapRationLibsSchema],
     compilationId: String,
     compilationName: String
 },
     {versionKey: false});
 
+
 let gjlComponentSchema = mongoose.Schema(
     {
         ID: Number,
@@ -25,8 +43,9 @@ let gjlComponentSchema = mongoose.Schema(
     {versionKey: false}
 );
 
+
 let gljSchema = new Schema({
-    deleted: false,
+    deleted: Boolean,
     repositoryId: Number,
     ID: Number,
     code: String,
@@ -45,7 +64,7 @@ let gljClassSchema = mongoose.Schema({
     ParentID: Number,
     NextSiblingID: Number,
     Name: String,
-    isDeleted: Boolean
+    deleted: Boolean
 }, {versionKey: false});
 
 let gljClassTemplate = mongoose.Schema({
@@ -53,7 +72,7 @@ let gljClassTemplate = mongoose.Schema({
     ParentID: Number,
     NextSiblingID: Number,
     Name: String,
-    isDeleted: Boolean
+    deleted: Boolean
 }, {versionKey: false});
 
 

+ 2 - 1
modules/std_glj_lib/routes/routes.js

@@ -24,7 +24,8 @@ module.exports = function (app) {
     router.post('/renameGljLib', gljMapController.auth, gljMapController.init, gljMapController.renameGljLib);
     router.post('/removeGljLib', gljMapController.auth, gljMapController.init, gljMapController.removeGljLib);
 
-
+    router.post("/updateRationBasePrc",gljController.auth, gljController.init, gljController.updateRationBasePrc);//更新定额单价
+    router.post("/getRationGljIds",gljController.auth, gljController.init, gljController.getRationGljIds);
     router.post("/createNewGljTypeNode",gljController.auth, gljController.init, gljController.createNewGljTypeNode);
     router.post("/updateGljNodes",gljController.auth, gljController.init, gljController.updateGljNodes);
     router.post("/deleteGljNodes",gljController.auth, gljController.init, gljController.deleteGljNodes);

+ 15 - 1
public/web/sheet/sheet_common.js

@@ -98,7 +98,12 @@ var sheetCommonObj = {
             sheet.setRowCount(data.length + 5);
         }
         else{
-            sheet.setRowCount(typeof repositoryGljObj !== 'undefined' && repositoryGljObj.currentOprParent === 1 ? data.length : data.length + 5);
+            sheet.setRowCount(typeof repositoryGljObj !== 'undefined' && repositoryGljObj.currentOprParent === 1 ? data.length : data.length + 10);
+        }
+        if(data.length === 0){
+            for(let i = 0; i < sheet.getRowCount(); i++){
+                sheet.getCell(i, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+            }
         }
         for (var col = 0; col < setting.header.length; col++) {
             var hAlign = "left", vAlign = "center";
@@ -118,6 +123,12 @@ var sheetCommonObj = {
             for (var row = 0; row < data.length; row++) {
                 //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
                 if(setting.header[col].dataCode === 'gljType' && data[row].gljType){
+                    if(typeof repositoryGljObj !== 'undefined' && typeof repositoryGljObj.allowComponent !== 'undefined' && repositoryGljObj.allowComponent.indexOf(data[row].gljType) !== -1){
+                        sheet.getCell(row, 4, GC.Spread.Sheets.SheetArea.viewport).locked(true);
+                    }
+                    else if(typeof repositoryGljObj !== 'undefined' && typeof repositoryGljObj.allowComponent !== 'undefined' && repositoryGljObj.allowComponent.indexOf(data[row].gljType) === -1){
+                        sheet.getCell(row, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+                    }
                     let distTypeVal =  distTypeTree.distTypes[distTypeTree.prefix + data[row].gljType].data.fullName;
                     sheet.setValue(row, col, distTypeVal, ch);
                 }
@@ -126,6 +137,9 @@ var sheetCommonObj = {
                     sheet.setTag(row, 0, data[row].ID, ch);
                 }
             }
+            for(let i = data.length; i < sheet.getRowCount(); i++){
+                sheet.getCell(i, 4, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+            }
         }
         sheet.resumeEvent();
         sheet.resumePaint();

+ 17 - 7
web/maintain/bills_lib/html/main.html

@@ -61,11 +61,15 @@
                       <label>清单规则名称</label>
                       <input id="createText" class="form-control" placeholder="输入清单规则名称" type="text">
                     </div>
+                      <div class="form-group">
+                          <label>编办名称</label>
+                          <select id="compilationSels" class="form-control"></select>
+                      </div>
                   </form>
                 </div>
                 <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a id="createA"  href="javascript:void(0);" class="btn btn-primary" data-dismiss="modal">新建</a>
+                    <button type="button" id="cancelBtn" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <a id="createA"  href="javascript:void(0);" class="btn btn-primary">新建</a>
                 </div>
             </div>
         </div>
@@ -130,17 +134,23 @@
 </script>
 <script>
     let userAccount = '<%= userAccount %>';
+    mainAjax.getCompilationList();
     mainAjax.getStdBillsLib();
     $(document).ready(function(){
         //main 增删改
         $("#createA").click(function(){
             let billsLibName = $("#createText").val();
-            if(billsLibName){
-                mainAjax.createStdBillsLib(userAccount, billsLibName);
-                $("#createText").val("");
+            let compilationName = $('#compilationSels option:selected').text();
+            let compilationId = $('#compilationSels option:selected').val();
+            if(billsLibName.trim().length === 0){
+                alert("请输入清单规则名称!");
+            }
+            else if(compilationName.trim().length === 0){
+                alert("编办不可为空!");
             }
-            else{
-                alert("请输入清单规则名称!");
+            else {
+                mainAjax.createStdBillsLib(userAccount, billsLibName, compilationId, compilationName);
+                $("#createText").val("");
             }
         });
 

+ 21 - 2
web/maintain/bills_lib/scripts/bills_lib_ajax.js

@@ -2,6 +2,24 @@
  * Created by vian on 2017/3/27.
  */
 var mainAjax = {
+    //获取编办
+    getCompilationList: function () {
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/getCompilationList',
+            dataType: 'json',
+            success: function (result) {
+                //addoptions
+                for(let i = 0; i < result.data.length; i++){
+                    let $option =  $("<option >"+ result.data[i].name +"</option>");
+                    $option.val( result.data[i]._id);
+                    $('#compilationSels').append($option);
+                }
+                $('#compilationSels').on("change", function () {
+                });
+            }
+        });
+    },
     getMaxNumber: function(billsLibId, field, callback){
         $.ajax({
             type: 'post',
@@ -60,11 +78,11 @@ var mainAjax = {
             }
         });
     },
-    createStdBillsLib: function(userAccount, billsLibName){
+    createStdBillsLib: function(userAccount, billsLibName, compilationId, compilationName){
         $.ajax({
             type: "POST",
             url: "/stdBillsEditor/createStdBillsLib",
-            data: {data: JSON.stringify({userAccount: userAccount, name: billsLibName}) },
+            data: {data: JSON.stringify({userAccount: userAccount, name: billsLibName, compilationId: compilationId, compilationName: compilationName}) },
             dataType: "json",
             success: function(result){
                 if(!result.error){
@@ -79,6 +97,7 @@ var mainAjax = {
                     var newHref = "stdBills?billsLibId="+id;
                     $("#tempId td:first a").attr("href", newHref);
                     $("#tempId").attr("id", id);
+                    $('#cancelBtn').click();
                 }
             }
         });

+ 8 - 8
web/maintain/ration_repository/gongliao.html

@@ -232,13 +232,13 @@
         let userAccount = '<%=userAccount %>';
         var gljSetting = {
             view: {
-                addHoverDom: gljTypeTreeOprObj.addHoverDom,
-                removeHoverDom: gljTypeTreeOprObj.removeHoverDom,
+               // addHoverDom: gljTypeTreeOprObj.addHoverDom,
+               // removeHoverDom: gljTypeTreeOprObj.removeHoverDom,
                 expandSpeed: "",
                 selectedMulti: false
             },
             edit: {
-                enable: true,
+                enable: false,
                 editNameSelectAll: true,
                 showRemoveBtn: true,
                 showRenameBtn: true,
@@ -255,17 +255,17 @@
                     name: "Name"
                 },
                 simpleData: {
-                    enable: true,
+                    enable: false,
                     idKey: "ID",
                     pIdKey: "ParentID",
                     rootPId: -1
                 }
             },
             callback:{
-                beforeRename: gljTypeTreeOprObj.beforeRename,
-                onRename: gljTypeTreeOprObj.onRename,
-                beforeRemove: gljTypeTreeOprObj.onBeforeRemove,
-                onRemove: gljTypeTreeOprObj.onRemove,
+               // beforeRename: gljTypeTreeOprObj.beforeRename,
+                //onRename: gljTypeTreeOprObj.onRename,
+               // beforeRemove: gljTypeTreeOprObj.onBeforeRemove,
+                //onRemove: gljTypeTreeOprObj.onRemove,
                 onClick: gljTypeTreeOprObj.onClick
             }
         };

+ 273 - 11
web/maintain/ration_repository/js/main.js

@@ -1,9 +1,10 @@
 /**
  * Created by Syusuke on 2017/3/17.
  */
-$(function(){
+/*$(function(){
+    let libNames = [];
     getCompilationList();
-    getRationLibs();
+    getRationLibs(libNames);
 })
 
 function addEvent_Addressdirect(){
@@ -69,22 +70,52 @@ function getCompilationList(){
         url: 'api/getCompilationList',
         dataType: 'json',
         success: function (result) {
+            console.log(result);
             //addoptions
-            for(let i = 0; i < result.data.length; i++){
-               let $option =  $("<option >"+ result.data[i].name +"</option>");
-                $option.val( result.data[i]._id);
+            for(let i = 0; i < result.data.compilation.length; i++){
+               let $option =  $("<option >"+ result.data.compilation[i].name +"</option>");
+                $option.val( result.data.compilation[i]._id);
                 $('#compilationSels').append($option);
             }
-            $('#compilationSels').on("change", function () {
+            //初始工料机库选项
+            if(result.data.compilation.length > 0 && result.data.gljLibs.length > 0){
+                let compilationId = result.data.compilation[0]._id;
+                //console.log(compilationId);
+                let gljLibOps = getGljLibOps(compilationId, result.data.gljLibs);
+                console.log(gljLibOps);
+                for(let i = 0; i < gljLibOps.length; i++){
+                    let $option =  $("<option >"+ gljLibOps[i].dispName +"</option>");
+                    $option.val(gljLibOps[i].ID);
+                    $('#gljLibSels').append($option);
+                }
 
-               console.log(this.selectedOptions);
-               console.log(this.selectedOptions[0].text);
-               console.log(this.selectedOptions[0].value);
+            }
+            $('#compilationSels').on("change", function () {
+                //刷新工料机库选项
+                $('#gljLibSels').children().remove();
+                let newGljLibOps = getGljLibOps(this.selectedOptions[0].value, result.data.gljLibs);
+                for(let i = 0; i < newGljLibOps.length; i++){
+                    let $option =  $("<option >"+ newGljLibOps[i].dispName +"</option>");
+                    $option.val(newGljLibOps[i].ID);
+                    $('#gljLibSels').append($option);
+                }
             });
         }
     });
 }
-function getRationLibs(){
+function getGljLibOps(compilationId, gljLibs){
+    let rst = [];
+    for(let i = 0; i < gljLibs.length; i++){
+        if(gljLibs[i]){
+            if(compilationId === gljLibs[i].compilationId){
+                rst.push(gljLibs[i]);
+            }
+        }
+    }
+    return rst;
+}
+
+function getRationLibs(libNames){
     $.ajax({
         type:"POST",
         url:"api/getRationDisplayNames",
@@ -96,7 +127,9 @@ function getRationLibs(){
             for(var i=0;i<result.data.length;i++){
                 addLibTag(result.data[i].dispName, result.data[i].ID, result.data[i].createDate);
                 storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data[i].ID, result.data[i].dispName);
+                libNames.push(result.data[i].dispName);
             }
+            console.log(libNames);
             addEvent_Addressdirect();
             addEvent_DeleteLib();
             addEvent_EditLib();
@@ -184,4 +217,233 @@ $("#edtOK").click(function(){
 
 });
 
-autoFlashHeight();
+autoFlashHeight();*/
+
+$(function () {
+    let dispNameArr;
+    getAllRationLib(function (dispNames) {
+        dispNameArr = dispNames;
+        //添加
+        $('#addBtn').click(function () {
+            let compilationName = $('#compilationSels option:selected').text();
+            let compilationId = $('#compilationSels option:selected').val();
+            let gljLibName = $('#gljLibSels option:selected').text();
+            let gljLibId = $('#gljLibSels option:selected').val();
+            let libName = $('#libNameTxt').val();
+            if(libName.trim().length === 0){
+                alert('名称不可为空!');
+                $('#libNameTxt').val('')
+            }
+            else if(dispNames.indexOf(libName) !== -1){
+                alert('此定额库已存在!');
+                $('#libNameTxt').val('')
+            }
+            else if(compilationName.trim().length === 0){
+                alert('编办不可为空!');
+            }
+            else if(gljLibName.trim().length === 0){
+                alert("请选择工料机库!");
+            }
+            else{
+                let newRationLib = {};
+                newRationLib.dispName = libName;
+                newRationLib.compilationId = compilationId;
+                newRationLib.compilationName = compilationName;
+                newRationLib.gljLib = gljLibId;
+                newRationLib.creator = userAccount;
+                newRationLib.appType = "建筑";
+                $('#libNameTxt').val('');
+                createRationLib(newRationLib, dispNameArr);
+            }
+        });
+        //重命名
+        $("#showArea").on("click", "[data-target = '#edit']", function(){
+            let renameId = $(this).parent().parent().attr("id");
+            $("#renameA").attr("renameId", renameId);
+        });
+        $("#renameA").click(function(){
+            let newName = $("#renameText").val();
+            let libId = $(this).attr("renameId");
+            let jqSel = "#" + libId + " td:first" + " a";
+            let orgName = $(jqSel).text();
+            if(newName.trim().length === 0){
+                alert("名称不可为空!");
+                $("#renameText").val('');
+            }
+            else if(dispNameArr.indexOf(newName) !== -1){
+                alert("该工料机库已存在!");
+                $("#renameText").val('');
+            }
+            else{
+                renameRationLib({ID: libId, newName: newName, orgName: orgName}, dispNameArr);
+            }
+        });
+        //删除
+        $("#showArea").on("click", "[data-target = '#del']", function(){
+            let deleteId = $(this).parent().parent().attr("id");
+            $("#deleteA").attr("deleteId", deleteId);
+        });
+        $("#deleteA").click(function(){
+            let deleteId = $(this).attr("deleteId");
+            let jqSel = "#" + deleteId + " td:first" + " a";
+            let libName = $(jqSel).text();
+            removeRationLib({libId: deleteId, libName: libName}, dispNameArr);
+        });
+
+
+    });
+    getCompilationList();
+});
+
+function getAllRationLib(callback){
+    $.ajax({
+        type: 'post',
+        url: 'api/getRationDisplayNames',
+        dataType: 'json',
+        success: function (result) {
+            let dispNames = [];
+            if(result.data.length > 0){
+                for(let i = 0; i < result.data.length; i++){
+                    storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data[i].ID, result.data[i].dispName);
+                    if(result.data[i].gljLib){
+                        storageUtil.setSessionCache("gljLib","repositoryID_" + result.data[i].ID, result.data[i].gljLib);
+                    }
+                    let id = result.data[i].ID;
+                    let libName = result.data[i].dispName;
+                    let createDate = result.data[i].createDate.split(' ')[0];
+                    dispNames.push(result.data[i].dispName);
+                    $("#showArea").append(
+                        "<tr id='tempId'>" +
+                        "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
+                        "<td>"+createDate+" </td>" +
+                        "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
+                        "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
+                        "<i class='fa fa-remove'></i></a></td></tr>");
+                    var newHref = "/rationRepository/ration?repository="+id;
+                    $("#tempId td:first a").attr("href", newHref);
+                    $("#tempId").attr("id", id);
+                }
+            }
+            callback(dispNames);
+        }
+    });
+}
+function getCompilationList(){
+    $.ajax({
+        type: 'post',
+        url: 'api/getCompilationList',
+        dataType: 'json',
+        success: function (result) {
+            console.log(result);
+            //addoptions
+            for(let i = 0; i < result.data.compilation.length; i++){
+                let $option =  $("<option >"+ result.data.compilation[i].name +"</option>");
+                $option.val( result.data.compilation[i]._id);
+                $('#compilationSels').append($option);
+            }
+            //初始工料机库选项
+            if(result.data.compilation.length > 0 && result.data.gljLibs.length > 0){
+                let compilationId = result.data.compilation[0]._id;
+                //console.log(compilationId);
+                let gljLibOps = getGljLibOps(compilationId, result.data.gljLibs);
+                console.log(gljLibOps);
+                for(let i = 0; i < gljLibOps.length; i++){
+                    let $option =  $("<option >"+ gljLibOps[i].dispName +"</option>");
+                    $option.val(gljLibOps[i].ID);
+                    $('#gljLibSels').append($option);
+                }
+
+            }
+            $('#compilationSels').on("change", function () {
+                //刷新工料机库选项
+                $('#gljLibSels').children().remove();
+                let newGljLibOps = getGljLibOps(this.selectedOptions[0].value, result.data.gljLibs);
+                for(let i = 0; i < newGljLibOps.length; i++){
+                    let $option =  $("<option >"+ newGljLibOps[i].dispName +"</option>");
+                    $option.val(newGljLibOps[i].ID);
+                    $('#gljLibSels').append($option);
+                }
+            });
+        }
+    });
+}
+function getGljLibOps(compilationId, gljLibs){
+    let rst = [];
+    for(let i = 0; i < gljLibs.length; i++){
+        if(gljLibs[i]){
+            if(compilationId === gljLibs[i].compilationId){
+                rst.push(gljLibs[i]);
+            }
+        }
+    }
+    return rst;
+}
+
+function createRationLib(rationObj, dispNamesArr){
+    $.ajax({
+        type: 'post',
+        url: 'api/addRationRepository',
+        data: {rationRepObj: JSON.stringify(rationObj)},
+        dataType: 'json',
+        success: function (result) {
+            if(result.data){
+                storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data.ID, result.data.dispName);
+                if(result.data.gljLib){
+                    storageUtil.setSessionCache("gljLib","repositoryID_" + result.data.ID, result.data.gljLib);
+                }
+                let id = result.data.ID;
+                let libName = result.data.dispName;
+                let createDate = result.data.createDate.split(' ')[0];
+                let compilationName = result.data.compilationName;
+                dispNamesArr.push(libName);
+                $("#showArea").append(
+                    "<tr id='tempId'>" +
+                    "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
+                    "<td>"+createDate+" </td>" +
+                    "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
+                    "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
+                    "<i class='fa fa-remove'></i></a></td></tr>");
+                var newHref = "/rationRepository/ration?repository="+id;
+                $("#tempId td:first a").attr("href", newHref);
+                $("#tempId").attr("id", id);
+            }
+            $('#cancelBtn').click();
+        }
+    })
+}
+function renameRationLib(renameObj, dispNames){
+    $.ajax({
+        type: 'post',
+        url: 'api/editRationLibs',
+        data: {oprtor: userAccount, renameObj: JSON.stringify(renameObj)},
+        dataType: 'json',
+        success: function (result) {
+            if(!result.error){
+                let jqSel = "#" + renameObj.ID + " td:first" + " a";
+                $(jqSel).text(renameObj.newName);
+                let index = dispNames.indexOf(renameObj.orgName);
+                dispNames.splice(index, 1);
+                dispNames.splice(index, 0, renameObj.newName);
+            }
+            $('#editCancelBtn').click();
+            $('#renameText').val('');
+        }
+    })
+}
+function removeRationLib(delObj, dispNames){
+    $.ajax({
+        type: 'post',
+        url: 'api/deleteRationLibs',
+        data: {oprtor: userAccount, libId: delObj.libId},
+        dataType: 'json',
+        success: function (result) {
+            if(!result.error){
+                var jqSel = "#"+ delObj.libId;
+                $(jqSel).remove();
+                let index = dispNames.indexOf(delObj.libName);
+                dispNames.splice(index, 1);
+                $('#delCancelBtn').click();
+            }
+        }
+    })
+}

+ 18 - 3
web/maintain/ration_repository/js/ration.js

@@ -20,14 +20,14 @@ var rationOprObj = {
     setting: {
         header:[
             {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
-            {headerName:"名称",headerWidth:300,dataCode:"name", dataType: "String"},
+            {headerName:"名称",headerWidth:280,dataCode:"name", dataType: "String"},
             {headerName:"单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
             {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
             {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00",  hAlign: "right"},
             {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
             {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
-            {headerName:"显示名称(以%s表示参数)",headerWidth:350,dataCode:"caption", dataType: "String"},
-            {headerName:"取费专业",headerWidth:120,dataCode:"feeType", dataType: "Number", hAlign: "center"}
+            {headerName:"显示名称(以%s表示参数)",headerWidth:280,dataCode:"caption", dataType: "String"},
+            {headerName:"取费专业",headerWidth:100,dataCode:"feeType", dataType: "Number", hAlign: "center"}
         ],
         view:{
             comboBox:[
@@ -44,6 +44,12 @@ var rationOprObj = {
     buildSheet: function(container) {
         let rationRepId = getQueryString("repository");
         var me = rationOprObj;
+        let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+        console.log(gljLibID);
+        if(!gljLibID || typeof gljLibID === 'undefined' || gljLibID == -1){
+            alert("没有引用工料机库!");
+            window.location.href = "/rationRepository/main";
+        }
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
         me.workBook.options.showHorizontalScrollbar = true;
         me.getRationsCodes(rationRepId);
@@ -440,6 +446,7 @@ var rationOprObj = {
                         else if (a.code < b.code) rst = -1;
                         return rst;
                     });
+                    me.mixUpdate = 1;
                     me.showRationItems(me.currentSectionId);
                     me.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
                 }
@@ -451,6 +458,7 @@ var rationOprObj = {
     getRationItems: function(sectionID){
         if (sectionID != -1) {
             var me = rationOprObj;
+            me.mixUpdate = 0;
             me.currentSectionId = sectionID;
             if (me.currentRations["_SEC_ID_" + sectionID]) {
                 me.showRationItems(sectionID);
@@ -498,6 +506,13 @@ var rationOprObj = {
                 var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
                 sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
                 sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
+
+                if(me.mixUpdate === 1){
+                    rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
+                        me.workBook.focus(true);
+                    });
+                }
+
             } else {
                 //清除ration数据及工料机数据
                 sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);

+ 33 - 29
web/maintain/ration_repository/js/ration_glj.js

@@ -174,38 +174,41 @@ var rationGLJOprObj = {
     onClipboardPasted: function(e, info) {
         var me = rationGLJOprObj, repId = storageUtil.getSessionCache("RationGrp","repositoryID");
         if (repId) {
-            if (info.cellRange.col == 0) {
-                var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
-                var codes = [];
-                for (var i = 0; i < tmpCodes.length; i++) {
-                    codes.push(tmpCodes[i].code);
-                }
-                me.addGljItems(codes, repId);
-            } else {
-                //修改用量
-                if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
-                    let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
-                    let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
+            let gljLibId = storageUtil.getSessionCache("gljLib", "repositoryID_" + repId);
+            if(gljLibId){
+                if (info.cellRange.col == 0) {
+                    var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
+                    var codes = [];
+                    for (var i = 0; i < tmpCodes.length; i++) {
+                        codes.push(tmpCodes[i].code);
+                    }
+                    me.addGljItems(codes, gljLibId, info.cellRange);
+                } else {
+                    //修改用量
+                    if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                        let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
+                        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++){
-                        me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = tempConsumes[i].consumeAmt;
+                        for(let i = 0; i < maxCount; i++){
+                            me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = tempConsumes[i].consumeAmt;
+                        }
+                        me.updateRationItem();
+                        if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
+                            me.sheet.suspendPaint();
+                            for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
+                                me.sheet.setValue(rowIdx, info.cellRange.col, '');
+                            }
+                            me.sheet.resumePaint();
+                        }
                     }
-                    me.updateRationItem();
-                    if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
+                    else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
                         me.sheet.suspendPaint();
-                        for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
+                        for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
                             me.sheet.setValue(rowIdx, info.cellRange.col, '');
                         }
                         me.sheet.resumePaint();
                     }
                 }
-                else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
-                    me.sheet.suspendPaint();
-                    for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
-                        me.sheet.setValue(rowIdx, info.cellRange.col, '');
-                    }
-                    me.sheet.resumePaint();
-                }
             }
         }
     },
@@ -252,11 +255,12 @@ var rationGLJOprObj = {
                 }
             } else*/
             if(args.editingText !== null && args.editingText.trim().length !== 0){
-                var repId = storageUtil.getSessionCache("RationGrp","repositoryID");
-                if (repId) {
+                let rationRepId = storageUtil.getSessionCache("RationGrp","repositoryID");
+                let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
+                if (gljLibID) {
                     var codes = [];
                     codes.push(args.editingText.trim());
-                    me.addGljItems(codes, repId, args);
+                    me.addGljItems(codes, gljLibID, args);
                 }
             }
         }
@@ -329,12 +333,12 @@ var rationGLJOprObj = {
                         $('#alertModalCls').click(function () {
                             sheetCommonObj.lockCells(me.sheet, me.setting);
                             me.showGljItems(me.currentRationItem.ID);
-                            args.sheet.setValue(args.row, args.col, '');
+                            me.sheet.setValue(args.row, args.col, '');
                         });
                         $('#alertModalCof').click(function () {
                             sheetCommonObj.lockCells(me.sheet, me.setting);
                             me.showGljItems(me.currentRationItem.ID);
-                           args.sheet.setValue(args.row, args.col, '');
+                           me.sheet.setValue(args.row, args.col, '');
                         })
                     }
                 }

+ 18 - 16
web/maintain/ration_repository/js/repository_glj.js

@@ -26,9 +26,13 @@ var pageOprObj = {
             repositoryGljObj.getRationGljIds(rationLibId);
             repositoryGljObj.getGljDistType(function () {
                 repositoryGljObj.currentRepositoryId = parseInt(rationLibId);
-                repositoryGljObj.getGljTree(rationLibId, function () {
-                    repositoryGljObj.getGljItems(rationLibId);
-                });
+                //引用的工料机库
+                let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationLibId);
+                if(gljLibID && typeof gljLibID !== 'undefined'){
+                    repositoryGljObj.getGljTree(gljLibID, function () {
+                        repositoryGljObj.getGljItems(gljLibID);
+                    });
+                }
                 sheetCommonObj.shieldAllCells(repositoryGljObj.workBook.getSheet(0), repositoryGljObj.setting);
             });
         }
@@ -116,12 +120,12 @@ var pageOprObj = {
             }
         })
     },
-    getGljTree: function(rationLibId, callback) {
+    getGljTree: function(gljLibID, callback) {
         var me = this;
         $.ajax({
             type:"POST",
             url:"api/getGljTree",
-            data:{"rationLibId": rationLibId},
+            data:{"gljLibID": gljLibID},
             dataType:"json",
             cache:false,
             timeout:20000,
@@ -141,12 +145,12 @@ var pageOprObj = {
             }
         })
     },
-    getGljItems: function(repId) {
+    getGljItems: function(gljLibID) {
         var me = this;
         $.ajax({
             type:"POST",
             url:"api/getGljItems",
-            data:{"repositoryId": repId},
+            data:{"gljLibID": gljLibID},
             dataType:"json",
             cache:false,
             timeout:5000,
@@ -190,13 +194,14 @@ var pageOprObj = {
     buildSheet: function(container) {
         var me = repositoryGljObj;
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
-        me.repositoryGljDelOpr();
+        me.workBook.getSheet(0).options.isProtected = true;
+       /* me.repositoryGljDelOpr();
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
         //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
-        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);*/
     },
      onEnterCell: function (sender, args) {
          let me = repositoryGljObj;
@@ -924,23 +929,20 @@ var gljTypeTreeOprObj = {
         var me = repositoryGljObj,
             gljTypeId = treeNode.ID;
         me.gljCurTypeId = treeNode.ID;
-        //me.currentCache = me.getCache();
         if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
             me.currentOprParent = 1;
             me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
-            sheetCommonObj.lockCodeCells(me.workBook.getSheet(0), me.currentCache.length);
+           // sheetCommonObj.lockCodeCells(me.workBook.getSheet(0), me.currentCache.length);
             me.workBook.getSheet(0).setRowCount(me.currentCache.length);
-            //sheetCommonObj.shieldAllCells(me.workBook.getSheet(0), me.setting);
         } else {
             me.currentOprParent = 0;
             me.currentCache = me.getCache();
-            //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
+            me.workBook.getSheet(0).setRowCount(me.currentCache.length);
             /*sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-            sheetCommonObj.lockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);*/
-            sheetCommonObj.unLockAllCells(me.workBook.getSheet(0));
-            sheetCommonObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);
+            sheetCommonObj.reLockSomeCodes(me.workBook.getSheet(0), 0, me.currentCache.length);*/
         }
         me.showGljItems(me.gljList, gljTypeId);
+        me.workBook.getSheet(0).setRowCount(me.currentCache.length);
     },
     beforeRename: function(treeId, treeNode, newName, isCancel) {
         if (newName.length == 0) {

+ 14 - 10
web/maintain/ration_repository/main.html

@@ -36,7 +36,7 @@
                     <div class="warp-p2 mt-3">
                       <table class="table table-hover table-bordered">
                         <thead><tr><th>定额库名称</th><th width="160">添加时间</th><th width="90">操作</th></tr></thead>
-                        <tbody>
+                        <tbody id="showArea">
                         </tbody>
                       </table>
                     </div>
@@ -83,7 +83,7 @@
                     <form>
                         <div class="form-group">
                             <label>定额库名称</label>
-                            <input class="form-control" placeholder="输入定额库名称" type="text">
+                            <input id="libNameTxt" class="form-control" placeholder="输入定额库名称" type="text">
                         </div>
                         <div class="form-group">
                             <label>编办名称</label>
@@ -96,8 +96,8 @@
                     </form>
                 </div>
                 <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="" class="btn btn-primary">新建</a>
+                    <button type="button" id="cancelBtn" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <a id="addBtn" href="javascript: void(0);" class="btn btn-primary">新建</a>
                 </div>
             </div>
         </div>
@@ -116,13 +116,15 @@
                   <form>
                     <div class="form-group">
                       <label>定额库名称</label>
-                      <input class="form-control" id = "inputRation" placeholder="输入编码" type="text" value="">
+                      <input class="form-control" id="renameText" placeholder="输入工料机库名称" type="text" value="">
                     </div>
                   </form>
                 </div>
                 <div class="modal-footer">
-                    <button type="button" id="edtCancel" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <button type="button"  id="edtOK" class="btn btn-secondary" data-dismiss="modal">确定</button>
+                    <!--<button type="button" id="edtCancel" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <button type="button"  id="edtOK" class="btn btn-secondary" data-dismiss="modal">确定</button>-->
+                    <button id="editCancelBtn" type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <a href="javascript: void(0);"  id="renameA" class="btn btn-primary">确定</a>
 
                 </div>
             </div>
@@ -130,7 +132,7 @@
     </div>
     <!--弹出删除-->
     <div class="modal fade" id="del" data-backdrop="static" style="display: none;" aria-hidden="true">
-        <input type="hidden" id="did" value="123">
+        <!--<input type="hidden" id="did" value="123">-->
         <div class="modal-dialog" role="document">
             <div class="modal-content">
                 <div class="modal-header">
@@ -143,8 +145,10 @@
                     <h5 class="text-danger">删除后无法恢复,确认是否删除?</h5>
                 </div>
                 <div class="modal-footer">
-                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="" id="deleteLib" class="btn btn-danger">删除</a>
+                    <!--<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <a href="" id="deleteLib" class="btn btn-danger">删除</a>-->
+                    <button id="delCancelBtn" type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                    <a id="deleteA" href="javascript: void(0);" class="btn btn-danger">删除</a>
                 </div>
             </div>
         </div>

+ 92 - 45
web/maintain/std_glj_lib/js/glj.js

@@ -7,9 +7,10 @@ var pageOprObj = {
     initPage : function(container, containerComponent) {
         var me = this, gljLibId = getQueryString("gljLibId");//获取定额库参数
         me.gljLibId = gljLibId;
-            repositoryGljObj.getGljLib(gljLibId);
+        repositoryGljObj.getGljLib(gljLibId, function () {
             repositoryGljObj.buildSheet(container);
             gljComponentOprObj.buildSheet(containerComponent);
+            //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
             //repositoryGljObj.getRationGljIds(gljLibId);
             repositoryGljObj.getGljDistType(function () {
                 repositoryGljObj.currentRepositoryId = parseInt(gljLibId);
@@ -18,7 +19,7 @@ var pageOprObj = {
                 });
                 sheetCommonObj.shieldAllCells(repositoryGljObj.workBook.getSheet(0), repositoryGljObj.setting);
             });
-       // }
+        });
     }
 }
 repositoryGljObj = {
@@ -29,7 +30,7 @@ repositoryGljObj = {
     currentCache: null,
     parentNodeIds: {},
     gljList: [],
-    allowComponent: [202, 203, 204, 3],
+    allowComponent: [202, 203, 204, 3],//可带组成物类型:混凝土、砂浆、配合比、机械
     distTypeTree: null,//add
     setting: {
 
@@ -104,8 +105,8 @@ repositoryGljObj = {
             }
         })
     },
-    getGljLib: function (libId) {
-        let me = this;
+    getGljLib: function (libId, callback) {
+        let me = repositoryGljObj;
         $.ajax({
             type: 'post',
             url: 'api/getGljLib',
@@ -113,10 +114,14 @@ repositoryGljObj = {
             dataType: 'json',
             success: function (result) {
                 if(!result.error){
-                    $(".navbar-text").append(
-                        "<a href='/stdGljRepository/main'>工料机库</a><i class='fa fa-angle-right fa-fw'></i>"+result.data[0].dispName
-                    );
-                    pageOprObj.gljLibName = result.data[0].dispName;
+                    if(result.data.length > 0){
+                        me.rationLibs = result.data[0].rationLibs;
+                        $(".navbar-text").append(
+                            "<a href='/stdGljRepository/main'>工料机库</a><i class='fa fa-angle-right fa-fw'></i>"+result.data[0].dispName
+                        );
+                        pageOprObj.gljLibName = result.data[0].dispName;
+                    }
+                    callback();
                 }
             }
         })
@@ -231,7 +236,8 @@ repositoryGljObj = {
         for(let i = 0; i < me.gljList.length; i++){
             if(glj.ID === me.gljList[i].ID){
                 me.gljList[i].basePrice = glj.basePrice;
-                me.workBook.getSheet(0).setValue(i - 1, 4, glj.basePrice);
+                me.workBook.getSheet(0).setValue(i, 4, glj.basePrice);
+                console.log(i);
                 break;
             }
         }
@@ -247,12 +253,13 @@ repositoryGljObj = {
             //that.workBook.getSheet(0).options.isProtected = true;
             sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, -1);
             me.workBook.focus(true);
-            me.currentGlj = null;
             me.currentComponent = [];
             if(row < me.currentCache.length){
+                //标记当前工料机
+                me.currentGlj = me.currentCache[row];
+                console.log(`me.currentCache`);
+                console.log(me.currentCache);
                 if(me.allowComponent.indexOf(me.currentCache[row].gljType) !== -1){
-                    //标记当前工料机
-                    me.currentGlj = me.currentCache[row];
                     that.workBook.getSheet(0).getRange(-1, 0 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
                     that.workBook.getSheet(0).getRange(-1, 4 , -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
                     //that.workBook.getSheet(0).options.isProtected = false;
@@ -266,6 +273,9 @@ repositoryGljObj = {
                     }
                 }
             }
+            else{
+                me.currentGlj = null;
+            }
         }
     },
     onEnterCell: function (sender, args) {
@@ -363,6 +373,8 @@ repositoryGljObj = {
             updateArr = [], addArr = [], updateBasePrcArr = [];
         me.editingRowIdx = args.row;
         rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
+        console.log(`me.currentGlj`);
+        console.log(me.currentGlj);
         if (me.currentEditingGlj["ID"]) {
             rObj["ID"] = me.currentEditingGlj["ID"];
             rObj.gljClass = me.currentEditingGlj.gljClass;
@@ -378,7 +390,8 @@ repositoryGljObj = {
                     }
                 }
             }
-           /* if(me.currentEditingGlj.basePrice !== rObj.basePrice){
+            //--------------------------------------
+            if(me.currentEditingGlj.basePrice !== rObj.basePrice){
                 //update basePrice of ration when editting basePrice of glj
                 let gljType = -1;
                 let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
@@ -391,15 +404,20 @@ repositoryGljObj = {
                 let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
                 if(gljBasePrcObj.gljType !== -1){
                     updateBasePrcArr.push(gljBasePrcObj);
-                    me.updateRationBasePrcRq(updateBasePrcArr);
+                    if(me.rationLibs.length > 0){//重算定额单价
+                        me.updateRationBasePrcRq(updateBasePrcArr);
+                    }
                 }
-            }*/
+            }
             //update basePrice of ration when editting gljType of glj
-           /* if(me.currentEditingGlj.gljType !== rObj.gljType){
+            if(me.currentEditingGlj.gljType !== rObj.gljType){
                 let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
                 updateBasePrcArr.push(gljTypeObj);
-                me.updateRationBasePrcRq(updateBasePrcArr);
-            }*/
+                if(me.rationLibs.length > 0){
+                    me.updateRationBasePrcRq(updateBasePrcArr);
+                }
+            }
+            //-----------------------------------------------------------
         } else {
             me.addGljObj = rObj;
             let isCanSav = true;
@@ -409,16 +427,21 @@ repositoryGljObj = {
             if(isCanSav){
                 me.addGljObj = null;
                 rObj.component = [];
+                //如果类型为混凝土、砂浆、配合比、机械时,添加时填写的单价清空
+                if(me.allowComponent.indexOf(rObj.gljType) !== -1){
+                    rObj.basePrice = 0;
+                }
                 addArr.push(rObj);
             }
         }
-        if(me.gljCurTypeId !== 1){
+        if(me.gljCurTypeId !== 732){
             rObj.gljClass = me.gljCurTypeId;
         }
         if(updateArr.length >0 || addArr.length >0){
             me.currentEditingGlj = null;
             //me.workBook.getSheet(0).setValue(11, 5, "人工");
             me.mixUpdateRequest(updateArr, addArr, []);
+            console.log(updateArr);
         }
     },
     repositoryGljDelOpr: function () {
@@ -430,14 +453,17 @@ repositoryGljObj = {
                 refGljCodes = [], //已被引用的工料机
                 updateBasePrcArr = [],//删除基价单位后重新计算
                 sels = sheet.getSelections(),
+                canUpdate = false,
                 cacheSection = me.currentCache;
             if(sels.length > 0 && cacheSection.length > 0){
                 for(let i = 0; i < sels.length; i++){
                     if(sels[i].colCount === me.setting.header.length){
                         for(let j = 0; j < sels[i].rowCount; j++){
                             if(sels[i].row + j < cacheSection.length){
-                                //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
                                 removeArr.push(cacheSection[sels[i].row + j].ID);
+                                //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
+                                //删除后重新计算引用了此工料机的定额单价
+                                updateBasePrcArr.push({gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1});
                             }
                         }
                     }
@@ -449,14 +475,21 @@ repositoryGljObj = {
                                     let updateObj = cacheSection[sels[i].row + j];
                                     for(let col = sels[i].col; col <= maxCol; col++){
                                         if(me.setting.header[col].dataCode === 'basePrice'){
-                                            updateObj[me.setting.header[col].dataCode] = 0;
-                                         //   updateBasePrcArr.push({gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0});
+                                            //如果类型不为混凝土、砂浆、配合比、机械,才可删除单价 basePrice = 0
+                                            if(me.allowComponent.indexOf(updateObj.gljType) === -1){
+                                                canUpdate = true;
+                                                updateObj[me.setting.header[col].dataCode] = 0;
+                                                updateBasePrcArr.push({gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0});
+                                            }
                                         }
                                         else{
+                                            canUpdate = true;
                                             updateObj[me.setting.header[col].dataCode] = '';
                                         }
                                     }
-                                    updateArr.push(updateObj);
+                                    if(canUpdate){
+                                        updateArr.push(updateObj);
+                                    }
                                 }
                             }
                         }
@@ -522,10 +555,16 @@ repositoryGljObj = {
                     });
                 }*/
                 if(removeArr.length > 0 || updateArr.length > 0){
-                    me.mixUpdateRequest(updateArr, [], removeArr);
-                   /* if(updateBasePrcArr.length > 0){
-                        me.updateRationBasePrcRq(updateBasePrcArr);
-                    }*/
+                    //删除警告
+                    $('#alertGljTxt').text('可能已有定额引用了当前工料机,导致定额查找不到此工料机。确定要删除吗?');
+                    $('#gljAlertBtn').click();
+                    //确认
+                    $('#aleConfBtn').click(function () {
+                        me.mixUpdateRequest(updateArr, [], removeArr);
+                        if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
+                            me.updateRationBasePrcRq(updateBasePrcArr);
+                        }
+                    });
                 }
             }
 
@@ -538,7 +577,7 @@ repositoryGljObj = {
         let rst = {}, backUpObj = {},
             me = repositoryGljObj,
             tempObj = me.currentCache[rowIdx],
-            //reCalBasePrc = false,
+            reCalBasePrc = false,
             isValid = true;
         //备份原始数据
         for(let atr in tempObj){
@@ -575,7 +614,7 @@ repositoryGljObj = {
             for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
                 if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
                     isExsit = true;
-                   // reCalBasePrc = true;
+                    reCalBasePrc = true;
                     tempObj.gljType = me.distTypeTree.comboDatas[i].value;
                     tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
 
@@ -587,15 +626,15 @@ repositoryGljObj = {
         pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) :
             me.currentCache[rowIdx].basePrice;
         if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
-          //  reCalBasePrc = true;
+            reCalBasePrc = true;
             tempObj.basePrice = pasteObj.basePrice;
         }
         if(isValid){
             rst.updateGlj = tempObj;
-            /*if(reCalBasePrc){
+            if(reCalBasePrc){
                 //重新计算定额基价对象
                 rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
-            }*/
+            }
         }
         else {
             for(let attr in backUpObj){
@@ -650,7 +689,7 @@ repositoryGljObj = {
         var updateArr = [], addArr = [];
         var items = sheetCommonObj.analyzePasteData(me.setting, info);
         let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,
-            maxRow = me.currentCache.length - 1, updateItems = [], addItems = [],
+            maxRow = me.currentCache.length - 1,
             updateBasePrcArr = [] ,
             updateCount, resumeArr = [];
         if(endRow <= maxRow){
@@ -659,9 +698,9 @@ repositoryGljObj = {
                 let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
                 if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
                     updateArr.push(updateObj.updateGlj);
-                   /* if(typeof updateObj.updateBasePrc !== 'undefined'){
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
                         updateBasePrcArr.push(updateObj.updateBasePrc);
-                    }*/
+                    }
                 }
                 else{
                     resumeArr.push(info.cellRange.row + i);
@@ -674,9 +713,9 @@ repositoryGljObj = {
                 let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
                 if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
                     updateArr.push(updateObj.updateGlj);
-                   /* if(typeof updateObj.updateBasePrc !== 'undefined'){
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
                         updateBasePrcArr.push(updateObj.updateBasePrc);
-                    }*/
+                    }
                 }
                 else{
                     resumeArr.push(info.cellRange.row + i);
@@ -685,7 +724,11 @@ repositoryGljObj = {
             if(info.cellRange.colCount === me.setting.header.length){
                 for(let i = updateCount ; i < items.length; i++){
                     if(me.isValidObj(items[i])){
-                        addItems.push(items[i]);
+                        items[i].component = [];
+                        //类型为混凝土、砂浆、配合比、机械时,基价只能组成物计算
+                        if(me.allowComponent.indexOf(items[i].gljType) !== -1){
+                            items[i].basePrice = 0;
+                        }
                         addArr.push(items[i]);
                     }
                     else{
@@ -703,6 +746,10 @@ repositoryGljObj = {
             if(info.cellRange.colCount === me.setting.header.length){
                 for(let i = 0; i < items.length; i++){
                     if(me.isValidObj(items[i])){
+                        items[i].component = [];
+                        if(me.allowComponent.indexOf(items[i].gljType) !== -1){
+                            items[i].basePrice = 0;
+                        }
                         addArr.push(items[i]);
                     }
                     else{
@@ -742,15 +789,15 @@ repositoryGljObj = {
         if (updateArr.length > 0 || addArr.length > 0) {
             me.mixUpdateRequest(updateArr, addArr, []);
         }
-       /* if(updateBasePrcArr.length > 0){
+        if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
             me.updateRationBasePrcRq(updateBasePrcArr);
-        }*/
+        }
     },
-   /* updateRationBasePrcRq: function (basePrcArr) {
+    updateRationBasePrcRq: function (basePrcArr) {
         $.ajax({
             type: 'post',
             url: 'api/updateRationBasePrc',
-            data:{data: JSON.stringify({repId: pageOprObj.rationLibId, lastOpr: userAccount, basePrcArr: basePrcArr})},
+            data:{basePrcArr: JSON.stringify(basePrcArr)},
             dataType: 'json',
             success: function (result) {
                 if(result.error){
@@ -758,7 +805,7 @@ repositoryGljObj = {
                 }
             }
         });
-    },*/
+    },
   /*  getRationGljIds: function (repId) {
         let me = repositoryGljObj;
         $.ajax({
@@ -843,7 +890,7 @@ repositoryGljObj = {
                 }
             }
         }
-        if (result && result.data.ops && result.data.ops.length > 0) {
+        if (result && result.data && result.data.ops && result.data.ops.length > 0) {
             for (var i = 0; i < result.data.ops.length; i++) {
                 for (var j = 0; j < cacheSection.length; j++) {
                     if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {

+ 42 - 13
web/maintain/std_glj_lib/js/gljComponent.js

@@ -55,7 +55,7 @@ let gljComponentOprObj = {
         return component;
     },
     gljComponentDelOpr: function () {
-        let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], removeArr = [], isUpdate = false;
+        let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], removeArr = [], isUpdate = false, updateBasePrc= [];
         me.workBook.commandManager().register('gljComponentDel', function () {
             let sels = me.workBook.getSheet(0).getSelections();
             if(sels.length > 0 && that.currentComponent.length > 0){
@@ -119,11 +119,16 @@ let gljComponentOprObj = {
                     }
                     //重新计算工料机
                     let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
-                    that.currentGlj.basePrice = gljBasePrc;
-                    that.reshowGljBasePrc(that.currentGlj);
+                    if(gljBasePrc !== that.currentGlj.basePrice){
+                        that.currentGlj.basePrice = gljBasePrc;
+                        that.reshowGljBasePrc(that.currentGlj);
+                        updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
+                    }
                     updateArr.push(that.currentGlj);
-                    console.log(updateArr);
                     me.updateComponent(updateArr);
+                    if(updateBasePrc.length > 0){
+                        that.updateRationBasePrcRq(updateBasePrc);
+                    }
                 }
             }
         });
@@ -136,7 +141,7 @@ let gljComponentOprObj = {
         me.currentEditingComponent = rObj;
     },
     onCellEditEnd: function (sender, args) {
-        let me = gljComponentOprObj, that = repositoryGljObj;
+        let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
         let gljList = that.gljList, updateArr = [], materialComponent = [202, 203, 204], machineComponent = [302, 303];
         if(args.editingText !== me.currentEditingComponent.code){
             if(args.col === 0 && args.editingText && args.editingText.trim().length > 0){
@@ -187,7 +192,12 @@ let gljComponentOprObj = {
 
                         }
                         else{
-                            alert("无效!");
+                            if(materialComponent.indexOf(that.currentGlj.gljType) === 1){
+                                alert("该组成物只能是普通材料!");
+                            }
+                            else if(that.currentGlj.gljType === 3){
+                                alert("该组成物只能是机械组成物或机上人工!")
+                            }
                             args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
                                 me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
                             //无效
@@ -195,7 +205,7 @@ let gljComponentOprObj = {
                     }
                 }
                 if(!hasCode){
-                    alert("不存在,请添加!");
+                    alert("不存在此工料机,请添加!");
                     args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
                         me.currentEditingComponent[me.setting.header[args.col].dataCode] : '');
                     //不存在
@@ -213,8 +223,12 @@ let gljComponentOprObj = {
                     that.currentComponent[args.row].consumeAmt = consumeAmt;
                     //计算工料机单价
                     let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
-                    that.currentGlj.basePrice = gljBasePrc;
-                    that.reshowGljBasePrc(that.currentGlj);
+                    if(gljBasePrc !== that.currentGlj.basePrice){
+                        that.currentGlj.basePrice = gljBasePrc;
+                        that.reshowGljBasePrc(that.currentGlj);
+                        //工料机单价改变,重算引用了该工料机的定额单价
+                        updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
+                    }
                     updateArr.push(that.currentGlj);
                 }
                 else{
@@ -230,7 +244,9 @@ let gljComponentOprObj = {
         }
         if(updateArr.length > 0){
             me.updateComponent(updateArr);
-            //保存
+            if(updateBasePrc.length > 0){
+                that.updateRationBasePrcRq(updateBasePrc)
+            }
         }
     },
     onClipboardPasting: function (sender, info) {
@@ -238,7 +254,7 @@ let gljComponentOprObj = {
     },
     onClipboardPasted: function (sender, info) {
         let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [] ,materialComponent = [202, 203, 204], machineComponent = [302, 303],
-            component = that.currentGlj.component, newComponent = [], concatComponent = [], isChange = false;
+            component = that.currentGlj.component, newComponent = [], concatComponent = [], isChange = false, updateBasePrc = [];
         let items = sheetCommonObj.analyzePasteData(me.setting, info);
         let gljCache = that.gljList;
         if(info.cellRange.col === 0){
@@ -295,6 +311,13 @@ let gljComponentOprObj = {
                 }
             }
             if(isChange){
+                //计算工料机单价
+                let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
+                if(gljBasePrc !== that.currentGlj.basePrice){
+                    that.currentGlj.basePrice = gljBasePrc;
+                    that.reshowGljBasePrc(that.currentGlj);
+                    updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
+                }
                 updateArr.push(that.currentGlj);
             }
         }
@@ -325,13 +348,19 @@ let gljComponentOprObj = {
             if(isChange){
                 //计算工料机单价
                 let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
-                that.currentGlj.basePrice = gljBasePrc;
-                that.reshowGljBasePrc(that.currentGlj);
+                if(gljBasePrc !== that.currentGlj.basePrice){
+                    that.currentGlj.basePrice = gljBasePrc;
+                    that.reshowGljBasePrc(that.currentGlj);
+                    updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
+                }
                 updateArr.push(that.currentGlj);
             }
         }
         if(updateArr.length > 0){
             me.updateComponent(updateArr);
+            if(updateBasePrc.length > 0){
+                that.updateRationBasePrcRq(updateBasePrc);
+            }
         }
     },
     updateComponent: function (updateArr) {

+ 7 - 2
web/maintain/std_glj_lib/js/main.js

@@ -86,12 +86,17 @@ function getAllGljLib(callback){
                     let libName = result.data[i].dispName;
                     let createDate = result.data[i].createDate.split(' ')[0];
                     let compilationName = result.data[i].compilationName;
+                    let rationLibs = result.data[i].rationLibs;
+                    let rationLibsName = '';
+                    for(let j = 0; j < rationLibs.length; j++){
+                        rationLibsName += rationLibs[j].dispName + "</br>";
+                    }
                     dispNames.push(result.data[i].dispName);
                     $("#showArea").append(
                         "<tr id='tempId'>" +
                         "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
                         "<td>"+compilationName+" </td>" +
-                        "<td>"+'xx定额库(xx)'+" </td>" +
+                        "<td>"+rationLibsName+" </td>" +
                         "<td>"+createDate+" </td>" +
                         "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
                         "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
@@ -140,7 +145,7 @@ function createGljLib(gljLibObj, dispNamesArr){
                     "<tr id='tempId'>" +
                     "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
                     "<td>"+compilationName+" </td>" +
-                    "<td>"+'xx定额库(xx)'+" </td>" +
+                    "<td>"+''+" </td>" +
                     "<td>"+createDate+" </td>" +
                     "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
                     "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +