Переглянути джерело

feat: 一些操作前重命名

vian 3 роки тому
батько
коміт
2a6ea23ff7

+ 3 - 3
modules/pm/facade/pm_facade.js

@@ -2583,7 +2583,7 @@ async function doDownLoadAndImport(privateDownloadUrl, info) {
               }
           } catch (error) {
               console.log(error.message);
-              doc.errorMsg = "导入失败,请检查文件!";
+              doc.errorMsg = error.message || "导入失败,请检查文件!";
               doc.status = "error";
           } finally {
               await importLogsModel.update({ key: info.key }, doc);
@@ -2968,8 +2968,8 @@ async function handleMainProjectDatas(mainData,updateData,userID) {
                 tasks.push({updateOne:{filter : updateData.update.query, update : {NextSiblingID:mainProjectID}}});
             }
             //查看是否重名;
-            let temp = await projectModel.findOne({userID:userID,ParentID:p.ParentID,name:p.name});
-            if(temp) p.name = p.name + '(' + moment(Date.now()).tz("Asia/Shanghai").format('MM-DD HH:mm:ss') + '导入)';
+            let temp = await projectModel.findOne({userID:userID,ParentID:p.ParentID,name:p.name, $or: notDeleted});
+            if(temp) throw new Error(`已存在建设项目“${p.name}”`);
         }else {
             p.ParentID = projectIDMap[p.ParentID];
             p.NextSiblingID = projectIDMap[p.NextSiblingID];

+ 22 - 0
web/building_saas/pm/html/project-management-share.html

@@ -83,4 +83,26 @@
             </div>
         </div>
     </div>
+</div>
+<div class="modal fade" id="share-rename-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">
+                    <div class="form-group">
+                        <input type="text" class="form-control" placeholder="输入名称" id="share-rename-input">
+                        <span class="form-text text-danger" id="share-rename-info" style="display: none;">已存在 “建筑工程1”</span>
+                    </div>
+            </div>
+            <div class="modal-footer">
+                <a href="javascript:void(0);" class="btn btn-primary" id="share-rename-confirm">确定</a>
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+            </div>
+        </div>
+    </div>
 </div>

+ 2 - 1
web/building_saas/pm/html/project-management.html

@@ -769,9 +769,10 @@
                     <div class="form-group row">
                         <label for="staticEmail" class="col-auto col-form-label col-form-label-sm">建设项目</label>
                         <div class="col">
-                            <input type="text" class="form-control form-control-sm" value="建设项目名称" readonly="">
+                            <input type="text" id="import-construction-name" class="form-control form-control-sm" value="建设项目名称">
                         </div>
                     </div>
+                    <p class="form-text text-danger" id="import-construction-name-info" style="display: none;">已存在 “建筑工程1”</p>
                     <div class="form-group row">
                         <label for="staticEmail" class="col-auto col-form-label col-form-label-sm">文件类型</label>
                         <div class="col">

+ 28 - 2
web/building_saas/pm/js/pm_import.js

@@ -276,9 +276,16 @@ const importView = (() => {
             feeFile: { name: curData.name, id: `newFeeRate@@${taxData.fee_lib.id}` }  //新建费率文件
         };
     }
+    function constructionExist() {
+        const name = $("#import-construction-name").val().trim();
+        const sameDepthProjs = getProjs(projTreeObj.tree.selected);
+        return sameDepthProjs.some(node => node.data.name === name);
+    }
+
     function eventListen() {
         //选择文件
         $('#customFile').change(async function () {
+            $("import-construction-name-info").hide();
             let file = $(this)[0].files[0];
             $('#import-confirm').prop('disabled', true);    //确认导入无效
             $('.custom-file-label').text(`${file ? file.name : ''}`);   //设置选择框文本
@@ -303,6 +310,11 @@ const importView = (() => {
                     $('.selFile input[name="fileKind-import"]:eq(0)').prop('checked', true);    //文件类型恢复成投标
                     $('#import-taxType').val('1');  //计税方法显示回默认的一般计税法
                     $('.selFile').show();   //显示建设项目、计价规则
+                    if (constructionExist()) {
+                        $('#import-construction-name').focus();
+                        $("#import-construction-name-info").show();
+                        $("#import-construction-name-info").text(`已存在 “${$("#import-construction-name").val().trim()}”`);
+                    }
                 } catch (err) {
                     console.log(err);
                     showUploadAlert(false, err);
@@ -322,11 +334,24 @@ const importView = (() => {
                 showUploadAlert(false, '不存在有效数据。');
                 return;
             }
-            let projectName = $('.selFile input:eq(0)').val();
-            if (!projectName) {
+            if (!xmlObj.name) {
                 showUploadAlert(false, '不存在有效建设项目。');
                 return;
             }
+
+            const constructionName = $("#import-construction-name").val().trim();
+            if (constructionExist()) {
+                $('#import-construction-name').focus();
+                $("#import-construction-name-info").show();
+                $("#import-construction-name-info").text(`已存在 “${constructionName}”`);
+                return;
+            }
+            if (!constructionName) {
+                $("#import-construction-name-info").text(`建设项目名不可为空`);
+                return;
+            }
+            $("#import-construction-name-info").hide();
+
             //文件类型
             let fileKind = $('.selFile input[name="fileKind-import"]:checked').val();
             if (!fileKind) {
@@ -420,6 +445,7 @@ const importView = (() => {
             }
             let pr = new SCComponent.InitProgressBar();
             try {
+                xmlObj.name = $("#import-construction-name").val().trim();
                 //建设项目设置选择的文件类型和选择的计税方法
                 xmlObj.property.fileKind = tbcObj.fileKind;
                 xmlObj.property.taxType = tbcObj.taxType;

+ 29 - 9
web/building_saas/pm/js/pm_share.js

@@ -812,10 +812,10 @@ const pmShare = (function () {
                       return !(selected && selected.data.allowCopy && selected.data.projType === projectType.project);
                   },
                   callback: function (key, opt) {
-                      if($(".p-title").text().includes('免费')){
+                      /* if($(".p-title").text().includes('免费')){
                         hintBox.versionBox('此功能仅在专业版中提供,免费版可选择单位工程进行拷贝');
                         return;
-                      }
+                      } */
                       copyContructionProject(tree.selected);
                   }
                 },
@@ -965,18 +965,19 @@ const pmShare = (function () {
         }
 
     }
-
+    let projectQueryResult = [];
     //拷贝分享的建设项目
     //@param {Object}selected 
-    async function copyContructionProject(selected){
+    async function copyContructionProject(selected, rename){
       try {
-        let newName = getCopyName(selected);
+        let newName = rename ? rename : getCopyName(selected);
         //获取单项工程的单位工程
         let projectQuery = {$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], userID: userID,projType: "Project"};
-        const rstData = await ajaxPost('/pm/api/getProjectsByQuery', {user_id: userID, query: projectQuery, options: '-_id -property'}, false, 10000);
-        for(let project of rstData){
+        projectQueryResult = await ajaxPost('/pm/api/getProjectsByQuery', {user_id: userID, query: projectQuery, options: '-_id -property'}, false, 10000);
+        for(let project of projectQueryResult){
             if(project.name === newName){
-                alert("已存在此建设项目");
+                $("#share-rename-dialog").modal('show');
+                $("#share-rename-input").val(newName);
                 return;
             }
         }
@@ -1007,7 +1008,7 @@ const pmShare = (function () {
             node = node.parent;
             userInfo = node.data.userInfo;
         }
-        return `${orgName} (${userInfo.name}分享拷贝)`;
+        return `${orgName}`;
     }
     //清除了该节点后,可能还有该节点的数据在树上(树允许有重复数据),需要更新分享信息
     function updateAfterCancel(userID, projectID) {
@@ -1184,6 +1185,25 @@ const pmShare = (function () {
                 $.bootstrapLoading.end();
             });
         });
+        // 拷贝重命名
+        $('#share-rename-dialog').on('show.bs.modal', () => {
+            $('#share-rename-info').hide();
+            setTimeout(() => {
+                $('#share-rename-input').focus();
+            }, 200)
+        });
+        $('#share-rename-confirm').click(function () {
+            const newName = $('#share-rename-input').val().trim();
+            for(let project of projectQueryResult){
+                if(project.name === newName){
+                    $('#share-rename-info').text(`已存在 “${newName}”`);
+                    $('#share-rename-info').show();
+                    return;
+                }
+            }
+            $("#share-rename-dialog").modal('hide');
+            copyContructionProject(tree.selected, newName);
+        });
     }
 
     return {