Browse Source

feat: 分享人材机库相关

vian 4 years ago
parent
commit
b865bb26e2

+ 4 - 0
config/gulpConfig.js

@@ -198,6 +198,9 @@ module.exports = {
         'lib/ztree/css/zTreeStyle.css',
     ],
     compleGlj_jspaths: [
+        'lib/pinyinjs/pinyin_dict_firstletter.js',
+        'lib/pinyinjs/pinyinUtil.js',
+        'web/common/components/share/index.js',
         'public/web/common_ajax.js',
         'public/web/treeDataHelper.js',
         'public/web/QueryParam.js',
@@ -207,6 +210,7 @@ module.exports = {
         'public/web/tree_sheet/tree_sheet_helper.js',
         'public/web/tools_const.js',
         'public/web/ration_glj_units.js',
+        'web/building_saas/complementary_glj_lib/js/init.js',
         'web/building_saas/complementary_glj_lib/js/glj.js',
         'web/building_saas/complementary_glj_lib/js/gljClassTree.js',
         'web/building_saas/complementary_glj_lib/js/gljComponent.js',

+ 2 - 1
modules/all_models/compleRation_ration.js

@@ -10,7 +10,8 @@ const deleteSchema = require('../all_schemas/delete_schema');
 const compleRationGljItemSchema = new Schema({
     gljId: Number,
     consumeAmt: String,
-    type: String    //std or complementary
+    type: String,    //std or complementary
+    fromUser: String,
 
 }, { _id: false });
 

+ 2 - 1
modules/all_models/ration_glj.js

@@ -36,7 +36,8 @@ var ration_glj = new Schema({
     rationItemQuantity:String,
     tenderQuantity:String,//调整后消耗量
     createType: {type: String,default:'normal'},//normal、add、replace  正常、添加工料机、替换工料机
-    from:{type: String,default:'std'}//std, cpt  来自标准工料机库、补充工料机库
+    from:{type: String,default:'std'},//std, cpt  来自标准工料机库、补充工料机库
+    fromUser: String, // 来自某个用户的人材机(分享补充人材机)
 },{versionKey:false});
 
 mongoose.model('ration_glj', ration_glj);

+ 54 - 21
modules/complementary_glj_lib/controllers/gljController.js

@@ -6,39 +6,58 @@ const stdgljutil = require("../../../public/cache/std_glj_type_util");
 const GljDao = require("../models/gljModel");
 const EngineeringLibModel = require("../../users/models/engineering_lib_model");
 let config = require("../../../config/config.js");
-
+const pmFacade = require('../../pm/facade/pm_facade');
+const { ShareLibType } = require('../../../public/common_constants');
 let gljDao = new GljDao();
 let callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
 };
 
+async function getGljLibId(sessionCompilation) {
+    let gljLibId = null,
+        rationValuation = sessionCompilation.ration_valuation,
+        billValuation = sessionCompilation.bill_valuation,
+        engineeringLibModel = new EngineeringLibModel(),
+        valuationIDs = [] ;
+    for(let r of rationValuation){//{ "glj_lib.0": {$exists:1} }
+        if(r.id){
+            valuationIDs.push(r.id);
+        }
+    }
+    for(let b of billValuation){
+        if(b.id){
+            valuationIDs.push(b.id);
+        }
+    }
+    if(valuationIDs.length > 0){
+        let engineeringInfo = await engineeringLibModel.findDataByCondition({'valuationID': {"$in": valuationIDs},"glj_lib.0": {$exists:1}});//数组大于0
+        gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
+    }
+    return gljLibId;
+}
+
 class GljController extends BaseController{
     async redirectGlj(req, res){
-        let gljLibId = null, engineeringId, sessionCompilation = req.session.sessionCompilation,
-            rationValuation = sessionCompilation.ration_valuation,
-            billValuation = sessionCompilation.bill_valuation,
-            engineeringLibModel = new EngineeringLibModel(),
-            valuationIDs = [] ;
-        for(let r of rationValuation){//{ "glj_lib.0": {$exists:1} }
-            if(r.id){
-                valuationIDs.push(r.id);
+        const { userID } = req.params;
+        const sessionUserID = req.session.sessionUser.id;
+        const compilationID = req.session.sessionCompilation._id;
+        if (userID !== sessionUserID) {
+            const receiveList = await pmFacade.getReceiveLibList(sessionUserID, compilationID, ShareLibType.GLJ_LIB);
+            const isValid = !!receiveList.find(user => String(user._id) === userID);
+            if (!isValid) {
+                return res.redirect(`/complementaryGlj/${sessionUserID}`);
             }
         }
-        for(let b of billValuation){
-            if(b.id){
-                valuationIDs.push(b.id);
-            }
-        }
-        if(valuationIDs.length > 0){
-            let engineeringInfo = await engineeringLibModel.findDataByCondition({'valuationID': {"$in": valuationIDs},"glj_lib.0": {$exists:1}});//数组大于0
-            gljLibId = engineeringInfo.glj_lib.length > 0 && typeof engineeringInfo.glj_lib !== 'undefined' ? engineeringInfo.glj_lib[0].id : null;
-        }
-        let overWriteUrl = req.session.sessionCompilation && req.session.sessionCompilation.overWriteUrl &&
-                            req.session.sessionCompilation._id !== '5b4d581023a924000b760f2d' ? req.session.sessionCompilation.overWriteUrl : null;
+        const sessionCompilation = req.session.sessionCompilation;
+        const gljLibId = await getGljLibId(sessionCompilation);
+        let overWriteUrl = sessionCompilation && req.session.sessionCompilation.overWriteUrl &&
+            compilationID !== '5b4d581023a924000b760f2d' ? req.session.sessionCompilation.overWriteUrl : null;
         const priceProperties = sessionCompilation.priceProperties || [];
         const consumeAmtProperties = sessionCompilation.consumeAmtProperties || [];
+        const isReadOnly = userID !== sessionUserID;
         res.render('building_saas/complementary_glj_lib/html/tools-gongliaoji.html',{
-            userID: req.session.sessionUser.id,
+            isReadOnly,
+            userID: sessionUserID,
             gljLibId: gljLibId,
             compilationId: sessionCompilation._id,
             compilationName: sessionCompilation.name,
@@ -49,6 +68,20 @@ class GljController extends BaseController{
             overWriteUrl: overWriteUrl,
         });
     }
+
+    async prepareInitData(req, res) {
+        try {
+            const { userID, projection } = JSON.parse(req.body.data);
+            const sessionUserID = req.session.sessionUser.id;
+            const gljLibID = await getGljLibId(req.session.sessionCompilation);
+            const compilationID = req.session.sessionCompilation._id;
+            const initData = await gljDao.prepareInitData(gljLibID, userID, sessionUserID, compilationID, projection);
+            res.json({error: 0, message: 'success', data: initData});
+        } catch (err) {
+            console.log(err);
+            res.json({error: 1, message: 'fail', data: null});
+        }
+    }
     getGljDistType (req, res) {
         let gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
         if(gljDistTypeCache.length >0 ){

+ 63 - 1
modules/complementary_glj_lib/models/gljModel.js

@@ -1,3 +1,33 @@
+/*
+ * @Descripttion: 
+ * @Author: vian
+ * @Date: 2020-12-16 17:48:47
+ */
+/*
+ * @Descripttion: 
+ * @Author: vian
+ * @Date: 2020-12-16 17:48:47
+ */
+/*
+ * @Descripttion: 
+ * @Author: vian
+ * @Date: 2020-12-16 17:48:47
+ */
+/*
+ * @Descripttion: 
+ * @Author: vian
+ * @Date: 2020-12-16 17:48:47
+ */
+/*
+ * @Descripttion: 
+ * @Author: vian
+ * @Date: 2020-12-16 17:48:47
+ */
+/*
+ * @Descripttion: 
+ * @Author: vian
+ * @Date: 2020-12-16 17:48:47
+ */
 /**
  * Created by Zhong on 2017/8/22.
  */
@@ -14,8 +44,27 @@ const libType = {
     stdGLJ: 1,
     complementaryGLJs: 2
 };
+const stdgljutil = require("../../../public/cache/std_glj_type_util");
+const { ShareLibType } = require('../../../public/common_constants');
 
 class GljDao {
+    
+    async prepareInitData(gljLibID, userID, sessionUserID, compilationID, projection) {
+        const pmFacade = require('../../pm/facade/pm_facade');
+        const receiveLibs = await pmFacade.getReceiveLibList(sessionUserID, compilationID, ShareLibType.GLJ_LIB);
+        const shareLibs = sessionUserID === userID ? await pmFacade.getLibShareList(sessionUserID, compilationID, ShareLibType.GLJ_LIB) : [];
+        const gljItems = await this.getGLJItemsSync(gljLibID, userID, compilationID, projection);
+        const mixTree = await this.getMixedTree(gljLibID, userID, compilationID);
+        const gljDistTypeCache = stdgljutil.getStdGljTypeCacheObj().toArray();
+        return {
+            receiveLibs,
+            shareLibs,
+            gljItems,
+            mixTree,
+            distTypeData: gljDistTypeCache,
+        };
+    }
+
     getGljTypes (gljLibId, callback){
         gljClassModel.find({"repositoryId": gljLibId},function(err,data){
             if(data.length) {
@@ -159,7 +208,6 @@ class GljDao {
                 catch (err) {
                     cb(err);
                 }
-
             },
             function (cb) {
                 if (!userId || !compilationId) {
@@ -189,6 +237,20 @@ class GljDao {
 
     }
 
+    async getGLJItemsSync(stdGljLibId, userId, compilationId, projection) {
+        const rst = { stdGljs: [], complementaryGljs: [] };
+        const task = [
+            stdGljModel.find({ repositoryId: stdGljLibId }, projection).lean(),
+            complementaryGljModel.find({ userId: userId, compilationId: compilationId }, '-_id').lean()
+        ];
+        const [ stdRst, cptRst ] = await Promise.all(task);
+        this.sortToNumber(stdRst);
+        rst.stdGljs = stdRst;
+        this.sortToNumber(cptRst);
+        rst.complementaryGljs = cptRst;
+        return rst;
+    }
+
     async getStdItems (stdGljLibId, projection, callback) {
         try {
             let stdItems = await stdGljModel.find({repositoryId: stdGljLibId}, projection).lean();

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

@@ -11,13 +11,14 @@ let gljController = new GljController();
 let compleRationController = new CompleRationController();
 
 module.exports = function (app) {
-    app.get('/complementaryGlj', gljController.init, gljController.redirectGlj);
+    app.get('/complementaryGlj/:userID', gljController.init, gljController.redirectGlj);
 
    /* router.post("/updateRationBasePrc",gljController.init, gljController.updateRationBasePrc);//更新定额单价
     router.post("/getRationGljIds", gljController.init, gljController.getRationGljIds);
     router.post("/createNewGljTypeNode", gljController.init, gljController.createNewGljTypeNode);
     router.post("/updateGljNodes", gljController.init, gljController.updateGljNodes);
     router.post("/deleteGljNodes", gljController.init, gljController.deleteGljNodes);*/
+    router.post("/initData", gljController.init, gljController.prepareInitData);
     router.post("/getGljDistType", gljController.init, gljController.getGljDistType);
     router.post("/getGljTree", gljController.init, gljController.getGljTree);
     router.post("/getGljItems", gljController.init, gljController.getGljItems);

+ 7 - 2
modules/complementary_ration_lib/models/compleRationModel.js

@@ -101,7 +101,8 @@ class CompleRatoinDao {
                     }
                 }
                 else if(ids[i].type === 'complementary'){
-                    let compleGlj = await complementaryGljModel.find({userId: userID, ID: ids[i].id, deleteInfo: null});
+                    const owner = ids[i].fromUser || userID;
+                    let compleGlj = await complementaryGljModel.find({userId: owner, ID: ids[i].id, deleteInfo: null});
                     if(compleGlj.length > 0){
                         compleGlj[0]._doc.type = 'complementary';
                         rst.push(compleGlj[0]);
@@ -150,6 +151,7 @@ class CompleRatoinDao {
                 comGljIds = [],
                 stdGljs = [],
                 comGljs = [];
+            const users = [userId];
             let gljAmtMapping = {};
             for(let rationGlj of ration.rationGljList){
                 gljAmtMapping[rationGlj.gljId] = rationGlj.consumeAmt;
@@ -157,6 +159,9 @@ class CompleRatoinDao {
                     stdGljIds.push(rationGlj.gljId);
                 }
                 else {
+                    if (rationGlj.fromUser && !users.includes(rationGlj.fromUser)) {
+                        users.push(rationGlj.fromUser);
+                    }
                     comGljIds.push(rationGlj.gljId);
                 }
             }
@@ -164,7 +169,7 @@ class CompleRatoinDao {
                 stdGljs = await stdGljModel.find({ID: {$in: stdGljIds}}).lean();
             }
             if(comGljIds.length > 0) {
-                comGljs = await complementaryGljModel.find({userId: userId, ID: {$in: comGljIds}}).lean();
+                comGljs = await complementaryGljModel.find({userId: { $in: users }, ID: {$in: comGljIds}}).lean();
             }
             let gljDatas = gljUtil.sortRationGLJ(stdGljs.concat(comGljs),true);
             if(ration.jobContent && ration.jobContent.toString().trim() !== ''){

+ 8 - 1
modules/main/facade/ration_facade.js

@@ -443,12 +443,16 @@ async function addRationGLJ(std,newRation,compilation) {
     }
     let ext = getExtendData(property,compilation);
     let first = +new Date();
+    const users = [std.userId];
     if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
         let stdGLJID =[];//标准工料机ID数组
         let cptGLJID=[];//补充工料机ID数组
             //let stdGLJID = _.map(std.rationGljList,'gljId');
         for(let tem_g  of std.rationGljList){
              if(tem_g.type == 'complementary'){
+               if (tem_g.fromUser && !users.includes(tem_g.fromUser)) {
+                 users.push(tem_g.fromUser);
+               }
                 cptGLJID.push(tem_g.gljId);
              }else {
                 stdGLJID.push(tem_g.gljId);
@@ -456,7 +460,7 @@ async function addRationGLJ(std,newRation,compilation) {
         }
        let stdGLJList = stdGLJID.length > 0 ? await std_glj_lib_gljList_model.find({'ID':{'$in':stdGLJID}}):[];//速度优化-------先一次性取出所有的工料机列表
        let stdGLJMap = _.indexBy(stdGLJList, 'ID');
-       let cptGLJList =  cptGLJID.length > 0 ? await complementary_glj_model.find({'userId':std.userId,'ID':{'$in':cptGLJID}}):[];
+       let cptGLJList =  cptGLJID.length > 0 ? await complementary_glj_model.find({'userId':{$in: users},'ID':{'$in':cptGLJID}}):[];
        let cptGLJMap = _.indexBy(cptGLJList, 'ID');
         let stdGLJMapTime = +new Date();
         console.log("找到工料机映射表时间-------------------------------"+(stdGLJMapTime - first));
@@ -472,6 +476,9 @@ async function addRationGLJ(std,newRation,compilation) {
           newGLJ.glj_repository_id = std.rationRepId;
           let std_glj = null;
           if(sub.type == 'complementary'){//有可能来自标准工料机库或补充工料机库
+            if (sub.fromUser) {
+              newGLJ.fromUser = sub.fromUser;
+            }
               std_glj = cptGLJMap[sub.gljId];
               newGLJ.from = 'cpt';
           }else {

+ 38 - 9
modules/ration_glj/controllers/ration_glj_controller.js

@@ -5,7 +5,8 @@ let mongoose = require("mongoose")
 let ration_glj_facade = require('../facade/ration_glj_facade')
 const EngineeringLibModel = require("../../users/models/engineering_lib_model");
 let logger = require("../../../logs/log_helper").logger;
-const { COMPILATION, COMPLEMENTARY_LIB } = require('../../../public/common_constants');
+const { COMPILATION, COMPLEMENTARY_LIB, ShareLibType } = require('../../../public/common_constants');
+const pmFacade = require('../../pm/facade/pm_facade');
 
 module.exports={
     createRationGLJ:createRationGLJ,
@@ -67,12 +68,18 @@ async function getGLJDataPaging(req, res) {
         const compilationId = req.session.sessionCompilation._id;
         const userID = req.session.sessionUser.id;
         let libData = null;
-        if (condition.gljLibID !== COMPLEMENTARY_LIB) {
+        const cptLibReg = new RegExp(COMPLEMENTARY_LIB);
+        if (!cptLibReg.test(condition.gljLibID)) {
             condition.gljLibID = +condition.gljLibID;
         }
         if (condition.initLibs) {
             libData = await ration_glj_facade.getLibOptionsForCompilation(compilationId);
-            libData.push({ name: '补充工料机', gljLibId: COMPLEMENTARY_LIB });
+            libData.push({ name: '我的补充人材机库', gljLibId: COMPLEMENTARY_LIB });
+            // 设置被分享的人材机库
+            const receiveData = await pmFacade.getReceiveLibList(userID, compilationId, ShareLibType.GLJ_LIB);
+            receiveData.forEach(user => {
+                libData.push({ name: `${user.real_name}的补充人材机库`, gljLibId: `${COMPLEMENTARY_LIB}*${user._id}` });
+            });
             if (condition.gljLibID) { // 替换人材机初始化会触发此条件(初始化库且定位了库)
                 const orgDefalutLib = libData.find(lib => lib.isDefault);
                 const newDefaultLib = libData.find(lib => lib.gljLibId === condition.gljLibID);
@@ -85,9 +92,16 @@ async function getGLJDataPaging(req, res) {
         if (!condition.gljLibID && libData) {
             condition.gljLibID = (libData.find(lib => lib.isDefault) || {}).gljLibId;
         }
-        const info = condition.gljLibID === COMPLEMENTARY_LIB
+        let info;
+        if (cptLibReg.test(condition.gljLibID)) {
+            const owner = condition.gljLibID.split('*')[1] || userID;
+            info = { gljLibId: null, userID: owner, compilationId  };
+        } else {
+            info = { gljLibId: condition.gljLibID, userID: null, compilationId: null };
+        }
+        /* const info = condition.gljLibID === COMPLEMENTARY_LIB
             ? { gljLibId: null, userID, compilationId  }
-            : { gljLibId: condition.gljLibID, userID: null, compilationId: null };
+            : { gljLibId: condition.gljLibID, userID: null, compilationId: null }; */
         result.data = await ration_glj_facade.getGLJDataPaging(info, condition);
         if (req.session.sessionCompilation.priceProperties) {
             result.data.priceProperties = req.session.sessionCompilation.priceProperties
@@ -133,15 +147,23 @@ async function getGLJData(req, res) {
     try {
         let libData = null;
         let { engineerID, gljLibId, isInitial } = req.params;
-        if (gljLibId !== COMPLEMENTARY_LIB) {
+        const userID = req.session.sessionUser.id;
+        const compilationId = req.session.sessionCompilation._id;
+        const cptLibReg = new RegExp(COMPLEMENTARY_LIB);
+        if (!cptLibReg.test(gljLibId)) {
             gljLibId = +gljLibId;
         }
         isInitial = JSON.parse(isInitial);
         if (!gljLibId || isInitial) { // 替换人材机的话,可能存在gljLibID,但是是初始化的操作
             libData = engineerID === COMPILATION 
-            ? await ration_glj_facade.getLibOptionsForCompilation(req.session.sessionCompilation._id)
+            ? await ration_glj_facade.getLibOptionsForCompilation(compilationId)
             : await ration_glj_facade.getLibOptions(engineerID);
             libData.push({ name: '补充工料机', gljLibId: COMPLEMENTARY_LIB });
+            // 设置被分享的人材机库
+            const receiveData = await pmFacade.getReceiveLibList(userID, compilationId, ShareLibType.GLJ_LIB);
+            receiveData.forEach(user => {
+                libData.push({ name: `${user.real_name}的补充人材机库`, gljLibId: `${COMPLEMENTARY_LIB}*${user._id}` });
+            });
             if (gljLibId) { // 替换人材机初始化会触发此条件
                 const orgDefalutLib = libData.find(lib => lib.isDefault);
                 const newDefaultLib = libData.find(lib => lib.gljLibId === gljLibId);
@@ -155,9 +177,16 @@ async function getGLJData(req, res) {
         if (!gljLibId && libData) {
             gljLibId = (libData.find(lib => lib.isDefault) || {}).gljLibId;
         }
-        const info = gljLibId === COMPLEMENTARY_LIB 
+        let info;
+        if (cptLibReg.test(gljLibId)) {
+            const owner = gljLibId.split('*')[1] || userID;
+            info = { gljLibId: null, userID: owner, compilationId  };
+        } else {
+            info = { gljLibId, userID: null, compilationId: null };
+        }
+/*         const info = gljLibId === COMPLEMENTARY_LIB 
             ? { gljLibId: null, userID: req.session.sessionUser.id, compilationId: req.session.sessionCompilation._id }
-            : { gljLibId, userID: null, compilationId: null };
+            : { gljLibId, userID: null, compilationId: null }; */
         info.skipGLJ = skipGLJ;
         ration_glj_facade.getGLJData(info,function (err,datas) {
             if(err){

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

@@ -188,6 +188,9 @@ function createNewRecord(ration_glj) {
     newRecoed.repositoryId = ration_glj.repositoryId;
     newRecoed.projectGLJID = ration_glj.projectGLJID;
     newRecoed.adjCoe = ration_glj.adjCoe;
+    if (ration_glj.fromUser) {
+        newRecoed.fromUser = ration_glj.fromUser;
+    }
     return newRecoed
 }
 
@@ -698,7 +701,8 @@ function getGLJSearchInfo(ration_glj) {
         supply_quantity:0,
         supply:0,
         materialIndexCoe:ration_glj.materialIndexCoe,
-        from: ration_glj.from ? ration_glj.from : 'std'//std:标准工料机库, cpt:补充工料机库
+        from: ration_glj.from ? ration_glj.from : 'std',//std:标准工料机库, cpt:补充工料机库
+        fromUser: ration_glj.fromUser,
     };
     let glj_type_object = glj_type_util.getStdGljTypeCacheObj();
     let type = glj_type_object.getItemById(data.type);

+ 11 - 4
web/building_saas/complementary_glj_lib/html/tools-gongliaoji.html

@@ -27,6 +27,11 @@
     <script type="text/javascript">
         let priceProperties = JSON.parse('<%- priceProperties %>');
         let consumeAmtProperties = JSON.parse('<%- consumeAmtProperties %>');
+        let userId = "<%= userID%>";
+        const userID = "<%= userID%>";
+        let compilationId = "<%= compilationId%>";
+        let stdGljLibId = "<%= gljLibId%>";//用户当前编办下的标准工料机库ID,目前认为一个编办只有一个标准工料机库
+        const isReadOnly = JSON.parse('<%= isReadOnly %>');
     </script>
 </head>
 <body>
@@ -150,6 +155,7 @@
             </div>
         </div>
     </div>
+    <%include ../../../common/components/share/index.html %>
     <!-- JS. -->
     <script src="/lib/jquery-contextmenu/jquery.contextMenu.min.js"></script>
     <script src="/lib/jquery-contextmenu/jquery.ui.position.js"></script>
@@ -160,6 +166,9 @@
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.exedit.js"></script>
     <!--inject:js-->
     <script src="/web/building_saas/js/global.js"></script>
+    <script src="/lib/pinyinjs/pinyin_dict_firstletter.js"></script>
+    <script src="/lib/pinyinjs/pinyinUtil.js"></script>
+    <script src="/web/common/components/share/index.js"></script>
     <!-- zTree -->
     <script type="text/javascript" src="/public/web/common_ajax.js"></script>
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
@@ -170,6 +179,7 @@
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
     <script type="text/javascript" src="/public/web/ration_glj_units.js"></script>
+    <script type="text/javascript" src="/web/building_saas/complementary_glj_lib/js/init.js"></script>
     <script type="text/javascript" src="/web/building_saas/complementary_glj_lib/js/glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/complementary_glj_lib/js/gljClassTree.js"></script>
     <script type="text/javascript" src="/web/building_saas/complementary_glj_lib/js/gljComponent.js"></script>
@@ -182,9 +192,6 @@
     <!--endinject-->
     <script type="text/javascript" src="<%= overWriteUrl %>"></script>
     <SCRIPT type="text/javascript">
-        let userId = "<%= userID%>";
-        let compilationId = "<%= compilationId%>";
-        let stdGljLibId = "<%= gljLibId%>";//用户当前编办下的标准工料机库ID,目前认为一个编办只有一个标准工料机库
         let gljSetting = {
             view: {
                 //addHoverDom: gljTypeTreeOprObj.addHoverDom,
@@ -262,7 +269,7 @@
             $('#componentTreeDiv').height($(window).height() - 300);
             $("#componentSheet").height($("#componentTreeDiv").height() - 15);
             $("#componentSheet").width($('#modalCon').width() * 0.63); */
-            pageOprObj.initPage($("#GLJListSheet")[0], $('#gljComponentSheet')[0], $("#componentSheet")[0]);
+            //pageOprObj.initPage($("#GLJListSheet")[0], $('#gljComponentSheet')[0], $("#componentSheet")[0]);
         });
         //组成物弹出窗大小设置
         /* $(window).resize(function () {

+ 7 - 4
web/building_saas/complementary_glj_lib/js/glj.js

@@ -308,7 +308,7 @@ let repositoryGljObj = {
     },
     getGljDistType: function (callback) {
         let me = this;
-        CommonAjax.post('complementartGlj/api/getGljDistType', {}, function (rstData) {
+        CommonAjax.post('/complementartGlj/api/getGljDistType', {}, function (rstData) {
             if (callback) {
                 me.distTypeTree = me.getComboData(rstData);
                 console.log(me.distTypeTree);
@@ -318,7 +318,7 @@ let repositoryGljObj = {
     },
     getGljTree: function (gljLibId, callback) {
         let me = this;
-        CommonAjax.post('complementartGlj/api/getGljTree', { gljLibId: gljLibId }, function (rstData) {
+        CommonAjax.post('/complementartGlj/api/getGljTree', { gljLibId: gljLibId }, function (rstData) {
             zTreeHelper.createTree(rstData, gljSetting, "repositoryTree", me);
             zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
             if (rstData && rstData.length > 0) {
@@ -464,6 +464,9 @@ let repositoryGljObj = {
     buildSheet: function (container) {
         let me = repositoryGljObj;
         me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
+        if (isReadOnly) {
+            sheetCommonObj.disableSpread(me.workBook);
+        }
         sheetCommonObj.spreadDefaultStyle(me.workBook);
         me.repositoryGljDelOpr();
         me.onContextmenuOpr();
@@ -1055,7 +1058,7 @@ let repositoryGljObj = {
                             "delete": {
                                 name: "删除",
                                 disabled: function () {
-                                    return !(me.currentCache && me.currentCache[target.row]);
+                                    return isReadOnly || !(me.currentCache && me.currentCache[target.row]);
                                 },
                                 icon: "fa-remove",
                                 callback: function (key, opt) {
@@ -1471,7 +1474,7 @@ let repositoryGljObj = {
         if (addArr.length > 0) {
             me.saveInString(addArr);
         }
-        let url = 'complementartGlj/api/mixUpdateGljItems';
+        let url = '/complementartGlj/api/mixUpdateGljItems';
         let post = { updateItems: updateArr, addItems: addArr, removeIds: removeIds };
         let scCaller = function (rstData) {
             me.updateCache(addArr, updateArr, removeIds, rstData);

+ 1 - 1
web/building_saas/complementary_glj_lib/js/gljClassTree.js

@@ -149,7 +149,7 @@ let gljClassTreeObj = {
     },
 
     gljClassTreeAjax: function (postData, scFunc, errFunc) {
-        CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
+        CommonAjax.post('/complementartGlj/api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
     },
     //模仿默认点击
     initSelection: function (node) {

+ 6 - 4
web/building_saas/complementary_glj_lib/js/gljComponent.js

@@ -100,7 +100,9 @@ let gljComponentOprObj = {
         me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
         me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
         sheetOpr.cleanData(me.workBook.getSheet(0), me.setting, -1);
-
+        if (isReadOnly) {
+            sheetCommonObj.disableSpread(me.workBook);
+        }
         me.onContextmenuOpr();//右键菜单
         me.gljComponentDelOpr();
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
@@ -228,7 +230,7 @@ let gljComponentOprObj = {
                         callback: function () { },
                         items: {
                             "insert": {
-                                name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
+                                name: "插入", disabled: isReadOnly || insertDis, icon: "fa-sign-in", callback: function (key, opt) {
                                     let oprFunc = function () {
                                         //默认radio所有工料机
                                         co.initRadio();
@@ -246,7 +248,7 @@ let gljComponentOprObj = {
                                 }
                             },
                             "delete": {
-                                name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
+                                name: "删除", disabled: isReadOnly || delDis, icon: "fa-remove", callback: function (key, opt) {
                                     //删除
                                     let deleteObj = that.currentComponent[target.row];
                                     let gljComponent = that.currentGlj.component;
@@ -518,7 +520,7 @@ let gljComponentOprObj = {
         that.saveInString(updateArr);
         $.ajax({
             type: 'post',
-            url: 'complementartGlj/api/updateComponent',
+            url: '/complementartGlj/api/updateComponent',
             data: { "userId": pageOprObj.userId, "updateArr": JSON.stringify(updateArr) },
             dataType: 'json',
             success: function (result) {

+ 124 - 0
web/building_saas/complementary_glj_lib/js/init.js

@@ -0,0 +1,124 @@
+const GLJ_INIT = (() => {
+  const params = location.href.split('/');
+  const curUserID = params[params.length - 1];
+  console.log('curUserID', curUserID);
+
+  // 头部按钮相关
+  function initHeaderTools(receiveList, shareList) {
+    // 设置下拉项
+    const selectHtml = `
+    <select class="form-control  form-control-sm" id="glj-libs">
+    </select>`;
+    // 设置分享按钮
+    const shareHtml = `
+    <span id="share-tip" class="ml-2" data-toggle="tooltip" data-placement="bottom" data-original-title="">
+        <a id="init-share" href="javascript:;" class="btn btn-xs btn-primary"><i class="fa fa-share-alt"></i> 分享</a>
+    </span>`;
+    const html = `
+        <div style="display: flex; align-items: center">
+            ${selectHtml}
+            ${shareHtml}
+        </div>
+    `
+    $('#fullpath').html(html);
+    initShareTip(shareList);
+    $('[data-toggle="tooltip"]').tooltip();
+    initLibOptions(receiveList);
+    // 分享给
+    SHARE_TO.handleEventListener();
+    $('#init-share').click(() => {
+      SHARE_TO.initModal(SHARE_TO.Mode.GLJ_LIB);
+      $('#share-tip').tooltip('hide');
+    });
+
+    // 库下拉
+    function initShareTip(shareList) {
+      if (shareList.length) {
+        const owners = shareList.map(owner => owner.real_name);
+        const tips = `已分享给 ${owners.join(' ')}`;
+        $('#share-tip').attr('data-original-title', tips);
+      }
+    }
+
+    // 库下拉
+    function initLibOptions(receiveList) {
+      const libList = [
+        `<option value="${userID}">我的补充人材机库</option>`
+      ];
+      const options = receiveList.map(owner => `<option value=${owner._id} ${curUserID === owner._id ? 'selected' : ''}>${owner.real_name}的补充人材机库</option>`);
+      libList.push(...options);
+      $('#glj-libs').html(libList.join(''))
+    }
+
+    $('#glj-libs').change(function () {
+      const userID = $(this).val();
+      window.location.href = `/complementaryGlj/${userID}`;
+    });
+  }
+
+  $(document).ready(() => {
+    $.bootstrapLoading.start();
+    const projection = {
+      _id: 0,
+      ID: 1,
+      code: 1,
+      unit: 1,
+      name: 1,
+      priceProperty: 1,
+      basePrice: 1
+    };
+    CommonAjax.post('/complementartGlj/api/initData', { projection, userID: curUserID }, res => {
+        if (res.error) {
+            alert('数据初始化失败,请重试。');
+            setTimeout(() => {
+                window.location.href = '/'
+            }, 1200);
+        } else {
+          const { receiveLibs, shareLibs, gljItems, mixTree, distTypeData } = res;
+          initHeaderTools(receiveLibs, shareLibs);
+          pageOprObj.stdGljLibId = stdGljLibId;
+          repositoryGljObj.currentRepositoryId = stdGljLibId;
+          pageOprObj.userId = userId;
+          pageOprObj.compilationId = compilationId;
+          //生成人材机表格列头
+          repositoryGljObj.setting.header = repositoryGljObj.initHeaders(priceProperties);
+          //生成列映射
+          sheetCommonObj.initColMapping(repositoryGljObj, repositoryGljObj.setting.header);
+          //生成单价列下标数组
+          repositoryGljObj.initPriceCols(priceProperties, repositoryGljObj.colMapping);
+          repositoryGljObj.buildSheet($("#GLJListSheet")[0]);
+          gljComponentOprObj.buildSheet($('#gljComponentSheet')[0]);
+          componentOprObj.buildSheet($("#componentSheet")[0]);
+          // distTypeTree
+          repositoryGljObj.distTypeTree = repositoryGljObj.getComboData(distTypeData);
+          // tree
+          gljClassTreeObj.treeData = mixTree;
+          if (mixTree.comple && mixTree.comple.length > 0) {
+            gljClassTreeObj.gljCurTypeId = mixTree.comple[0].ID;
+          }
+          gljClassTreeObj.buildSheet();
+          gljClassTreeObj.initTree(mixTree.comple);
+          gljClassTreeObj.cache = gljClassTreeObj.tree.items;
+          repositoryGljObj.updateParentNodeIds(gljClassTreeObj.cache, repositoryGljObj);
+          gljClassTreeObj.initController(gljClassTreeObj.tree, gljClassTreeObj.sheet, gljClassTreeObj.setting.sheet);
+          gljClassTreeObj.controller.showTreeData();
+          gljClassTreeObj.sheet.setFormatter(-1, 0, '@');
+          // gljItems
+          repositoryGljObj.stdGljList = gljItems.stdGljs;
+          // 兼容多单价情况
+          for (const sGlj of repositoryGljObj.stdGljList) {
+              if (sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined') {
+                  sGlj.basePrice = sGlj.priceProperty.price1;
+              }
+          }
+          repositoryGljObj.sortGlj(repositoryGljObj.stdGljList);
+          repositoryGljObj.setProp('isStd', true, repositoryGljObj.stdGljList);
+          repositoryGljObj.complementaryGljList = gljItems.complementaryGljs;
+          repositoryGljObj.sortGlj(repositoryGljObj.complementaryGljList);
+          gljClassTreeObj.initSelection(gljClassTreeObj.tree.selected);
+        }
+        $.bootstrapLoading.end();
+    });
+  });
+
+})();

+ 2 - 1
web/building_saas/complementary_ration_lib/js/gljSelect.js

@@ -247,7 +247,8 @@ let gljSelOprObj = {
         let me = gljSelOprObj;
         //选择改变,数据重新筛选显示
         me.showGljList = [];
-        if (gljLib === commonConstants.COMPLEMENTARY_LIB) {
+        const cptLibReg = new RegExp(commonConstants.COMPLEMENTARY_LIB);
+        if (cptLibReg.test(gljLib)) {
             me.setShowGljList(me.complementaryGljList);
         } else {
             me.setShowGljList(me.stdGljList);

+ 12 - 1
web/building_saas/complementary_ration_lib/js/ration_glj.js

@@ -580,7 +580,12 @@ var rationGLJOprObj = {
         if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
             var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
             for (var i = 0; i < cacheArr.length; i++) {
-                rst.push({ gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, type: cacheArr[i].type });
+                const newItem = { gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, type: cacheArr[i].type };
+                if (cacheArr[i].userId && cacheArr[i].userId !== userID) {
+                    // 是分享人材机
+                    newItem.fromUser = cacheArr[i].userId;
+                }
+                rst.push(newItem);
             }
         }
         return rst;
@@ -597,6 +602,9 @@ var rationGLJOprObj = {
         rst.unit = repGlj.unit;
         rst.basePrice = repGlj.basePrice;
         rst.gljType = repGlj.gljType;
+        if (rItem.fromUser) {
+            rst.userId = rItem.fromUser;
+        }
         return rst;
     },
     getGljItems: function (rationItem, callback) {
@@ -610,6 +618,9 @@ var rationGLJOprObj = {
                 let idObj = Object.create(null);
                 idObj.type = rationGljList[i].type;
                 idObj.id = rationGljList[i].gljId;
+                if (rationGljList[i].fromUser) {
+                    idObj.fromUser = rationGljList[i].fromUser;
+                }
                 gljIds.push(idObj);
             }
             CommonAjax.post('/complementaryRation/api/getGljItemsByIds', { ids: gljIds }, function (rstData) {

+ 9 - 0
web/building_saas/main/js/models/ration_glj.js

@@ -753,6 +753,9 @@ let ration_glj = {
                 const glj = allGLJ.find(item => gljOprObj.getIndex(item, gljLibKeyArray) === selKey);
                 if (glj) {
                     const rationGLJ = me.getAddDataByStd(glj, ration.ID, ration.billsItemID, ration.projectID);
+                    if (glj.userId) {
+                        rationGLJ.fromUser = glj.userId;
+                    }
                     gljList.push(rationGLJ);
                 }
             });
@@ -840,6 +843,9 @@ let ration_glj = {
             oldData. materialIndexCoe =  glj.materialIndexCoe;
             if (glj.hasOwnProperty("compilationId")) {
                 oldData.from = "cpt";
+                if (glj.userId) {
+                    oldData.fromUser = glj.userId;
+                }
                 if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
                     oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
                 }
@@ -909,6 +915,9 @@ let ration_glj = {
             };
             if (glj.hasOwnProperty("compilationId")) {
                 doc.from = "cpt";
+                if (glj.userId) {
+                    doc.fromUser = glj.userId;
+                }
                 if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
                     doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
                 }

+ 7 - 5
web/building_saas/main/js/views/glj_view.js

@@ -78,7 +78,7 @@ var gljOprObj = {
                         me.gljCurTypeId = treeNode.ID;
                         /* me.filterLibGLJSheetData();
                          me.showLibGLJSheetData();*/
-                        me.loadPageData(gljOprObj.gljLibSheet, true, 0);
+                        me.loadPageData(gljOprObj.gljLibSheet, true, 0, $('#glj-lib-select').val());
                         //gljOprObj.initSelection({row: me.gljLibSheet.getActiveRowIndex()});
                     }
                 } else {
@@ -338,8 +338,8 @@ var gljOprObj = {
             me.loadPageData(args.sheet, false, curRecord.length);
         }
     },
-    loadPageData: function (sheet, reset, index) {
-        let condition = this.getPagingCondition(false, reset, false, index, false, null);
+    loadPageData: function (sheet, reset, index, gljLibID = null) {
+        let condition = this.getPagingCondition(false, reset, false, index, false, gljLibID);
         let getPagingFun =  typeof unitPriceObj != 'undefined' ? unitPriceObj.getGLJDataPaging:projectObj.project.ration_glj.getGLJDataPaging;
         getPagingFun(condition, function (data) {
             sheetCommonObj.appendData(sheet, condition.index, 0, gljOprObj.gljLibSheetSetting, data);
@@ -1179,6 +1179,7 @@ var gljOprObj = {
             // 搜索文本
             search: ''
         };
+        const cptLibReg = new RegExp(commonConstants.COMPLEMENTARY_LIB);
         // 触发入口(添加、替换、批量替换)
         const actionType = $('#actionType').val();
         const replaceActions = ['replace', 'm_replace'];
@@ -1201,12 +1202,13 @@ var gljOprObj = {
         } else {
             if (condition.replace) {
                 const selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
-                condition.gljLibID =  selected.from === 'cpt' || !selected.repositoryId ? commonConstants.COMPLEMENTARY_LIB : selected.repositoryId;
+                const cptLibID = selected.fromUser && selected.fromUser !== userID ? `${commonConstants.COMPLEMENTARY_LIB}*${selected.fromUser}` : commonConstants.COMPLEMENTARY_LIB;
+                condition.gljLibID =  selected.from === 'cpt' || !selected.repositoryId ? cptLibID : selected.repositoryId;
             } else {
                 condition.gljLibID = initLibs ? null : $('#glj-lib-select').val();
             }
         }
-        if (condition.gljLibID === commonConstants.COMPLEMENTARY_LIB) {
+        if (cptLibReg.test(condition.gljLibID)) {
             condition.type = this.pagingType.complementaryGLJs;
         }
         if (init) {

+ 4 - 2
web/common/components/share/index.js

@@ -12,11 +12,13 @@ const SHARE_TO = (() => {
 
     const Mode = {
         PROJECT: 1,
-        RATION_LIB: 2
+        RATION_LIB: 2,
+        GLJ_LIB: 3,
     };
 
     const ModeToLibType = {
-        [Mode.RATION_LIB]: ShareLibType.RATION_LIB
+        [Mode.RATION_LIB]: ShareLibType.RATION_LIB,
+        [Mode.GLJ_LIB]: ShareLibType.GLJ_LIB,
     };
 
     // 当前模式

+ 1 - 1
web/common/html/header.html

@@ -67,7 +67,7 @@
                 <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-wrench" data-placement="bottom"></i> 工具</a>
                 <div class="dropdown-menu dropdown-menu-right">
                     <a id="compleRationLib" class="dropdown-item compleRationLib" href=<%- "/complementaryRation/ration/" + userID %> target="_blank">定额库编辑器</a>
-                    <a id="compleGljLib" class="dropdown-item compleGljLib" href=<%- "/complementaryGlj" %> target="_blank">人材机库编辑器</a>
+                    <a id="compleGljLib" class="dropdown-item compleGljLib" href=<%- "/complementaryGlj/" + userID %> target="_blank">人材机库编辑器</a>
                 </div>
             </li>
             <% } %>