Sfoglia il codice sorgente

工料机汇总页面切换单价文件

olym 8 anni fa
parent
commit
843c140fda

+ 74 - 3
modules/glj/controllers/glj_controller.js

@@ -10,6 +10,7 @@ import GLJTypeConst from "../../common/const/glj_type_const";
 import GLJListModel from "../models/glj_list_model";
 import UnitPriceModel from "../models/unit_price_model";
 import MixRatioModel from "../models/mix_ratio_model";
+import UnitPriceFileModel from "../models/unit_price_file_model";
 
 const ProjectModel = require('../../pm/models/project_model').project;
 class GLJController extends BaseController {
@@ -54,11 +55,12 @@ class GLJController extends BaseController {
             // 获取使用该单价文件的项目数据
             let tenderData = await ProjectModel.getTenderByUnitPriceFileId(unitPriceFileId);
             let usedTenderList = [];
-            let usedUnitPriceName = '';
+            let usedUnitPriceInfo = {};
             if (tenderData !== null) {
                 for (let tmp of tenderData) {
                     usedTenderList.push(tmp.name);
-                    usedUnitPriceName = tmp.property.unitPriceFile.name;
+                    usedUnitPriceInfo.name = tmp.property.unitPriceFile.name;
+                    usedUnitPriceInfo.id = tmp.property.unitPriceFile.id;
                 }
             }
 
@@ -75,7 +77,7 @@ class GLJController extends BaseController {
                 hostname: request.hostname,
                 roomId: unitPriceFileId,
                 GLJTypeConst: JSON.stringify(GLJTypeConst),
-                usedUnitPriceName: usedUnitPriceName
+                usedUnitPriceInfo: usedUnitPriceInfo
             };
         } catch (error) {
             responseData.err = 1;
@@ -243,6 +245,75 @@ class GLJController extends BaseController {
     }
 
     /**
+     * 获取项目与单价文件对应的数据
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async getProjectInfo(request, response) {
+        let projectId = request.body.project_id;
+        projectId = parseInt(projectId);
+        let responseData = {
+            err: 0,
+            data: null
+        };
+        try {
+            let sessionUserData = request.session.sessionUser;
+            // 获取对应用户所有的建设项目数据
+            let projectList = await ProjectModel.getUserProjectData(sessionUserData.ssoId);
+            if (projectList === null) {
+                throw '没有找到对应的项目数据';
+            }
+            // 转换mongoose数据
+            projectList = JSON.stringify(projectList);
+            projectList = JSON.parse(projectList);
+
+            let result = {
+                self: [],
+                other: []
+            };
+            for (let index in projectList) {
+                // 获取对应建设项目下所有的单位工程id
+                let idList = await ProjectModel.getTenderByProjectId(projectList[index].ID);
+                if (idList.length <= 0) {
+                    continue;
+                }
+
+                // 获取对应的单价文件
+                let unitPriceFileModel = new UnitPriceFileModel();
+                let unitPriceFileData = await unitPriceFileModel.getDataByTenderId(idList);
+                projectList[index].unitPriceList = unitPriceFileData;
+
+                // 归类
+                if (idList.indexOf(projectId) >= 0) {
+                    result.self = unitPriceFileData;
+                } else {
+                    result.other.push(projectList[index]);
+                }
+            }
+            responseData.data = result;
+            response.json(responseData);
+
+        } catch (error) {
+            responseData.err = 1;
+            response.json(responseData);
+        }
+    }
+
+    /**
+     * 更改单价文件
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    changeUnitPriceFile(request, response) {
+        let unitPriceModel = new UnitPriceModel();
+
+    }
+
+    /**
      * 模拟定额插入
      *
      * @param {object} request

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

@@ -17,6 +17,7 @@ router.post('/getData', gljController.init, gljController.getGljList);
 router.post('/update', gljController.init, gljController.updateData);
 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.get('/test', gljController.init, gljController.test);
 router.get('/testModify', gljController.init, gljController.testModify);

+ 17 - 0
modules/pm/models/project_model.js

@@ -299,6 +299,23 @@ ProjectsDAO.prototype.getUnitPriceFileId = async function(projectId) {
     return result;
 };
 
+/**
+ * 获取当前用户的建设项目数据
+ *
+ * @param {Number} userId
+ * @return {Promise}
+ */
+ProjectsDAO.prototype.getUserProjectData = async function(userId) {
+    let projectList = await Projects.find({
+        '$or': [
+            {'userID': userId, 'deleteInfo': null, projType: 'Project'},
+            {'userID': userId, 'deleteInfo.deleted': {'$in': [null, false]}, projType: 'Project'}
+            ]
+    }, {_id: 0, name: 1, ID: 1});
+
+    return projectList;
+};
+
 module.exports ={
     project: new ProjectsDAO(),
     projType: projectType

+ 50 - 0
web/building_saas/glj/html/glj_index.html

@@ -1,3 +1,8 @@
+<style type="text/css">
+    .copy{
+        display: none;
+    }
+</style>
 <div class="toolsbar px-1">
     <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>)
@@ -45,6 +50,51 @@
         </div>
     </div>
 </div>
+<!--弹出更换-->
+<div class="modal fade" id="change-dj" 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 class="custom-control custom-radio">
+                        <input name="change-type" type="radio" class="custom-control-input" checked="checked" value="0">
+                        <span class="custom-control-indicator"></span>
+                        <span class="custom-control-description">从本建设项目中选择</span>
+                    </label>
+                    <label class="custom-control custom-radio">
+                        <input name="change-type" type="radio" class="custom-control-input" value="1">
+                        <span class="custom-control-indicator"></span>
+                        <span class="custom-control-description">从其他建设项目中复制</span>
+                    </label>
+                </div>
+                <!--从本建设项目中选择-->
+                <div class="form-group select option">
+                    <label id="current-project-name"></label>
+                    <select class="form-control" id="self-file"></select>
+                </div>
+                <!--从其他建设项目中复制-->
+                <div class="form-group copy option">
+                    <label>选择建设项目</label>
+                    <select class="form-control" id="other-project"></select>
+                </div>
+                <div class="form-group copy option">
+                    <select class="form-control" id="other-file"></select>
+                    <small class="form-text text-muted">你选择的单价文件将复制一份至新项目,不会影响原建设项目的单价文件。</small>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <a href="" class="btn btn-primary" id="change-file-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/socket.js"></script>

+ 94 - 5
web/building_saas/glj/js/project_glj.js

@@ -19,7 +19,9 @@ let GLJTypeConst = [];
 // spreadjs载入数据所需
 let jsonData = [];
 let mixRatioConnectData = [];
-
+// 单价文件相关
+let usedUnitPriceInfo = {};
+let otherFileData = {};
 let currentTag = '';
 let isChanging = false;
 $(document).ready(function () {
@@ -27,6 +29,94 @@ $(document).ready(function () {
         init();
     });
 
+    // 单价文件切换弹框
+    $('#change-dj').on('shown.bs.modal', function () {
+        // 获取当前建设项数据
+        let projectName = projectInfoObj.projectInfo.fullFolder !== undefined &&
+            projectInfoObj.projectInfo.fullFolder.length > 0 ? projectInfoObj.projectInfo.fullFolder[0] : '';
+        $("#current-project-name").text(projectName);
+
+        // 获取切换单价文件相关数据
+        $.ajax({
+            url: '/glj/get-project-info',
+            type: 'post',
+            data: {project_id: scUrlUtil.GetQueryString('project')},
+            dataType: 'json',
+            success: function(response) {
+                if (response.err === 1) {
+                    alert('数据传输错误!');
+                    return false;
+                }
+                let data = response.data;
+                // 本项目中的单价文件
+                if (data.self.length > 0) {
+                    let selfFileHtml = '';
+                    for(let tmp of data.self) {
+                        let select = usedUnitPriceInfo === tmp.id ? ' selected="selected"' : '';
+                        selfFileHtml += '<option'+ select +' value="'+ tmp.id +'">'+ tmp.name +'</option>';
+                    }
+                    $("#self-file").html(selfFileHtml);
+                }
+
+                // 其他建设项目数据
+                if (data.other.length > 0) {
+                    let otherProjectHtml = '';
+                    let otherFileHtml = '';
+                    for(let tmp of data.other) {
+                        otherProjectHtml += '<option value="'+ tmp.ID +'">'+ tmp.name +'</option>';
+                        otherFileData[tmp.ID] = tmp.unitPriceList;
+                        if (otherFileHtml !== '') {
+                            continue;
+                        }
+                        for(let unitPrice of tmp.unitPriceList) {
+                            otherFileHtml += '<option value="'+ unitPrice.id +'">'+ unitPrice.name +'</option>';
+                        }
+                    }
+                    $("#other-project").html(otherProjectHtml);
+                    $("#other-file").html(otherFileHtml);
+                }
+            }
+        });
+    });
+
+    // 从其他建设项目中复制 选择建设项目
+    $("#other-project").change(function() {
+        let projectId = $(this).val();
+        if (otherFileData[projectId] === undefined) {
+            return false;
+        }
+        let otherFileHtml = '';
+        for(let unitPrice of otherFileData[projectId]) {
+            otherFileHtml += '<option value="'+ unitPrice.id +'">'+ unitPrice.name +'</option>';
+        }
+        $("#other-file").html(otherFileHtml);
+    });
+
+    // 单价文件选项切换
+    $("input[name='change-type']").change(function() {
+        let type = $(this).val();
+        type = parseInt(type);
+        $("#change-dj .option").hide();
+        if (type === 0) {
+            $(".option.select").show();
+        } else {
+            $(".option.copy").show();
+        }
+    });
+
+    // 单价文件切换确认
+    $("#change-file-confirm").click(function() {
+        let type = $("input[name='change-type']:checked").val();
+        type = parseInt(type);
+        if (type === 0) {
+            // 从本项目中选择
+
+        } else {
+            // 从其他项目中复制
+
+        }
+    });
+
     // 是否主动更改数据
     // $("#message").on('click', '#load-data', function() {
     //     $("#notify").slideUp('fast');
@@ -77,14 +167,13 @@ function init() {
             GLJTypeConst = data.constData.GLJTypeConst !== undefined ? JSON.parse(data.constData.GLJTypeConst) : GLJTypeConst;
 
             let usedTenderList = data.usedTenderList !== undefined ? data.usedTenderList : [];
-            let usedUnitFileName = data.constData.usedUnitPriceName !== undefined ?
-                data.constData.usedUnitPriceName : '';
+            usedUnitPriceInfo = data.constData.usedUnitPriceInfo !== undefined ?
+                data.constData.usedUnitPriceInfo : {};
             // 存入缓存
             projectObj.project.projectGLJ.datas = jsonData;
-            console.log(projectObj.project);
 
             spreadInit();
-            unitPriceFileInit(usedUnitFileName, usedTenderList);
+            unitPriceFileInit(usedUnitPriceInfo.name, usedTenderList);
         }
     });