Bläddra i källkod

feat: 新增标段概括-拷贝设置功能

lanjianrong 4 år sedan
förälder
incheckning
9a8920a227

+ 15 - 0
app/controller/tender_controller.js

@@ -878,6 +878,21 @@ module.exports = app => {
                 ctx.body = this.ajaxErrorBody(err, '保存审批流程设置失败');
             }
         }
+        /**
+         * 拷贝设置
+         * @param {object} ctx - 上下文
+         */
+        async copyTender(ctx) {
+            try {
+                const id = ctx.tender.data.id;
+                const { id: copy_id } = JSON.parse(ctx.request.body.data);
+                await ctx.service.tenderInfo.copyTenderHandler(id, copy_id);
+                ctx.body = { err: 0, msg: '' };
+            } catch (error) {
+                this.log(error);
+                ctx.body = this.ajaxErrorBody(error, '保存审批流程设置失败');
+            }
+        }
     }
 
     return TenderController;

+ 22 - 5
app/public/js/tender_copy_setting.js

@@ -95,6 +95,7 @@ function initTenderTree () {
     }
 }
 function recursiveGetTenderNodeHtml (node, arr, pid) {
+    if (node.id === tender.id) return ''
     const html = [];
     html.push('<tr pid="' + pid + '">');
     // 名称
@@ -112,7 +113,8 @@ function recursiveGetTenderNodeHtml (node, arr, pid) {
     // 创建人
     html.push('<td>');
     if (!node.cid) {
-        html.push('<input data-tid="'+ node.id +'" type="radio">');
+        // html.push('<input data-tid="'+ node.id +'" type="radio"> '+ (node.copy_id === tender.copy_id ? 'checked' : '') + '/>');
+        html.push(`<input data-tid=${node.id} type="radio" ${node.id === tender.copy_id ? 'checked' : ''}>`);
     }
     html.push('</td>');
     html.push('</tr>');
@@ -145,9 +147,24 @@ function getTenderTreeHtml () {
 $(document).ready(function () {
     initTenderTree()
     $('#copyBtn').click(() => {
-        console.log('1111')
         const html = getTenderTreeHtml();
-        $('#copyModalContent').html(html)
-        $('#bd-set-8').modal('show')
-    })
+        $('#copyModalContent').html(html);
+        $('#bd-set-8').modal('show');
+    });
+
+    $('#copyModalContent').on('click', 'input[type="radio"]', function() {
+        $('#copyModalContent tbody').children().each(function () {
+            $(this).find('input:radio').prop("checked", false);
+        })
+        $(this).prop("checked", true);
+    });
+
+    $('#copy_comfirm_btn').click(function() {
+        const id = $('#copyModalContent').find('input:checked').data('tid');
+        if (id) {
+            postData(window.location.pathname + '/copy-setting', { id }, function() {
+                window.location.reload()
+            })
+        }
+    });
 })

+ 1 - 0
app/router.js

@@ -113,6 +113,7 @@ module.exports = app => {
     app.get('/tender/:id/shenpi', sessionAuth, tenderCheck, 'tenderController.shenpiSet');
     app.post('/tender/:id/shenpi/save', sessionAuth, tenderCheck, 'tenderController.saveTenderInfoShenpi');
     app.post('/tender/:id/shenpi/audit/save', sessionAuth, tenderCheck, 'tenderController.saveShenpiAudit');
+    app.post('/tender/:id/copy-setting', sessionAuth, tenderCheck, 'tenderController.copyTender');
 
     // 预付款
     app.get('/tender/:id/advance', sessionAuth, tenderCheck, 'advanceController.index');

+ 7 - 7
app/service/tender.js

@@ -12,7 +12,7 @@ const tenderConst = require('../const/tender');
 const auditConst = require('../const/audit');
 const fs = require('fs');
 const path = require('path');
-const commonQueryColumns = ['id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id', 'valuation', 'total_price', 'deal_tp'];
+const commonQueryColumns = ['id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id', 'valuation', 'total_price', 'deal_tp', 'copy_id'];
 
 module.exports = app => {
 
@@ -285,16 +285,16 @@ module.exports = app => {
                 await transaction.delete(this.ctx.service.stageAudit.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.stageBills.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.stagePos.tableName, { tid: id });
-                await transaction.delete(this.ctx.service.stageBillsDgn.tableName, {tid: id});
-                await transaction.delete(this.ctx.service.stageBillsFinal.tableName, {tid: id});
-                await transaction.delete(this.ctx.service.stagePosFinal.tableName, {tid: id});
+                await transaction.delete(this.ctx.service.stageBillsDgn.tableName, { tid: id });
+                await transaction.delete(this.ctx.service.stageBillsFinal.tableName, { tid: id });
+                await transaction.delete(this.ctx.service.stagePosFinal.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.stageDetail.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.stagePay.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.stageChange.tableName, { tid: id });
 
-                await transaction.delete(this.ctx.service.stageJgcl.tableName, {tid: id});
-                await transaction.delete(this.ctx.service.stageBonus.tableName, {tid: id});
-                await transaction.delete(this.ctx.service.stageOther.tableName, {tid: id});
+                await transaction.delete(this.ctx.service.stageJgcl.tableName, { tid: id });
+                await transaction.delete(this.ctx.service.stageBonus.tableName, { tid: id });
+                await transaction.delete(this.ctx.service.stageOther.tableName, { tid: id });
 
                 await transaction.delete(this.ctx.service.change.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.changeAudit.tableName, { tid: id });

+ 16 - 0
app/service/tender_info.js

@@ -350,6 +350,22 @@ module.exports = app => {
             const shenpiInfo = !info.shenpi || info.shenpi === null || info.shenpi === '' ? defaultShenpiInfo : JSON.parse(info.shenpi);
             return shenpiInfo;
         }
+
+        /**
+         * 拷贝标段数据至当前标段
+         * @param {number} id - 当前标段id
+         * @param {number} copy_id - 被拷贝的标段id
+         * @return {Boolean} - 返回更新结果
+         */
+        async copyTenderHandler(id, copy_id) {
+            const [data] = await this.getAllDataByCondition({
+                where: {
+                    tid: copy_id,
+                },
+                columns: ['deal_info', 'construction_unit', 'tech_param', 'chapter', 'pay_account'],
+            });
+            return await this.update(data, { tid: id });
+        }
     }
 
     return TenderInfo;

+ 1 - 0
app/view/tender/detail.ejs

@@ -151,6 +151,7 @@
 <script type="text/javascript">
     const category = JSON.parse('<%- JSON.stringify(categoryData) %>');
     const tenders = JSON.parse('<%- JSON.stringify(tenders) %>');
+    const tender = JSON.parse('<%- JSON.stringify(tender) %>');
     //4 标段期数计量进度//
     var myChart = echarts.init(document.getElementById('chartContainer4'));
     var option = {

+ 1 - 1
app/view/tender/detail_modal.ejs

@@ -648,7 +648,7 @@
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">关闭</button>
-                <button type="button" class="btn btn-sm btn-primary">确认</button>
+                <button type="button" class="btn btn-sm btn-primary" id="copy_comfirm_btn">确认</button>
             </div>
         </div>
     </div>