Browse Source

另存为

vian 5 years ago
parent
commit
b644a0653a

+ 54 - 29
modules/pm/facade/pm_facade.js

@@ -392,14 +392,14 @@ async function accessToCopyProject(userID, compilationID, data, newProjectID) {
         create_time: +new Date()
     };
     await importLogsModel.create(logData);
-    handleCopyProject(logData.key, userID, compilationID,data,newProjectID);
+    handleCopyProject(logData.key, userID, compilationID, data, newProjectID, false);
     return 'copying project';
 }
 
 async function handleCopyProject(key, userID, compilationID, data, newProjectID) {
     const doc = { status: 'finish' };
     try {
-        const projectMap = await copyProject(userID, compilationID, data, newProjectID);
+        const projectMap = await copyProject(userID, compilationID, data, newProjectID, false);
         doc.projectID = projectMap.copy.document.ID;
     } catch (err) {
         doc.status = 'error';
@@ -411,15 +411,22 @@ async function handleCopyProject(key, userID, compilationID, data, newProjectID)
 
 async function copyProject(userID, compilationID, data, newProjectID = null, delayProjectTask = false) {
     let projectMap = data.projectMap;
+    const isSaveAs =  isDef(projectMap.isSaveAs) ? projectMap.isSaveAs : false; // 只有另存为的行为为true,这里需要区分是因为,另存为中另存费率单价文件时,若有重名需要直接报错提示,而不是自动加(xxx复制)的后缀
+    const saveAsFile = isDef(projectMap.saveAsFile) ? projectMap.saveAsFile : true; // 是否另存费率、单价文件,默认是另存的。
+    const projectParentID = projectMap['copy'].document.ParentID;
+    const projectName = projectMap['copy'].document.name;
+    if (isSaveAs) {
+        const isExist = await isProjectNameExist(projectParentID, projectName);
+        if (isExist) {
+            throw `分段文件[${projectName}]已存在。`;
+        }
+    }
     let originalID = projectMap['copy'].document.ID;
     if (!newProjectID) {
         newProjectID = await getCounterID("projects");
     }
-    let newFeeName = null,newUnitName = null;
     let calcProgramFileID = uuidV1();//新的计算程序文件ID
     let labourCoeFileID = uuidV1();//新的人工调整系数文件ID
-    let feeRateFileID = uuidV1();//新的费率文件ID
-    let unitPriceFileID = await getCounterID("unit_price_file");//新的单价文件ID
     let originalProject = await projectModel.findOne({'ID':originalID});//查找最新的那项目信息,前端缓存的数据有可能不是最新的
     if(!originalProject){
         throw new Error('没有找到对应的项目,复制失败!');
@@ -431,19 +438,6 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
     let originalProperty = _.cloneDeep(property);
     projectMap['copy'].document.property = property;
     logger.info("复制项目: 旧项目ID: "+originalID+ " ------- 新项目ID: "+newProjectID);
-    //费率文件、单价文件重名检查
-    let feeRate =  await feeRateFileModel.findOne({rootProjectID:originalProperty.rootProjectID,name:originalProperty.feeFile.name,deleteInfo:null});
-    if(feeRate){//存在重名的文件
-        newFeeName = originalProperty.feeFile.name + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
-        projectMap['copy'].document.property.feeFile.name = newFeeName;
-    }
-
-    let unitPriceFile =  await unitPriceFileModel.findOne({root_project_id: originalProperty.rootProjectID,name:originalProperty.unitPriceFile.name,deleteInfo: null});
-    if(unitPriceFile){//存在重名的文件
-        newUnitName = originalProperty.unitPriceFile.name + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
-        projectMap['copy'].document.property.unitPriceFile.name = newUnitName;
-    }
-
     //更新项目的属性;
     projectMap['copy'].document.ID = newProjectID;
     if(projectMap['copy'].document.property.calcProgramFile){
@@ -452,12 +446,6 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
     if(projectMap['copy'].document.property.labourCoeFile){
         projectMap['copy'].document.property.labourCoeFile.ID = labourCoeFileID;
     }
-    if(projectMap['copy'].document.property.feeFile){
-        projectMap['copy'].document.property.feeFile.id = feeRateFileID;
-    }
-    if(projectMap['copy'].document.property.unitPriceFile){
-        projectMap['copy'].document.property.unitPriceFile.id = unitPriceFileID;
-    }
     projectMap['copy'].document.userID = userID;
     projectMap['copy'].document.compilation = compilationID;
     projectMap['copy'].document.createDateTime = new Date();
@@ -487,11 +475,41 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
     if(originalProperty.labourCoeFile){
         copyTasks.push(commonCopy(newProjectID,originalProperty.labourCoeFile.ID,labourCoeFileID,labourCoesModel));
     }
-    if(originalProperty.feeFile){
-        copyTasks.push(copyFeeRate(originalProperty.rootProjectID,userID,originalProperty.feeFile.id,feeRateFileID,newFeeName));
-    }
-    if(originalProperty.unitPriceFile){
-        copyTasks.push(copyUnitPriceFile(newProjectID,originalProperty.rootProjectID,userID,originalProperty.unitPriceFile.id,unitPriceFileID,newUnitName));
+    // 处理单价、费率文件
+    if (saveAsFile) {
+        let feeRateFileName = isSaveAs ? projectName : originalProperty.feeFile.name;
+        let unitPriceFileName = isSaveAs ? projectName : originalProperty.unitPriceFile.name;
+        let feeRateFileID = uuidV1();//新的费率文件ID
+        let unitPriceFileID = await getCounterID("unit_price_file");//新的单价文件ID
+        //费率文件、单价文件重名检查
+        let feeRate = await feeRateFileModel.findOne({ rootProjectID: originalProperty.rootProjectID, name: feeRateFileName, deleteInfo: null });
+        if (feeRate) {//存在重名的文件
+            if (isSaveAs) {
+                throw `费率文件[${feeRateFileName}]已存在,请手工检查数据是否正确。`;
+            }
+            feeRateFileName = feeRateFileName + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
+        }
+        projectMap['copy'].document.property.feeFile.name = feeRateFileName;
+        let unitPriceFile = await unitPriceFileModel.findOne({ root_project_id: originalProperty.rootProjectID, name: unitPriceFileName, deleteInfo: null });
+        if (unitPriceFile) {//存在重名的文件
+            if (isSaveAs) {
+                throw `单价文件[${unitPriceFileName}]已存在,请手工检查数据是否正确。`;
+            }
+            unitPriceFileName = unitPriceFileName + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '复制)';
+        }
+        projectMap['copy'].document.property.unitPriceFile.name = unitPriceFileName;
+        if(projectMap['copy'].document.property.feeFile){
+            projectMap['copy'].document.property.feeFile.id = feeRateFileID;
+        }
+        if(projectMap['copy'].document.property.unitPriceFile){
+            projectMap['copy'].document.property.unitPriceFile.id = unitPriceFileID;
+        }
+        if(originalProperty.feeFile){
+            copyTasks.push(copyFeeRate(originalProperty.rootProjectID,userID,originalProperty.feeFile.id,feeRateFileID,feeRateFileName));
+        }
+        if(originalProperty.unitPriceFile){
+            copyTasks.push(copyUnitPriceFile(newProjectID,originalProperty.rootProjectID,userID,originalProperty.unitPriceFile.id,unitPriceFileID,unitPriceFileName));
+        }
     }
     await Promise.all(copyTasks);
     // 最后再处理项目数据
@@ -504,6 +522,13 @@ async function copyProject(userID, compilationID, data, newProjectID = null, del
     }
 }
 
+// 判断项目名称是否存在
+async function isProjectNameExist(parentID, name) {
+    const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
+    const count = await projectModel.count({ ParentID: parentID, name, $or: notDeleted });
+    return !!count;
+}
+
 async function createIDsAndReturn(originalID,model) {
     let uuidMaping = {};//做ID映射
     let datas = [];

+ 29 - 0
web/building_saas/pm/html/project-management.html

@@ -484,6 +484,35 @@
         </div>
     </div>
 </div>
+<!-- 弹出另存为 -->
+<div class="modal fade" id="save-as-dialog" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">另存为</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form>
+                    <div class="form-group">
+                        <p>输入文件名:</p>
+                        <input type="text" class="form-control" id="save-as-name">
+                    </div>
+                    <div class="custom-control custom-checkbox">
+                        <input type="checkbox" class="custom-control-input" id="save-file" checked>
+                        <label class="custom-control-label" for="save-file">同时另存费率、单价文件</label>
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <a href="javascript:void(0);" class="btn btn-primary" id="save-as-confirm">确定</a>
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+            </div>
+        </div>
+    </div>
+</div>
 <!--弹出复制到-->
 <div class="modal fade" id="copy-to-dialog" data-backdrop="static">
     <div class="modal-dialog middle-modal-width" role="document">

+ 54 - 0
web/building_saas/pm/js/pm_newMain.js

@@ -302,6 +302,17 @@ const projTreeObj = {
                 $('#copy-to-dialog').modal('show');
             }
         },
+        saveAs: {
+            name: "另存为",
+            icon: 'fa-copy',
+            disabled: function () {
+                const node = projTreeObj.tree.selected;
+                return !(node && node.data.projType === projectType.tender);
+            },
+            callback: function (key, opt) {
+                $('#save-as-dialog').modal('show');
+            }
+        },
         share: {
             name: "分享",
             icon: 'fa-share',
@@ -421,6 +432,7 @@ const projTreeObj = {
                 "rename": me.contextMenuItems.rename,
                 "delete": me.contextMenuItems.delete,
                 "copyTo": me.contextMenuItems.copyTo,
+                "saveAs": me.contextMenuItems.saveAs,
                 "spr2": '--------',
                 "share": me.contextMenuItems.share,
                 "spr3": '--------',
@@ -2048,6 +2060,48 @@ $(document).ready(function() {
             alert(err);
         }
     });
+
+    // 另存为操作
+    $('#save-as-dialog').on('show.bs.modal', function () {
+        const selected = projTreeObj.tree.selected;
+        const name = selected.data.name;
+        $('#save-file').prop('checked', true);
+        $('#save-as-name').val(name);
+        setTimeout(() => $('#save-as-name')[0].focus(), 300);
+    });
+    $('#save-as-confirm').click(async function () {
+        try {
+            const name = $('#save-as-name').val().trim();
+            if (!name) {
+                throw new Error('名称不可为空。');
+            }
+            const saveAsFile = $('#save-file').prop('checked');
+            const originalNode = projTreeObj.tree.selected;
+            const projectMap = {
+                isSaveAs: true,
+                saveAsFile,
+            };
+            const parent = originalNode.parent;
+            const next = parent.firstChild();
+            const nextID = next ? next.id() : -1;
+            const projectData = _.cloneDeep(originalNode.data);
+            projectData['ParentID'] = parent.id();
+            projectData['NextSiblingID'] = nextID;
+            projectData['property'] = {};
+            projectData['property']['rootProjectID'] = parent.id();
+            projectData['shareInfo'] = [];
+            projectData['name'] = name;
+            projectMap['copy'] = { document: projectData };
+            $("#save-as-dialog").modal('hide');
+            $.bootstrapLoading.progressStart('拷贝项目', true);
+            $("#progress_modal_body").text('正在拷贝项目,请稍候……');
+            await ajaxPost('/pm/api/copyProjects', {projectMap:projectMap,user_id: userID, tenderCount: 1});
+            await importProcessChecking(null, null, (newProjectData) => handleTenderAfterChecking(newProjectData, projectData));
+        } catch (err) {
+            alert(err);
+        }
+    });
+
     $('#selectSameTypeProject').click(function(){
         let value = $(this).prop('checked') == true?1:0;
             projTreeObj.selectSameTypeProject(value);