Browse Source

新增单价文件另存为操作

olym 7 years ago
parent
commit
c0400a0fce

+ 45 - 0
modules/glj/controllers/glj_controller.js

@@ -352,6 +352,51 @@ class GLJController extends BaseController {
     }
 
     /**
+     * 单价文件另存为
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async unitPriceSaveAs(request, response) {
+        let responseData = {
+            err: 0,
+            msg: ''
+        };
+        let projectId = request.body.project_id;
+        let name = request.body.name;
+        try {
+            // 当前单价文件id
+            let currentUnitPriceId = await ProjectModel.getUnitPriceFileId(projectId);
+
+            // 新增单价文件信息
+            let unitPriceFileModel = new UnitPriceFileModel();
+            let insertData = {
+                name: name,
+                project_id: projectId
+            };
+            let addResult = await unitPriceFileModel.add(insertData);
+            if (!addResult) {
+                throw '单价文件另存为失败';
+            }
+
+            // 查找对应单价文件的项目工料机数据
+            let unitPriceModel = new UnitPriceModel();
+            let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, addResult.id);
+            // 复制成功后更改project数据
+            if (!copyResult) {
+                throw '复制数据失败';
+            }
+
+        } catch (error) {
+            responseData.err = 1;
+            responseData.msg = error;
+        }
+
+        response.json(responseData);
+    }
+
+    /**
      * 模拟定额插入
      *
      * @param {object} request

+ 1 - 0
modules/glj/routes/glj_router.js

@@ -19,6 +19,7 @@ router.post('/get-ratio', gljController.init, gljController.getRatio);
 router.post('/delete-ratio', gljController.init, gljController.deleteMixRatio);
 router.post('/get-project-info', gljController.init, gljController.getProjectInfo);
 router.post('/change-file', gljController.init, gljController.changeUnitPriceFile);
+router.post('/save-as', gljController.init, gljController.unitPriceSaveAs);
 
 router.get('/test', gljController.init, gljController.test);
 router.get('/testModify', gljController.init, gljController.testModify);

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

@@ -1,5 +1,5 @@
 <style type="text/css">
-    .copy{
+    .copy,#save-as-tips{
         display: none;
     }
 </style>
@@ -7,7 +7,7 @@
     <div class="form-inline py-1">
         <label class="mx-2">当前使用:<span id="used-name"></span>(<a href="#" id="pop-dj" data-original-title="" title=""><span id="used-count">0</span> 单位工程使用</a>)
             <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#change-dj"><i class="fa fa-exchange"></i> 选择其他</a>
-            <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#copy-dj"><i class="fa fa-files-o"></i> 另存单独用</a></label>
+            <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#file-save-as-dialog"><i class="fa fa-files-o"></i> 另存单独用</a></label>
     </div>
 </div>
 <div class="container-fluid">
@@ -95,6 +95,30 @@
         </div>
     </div>
 </div>
+<!--弹出 另存新文件-->
+<div class="modal fade" id="file-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">
+                <div class="form-group">
+                    <label>单价文件名称</label>
+                    <input class="form-control" id="save-as-name" value="">
+                    <small class="form-text text-danger" id="save-as-tips">已存在同名单价文件。</small>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="javascript:void(0);" class="btn btn-primary" id="save-as-confirm">确定</a>
+            </div>
+        </div>
+    </div>
+</div>
 <script type="text/javascript" src="/web/building_saas/glj/js/project_glj.js"></script>
 <script type="text/javascript" src="/web/building_saas/glj/js/composition.js"></script>
 <script type="text/javascript" src="/web/building_saas/glj/js/common_spread.js"></script>

+ 41 - 0
web/building_saas/glj/js/project_glj.js

@@ -79,6 +79,47 @@ $(document).ready(function () {
         });
     });
 
+    // 单价文件另存为弹框
+    $("#file-save-as-dialog").on('shown.bs.modal', function() {
+        // 获取当前建设项数据
+        $("#save-as-name").val(usedUnitPriceInfo.name + '(复件)');
+    });
+
+    // 单价文件另存为操作
+    $("#save-as-confirm").click(function() {
+        let name = $("#save-as-name").val();
+        if (name === '') {
+            $("#save-as-tips").text('请填写单价文件名称').show();
+            return false;
+        }
+        if (isChanging) {
+            return false;
+        }
+
+        $.ajax({
+            url: '/glj/save-as',
+            type: 'post',
+            data: {name: name, project_id: scUrlUtil.GetQueryString('project')},
+            dataType: 'json',
+            error: function() {
+                isChanging = false;
+            },
+            beforeSend: function() {
+                isChanging = true;
+            },
+            success: function(response) {
+                isChanging = false;
+                if (response.err === 1) {
+                    let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
+                    $("#save-as-tips").text(msg).show();
+                    return false;
+                }
+                $("#file-save-as-dialog").modal("hide");
+            }
+        });
+
+    });
+
     // 从其他建设项目中复制 选择建设项目
     $("#other-project").change(function() {
         let projectId = $(this).val();