ソースを参照

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

MaiXinRong 5 年 前
コミット
ebb3d69177

+ 40 - 0
app/controller/setting_controller.js

@@ -590,6 +590,46 @@ module.exports = app => {
                 ctx.body = { err: 1, msg: error.toString(), data: null };
             }
         }
+
+        /**
+         * 显示设置(Get)
+         * @param {Object} ctx -egg全局变量
+         * @return {void}
+         */
+        async show(ctx) {
+            try {
+                // 获取项目数据
+                const projectId = ctx.session.sessionProject.id;
+                const projectData = await ctx.service.project.getDataById(projectId);
+                if (!projectData) {
+                    throw '没有对应的项目数据';
+                }
+                const showList = await ctx.service.settingShow.getList();
+                const renderData = { projectData, showList };
+                await this.layout('setting/show.ejs', renderData);
+            } catch (error) {
+                this.log(error);
+                ctx.redirect('/dashboard');
+            }
+        }
+
+        /**
+         * 更新显示设置列表
+         * @param {Object} ctx -egg全局变量
+         * @return {void}
+         */
+        async showListUpdate(ctx) {
+            try {
+                const { data } = ctx.request.body;
+                const { id } = JSON.parse(data);
+                const result = await ctx.service.settingShow.setDefaultLabel(id);
+                const responseData = { err: 0, msg: '', data: result };
+                ctx.body = responseData;
+            } catch (error) {
+                this.log(error);
+                ctx.body = { err: 1, msg: error.toString(), data: null };
+            }
+        }
     }
 
     return SettingController;

+ 15 - 13
app/controller/tender_controller.js

@@ -42,7 +42,7 @@ module.exports = app => {
                 for (const t of tenderList) {
                     if (t.user_id === this.ctx.session.sessionUser.accountId && (
                         t.ledger_status === auditConst.ledger.status.checkNo || t.ledger_status === auditConst.ledger.status.uncheck)) {
-                        const sum = await this.ctx.service.ledger.addUp({tender_id: t.id/*, is_leaf: true*/});
+                        const sum = await this.ctx.service.ledger.addUp({ tender_id: t.id/* , is_leaf: true*/ });
                         t.total_price = sum.total_price;
                         t.deal_tp = sum.deal_tp;
                     }
@@ -50,8 +50,7 @@ module.exports = app => {
                         t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
 
                         if (!t.lastStage) continue;
-                        if (t.lastStage.status === auditConst.stage.status.uncheck && t.lastStage.user_id !== this.ctx.session.sessionUser.accountId)
-                            t.lastStage = await this.ctx.service.stage.getLastestStage(t.id);
+                        if (t.lastStage.status === auditConst.stage.status.uncheck && t.lastStage.user_id !== this.ctx.session.sessionUser.accountId) { t.lastStage = await this.ctx.service.stage.getLastestStage(t.id); }
 
                         if (!t.lastStage) continue;
                         await this.ctx.service.stage.checkStageGatherData(t.lastStage);
@@ -118,7 +117,7 @@ module.exports = app => {
             } catch (err) {
                 console.log('error', err);
                 this.log(err);
-                this.ctx.redirect('/dashboard')
+                this.ctx.redirect('/dashboard');
             }
         }
 
@@ -126,6 +125,8 @@ module.exports = app => {
             this.jsFiles = this.app.jsFiles.tender.list;
             const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
             const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
+            const { path = 'list' } = await ctx.service.settingShow.getDefaultPath();
+            ctx.curListUrl = path;
             const renderData = {
                 accountInfo,
                 userPermission,
@@ -269,7 +270,8 @@ module.exports = app => {
          */
         async deleteTender(ctx) {
             try {
-                const data = JSON.parse(ctx.request.body.data), result = [];
+                const data = JSON.parse(ctx.request.body.data),
+                    result = [];
                 if (!(data instanceof Array) && (data.length === 0)) {
                     throw '提交数据有误';
                 }
@@ -278,9 +280,9 @@ module.exports = app => {
                         result.push(id);
                     }
                 }
-                ctx.body = {err: 0, msg: '', data: result};
+                ctx.body = { err: 0, msg: '', data: result };
             } catch (err) {
-                ctx.body = {err: 1, msg: err.toString(), data: []}
+                ctx.body = { err: 1, msg: err.toString(), data: [] };
             }
         }
 
@@ -295,12 +297,12 @@ module.exports = app => {
                 const tender = ctx.tender.data;
                 if (tender.user_id === this.ctx.session.sessionUser.accountId && (
                     tender.ledger_status === auditConst.ledger.status.checkNo || tender.ledger_status === auditConst.ledger.status.uncheck)) {
-                    const sum = await this.ctx.service.ledger.addUp({tender_id: tender.id/*, is_leaf: true*/});
+                    const sum = await this.ctx.service.ledger.addUp({ tender_id: tender.id/* , is_leaf: true*/ });
                     tender.total_price = sum.total_price;
                     tender.deal_tp = sum.deal_tp;
                 }
                 const stages = await ctx.service.stage.getValidStages(ctx.tender.id);
-                const lastStage = stages.length > 0 ? stages[0] : null; //await ctx.service.stage.getLastestStage(ctx.tender.id);
+                const lastStage = stages.length > 0 ? stages[0] : null; // await ctx.service.stage.getLastestStage(ctx.tender.id);
                 if (lastStage) {
                     await this.ctx.service.stage.checkStageGatherData(lastStage);
                     tender.gather_tp = ctx.helper.add(lastStage.contract_tp, lastStage.qc_tp);
@@ -319,17 +321,17 @@ module.exports = app => {
                 const monthProgress = [];
                 for (const s of stages) {
                     if (s.s_time) {
-                        let progress = monthProgress.find(function (x) {
+                        let progress = monthProgress.find(function(x) {
                             return x.month === s.s_time;
                         });
                         if (!progress) {
-                            progress = {month: s.s_time};
+                            progress = { month: s.s_time };
                             monthProgress.push(progress);
                         }
                         progress.tp = ctx.helper.add(ctx.helper.add(progress.tp, s.contract_tp), s.qc_tp);
                     }
                 }
-                monthProgress.sort(function (x, y) {
+                monthProgress.sort(function(x, y) {
                     return Date.parse(x.month) - Date.parse(y.month);
                 });
                 let sum = 0;
@@ -340,7 +342,7 @@ module.exports = app => {
                     p.end_ratio = ctx.helper.mul(ctx.helper.div(p.end_tp, tender.sum, 4), 100);
                 }
                 const renderData = {
-                    tender: tender,
+                    tender,
                     tenderInfo: ctx.tender.info,
                     tenderMenu: this.menu.tenderMenu,
                     preUrl: '/tender/' + ctx.tender.id,

+ 2 - 2
app/extend/helper.js

@@ -1073,9 +1073,9 @@ module.exports = {
      * @return {void}
      */
     async delFiles(fileList) {
-        if (fileList.length !== 0) {
+        if (fileList.length) {
             for (const att of fileList) {
-                if (fs.existsSync(path.join(this.app.baseDir, att.filepath))) {
+                if (att.filepath && fs.existsSync(path.join(this.app.baseDir, att.filepath))) {
                     await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
                 }
             }

+ 24 - 0
app/public/js/setting.js

@@ -169,6 +169,30 @@ $(document).ready(() => {
         $('#bind_account').text(accountData.name + ' ' + accountData.mobile);
         $('#account_id').val(id);
     })
+
+    // 设置显示默认
+    $('body').on('click', '#set-default', function () {
+        const attid = $(this).data('attid');
+        const data = {id: attid};
+        postData('/setting/show/update', data, function (result) {
+           let html = ''
+            result.forEach(item => {
+                html += `<li class="list-group-item">${item.label_name}`
+                html+= item.is_default ? `<span class="pull-right">默认</span></li>`:`<a href="javascript:void(0)" id="set-default" class="btn btn-primary btn-sm pull-right" data-attid="${item.id}">设为默认</a></li>`
+            })
+            // <li class="list-group-item">
+            // 标段列表<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
+            // </li>
+            // <li class="list-group-item">金额概况<span class="pull-right">默认</span></li>
+            // <li class="list-group-item">
+            //     计量进度<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
+            // </li>
+            $('.list-group').empty()
+            $('.list-group').append(html)
+            const item = result.find(i => i.id === attid)
+            $('#nav_tender').attr('href', item.path)
+        });
+    });
 });
 
 function checkPasswordForm() {

+ 4 - 0
app/router.js

@@ -59,6 +59,10 @@ module.exports = app => {
     app.post('/setting/user/exist', sessionAuth, 'settingController.accountExist');
     app.post('/setting/user/unbind', sessionAuth, 'settingController.userUnbind');
 
+    // 显示设置
+    app.get('/setting/show', sessionAuth, 'settingController.show');
+    app.post('/setting/show/update', sessionAuth, 'settingController.showListUpdate');
+
     // 标段自定义类别
     app.get('/setting/category', sessionAuth, 'settingController.category');
     app.post('/setting/category/add', sessionAuth, 'settingController.addCategory');

+ 58 - 0
app/service/setting_show.js

@@ -0,0 +1,58 @@
+'use strict';
+
+/**
+ * Created by LanJianRong on 2020/7/6.
+
+ * 项目设置->显示设置表数据模型
+ * @author LanJianRong
+ * @date 2020/07/06
+ * @version
+ */
+
+const BaseService = require('../base/base_service');
+module.exports = app => {
+
+    class settingShow extends BaseService {
+
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'setting_show';
+        }
+
+        /**
+         * 获取设置表所有记录
+         * @return {Promise<void>} 查询结果集
+         */
+        async getList() {
+            return await this.db.select(this.tableName);
+        }
+
+        /**
+         * 设置默认显示字段
+         * @param {Number} id 标签id
+         * @return {Promise<void>} 查询结果集
+         */
+        async setDefaultLabel(id) {
+            const record = await this.getDataByCondition({ is_default: 1 });
+            if (!record) throw '该标签不存在';
+            await this.update({ is_default: 0 }, { id: record.id });
+            await this.update({ is_default: 1 }, { id });
+            return await this.db.select(this.tableName);
+        }
+
+        /**
+         * 返回项目默认打开的url
+         * @return {String} path 默认url
+         */
+        async getDefaultPath() {
+            return await this.getDataByCondition({ is_default: 1 });
+        }
+    }
+    return settingShow;
+};

+ 1 - 1
app/view/layout/menu.ejs

@@ -12,7 +12,7 @@
             <% for (const index in ctx.menuList) { %>
             <% if (ctx.menuList[index].display === undefined || !ctx.menuList[index].display) { continue } %>
             <li <% if(ctx.controllerName === index || (ctx.controllerName === 'list' && index === 'tender')) { %>class="active"<% } %>>
-                <a href="<%- ctx.menuList[index].url %>" data-toggle="tooltip" data-placement="right" title="" data-original-title="<%- ctx.menuList[index].name %>">
+                <a href="<%- ctx.menuList[index].url === 'list' ? ctx.curListUrl : ctx.menuList[index].url %>" id="<%- 'nav_' + index%>" data-toggle="tooltip" data-placement="right" title="" data-original-title="<%- ctx.menuList[index].name %>">
                     <i class="fa <%- ctx.menuList[index].icon %>"></i>
                     <% if (ctx.menuList[index].caption) { %>
                     <span><%- ctx.menuList[index].caption %></span>

+ 49 - 0
app/view/setting/show.ejs

@@ -0,0 +1,49 @@
+<% include ./sub_menu.ejs %>
+<div class="panel-content">
+    <div class="panel-title">
+        <div class="title-main">
+            <h2>显示设置</h2>
+        </div>
+    </div>
+    <div class="content-wrap">
+        <div class="c-body">
+            <div class="sjs-height-0">
+                <div class="row m-0 mt-3">
+                    <div class="col-5">
+                        <div class="form-group">
+                            <label>项目列表默认显示</label>
+                            <div class="card w-50">
+                                <ul class="list-group list-group-flush">
+                                    <% showList.forEach(function(item) { %>
+                                        <li class="list-group-item">
+                                            <%= item.label_name %>
+                                            <% if(!item.is_default) { %>
+                                                <a href="javascript:void(0)" id="set-default" class="btn btn-primary btn-sm pull-right" data-attid="<%- item.id %>">设为默认</a>
+                                            <% } else {%>
+                                                <span class="pull-right">默认</span>
+                                            <% } %>
+                                        </li>
+                                    <% }) %>
+                                    <!-- <li class="list-group-item">
+                                        标段列表<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
+                                    </li>
+                                    <li class="list-group-item">金额概况<span class="pull-right">默认</span></li>
+                                    <li class="list-group-item">
+                                        计量进度<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
+                                    </li> -->
+                                </ul>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="/public/js/setting.js"></script>
+<script>
+    $(function () {
+        autoFlashHeight();
+    })
+      const showList = JSON.parse('<%- JSON.stringify(showList) %>');
+</script>

+ 6 - 0
config/menu.js

@@ -261,6 +261,12 @@ const settingMenu = {
         url: '/setting/user',
         caption: '账号设置',
     },
+    show: {
+        name: '显示设置',
+        display: true,
+        url: '/setting/show',
+        caption: '显示设置',
+    },
     category: {
         name: '标段自定义类别',
         display: true,

+ 14 - 0
sql/update.sql

@@ -83,3 +83,17 @@ ADD COLUMN `pre_sf_tp`  decimal(24,8) NULL DEFAULT NULL COMMENT '截止上期实
 
 ALTER TABLE `zh_stage_detail`
 ADD COLUMN `calc_img_remark` TEXT NULL DEFAULT NULL COMMENT '草图备注' AFTER `custom_define`;
+
+CREATE TABLE `zh_setting_show` (
+  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
+  `label_name` varchar(45) COLLATE utf8_unicode_ci NOT NULL COMMENT '标签名',
+  `is_default` int(11) NOT NULL DEFAULT '0' COMMENT '设置默认值,1为设置',
+  `path` varchar(45) COLLATE utf8_unicode_ci NOT NULL COMMENT '对应标签跳转路径',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+INSERT INTO `calculation`.`zh_setting_show`
+(`label_name`,`is_default`,`path`)
+VALUES
+('标段列表',0,'/list'),('金额概况',0,'/list/info'),('计量进度',1,'/list/progress');
+