MaiXinRong 4 سال پیش
والد
کامیت
bc2fda3d83

+ 7 - 7
app/const/third_party.js

@@ -9,15 +9,15 @@
  */
 
 const gxby = [
-    {value: 0, name: '未开始'},
-    {value: 1, name: '进行中'},
-    {value: 2, name: '已完成', color: '#5ACD94'}
+    { value: 0, name: '未开始', limit: false, },
+    { value: 1, name: '进行中', limit: false, },
+    { value: 2, name: '已完成', color: '#5ACD94', limit: true, }
 ];
 const dagl = [
-    {value: 0, name: '未完备'},
-    {value: 1, name: '第一阶段'},
-    {value: 2, name: '第二阶段'},
-    {value: 10, name: '完备', color: '#5ACD94'}
+    { value: 0, name: '未完备', limit: false },
+    { value: 1, name: '第一阶段', limit: true, ratio: 100, },
+    { value: 2, name: '第二阶段', limit: true, ratio: 100, },
+    { value: 10, name: '完备', color: '#5ACD94', limit: true, ratio: 100 }
 ];
 
 module.exports = {

+ 34 - 6
app/controller/setting_controller.js

@@ -34,11 +34,10 @@ module.exports = app => {
         }
 
         async _checkMenu(pid) {
-            const s2bData = new S2b(this.ctx);
-            const s2bProj = await s2bData.getS2bProj(pid);
-            // this.ctx.subMenu.s2b.display = !!s2bProj && (!!s2bProj.gxby || !!s2bProj.dagl);
-            this.ctx.subMenu.s2b.display = false;
-            return s2bProj;
+            const ctx = this.ctx;
+            await this.ctx.service.s2bProj.refreshSessionS2b(pid);
+            ctx.subMenu.s2b.display = !!ctx.session.sessionProject.gxby || !!ctx.session.sessionProject.dagl;
+            // this.ctx.subMenu.s2b.display = false;
         }
 
         /**
@@ -804,7 +803,36 @@ module.exports = app => {
                 ctx.body = { err: 0, msg: '', data: null };
             } catch (error) {
                 ctx.helper.log(error);
-                ctx.ajaxError(error, '保存数据错误');
+                this.ajaxErrorBody(error, '保存数据失败');
+            }
+        }
+
+        async s2bUpdateStatus(ctx) {
+            try {
+                const projectId = ctx.session.sessionProject.id;
+                const projectData = await ctx.service.project.getDataById(projectId);
+                if (projectData === null) throw '没有对应的项目数据';
+                if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
+
+                const data = JSON.parse(ctx.request.body.data);
+                console.log(data);
+                if (!data.type || data.status === undefined) throw '提交数据错误';
+
+                const responseData = { err: 0, msg: '', data: null };
+                switch (data.type) {
+                    case 'gxby':
+                        responseData.data = await this.ctx.service.s2bProj.updateGxbyStatus(projectId, data.status, data.limit);
+                        break;
+                    case 'dagl':
+                        responseData.data = await this.ctx.service.s2bProj.updateDaglStatus(projectId, data.status, data.limit, data.ratio);
+                        break;
+                    default: throw '提交数据错误';
+                }
+                ctx.body = responseData;
+            } catch (error) {
+                console.log(error);
+                ctx.helper.log(error);
+                this.ajaxErrorBody(error, '保存数据失败');
             }
         }
     }

+ 2 - 0
app/controller/stage_controller.js

@@ -365,7 +365,9 @@ module.exports = app => {
                 const checkDataModel = require('../lib/ledger').checkData;
                 const checkData = new checkDataModel(ctx);
                 checkData.loadData(ledgerData, posData);
+                await this.ctx.service.s2bProj.refreshSessionS2b();
                 const check3fResult = checkData.check3fLimit(ctx.tender.data);
+
                 const [qtyData, overData] = ctx.helper.checkBillsWithPos2(ledgerData, posData,
                     ['contract_qty', 'qc_qty'], projRela.banOver, this.ctx.tender.data.measure_type === measureType.tz.value);
                 qtyData.error.forEach(x => { x.errorType = 'qty'; });

+ 23 - 8
app/lib/ledger.js

@@ -600,7 +600,7 @@ class checkData {
             if (data.contract_qty || data.qc_qty || data.pre_contract_qty || data.pre_qc_qty) return 1; // 违规
         }
         if (limit === 1) {
-            if (ratio === 0) {
+            if (!ratio || ratio === 0) {
                 if (!data.contract_qty && !data.qc_qty && !data.pre_contract_qty && !data.pre_qc_qty) return 2; // 漏计
             } else {
                 const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, unit);
@@ -613,6 +613,23 @@ class checkData {
         return 0; // 合法
     }
 
+    _getRatio(type, status) {
+        if (type === 'gxby') return null;
+        const gs = this.ctx.session.sessionProject.dagl_status.find(x => { return x.value === status });
+        return gs ? gs.ratio : null;
+    }
+
+
+    _getValid = function (type, status, limit) {
+        if (limit) {
+            const statusConst = type === 'gxby' ? this.ctx.session.sessionProject.gxby_status : this.ctx.session.sessionProject.dagl_status;
+            const sc = statusConst.find(x => { return x.value === status; });
+            return sc ? (sc.limit ? 1 : 0) : 0;
+        } else {
+            return -1;
+        }
+    };
+
     _checkLeafBills3fLimit(checkType, bills, result, checkInfo) {
         const over = [], lost = [];
         const posRange = this.checkPos.getLedgerPos(bills.id);
@@ -620,13 +637,12 @@ class checkData {
             for (const p of posRange) {
                 const posCheckInfo = this.ctx.helper._.assign({}, checkInfo);
                 for (const ct of checkType) {
-                    if (p[ct + '_limit'] >= 0) {
+                    if (p[ct + '_limit'] > 0) {
                         posCheckInfo[ct + '_limit'] = p[ct + '_limit'];
-                        posCheckInfo[ct + '_ratio'] = p[ct + '_ratio'];
                     }
                 }
                 for (const ct of checkType) {
-                    const checkResult = this._check3fQty(p, posCheckInfo[ct + '_limit'], posCheckInfo[ct + '_ratio'], bills.unit);
+                    const checkResult = this._check3fQty(p, this._getValid(ct, p[ct + '_status'], posCheckInfo[ct + '_limit']), this._getRatio(ct, p[ct+'_status']), bills.unit);
                     if (checkResult === 1) {
                         if (over.indexOf(ct) === -1) over.push(ct);
                     }
@@ -638,8 +654,8 @@ class checkData {
         } else {
             for (const ct of checkType) {
                 const checkResult = bills.is_tp
-                    ? this._check3f(bills, checkInfo[ct + '_limit'], checkInfo[ct + '_ratio'])
-                    : this._check3fQty(bills, checkInfo[ct + '_limit'], checkInfo[ct + '_ratio'], bills.unit);
+                    ? this._check3f(bills, this._getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), this._getRatio(ct, bills[ct+'_status']))
+                    : this._check3fQty(bills, this._getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), this._getRatio(ct, bills[ct+'_status']), bills.unit);
                 if (checkResult === 1) {
                     if (over.indexOf(ct) === -1) over.push(ct);
                 }
@@ -672,9 +688,8 @@ class checkData {
     _recursiveCheckBills3fLimit(checkType, bills, result, parentCheckInfo) {
         const checkInfo = this.ctx.helper._.assign({}, parentCheckInfo);
         for (const ct of checkType) {
-            if (bills[ct + '_limit'] >= 0) {
+            if (bills[ct + '_limit'] > 0) {
                 checkInfo[ct + '_limit'] = bills[ct + '_limit'];
-                checkInfo[ct + '_ratio'] = bills[ct + '_ratio'];
             }
         }
         if (bills.children && bills.children.length > 0) {

+ 21 - 8
app/public/js/ledger_check.js

@@ -144,6 +144,20 @@ const ledgerCheckUtil = {
             }
             return list.other;
         };
+        const getRatio = function (type, status) {
+            if (type === 'gxby') return null;
+            const gs = option.status.dagl.find(x => { return x.value === status });
+            return gs ? gs.ratio : null;
+        };
+        const getValid = function (type, status, limit) {
+            if (limit) {
+                const statusConst = type === 'gxby' ? option.status.gxby : option.status.dagl;
+                const sc = statusConst.find(x => { return x.value === status; });
+                return sc ? (sc.limit ? 1 : 0) : 0;
+            } else {
+                return -1;
+            }
+        };
         const check3f = function (data, limit, ratio) {
             if (limit === 0) {
                 if (data.contract_tp || data.pre_contract_tp) return 1; // 违规
@@ -165,7 +179,7 @@ const ledgerCheckUtil = {
                 if (data.contract_qty || data.qc_qty || data.pre_contract_qty || data.pre_qc_qty) return 1; // 违规
             }
             if (limit === 1) {
-                if (ratio <= 0) {
+                if (!ratio || ratio === 0) {
                     if (!data.contract_qty && !data.qc_qty && !data.pre_contract_qty && !data.pre_qc_qty) return 2; // 漏计
                 } else {
                     const precision = findPrecision(tenderInfo.precision, unit);
@@ -184,13 +198,13 @@ const ledgerCheckUtil = {
                 for (const p of posRange) {
                     const posCheckInfo = _.assign({}, checkInfo);
                     for (const ct of option.checkType) {
-                        if (p[ct + '_limit'] >= 0) {
+                        if (p[ct + '_limit'] > 0) {
                             posCheckInfo[ct + '_limit'] = p[ct + '_limit'];
-                            posCheckInfo[ct + '_ratio'] = p[ct + '_ratio'];
                         }
                     }
                     for (const ct of option.checkType) {
-                        const checkResult = check3fQty(p, posCheckInfo[ct + '_limit'], posCheckInfo[ct + '_ratio'], bills.unit);
+                        const checkResult = check3fQty(p, getValid(ct, p[ct + '_status'], posCheckInfo[ct + '_limit']),
+                            getRatio(ct, p[ct + '_status']), bills.unit);
                         if (checkResult === 1) {
                             if (over.indexOf(ct) === -1) over.push(ct);
                         }
@@ -202,8 +216,8 @@ const ledgerCheckUtil = {
             } else {
                 for (const ct of option.checkType) {
                     const checkResult = bills.is_tp
-                        ? check3f(bills, checkInfo[ct + '_limit'], checkInfo[ct + '_ratio'])
-                        : check3fQty(bills, checkInfo[ct + '_limit'], checkInfo[ct + '_ratio'], bills.unit);
+                        ? check3f(bills, getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), getRatio(ct, bills[ct + '_status']))
+                        : check3fQty(bills, getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), getRatio(ct, bills[ct + '_status']), bills.unit);
                     if (checkResult === 1) {
                         if (over.indexOf(ct) === -1) over.push(ct);
                     }
@@ -221,9 +235,8 @@ const ledgerCheckUtil = {
         const recursiveCheckBills3fLimit = function (bills, parentCheckInfo) {
             const checkInfo = _.assign({}, parentCheckInfo);
             for (const ct of option.checkType) {
-                if (bills[ct + '_limit'] >= 0) {
+                if (bills[ct + '_limit'] > 0) {
                     checkInfo[ct + '_limit'] = bills[ct + '_limit'];
-                    checkInfo[ct + '_ratio'] = bills[ct + '_ratio'];
                 }
             }
             if (bills.children && bills.children.length > 0) {

+ 1 - 2
app/public/js/stage.js

@@ -242,7 +242,7 @@ $(document).ready(() => {
             enable: 1, isTz: checkTzMeasureType(),
         },
         limit3f: {
-            enable: 1, checkType: [],
+            enable: 1, checkType: [], status: thirdParty,
         }
     };
     if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
@@ -1924,7 +1924,6 @@ $(document).ready(() => {
         },
         selectionChanged: function (e, info) {
             stagePosSpreadObj.loadExprToInput(info.sheet);
-            console.log(SpreadJsObj.getSelectObject(info.sheet));
         },
         addPegs: function (pegs) {
             if (!pegs || pegs.length <= 0) return;

+ 1 - 0
app/router.js

@@ -91,6 +91,7 @@ module.exports = app => {
     // 接口设置
     app.get('/setting/api', sessionAuth, 'settingController.s2b');
     app.post('/setting/api/update', sessionAuth, 'settingController.s2bUpdate');
+    app.post('/setting/api/update-status', sessionAuth, 'settingController.s2bUpdateStatus');
 
 
     // 项目相关

+ 4 - 4
app/service/ledger_revise.js

@@ -100,12 +100,12 @@ module.exports = app => {
                 '     quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '     sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr, check_calc,' +
-                '     gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio)' +
+                '     gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit)' +
                 '  Select id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '      quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '      sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
                 '      sgfh_expr, sjcl_expr, qtcl_expr, 0,' +
-                '      gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio' +
+                '      gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit' +
                 '  From ' + this.ctx.service.ledger.tableName +
                 '  Where `tender_id` = ?';
             const sqlParam = [tid];
@@ -117,11 +117,11 @@ module.exports = app => {
                 '  (id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
                 '     sgfh_qty, sjcl_qty, qtcl_qty, crid, in_time, porder, position,' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
-                '     gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio)' +
+                '     gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit)' +
                 '  Select id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
                 '     sgfh_qty, sjcl_qty, qtcl_qty, crid, in_time, porder, position,' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
-                '     gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio' +
+                '     gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit' +
                 '  From ' + this.ctx.service.pos.tableName +
                 '  Where `tid` = ?';
             const sqlParam = [tid];

+ 3 - 3
app/service/pos.js

@@ -29,7 +29,7 @@ module.exports = app => {
                 where: condition,
                 columns: ['id', 'tid', 'lid', 'name', 'quantity', 'position', 'drawing_code', 'sgfh_qty', 'sjcl_qty',
                     'qtcl_qty', 'in_time', 'porder', 'add_stage', 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'real_qty',
-                    'dagl_status', 'dagl_url', 'gxby_status', 'gxby_limit', 'gxby_ratio', 'dagl_limit', 'dagl_status'],
+                    'dagl_status', 'dagl_url', 'gxby_status', 'gxby_limit', 'dagl_limit', 'dagl_status'],
                 order: [['porder', 'ASC']],
             });
         }
@@ -38,7 +38,7 @@ module.exports = app => {
             const sql = 'SELECT p.id, p.tid, p.lid, p.name, p.quantity, p.position, p.drawing_code,' +
                 '    p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.porder, p.add_stage, p.add_times, p.add_user, s.order As add_stage_order,' +
                 '    p.sgfh_expr, p.sjcl_expr, p.qtcl_expr, p.real_qty, p.gxby_status, p.dagl_status, p.dagl_url,' +
-                '    p.gxby_limit, p.dagl_limit, p.gxby_ratio, p.dagl_ratio' +
+                '    p.gxby_limit, p.dagl_limit' +
                 '  FROM ' + this.tableName + ' p ' +
                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s' +
                 '  ON p.add_stage = s.id'
@@ -50,7 +50,7 @@ module.exports = app => {
             if (ids instanceof Array && ids.length > 0) {
                 const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
                     '    sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
-                    '    dagl_status, dagl_url, gxby_status, gxby_limit, dagl_limit, gxby_ratio, dagl_ratio' +
+                    '    dagl_status, dagl_url, gxby_status, gxby_limit, dagl_limit' +
                     '  FROM ' + this.tableName +
                     '  WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
                 return await this.db.query(sql, []);

+ 0 - 1
app/service/project.js

@@ -164,7 +164,6 @@ module.exports = app => {
             });
             return result.affectedRows === 1;
         }
-
     }
 
     return Project;

+ 1 - 13
app/service/project_account.js

@@ -13,7 +13,6 @@ const crypto = require('crypto');
 const SSO = require('../lib/sso');
 const SMS = require('../lib/sms');
 const SmsAliConst = require('../const/sms_alitemplate');
-const thirdPartyConst = require('../const/third_party');
 const loginWay = require('../const/setting').loginWay;
 const smsTypeConst = require('../const/sms_type').type;
 module.exports = app => {
@@ -229,19 +228,8 @@ module.exports = app => {
                         // cooperation,
                     };
 
-                    const thirdParty = await this.db.get('zh_s2b_proj', { pid: projectInfo.id });
-                    if (thirdParty) {
-                        thirdParty.gxby_option = thirdParty.gxby_option ? JSON.parse(thirdParty.gxby_option) : null;
-                        projectInfo.gxby = thirdParty.gxby;
-                        projectInfo.gxby_status = thirdParty.gxby_option && thirdParty.gxby_option.status
-                            ? thirdParty.gxby_option.status : thirdPartyConst.gxby;
-
-                        thirdParty.dagl_option = thirdParty.dagl_option ? JSON.parse(thirdParty.dagl_option) : null;
-                        projectInfo.dagl = thirdParty.dagl;
-                        projectInfo.dagl_status = thirdParty.dagl_option && thirdParty.dagl_option.status
-                            ? thirdParty.dagl_option.status : thirdPartyConst.dagl;
-                    }
                     this.ctx.session.sessionProject = projectInfo;
+                    await this.ctx.service.s2bProj.refreshSessionS2b();
                     this.ctx.session.sessionProjectList = projectList;
                     // 记录登录日志
                     await this.ctx.service.loginLogging.addLoginLog(loginType, loginStatus);

+ 4 - 4
app/service/revise_audit.js

@@ -304,12 +304,12 @@ module.exports = app => {
                 '     quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '     sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr, check_calc,' +
-                '     gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio)' +
+                '     gxby_status, dagl_status, dagl_url, gxby_limit,  dagl_limit)' +
                 '  Select id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '      quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '      sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp, ' +
                 '      sgfh_expr, sjcl_expr, qtcl_expr, check_calc,' +
-                '      gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio' +
+                '      gxby_status, dagl_status, dagl_url, gxby_limit,  dagl_limit' +
                 '  From ' +
                 this.ctx.service.reviseBills.tableName +
                 '  Where `tender_id` = ?';
@@ -321,11 +321,11 @@ module.exports = app => {
                 '  (id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
                 '     sgfh_qty, sjcl_qty, qtcl_qty, crid, porder, position, ' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
-                '     gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio)' +
+                '     gxby_status, dagl_status, dagl_url, gxby_limit,  dagl_limit)' +
                 '  Select id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
                 '     sgfh_qty, sjcl_qty, qtcl_qty, crid, porder, position,' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
-                '     gxby_status, dagl_status, dagl_url, gxby_limit, gxby_ratio, dagl_limit, dagl_ratio' +
+                '     gxby_status, dagl_status, dagl_url, gxby_limit,  dagl_limit' +
                 '  From ' +
                 this.ctx.service.revisePos.tableName +
                 '  Where `tid` = ?';

+ 68 - 0
app/service/s2b_proj.js

@@ -0,0 +1,68 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2021/6/17
+ * @version
+ */
+const thirdPartyConst = require('../const/third_party');
+
+module.exports = app => {
+
+    class S2bProj extends app.BaseService {
+
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 's2b_proj';
+        }
+
+        async getDataByPid(pid) {
+            const sp = await this.getDataByCondition({ pid });
+            if (sp) {
+                sp.gxby_option = sp.gxby_option ? JSON.parse(sp.gxby_option) : null;
+                sp.dagl_option = sp.dagl_option ? JSON.parse(sp.dagl_option) : null;
+                sp.gxby_status = sp.gxby_status ? JSON.parse(sp.gxby_status) : thirdPartyConst.gxby;
+                sp.dagl_status = sp.dagl_status ? JSON.parse(sp.dagl_status) : thirdPartyConst.dagl;
+            }
+            return sp;
+        }
+
+        async refreshSessionS2b() {
+            const s2bProj = await this.getDataByPid(this.ctx.session.sessionProject.id);
+            this.ctx.session.sessionProject.gxby = s2bProj ? s2bProj.gxby : false;
+            this.ctx.session.sessionProject.gxby_status = s2bProj ? s2bProj.gxby_status : thirdPartyConst.gxby;
+            this.ctx.session.sessionProject.dagl = s2bProj ? s2bProj.dagl : false;
+            this.ctx.session.sessionProject.dagl_status = s2bProj ? s2bProj.dagl_status : thirdPartyConst.dagl;
+        }
+
+        async updateGxbyStatus(pid, status, limit) {
+            const sp = await this.getDataByPid(pid);
+            const gs = sp.gxby_status.find(x => { return x.value === status; });
+            if (!gs) throw '提交数据错误';
+            gs.limit = limit;
+            await this.db.update(this.tableName, { gxby_status: JSON.stringify(sp.gxby_status) }, { where: { pid } });
+            return gs;
+        }
+
+        async updateDaglStatus(pid, status, limit, ratio) {
+            const sp = await this.getDataByPid(pid);
+            const ds = sp.dagl_status.find(x => { return x.value === status; });
+            if (!ds) throw '提交数据错误';
+            if (limit !== undefined && limit !== null) ds.limit = limit;
+            if (ratio !== undefined && ratio !== null) ds.ratio = this.ctx.helper.round(ratio, 2);
+            await this.db.update(this.tableName, { dagl_status: JSON.stringify(sp.dagl_status) }, { where: { pid } });
+            return ds;
+        }
+
+    }
+
+    return S2bProj;
+};

+ 140 - 52
app/view/setting/s2b.ejs

@@ -8,65 +8,153 @@
     <div class="content-wrap">
         <div class="c-body">
             <div class="sjs-height-0">
-                <% if (tenders.length === 0) { %>
-                <div class="jumbotron m-3">
-                    <h3 class="display-6">没有标段数据</h3>
-                </div>
-                <% } else { %>
+                <nav class="nav nav-tabs m-3" role="tablist">
+                    <a class="nav-item nav-link active" data-toggle="tab" href="#user-purview" role="tab">业务配置</a>
+                    <a class="nav-item nav-link" data-toggle="tab" href="#user-list" role="tab">标段列表</a>
+                </nav>
                 <div class="m-3">
-                    <table class="table table-hover table-bordered">
-                        <thead>
-                        <tr>
-                            <th class="text-center" >名称</th>
-                            <th class="text-center" >计量模式</th>
-                            <th class="text-center" >计量期数</th>
-                            <th class="text-center" >创建人</th>
-                            <th class="text-center" >标段创建时间/期审批时间</th>
-                            <th class="text-center">工序报验</th>
-                            <th class="text-center">档案管理</th>
-                        </tr>
-                        </thead>
-                        <% for (const t of tenders) { %>
-                        <tr tid="<%- t.id %>">
-                            <td><%- t.name %></td>
-                            <td><%- t.measure_type_str %></td>
-                            <td><%- t.stage_count_str %></td>
-                            <td><%- t.user_str %></td>
-                            <td><%- ctx.moment(t.show_time).format('YYYY-MM-DD HH:mm:ss') %></td>
-                            <td class="text-center">
-                                <div class="form-check form-check-inline">
-                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox1" <% if (t.s2b_gxby_check) { %>checked<% } %> name="gxby_check" onchange="updateS2bSetting(this);" value="<%- t.s2b_gxby_check %>">
-                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                    <label class="form-check-label" for="inlineCheckbox1">检查计量</label>
-                                </div>
-                                <div class="form-check form-check-inline">
-                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox2" <% if (t.s2b_gxby_limit) { %>checked<% } %> name="gxby_limit" onchange="updateS2bSetting(this);" value="<%- t.s2b_gxby_limit %>">
-                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                    <label class="form-check-label" for="inlineCheckbox2">限制上报</label>
-                                </div>
-                            </td>
-                            <td class="text-center">
-                                <div class="form-check form-check-inline">
-                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox3" <% if (t.s2b_dagl_check) { %>checked<% } %> name="dagl_check" onchange="updateS2bSetting(this);" value="<%- t.s2b_dagl_check %>">
-                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                    <label class="form-check-label" for="inlineCheckbox3">检查计量</label>
-                                </div>
-                                <div class="form-check form-check-inline">
-                                    <input class="form-check-input" type="checkbox" id="inlineCheckbox4" <% if (t.s2b_dagl_limit) { %>checked<% } %> name="dagl_limit" onchange="updateS2bSetting(this);" value="<%- t.s2b_dagl_limit %>">
-                                    <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
-                                    <label class="form-check-label" for="inlineCheckbox4">限制上报</label>
-                                </div>
-                            </td>
-                        </tr>
-                        <% } %>
-                    </table>
+                    <div class="tab-content">
+                        <div class="tab-pane active" id="user-purview">
+                            <div class="col-4">
+                                <legend>工序报验</legend>
+                                <table class="table table-hover table-bordered">
+                                    <thead><tr><th>值</th><th>名称</th><th>允许计量</th></tr></thead>
+                                    <tbody id="gxby_list">
+                                    <% for (const s of ctx.session.sessionProject.gxby_status) { %>
+                                    <tr>
+                                        <td><%- s.value %></td>
+                                        <td><%- s.name %></td>
+                                        <td>
+                                            <div class="form-check form-check-inline">
+                                                <input class="form-check-input" type="checkbox" id="inlineCheckbox-g<%- s.value %>" <% if (s.limit) { %>checked<% } %> status="<%- s.value %>" onchange="updateStatusLimit(this, 'gxby');">
+                                                <label class="form-check-label" for="inlineCheckbox-g<%- s.value %>"></label>
+                                            </div>
+                                        </td>
+                                    </tr>
+                                    <% } %>
+                                    </tbody>
+                                </table>
+
+                                <legend>档案管理</legend>
+                                <table class="table table-hover table-bordered">
+                                    <thead><tr><th>值</th><th>名称</th><th>允许计量</th><th>计量比例</th></tr></thead>
+                                    <% for (const s of ctx.session.sessionProject.dagl_status) { %>
+                                    <tbody id="dagl_list">
+                                    <tr>
+                                        <td><%- s.value %></td>
+                                        <td><%- s.name %></td>
+                                        <td>
+                                            <div class="form-check form-check-inline">
+                                                <input class="form-check-input" type="checkbox" id="inlineCheckbox-d<%- s.value %>" <% if (s.limit) { %>checked<% } %> status="<%- s.value %>" onchange="updateStatusLimit(this, 'dagl');">
+                                                <label class="form-check-label" for="inlineCheckbox-d<%- s.value %>"></label>
+                                            </div>
+                                        </td>
+                                        <% if (s.value === 0) { %>
+                                        <td>-</td>
+                                        <% } else { %>
+                                        <td>
+                                            <div class="input-group input-group-sm" style="width:90px">
+                                                <input type="number" class="form-control" max="100" min="0" step="2" value="100" value="<%- s.ratio || 100 %>" status="<%- s.value %>" onchange="updateStatusRatio(this);">
+                                                <div class="input-group-append">
+                                                    <span class="input-group-text">%</span>
+                                                </div>
+                                            </div>
+                                        </td>
+                                        <% } %>
+                                    </tr>
+                                    <% } %>
+                                    </tbody>
+                                </table>
+                            </div>
+                        </div>
+                        <div class="tab-pane" id="user-list">
+                            <!--没有标段数据-->
+                            <% if (tenders.length === 0) { %>
+                            <div class="jumbotron m-3">
+                                <h3 class="display-6">没有标段数据</h3>
+                            </div>
+                            <% } else { %>
+                            <table class="table table-hover table-bordered">
+                                <thead>
+                                <tr>
+                                    <th class="text-center" >名称</th>
+                                    <th class="text-center" >计量模式</th>
+                                    <th class="text-center" >计量期数</th>
+                                    <th class="text-center" >创建人</th>
+                                    <th class="text-center" >标段创建时间/期审批时间</th>
+                                    <th class="text-center">工序报验</th>
+                                    <th class="text-center">档案管理</th>
+                                </tr>
+                                </thead>
+                                <% for (const t of tenders) { %>
+                                <tr tid="<%- t.id %>">
+                                    <td><%- t.name %></td>
+                                    <td><%- t.measure_type_str %></td>
+                                    <td><%- t.stage_count_str %></td>
+                                    <td><%- t.user_str %></td>
+                                    <td><%- ctx.moment(t.show_time).format('YYYY-MM-DD HH:mm:ss') %></td>
+                                    <td class="text-center">
+                                        <div class="form-check form-check-inline">
+                                            <input class="form-check-input" type="checkbox" id="inlineCheckbox1" <% if (t.s2b_gxby_check) { %>checked<% } %> name="gxby_check" onchange="updateS2bSetting(this);" value="<%- t.s2b_gxby_check %>">
+                                            <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                            <label class="form-check-label" for="inlineCheckbox1">检查计量</label>
+                                        </div>
+                                        <div class="form-check form-check-inline">
+                                            <input class="form-check-input" type="checkbox" id="inlineCheckbox2" <% if (t.s2b_gxby_limit) { %>checked<% } %> name="gxby_limit" onchange="updateS2bSetting(this);" value="<%- t.s2b_gxby_limit %>">
+                                            <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                            <label class="form-check-label" for="inlineCheckbox2">限制上报</label>
+                                        </div>
+                                    </td>
+                                    <td class="text-center">
+                                        <div class="form-check form-check-inline">
+                                            <input class="form-check-input" type="checkbox" id="inlineCheckbox3" <% if (t.s2b_dagl_check) { %>checked<% } %> name="dagl_check" onchange="updateS2bSetting(this);" value="<%- t.s2b_dagl_check %>">
+                                            <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                            <label class="form-check-label" for="inlineCheckbox3">检查计量</label>
+                                        </div>
+                                        <div class="form-check form-check-inline">
+                                            <input class="form-check-input" type="checkbox" id="inlineCheckbox4" <% if (t.s2b_dagl_limit) { %>checked<% } %> name="dagl_limit" onchange="updateS2bSetting(this);" value="<%- t.s2b_dagl_limit %>">
+                                            <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>">
+                                            <label class="form-check-label" for="inlineCheckbox4">限制上报</label>
+                                        </div>
+                                    </td>
+                                </tr>
+                                <% } %>
+                            </table>
+                            <% } %>
+                        </div>
+                    </div>
                 </div>
-                <% } %>
             </div>
         </div>
     </div>
 </div>
 <script>
+    const updateStatusLimit = function (obj, type) {
+        const data = { type };
+        data.status = parseInt(obj.getAttribute('status'));
+        data.limit = obj.checked;
+        postData('api/update-status', data, function(result) {
+        }, function () {
+            obj.checked = !obj.checked;
+        });
+    }
+    const updateStatusRatio = function (obj) {
+
+        const data = { type: 'dagl' };
+        data.status = parseInt(obj.getAttribute('status'));
+        try {
+            data.ratio = parseFloat(obj.value);
+        } catch (error) {
+            toastr.warning('请输入0-100间的数字');
+            return;
+        }
+        postData('api/update-status', data, function(result) {
+            obj.org = result.ratio;
+            obj.value = result.ratio;
+        }, function () {
+            obj.value = obj.org;
+        });
+    }
     const updateS2bSetting = function (obj) {
         try {
             const name = obj.getAttribute('name');