فهرست منبع

1.修改工料机相关数据字段
2.修复项目管理页面bug

olym 8 سال پیش
والد
کامیت
bf96ef0dda

+ 4 - 8
modules/glj/models/glj_list_model.js

@@ -412,7 +412,6 @@ class GLJListModel extends BaseModel {
         // 查找对应组成物的项目工料机数据
         let [projectGljList, compositionList] = await this.getCompositionGLJList(code, projectId, 'name');
 
-
         // 整理配合比待插入数据
         let mixRatioInsertData = [];
         for (let tmp of compositionList) {
@@ -434,7 +433,6 @@ class GLJListModel extends BaseModel {
         if (!addMixRatioResult) {
             throw '组成物插入单价数据失败!';
         }
-
         // 如果已经存在则后续操作停止
         if(projectGljList.length === compositionList.length) {
             return;
@@ -456,11 +454,10 @@ class GLJListModel extends BaseModel {
         if (notInGLJId.length <= 0) {
             return;
         }
-
         // 查找对应工料机总库数据
         let stdRationLibGLJListModel = new STDRationLibGLJListModel();
         let stdGLJData = await stdRationLibGLJListModel.getDataById(notInGLJId);
-        if (stdGLJData === null) {
+        if (stdGLJData === null || stdGLJData.length <= 0) {
             throw '没有找到对应的工料机总库数据';
         }
 
@@ -480,7 +477,9 @@ class GLJListModel extends BaseModel {
                 glj_id: tmp.ID,
                 project_id: projectId,
                 code: tmp.code,
-                name: tmp.name
+                name: tmp.name,
+                specs: tmp.specs,
+                unit: tmp.unit,
             };
             gljInsertData.push(gljData);
 
@@ -491,8 +490,6 @@ class GLJListModel extends BaseModel {
                 market_price: tmp.basePrice,
                 code: tmp.code,
                 name: tmp.name,
-                specs: tmp.specs,
-                unit: tmp.unit,
                 unit_price_file_id: unitPriceFileId,
                 // 如果没有对应的工料机类型则默认设置为普通材料
                 type: gljType[tmp.gljDistType] !== undefined ? gljType[tmp.gljDistType] : GLJTypeConst.GENERAL_MATERIAL
@@ -526,7 +523,6 @@ class GLJListModel extends BaseModel {
         try {
             // 查找对应的项目工料机数据
             let projectGLJData = await this.getDataById(projectGLJId);
-
             let allowType = [GLJTypeConst.MIX_RATIO, GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR,
                 GLJTypeConst.GENERAL_MACHINE];
 

+ 7 - 0
modules/glj/models/schemas/glj.js

@@ -62,6 +62,13 @@ let modelSchema = {
         type: Number,
         default: 1
     },
+    // 规格型号
+    specs: {
+        type: String,
+        default: ''
+    },
+    // 单位
+    unit: String,
     // 显示调整基价
     adjust_price: Number,
     // 显示关联单价文件的字段

+ 0 - 7
modules/glj/models/schemas/unit_price.js

@@ -26,13 +26,6 @@ let modelSchema = {
         type: String,
         index: true
     },
-    // 规格型号
-    specs: {
-        type: String,
-        default: ''
-    },
-    // 单位
-    unit: String,
     // 类型
     type: Number,
     // 单价文件表id

+ 1 - 3
modules/glj/models/unit_price_model.js

@@ -83,7 +83,7 @@ class UnitPriceModel extends BaseModel {
             return [null, false];
         }
 
-        // 先查找是否有同code的单价记录 @todo 后续可能会加入单位这个字段进一步确定唯一性
+        // 先查找是否有同code的单价记录
         let unitPriceData = await this.findDataByCondition({code: data.code, unit_price_file_id: unitPriceFileId}, null, false);
 
         // 如果有记录,判断是否存在一样的市场单价,有则直接返回数据
@@ -98,7 +98,6 @@ class UnitPriceModel extends BaseModel {
             let firstUnitPrice = unitPriceData[0] !== undefined ? unitPriceData[0] : [];
             data.base_price = firstUnitPrice.base_price !== undefined ? firstUnitPrice.base_price : 0;
             data.type = firstUnitPrice.type !== undefined ? firstUnitPrice.type : 0;
-            data.unit = firstUnitPrice.unit !== undefined ? firstUnitPrice.unit : 0;
         }
 
         // 更改名称
@@ -116,7 +115,6 @@ class UnitPriceModel extends BaseModel {
             unit_price_file_id: unitPriceFileId,
             name: data.name,
             type: data.type,
-            unit: data.unit
         };
 
         let addPriceResult = await this.add(insertData);

+ 1 - 1
modules/pm/controllers/pm_controller.js

@@ -67,7 +67,7 @@ module.exports = {
     },
     rename: function (req, res) {
         let data = JSON.parse(req.body.data);
-        ProjectsData.rename(req.session.sessionUser.ssoId, data.id, data.newName, function (err, message) {
+        ProjectsData.rename(req.session.sessionUser.ssoId, data, function (err, message) {
             callback(req, res, err, message, null);
         });
     },

+ 29 - 10
modules/pm/models/project_model.js

@@ -54,7 +54,10 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, datas, callbac
     if (datas){
         for (i = 0; i < datas.length && !hasError; i++){
             data = datas[i];
-            data.updateData.name = data.updateData.name !== undefined ? data.updateData.name.trim() : null;
+            if (data.updateData.name !== undefined) {
+                data.updateData.name = data.updateData.name.trim();
+            }
+
             if (data.updateType === 'update') {
                 Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll)
             } else if (data.updateType === 'new') {
@@ -138,14 +141,31 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
     }
 };
 
-ProjectsDAO.prototype.rename = function (userId, projectId, newName, callback){
-    Projects.update({userID: userId, ID: projectId}, {name: newName}, function(err){
-       if (err){
-           callback(1, '项目不存在.');
-       } else {
-           callback(0, '');
-       }
-    });
+ProjectsDAO.prototype.rename = async function (userId, data, callback){
+    try {
+        if (data.id === undefined || data.id === '') {
+            throw '数据错误!';
+        }
+        if (data.newName === undefined || data.newName === '') {
+            throw '请填写名称!';
+        }
+
+        // 查找同级是否存在同名数据
+        let exist = await this.isExist(data.newName, data.parentID);
+        if (exist) {
+            throw '同级目录已存在相同名称数据';
+        }
+
+        Projects.update({userID: userId, ID: data.id}, {name: data.newName}, function(err){
+            if (err){
+                throw '项目不存在';
+            }
+        });
+    } catch (error) {
+        callback(1, error, null);
+        return;
+    }
+    callback(0, '');
 };
 
 ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback){
@@ -196,7 +216,6 @@ ProjectsDAO.prototype.isExist = async function(name, parentID) {
         return true;
     }
     let count = await Projects.count({ParentID: parentID, name: name});
-
     return count > 0;
 };
 

+ 10 - 5
web/building_saas/pm/html/project-management.html

@@ -17,6 +17,11 @@
         var userAccount = '<%- userAccount %>';
         var userID = '<%- userID %>';
     </script>
+    <style type="text/css">
+        .hidden-area{
+            display: none;
+        }
+    </style>
 </head>
 
 <body>
@@ -331,10 +336,14 @@
                         <input type="text" class="form-control" placeholder="输入单位工程名称" id="tender-name">
                     </div>
                     <div class="form-group">
+                        <label>工程专业</label>
+                        <select class="form-control" id="tender-engineering"><option>建筑工程</option></select>
+                    </div>
+                    <div class="form-group hidden-area">
                         <label>单价文件</label>
                         <select class="form-control"><option>新建单价文件</option></select>
                     </div>
-                    <div class="form-group">
+                    <div class="form-group hidden-area">
                         <label>费率文件</label>
                         <select class="form-control" id="tender-fee-rate"><option>请选择费率文件</option></select>
                     </div>
@@ -357,10 +366,6 @@
                         <label>计价规则</label>
                         <select class="form-control" id="tender-valuation" disabled><option>重庆[2008]调整人工单价</option></select>
                     </div>
-                    <div class="form-group">
-                        <label>工程专业</label>
-                        <select class="form-control" id="tender-engineering"><option>建筑工程</option></select>
-                    </div>
                 </form>
             </div>
             <div class="modal-footer">

+ 25 - 10
web/building_saas/pm/js/pm_main.js

@@ -342,8 +342,7 @@ $(document).ready(function() {
             dialog.modal('hide');
             return false;
         }
-
-        RenameProject(select.id(), newName, function () {
+        RenameProject(select.id(), newName, select.data.ParentID, function () {
             dialog.modal('hide');
             select.data.name = newName;
             Tree.refreshNodesDom([select]);
@@ -364,6 +363,7 @@ $(document).ready(function() {
 
     // 移动到操作
     $('#move-to-confirm').click(function () {
+        console.log(111);
         let updateData = null;
         let dialog = $('#move-to-dialog');
         let target = GetTargetTreeNode($.fn.zTree.getZTreeObj('treeDemo'));
@@ -377,6 +377,18 @@ $(document).ready(function() {
             alert("请移动到单项工程中!");
             return false;
         }
+        // 判断同级是否有同名
+        if (target.children.length > 0) {
+            for (let tmp in target.children) {
+                if (tmp === 0) {
+                    continue;
+                }
+                if (target.children[tmp].data.name === cur.data.name) {
+                    alert("对应单项工程中存在同名数据!");
+                    return false;
+                }
+            }
+        }
 
         let parent = target;
         let next = target.firstChild();
@@ -500,6 +512,7 @@ $(document).ready(function() {
         }
         $("#tender-fee-rate").html(feeHtml);
 
+        $(this).parent().siblings('.hidden-area').slideDown('fast');
     });
 });
 
@@ -696,6 +709,7 @@ function AddTender() {
         $('#tender-name').val('');
         $("#tender-fee-rate").children("option").removeAttr("selected");
         $("#tender-engineering").children("option").removeAttr("selected");
+        $(".hidden-area").hide();
     };
     let selectedItem = Tree.selected();
     let tenderInfo = {
@@ -727,6 +741,10 @@ function AddFolder() {
     }
 
     let selectedItem = Tree.selected();
+    let callback = function() {
+        $("#add-folder-dialog").modal("hide");
+        $("#folder-name").val('');
+    };
     if (selectedItem !== null) {
         // 判断是否超过3层
         if (selectedItem.parent !== null && selectedItem.parent.parent !== null &&
@@ -734,13 +752,9 @@ function AddFolder() {
             alert("文件夹不能超过3层");
             return false;
         }
-        AddChildrenItem(name, null, projectType.folder, function() {
-            $("#add-folder-dialog").modal("hide");
-        });
+        AddChildrenItem(name, null, projectType.folder, callback);
     } else {
-        AddSiblingsItem(name, null, projectType.folder, function() {
-            $("#add-folder-dialog").modal("hide");
-        });
+        AddSiblingsItem(name, null, projectType.folder, callback);
     }
 }
 
@@ -864,14 +878,15 @@ function GetNewProjectId(callback) {
  *
  * @param {Number} projectId
  * @param {String} newName
+ * @param {Number} parentID
  * @param {function} callback
  * @return {void}
  */
-function RenameProject(projectId, newName, callback) {
+function RenameProject(projectId, newName, parentID, callback) {
     $.ajax({
         type: "POST",
         url: '/pm/api/renameProject',
-        data: {'data': JSON.stringify({"user_id": userID, "id": projectId, "newName": newName})},
+        data: {'data': JSON.stringify({"user_id": userID, "id": projectId, "newName": newName, "parentID": parentID})},
         dataType: 'json',
         cache: false,
         timeout: 5000,

+ 2 - 2
web/glj/html/glj_index.html

@@ -92,7 +92,7 @@
 <script type="text/javascript" src="/web/building_saas/js/global.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
-    let projectId = getQueryString("project");
-    $(".nav li > a").not(".active").attr("href", "/main?project=" + projectId);
+//    let projectId = getQueryString("project");
+//    $(".main-nav .nav li > a").not(".active").attr("href", "/main?project=" + projectId);
 });
 </script>

+ 3 - 2
web/glj/js/common_spread.js

@@ -33,8 +33,9 @@ CommonSpreadJs.prototype.init = function(target) {
     };
     this.columnInfo = [];
     for(let tmp of this.header) {
-        setting.header.push({headerName: tmp.name, headerWidth: 120});
-        this.columnInfo.push({name: tmp.field, displayName: tmp.name, visible: tmp.visible, cellType: tmp.cellType, size: 120});
+        let width = tmp.field === 'name' ? 200 : 120;
+        setting.header.push({headerName: tmp.name, headerWidth: width});
+        this.columnInfo.push({name: tmp.field, displayName: tmp.name, visible: tmp.visible, cellType: tmp.cellType, size: width});
     }
 
     this.spread = sheetCommonObj.buildSheet(document.getElementById(target), setting, 10);

+ 3 - 2
web/glj/js/composition_spread.js

@@ -29,7 +29,7 @@ CompositionSpread.prototype.init = function(target) {
     let header = [
         {name: '编码', field: 'code', visible: true},
         {name: '名称', field: 'name', visible: true},
-        {name: '单位', field: 'unit_price.unit', visible: true},
+        {name: '单位', field: 'unit', visible: true},
         {name: 'ID', field: 'id', visible: false},
         {name: '类型', field: 'unit_price.type', visible: false},
         {name: '基价单价', field: "unit_price.base_price", visible: true},
@@ -44,7 +44,7 @@ CompositionSpread.prototype.init = function(target) {
 
     // 获取列号
     let codeColumn = this.sheetObj.getFieldColumn('code');
-    let unitColumn = this.sheetObj.getFieldColumn('unit_price.unit');
+    let unitColumn = this.sheetObj.getFieldColumn('unit');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
 
     // 居中样式
@@ -125,6 +125,7 @@ CompositionSpread.prototype.getRatioData = function(projectGLJid) {
         success: function(response) {
             if (response.err === 0) {
                 response.data = JSON.parse(response.data);
+                console.log(response.data);
                 // 设置数据
                 self.sheetObj.setData(response.data);
                 self.specialColumn(response.data);

+ 6 - 7
web/glj/js/project_glj_spread.js

@@ -29,8 +29,8 @@ ProjectGLJSpread.prototype.init = function () {
     let header = [
         {name: '编码', field: 'code', visible: true},
         {name: '名称', field: 'name', visible: true},
-        {name: '规格型号', field: 'unit_price.specs', visible: true},
-        {name: '单位', field: 'unit_price.unit', visible: true},
+        {name: '规格型号', field: 'specs', visible: true},
+        {name: '单位', field: 'unit', visible: true},
         {name: 'ID', field: 'id', visible: false},
         {name: '类型', field: 'unit_price.type', visible: false},
         {name: '总消耗量', field: 'quantity', visible: true},
@@ -69,7 +69,7 @@ ProjectGLJSpread.prototype.init = function () {
     // 获取列号
     let isEvaluateColumn = this.sheetObj.getFieldColumn('is_evaluate');
     let isAdjustPriceColumn = this.sheetObj.getFieldColumn('is_adjust_price');
-    let unitColumn = this.sheetObj.getFieldColumn('unit_price.unit');
+    let unitColumn = this.sheetObj.getFieldColumn('unit');
     let quantityColumn = this.sheetObj.getFieldColumn('quantity');
     let basePriceColumn = this.sheetObj.getFieldColumn('unit_price.base_price');
     let adjustPriceColumn = this.sheetObj.getFieldColumn('adjust_price');
@@ -170,7 +170,7 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
     // 直接在前端计算后传值后台改
     let extend = {};
     let parentMarketPrice = projectGLJSpread.compositionCalculate(row);
-    if (Object.keys(parentMarketPrice).length > 0) {
+    if (parentMarketPrice !== null && Object.keys(parentMarketPrice).length > 0) {
         for (let activeCode in parentMarketPrice) {
             let tmpObject = {
                 market_price: parentMarketPrice[activeCode],
@@ -178,6 +178,7 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
             extend[activeCode] = tmpObject;
         }
     }
+
     extend = Object.keys(extend).length > 0 ?  JSON.stringify(extend) : '';
     $.ajax({
         url: '/glj/update',
@@ -273,13 +274,11 @@ ProjectGLJSpread.prototype.compositionCalculate = function(row) {
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
 
     let activeConnectCode = activeSheet.getValue(row, connectCodeColumn);
-
     // 不属于组成物则忽略
-    if (activeConnectCode === '' || activeConnectCode === undefined) {
+    if (activeConnectCode === '' || activeConnectCode === null) {
         return null;
     }
     activeConnectCode = activeConnectCode.split(',');
-
     // 计算同级组成物的价格
     // 遍历所有记录
     let maxRow = activeSheet.getRowCount();