浏览代码

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

Conflicts:
	public/web/common_util.js
zhangweicheng 7 年之前
父节点
当前提交
40a0a10356

+ 6 - 0
modules/all_models/projects.js

@@ -7,6 +7,11 @@ const Schema = mongoose.Schema;
 const deleteSchema = require('../all_schemas/delete_schema');
 
 const collectionName = 'projects';
+const shareSchema = new Schema({
+    receiver: String, //userID
+    allowCopy: {type: Boolean, default: false},
+    shareDate: String,
+}, {versionKey: false, _id: false});
 const ProjectSchema = new Schema({
     "ID": Number,
     "ParentID": Number,
@@ -19,6 +24,7 @@ const ProjectSchema = new Schema({
     "compilation": String,
     "deleteInfo": deleteSchema,
     'fullFolder': Array,
+    "shareInfo": [shareSchema],
     "property": {
         type: Schema.Types.Mixed,
         default: {}

+ 10 - 0
modules/pm/controllers/pm_controller.js

@@ -419,5 +419,15 @@ module.exports = {
             result.message = err.message;
         }
         res.json(result);
+    },
+    projectShareInfo: async function(req, res){
+        try{
+            let data = JSON.parse(req.body.data);
+            let shareInfo = await projectModel.findOne({ID: data.projectID, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]}, 'shareInfo');
+            callback(req, res, 0, 'success', shareInfo);
+        }
+        catch (err){
+            callback(req, res, 1, err, null);
+        }
     }
 };

+ 2 - 0
modules/pm/routes/pm_route.js

@@ -50,6 +50,8 @@ module.exports = function (app) {
     pmRouter.post('/getGCDatas', pmController.getGCDatas);
     pmRouter.post('/recGC', pmController.recGC);
     pmRouter.post('/delGC', pmController.delGC);
+    //share
+    pmRouter.post('/getProjectShareInfo', pmController.projectShareInfo);
 
     app.use('/pm/api', pmRouter);
 };

+ 15 - 0
modules/users/controllers/user_controller.js

@@ -264,6 +264,21 @@ class UserController extends BaseController {
         }
     }
 
+    /*
+    * 获取用户信息
+    * */
+    async getUserByMobile(req, res){
+        try{
+            let userModel = new UserModel();
+            let data = JSON.parse(req.body.data);
+            let userData = await userModel.findDataByMobile(data.mobile);
+            res.json({error: 0, msg: 'success', data: userData});
+        }
+        catch (err){
+            res.json({error: 1, msg: err, data: null});
+        }
+    }
+
 }
 
 export default UserController;

+ 10 - 0
modules/users/models/user_model.js

@@ -154,6 +154,16 @@ class UserModel extends BaseModel {
     }
 
     /**
+     * 根据手机号查找数据
+     *
+     * @param {string} mobile
+     * @return {object}
+     */
+    findDataByMobile(mobile) {
+        return this.db.findOne({mobile: mobile});
+    }
+
+    /**
      * 根据userId查找数据
      *
      * @param {string} ssoId

+ 1 - 0
modules/users/routes/user_route.js

@@ -19,6 +19,7 @@ module.exports = function (app) {
     router.get('/preferences', userController.init, userController.preferences);
     router.post('/save-preferences', userController.init, userController.savePreferences);
     router.post('/info', userController.init, userController.saveData);
+    router.post('/getUserByMobile', userController.init, userController.getUserByMobile);
 
     router.post('/getVersionInfo', userController.init, userController.getVersionInfo);
     app.use('/user',router);

+ 14 - 9
public/web/common_util.js

@@ -13,25 +13,30 @@ String.prototype.hasSubStr = function (str) {
     return this.toLowerCase().indexOf(str.toLowerCase()) > -1;
 };
 
+// 判断字符串是否是数字形式的字符串
+String.prototype.isNumberStr = function () {
+    return this == +this;
+};
+
 // 树结点计算时,取费会出现值为NaN的情况,导致往父节点汇总(递归相加)会出现错误。
 function parseFloatPlus(value){
     let rst = parseFloat(value);
     return  isNaN(rst) ? 0 : rst;
 };
 
-// 将arr2合并到arr1,并去重复。
-function mergeArr(arr1, arr2){
-    if (arr2.length > 0){
-        for (let e of arr2){
-            if (!arr1.includes(e)) arr1.push(e);
+// 数组合并,并去重复。
+Array.prototype.merge = function (arr) {
+    if (arr.length > 0){
+        for (let e of arr){
+            if (!this.includes(e)) this.push(e);
         };
     }
 };
 
-// 判断 sub 是否是 arr 的子数组。
-function isSubArr(sub, arr){
-    for(var i = 0, len = sub.length; i < len; i++){
-        if(arr.indexOf(sub[i]) == -1) return false;
+// 数组是否包含另一个数组。
+Array.prototype.hasSubArr = function (subArr){
+    for(var i = 0, len = subArr.length; i < len; i++){
+        if(this.indexOf(subArr[i]) == -1) return false;
     }
     return true;
 };

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

@@ -899,6 +899,7 @@
                             <button class="btn btn-secondary btn-sm" id="divOpr">/</button>
                             <button class="btn btn-secondary btn-sm" id="leftOpr">(</button>
                             <button class="btn btn-secondary btn-sm" id="rightOpr">)</button>
+                            <span id="errorInfo" style="margin-left:15px;"></span>
                         </p>
                     </div>
                     <div class="row" id="cbRowDiv">

+ 46 - 14
web/building_saas/main/js/models/calc_program.js

@@ -909,6 +909,7 @@ const rationCalcBases = {
 };
 
 let analyzer = {
+    error: '',
     standard: function(expr){
         let str = expr;
         str = str.replace(/\s/g, "");               // 去空格、去中文空格
@@ -952,8 +953,18 @@ let analyzer = {
         return template.calcItems[idx];
     },
     isCycleCalc: function (expression, ID, template) {     // 这里判断expression,是ID引用: @5+@6
-        if (expression.includes(`@${ID}`))
-            return true;
+        let atID = `@${ID}`;
+        // 避免部分匹配,如:@10匹配@1
+        let idx = expression.indexOf(atID);
+        if (idx >= 0){
+            let nextPos = idx + atID.length;
+            if (nextPos >= expression.length)
+                return true;
+
+            let char = expression.charAt(nextPos);
+            if (!char.isNumberStr())
+                return true;
+        };
 
         let atIDs = analyzer.getAtIDArr(expression);
         for (let atID of atIDs) {
@@ -970,6 +981,7 @@ let analyzer = {
             try {
                 expr = expr.replace(/\[[\u4E00-\u9FA5]+\]/gi, '0');
                 expr = expr.replace(/@\d+/gi, '0');
+                expr = expr.replace(/L/gi, '0');
                 if (expr.includes('00'))
                     return false;
 
@@ -985,14 +997,16 @@ let analyzer = {
         let expr = me.standard(dispExpr);
         let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]FL%]/g;
         if (invalidChars.test(expr)){
-            hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
+            analyzer.error = `表达式中含有${hintBox.font('无效字符')}!`;
+            // hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
             return false;
         };
 
         let i = expr.search(/\df/ig);   // 4F3
         let j = expr.search(/\d\[/ig);  // 4[定额基价人工费]
         if (i > -1 || j > -1){
-            hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
+            analyzer.error = `表达式中${hintBox.font('缺少运算符')}!`;
+            // hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
             return false;
         }
 
@@ -1001,26 +1015,30 @@ let analyzer = {
         let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
         let arrBase = expr.match(pattBase);
         if (arrCn && !arrBase){
-            hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
+            analyzer.error = `定额基数必须用中括号${hintBox.font('[]')}括起来!`;
+            // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
             return false;
         };
         if (arrCn && arrBase && (arrCn.length != arrBase.length)){
             for (let cn of arrCn){
                 let tempBase = `[${cn}]`;
                   if (!arrBase.includes(tempBase)){
-                      hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
+                      analyzer.error = `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`;
+                      // hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
                       return false;
                   }
             };
             // 这里要加一个保险。因为上面的 for 循环在“主材费 + [主材费]” 情况下有Bug
-            hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
+            analyzer.error =`定额基数必须用中括号${hintBox.font('[]')}括起来!`;
+            // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
             return false;
         };
         if (arrBase){
             for (let base of arrBase){
                 let baseName = base.slice(1, -1);
                 if (!rationCalcBases[baseName]){
-                    hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}末定义!`, 1);
+                    analyzer.error = `定额基数${hintBox.font('[' +baseName + ']')}末定义!`;
+                    // hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}末定义!`, 1);
                     return false;
                 }
             };
@@ -1031,18 +1049,21 @@ let analyzer = {
             let num = F.slice(1);
             if (num > template.calcItems.length){
                 let s = hintBox.font('F'+num);
-                hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
+                analyzer.error = `表达式中 “${hintBox.font(s)}” 行号引用错误!`;
+                // hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
                 return false;
             };
         };
 
         let expression = me.getExpression(expr, template);
         if (me.isCycleCalc(expression, itemID, template)){
-            hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
+            analyzer.error = `表达式中有${hintBox.font('循环计算')}!`;
+            // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
             return false;
         };
         if (!testValue(expression)){
-            hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
+            analyzer.error = `表达式中有${hintBox.font('语法错误')}!`;
+            // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
             return false;
         };
 
@@ -1146,6 +1167,17 @@ let analyzer = {
         }
         return false;
     },
+    refreshUsedCalcItemsStatement: function(template, calcItem){
+        let atID = '@' + calcItem.ID;
+        for (var i = 0; i < template.calcItems.length; i++) {
+            let item = template.calcItems[i];
+            let atIDArr = analyzer.getAtIDArr(item.expression);
+            if (atIDArr.indexOf(atID) >= 0){
+                item.statement = analyzer.getStatement(item.expression, template);
+            };
+        }
+    },
+
     calcItemLabourCoe: function(calcItem){
         let lc = 0;
         if (calcItem.labourCoeID)
@@ -1831,11 +1863,11 @@ class CalcProgram {
                 leafBills.push(leafBill);
         };
 
-        mergeArr(billNodes, leafBills);
+        billNodes.merge(leafBills);
 
         for (let bill of billNodes){
             let changeBills = me.calculate(bill, true, false, tender);
-            mergeArr(allChangedNodes, changeBills);
+            allChangedNodes.merge(changeBills);
         };
 
         me.calcFormulaNodes(allChangedNodes, tender);
@@ -1877,7 +1909,7 @@ class CalcProgram {
             };
 
             let curChangeds = me.calculate(treeNode, true, true, tender);
-            mergeArr(changedNodes, curChangeds);
+            changedNodes.merge(curChangeds);
             me.saveNodes(changedNodes);
         };
     };

+ 1 - 1
web/building_saas/main/js/models/main_consts.js

@@ -100,7 +100,7 @@ const CP_Col_Width = {          // 多处计算程序界面的列宽统一设置
     feeRate: 60,
     displayFieldName: 120,
     statement: 380,
-    memo: 110,
+    memo: 120,
     unitFee: 90,
     totalFee: 90
 };

+ 8 - 3
web/building_saas/main/js/views/calc_base_view.js

@@ -236,9 +236,10 @@ let calcBaseView = {
             operators[i].bind('click', function () {
                 let v = $(this)[0].textContent;
                 let insertStr = me.insertStr(v);
-                if(me.arithmeticLegal(insertStr)){
+                me.inputExpr.val(insertStr);
+                /*if(me.arithmeticLegal(insertStr)){
                     me.inputExpr.val(insertStr);
-                }
+                }*/
                 me.inputExpr.focus();
             });
         }
@@ -314,6 +315,9 @@ let calcBaseView = {
                                 $.bootstrapLoading.end();
                             }
                         });
+                    }
+                    else{
+                        $('#errorInfo').html(analyzer.error);
                     };
                 }
                 else
@@ -408,6 +412,7 @@ $(document).ready(function () {
     });
 
     $('#qd-jsjs').on('hidden.bs.modal', function () {
+        $('#errorInfo').text('');
         //清空输入框
         calcBaseView.inputExpr.val('');
         calcBaseView.workBook.destroy();
@@ -422,7 +427,7 @@ $(document).ready(function () {
     calcBaseView.clickOpr([$('#addOpr'), $('#subOpr'), $('#mulOpr'), $('#divOpr'), $('#leftOpr'), $('#rightOpr')]);
 
     //bind input control
-    calcBaseView.inputControl();
+    //calcBaseView.inputControl();
 
     //confirmBtn
     calcBaseView.calcBaseConf();

+ 46 - 26
web/building_saas/main/js/views/calc_program_manage.js

@@ -136,18 +136,35 @@ let calcProgramManage = {
         };
 
         curCalcItem[dataCode] = args.newValue;
-        let data = {
-            'projectID': projectObj.project.ID(),
-            'templatesID': template.ID,
-            'calcItem': curCalcItem
-        };
-        me.saveCalcItem(data, function (rst) {
-            if (rst){
-                let relationNodes = calcTools.getNodesByProgramID(template.ID);
-                projectObj.project.calcProgram.calcNodesAndSave(relationNodes);
-            }
-        });
-        $.bootstrapLoading.end();
+
+        if (dataCode == 'name'){
+            analyzer.refreshUsedCalcItemsStatement(template, curCalcItem);
+            let data = {
+                'projectID': projectObj.project.ID(),
+                'ID': template.ID,
+                'calcItems': template.calcItems
+            };
+            calcProgramManage.updateTemplate(data, function (rst) {
+                if (rst){
+                    calcProgramManage.refreshDetailSheet();
+                    $.bootstrapLoading.end();
+                }
+            });
+        }
+        else{
+            let data = {
+                'projectID': projectObj.project.ID(),
+                'templatesID': template.ID,
+                'calcItem': curCalcItem
+            };
+            me.saveCalcItem(data, function (rst) {
+                if (rst){
+                    let relationNodes = calcTools.getNodesByProgramID(template.ID);
+                    projectObj.project.calcProgram.calcNodesAndSave(relationNodes);
+                    $.bootstrapLoading.end();
+                }
+            });
+        }
     },
     onDetailEnterCell: function (sender, args) {
         // for test.
@@ -356,21 +373,24 @@ let calcProgramManage = {
                             return;
                         };
 
-                        template.calcItems.splice(idx, 1);
-                        let data = {
-                            'projectID': projectObj.project.ID(),
-                            'ID': template.ID,
-                            'calcItems': template.calcItems
+                        hintBox.infoBox('系统提示', `确定要删除计算规则“${item.name}”吗?`, 2, cbYes);
+                        function cbYes() {
+                            template.calcItems.splice(idx, 1);
+                            let data = {
+                                'projectID': projectObj.project.ID(),
+                                'ID': template.ID,
+                                'calcItems': template.calcItems
+                            };
+                            calcProgramManage.updateTemplate(data, function (rst) {
+                                if (rst){
+                                    projectObj.project.calcProgram.compileTemplate(template);
+                                    calcProgramManage.refreshDetailSheet();
+                                    let relationNodes = calcTools.getNodesByProgramID(template.ID);
+                                    projectObj.project.calcProgram.calcNodesAndSave(relationNodes);
+                                    $.bootstrapLoading.end();
+                                }
+                            });
                         };
-                        calcProgramManage.updateTemplate(data, function (rst) {
-                            if (rst){
-                                projectObj.project.calcProgram.compileTemplate(template);
-                                calcProgramManage.refreshDetailSheet();
-                                let relationNodes = calcTools.getNodesByProgramID(template.ID);
-                                projectObj.project.calcProgram.calcNodesAndSave(relationNodes);
-                            }
-                        });
-                        $.bootstrapLoading.end();
                     }
                 }
             }

+ 0 - 1
web/building_saas/main/js/views/project_view.js

@@ -41,7 +41,6 @@ var projectObj = {
         }
         //zhong 2017-9-1 特征及内容
         if(pageCCOprObj.active){
-            console.log('enterCC');
             pageCCOprObj.mainActiveCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];//mainSpread焦点单元格
             pageCCOprObj.setCacheAndShow(node);
         }

文件差异内容过多而无法显示
+ 48 - 19
web/building_saas/pm/html/project-management.html


+ 56 - 2
web/building_saas/pm/js/pm_newMain.js

@@ -258,10 +258,14 @@ const projTreeObj = {
                     name: "分享",
                     icon: 'fa-share',
                     disabled: function () {
+                        let selectedItem = projTreeObj.tree.selected;
                         return true;
+                        // return !(selectedItem && selectedItem.data.projType === projectType.tender);
                     },
                     callback: function (key, opt) {
-
+                        $('#share-info').hide();
+                        $('#share').find('.card').hide();
+                        $('#share').modal('show');
                     }
                 },
             }
@@ -2814,4 +2818,54 @@ function refreshTenderFile(tenders, type, newName){
    });
 }
 
-//获取当前版本信息
+//添加分享
+$('#sharePhone').change(function () {
+    let phone = $(this).val();
+    let hintInfo = $('#share-info');
+    if(!phone || phone.trim() === ''){
+        replaceClass(hintInfo, 'text-info', 'text-danger');
+        setDangerInfo(hintInfo, '请输入手机号码。', true);
+        return;
+    }
+    //根据手机号获取用户
+    CommonAjax.post('/user/getUserByMobile', {mobile: phone}, function (rstData) {
+        if(!rstData){
+            replaceClass(hintInfo, 'text-info', 'text-danger');
+            setDangerInfo(hintInfo, '账号不存在。', true);
+        }
+        else{
+            console.log(rstData);
+            $('#user_name').text(rstData.real_name ? rstData.real_name : '');
+            $('#user_company').text(rstData.company ? rstData.company : '');
+            $('#user_mobile').text(rstData.mobile ? rstData.mobile : '');
+            $('#user_email').text(rstData.email ? rstData.email : '');
+            $('#share').find('.card').show();
+            //判断项目是否已经分享
+            //CommonAjax.post('/pm/api/getProjectShareInfo');
+        }
+    });
+});
+
+function shareTender(){
+    let phone = $('#sharePhone').val();
+    let hintInfo = $('#share-info');
+    if(!phone || phone.trim() === ''){
+        replaceClass(hintInfo, 'text-info', 'text-danger');
+        setDangerInfo(hintInfo, '请输入手机号码。', true);
+        return;
+    }
+    //根据手机号获取用户
+    CommonAjax.post('/user/getUserByMobile', {mobile: phone}, function (rstData) {
+        if(!rstData){
+            replaceClass(hintInfo, 'text-info', 'text-danger');
+            setDangerInfo(hintInfo, '账号不存在。', true);
+        }
+        else{
+            $('#user_name').text(rstData.real_name ? rstData.real_name : '');
+            $('#user_company').text(rstData.company ? rstData.company : '');
+            $('#user_mobile').text(rstData.mobile ? rstData.mobile : '');
+            $('#user_email').text(rstData.email ? rstData.email : '');
+            $('#share').find('.card').show();
+        }
+    });
+}