Просмотр исходного кода

Merge branch 'master' of http://smartcost.f3322.net:3000/caiaolin/Calculation

MaiXinRong 6 лет назад
Родитель
Сommit
e6b7b4c6ca

+ 11 - 3
app/controller/change_controller.js

@@ -447,15 +447,23 @@ module.exports = app => {
          */
         async save(ctx) {
             try {
-                // console.log(ctx.request.body);
                 const result = await ctx.service.change.save(ctx.request.body, ctx.session.sessionUser.tenderId);
                 if (!result) {
                     throw '上报失败';
                 }
-                ctx.redirect('/tender/' + ctx.session.sessionUser.tenderId + '/change');
+                if (ctx.request.body.changestatus !== undefined && parseInt(ctx.request.body.changestatus) === 2) {
+                    console.log('hello');
+                    ctx.body = { err: 0, msg: '保存成功' };
+                } else {
+                    ctx.redirect('/tender/' + ctx.session.sessionUser.tenderId + '/change');
+                }
             } catch (err) {
                 this.log(err);
-                ctx.redirect('/tender/' + ctx.session.sessionUser.tenderId + '/change/' + ctx.request.body.cid + '/info');
+                if (ctx.request.body.changestatus !== undefined && parseInt(ctx.request.body.changestatus) === 2) {
+                    ctx.body = { err: 1, msg: err.toString() };
+                } else {
+                    ctx.redirect('/tender/' + ctx.session.sessionUser.tenderId + '/change/' + ctx.request.body.cid + '/info');
+                }
             }
         }
 

+ 83 - 25
app/public/js/change_set.js

@@ -18,27 +18,29 @@ $(document).ready(() => {
     let listHtml = '';
     let list_index = 1;
     for (const gcl of gclGatherData) {
+        const quantity = gcl.quantity !== undefined ? gcl.quantity : 0;
         listHtml += '<tr data-lid="' + list_index + '" data-gcl="' + (list_index-1) + '" data-index="' + list_index + '" data-detail="">' +
             '<td>' + list_index + '</td>' +
             '<td>' + gcl.b_code + '</td>' +
             '<td>' + gcl.name + '</td>' +
             '<td>' + gcl.unit + '</td>' +
             '<td>' + roundnum(gcl.unit_price, totalPriceUnit) + '</td>' +
-            '<td>' + roundnum(gcl.quantity, findDecimal(gcl.unit)) + '</td>' +
-            '<td>' + roundnum(parseFloat(gcl.unit_price).mul(parseFloat(gcl.quantity)), totalPriceUnit) + '</td>' +
+            '<td>' + roundnum(quantity, findDecimal(gcl.unit)) + '</td>' +
+            // '<td>' + roundnum(parseFloat(gcl.unit_price).mul(parseFloat(gcl.quantity)), totalPriceUnit) + '</td>' +
             '</tr>';
         list_index++;
     }
     // 再加载签约清单
     for (const db of dealBillList) {
+        const quantity = db.quantity !== undefined ? db.quantity : 0;
         listHtml += '<tr data-lid="' + db.id + '" data-index="' + list_index + '" data-detail="">' +
             '<td>' + list_index + '</td>' +
             '<td>' + db.code + '</td>' +
             '<td>' + db.name + '</td>' +
             '<td>' + db.unit + '</td>' +
             '<td>' + roundnum(db.unit_price, totalPriceUnit) + '</td>' +
-            '<td>' + roundnum(db.quantity, findDecimal(db.unit)) + '</td>' +
-            '<td>' + roundnum(parseFloat(db.unit_price).mul(parseFloat(db.quantity)), totalPriceUnit) + '</td>' +
+            '<td>' + roundnum(quantity, findDecimal(db.unit)) + '</td>' +
+            // '<td>' + roundnum(parseFloat(db.unit_price).mul(parseFloat(db.quantity)), totalPriceUnit) + '</td>' +
             '</tr>';
         list_index++;
     }
@@ -142,6 +144,30 @@ $(document).ready(() => {
         }
     });
 
+    // 保存修改ajax提交(不刷新页面)
+    $('#save_change').on('click', function () {
+        // 保存修改modal
+        $('#changeStatus').val(2);
+        // 获取auditlist并填入input中
+        getAuditList();
+        if ($('input[name="code"]').val() === '') {
+            toastr.error('申请编号不能为空!');
+            return;
+        }
+        if ($('input[name="name"]').val() === '') {
+            toastr.error('工程名称不能为空!');
+            return;
+        }
+        $('#change_form').ajaxSubmit(function (result) {
+            if ( result.err === 0) {
+                toastr.success(result.msg);
+            } else {
+                toastr.error(result.msg);
+            }
+        });
+        return false;
+    });
+
     // 审批人分组选择
     $('#account_group').change(function () {
         let account_html = '<option value="0">选择审批人</option>';
@@ -228,24 +254,27 @@ $(document).ready(() => {
     // 清单选中和移除
     $('body').on('click', '#table-list-select tr', function () {
         const isCheck = $(this).hasClass('table-success') ? true : false;
-        const detail = $(this).attr('data-detail');
+        const data_detail = $(this).attr('data-detail').split('$#$');
         const isDeal = $(this).data('gcl') !== undefined ? true : false;
-        let codeHtml = '<tr><td colspan="3">自行编辑变更详情</td><td><input type="checkbox"></td></tr>';
+        let codeHtml = '<tr quantity="0"><td colspan="3">自行编辑变更详情</td><td><input type="checkbox"></td></tr>';
         if (isDeal) {
             const gcl = gclGatherData[$(this).data('gcl')];
-            codeHtml = '<tr><td colspan="3">自行编辑变更详情</td><td><input type="checkbox" ';
-            codeHtml += detail == 0 && isCheck ? 'checked' : '';
+            codeHtml = '<tr quantity="0"><td colspan="3">自行编辑变更详情</td><td><input type="checkbox" ';
+            // 判断自行编辑变更详情是否已选中
+            codeHtml += data_detail.indexOf('0;0') !== -1 && isCheck ? 'checked' : '';
             codeHtml += '></td></tr>';
             for (const leaf of gcl.leafXmjs) {
-                const isChecked = detail == leaf.code + '_' + leaf.bwmx && isCheck ? 'checked' : '';
-                codeHtml += '<tr><td>' + leaf.code + '</td>' +
+                const quantity = leaf.quantity !== undefined ? leaf.quantity : 0;
+                const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
+                const isChecked = data_detail.indexOf(leaf.code + '_' + bwmx + ';' + quantity) !== -1 && isCheck ? 'checked' : '';
+                codeHtml += '<tr quantity="' + quantity + '"><td>' + leaf.code + '</td>' +
                     '<td>' + leaf.jldy + '</td>' +
-                    '<td>' + leaf.bwmx + '</td>' +
+                    '<td>' + bwmx + '</td>' +
                     '<td><input type="checkbox"' + isChecked +
-                    '></td></tr>'
+                    '></td></tr>';
             }
         } else if (!isDeal && isCheck) {
-            codeHtml = '<tr><td colspan="3">自行编辑变更详情</td><td><input type="checkbox" checked></td></tr>';
+            codeHtml = '<tr quantity="0"><td colspan="3">自行编辑变更详情</td><td><input type="checkbox" checked></td></tr>';
         }
         $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
         $('#code-list').html(codeHtml);
@@ -256,18 +285,41 @@ $(document).ready(() => {
         let index = $('#code-list').attr('data-index');
         if ($(this).is(':checked')) {
             // 去除其它可能已选的checked
-            $('#code-list input').prop('checked', false);
+            // $('#code-list input').prop('checked', false);
             $(this).prop('checked', true);
             // 左边表单传值并添加class
             $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
-            // 判断是否选择了自行编辑变更详情
-            const tr = $(this).parents('tr');
-            const length = tr.children('td').length;
-            const detail = length === 4 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
-            $('#table-list-select tr[data-index="' + index + '"]').attr('data-detail', detail);
+            // 去除部分data-detail值
+            let data_detail = [];
+            $('#code-list input:checked').each(function () {
+                const tr = $(this).parents('tr');
+                const length = tr.children('td').length;
+                const detail = length === 4 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
+                const quantity = tr.attr('quantity');
+                const de_qu = detail + ';' + quantity;
+                data_detail.push(de_qu);
+            });
+            data_detail = data_detail.join('$#$');
+            $('#table-list-select tr[data-index="' + index + '"]').attr('data-detail', data_detail);
         } else {
-            $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
-            $('#table-list-select tr[data-index="' + index + '"]').attr('data-detail', '');
+            // 判断还有无选中项目节编号
+            if ($('#code-list input').is(':checked')) {
+                // 去除部分data-detail值
+                let data_detail = [];
+                $('#code-list input:checked').each(function () {
+                    const tr = $(this).parents('tr');
+                    const length = tr.children('td').length;
+                    const detail = length === 4 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
+                    const quantity = tr.attr('quantity');
+                    const de_qu = detail + ';' + quantity;
+                    data_detail.push(de_qu);
+                });
+                data_detail = data_detail.join('$#$');
+                $('#table-list-select tr[data-index="' + index + '"]').attr('data-detail', data_detail);
+            } else {
+                $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
+                $('#table-list-select tr[data-index="' + index + '"]').attr('data-detail', '');
+            }
         }
     });
 
@@ -426,16 +478,22 @@ function maketablelist(status){
         let name = $(this).children('td').eq(2).text();
         let unit = $(this).children('td').eq(3).text();
         let price = $(this).children('td').eq(4).text();
-        let oamount = $(this).children('td').eq(5).text();
+        // let oamount = $(this).children('td').eq(5).text();
 
         // 根据单位获取数量的位数,并得出
         let numdecimal = findDecimal(unit);
 
         let scnum = makedecimalzero(numdecimal);
-        let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
+        // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
         let lid = $(this).data('lid');
-        let trlist = [code, name, unit, price, oamount, scnum, detail, lid];
-        radionList.push(trlist.join(';'));
+        // 原清单和数量改变
+        let data_detail = $(this).attr('data-detail').split('$#$');
+        for (const d of data_detail) {
+            const oamount = d.split(';')[1];
+            let detail = d.split(';')[0] != 0 ? d.split(';')[0].split('_')[1] : '';
+            let trlist = [code, name, unit, price, oamount, scnum, detail, lid];
+            radionList.push(trlist.join(';'));
+        }
     });
     // 排序
     radionList.sort();

Разница между файлами не показана из-за своего большого размера
+ 23 - 0
app/public/js/jquery/jquery.form.min.js


+ 3 - 2
app/view/change/info.ejs

@@ -136,13 +136,13 @@
             <!--info状态区分-->
             <% if (auditStatus === 1) { %>
             <div>
-                <a href="#sub-ap" data-category="save_change" data-toggle="modal" data-target="#sub-ap" class="btn btn-sm btn-success pull-right">保存修改</a>
+                <button class="btn btn-sm btn-success pull-right" id="save_change">保存修改</button>
                 <a href="#sub-ap" data-category="up_change" data-toggle="modal" data-target="#sub-ap" class="btn btn-primary btn-sm pull-right">上报审批</a>
                 <!--<a href="#" class="btn btn-outline-danger btn-sm pull-right text-truncate" style="max-width: 100px;" title="删除 <%- change.code %>">删除 <%- change.code %></a>-->
             </div>
             <% } else if (auditStatus === 2) { %>
             <div>
-                <a href="#sub-sp2" data-category="save_change" data-toggle="modal" data-target="#sub-sp2" class="btn btn-sm btn-success pull-right">保存修改</a>
+                <button class="btn btn-sm btn-success pull-right" id="save_change">保存修改</button>
                 <a href="#sub-sp2" data-category="up_change" data-toggle="modal" data-target="#sub-sp2" class="btn btn-primary btn-sm pull-right">重新上报</a>
                 <!--<a href="#" class="btn btn-outline-danger btn-sm pull-right text-truncate" style="max-width: 100px;" title="删除 <%- change.code %>">删除 <%- change.code %></a>-->
             </div>
@@ -758,6 +758,7 @@
 </script>
 <script src="/public/js/path_tree.js"></script>
 <script src="/public/js/gcl_gather.js"></script>
+<script src="/public/js/jquery/jquery.form.min.js"></script>
 <script src="/public/js/change_set.js"></script>
 <% } else if (auditStatus === 3 || auditStatus === 4 || auditStatus === 5 || auditStatus === 7) { %>
 <script>

+ 1 - 1
app/view/change/info_modal.ejs

@@ -108,7 +108,7 @@
                     <div class="col-7">
                         <div style="height:400px;overflow-y:auto">
                             <table class="table table-striped table-bordered table-condensed">
-                                <thead><tr><th>序号</th><th>清单编号</th><th>名称</th><th>单位</th><th>单价</th><th>数量</th><th>金额</th></tr></thead>
+                                <thead><tr><th>序号</th><th>清单编号</th><th>名称</th><th>单位</th><th>单价</th><th>数量</th></tr></thead>
                                 <tbody id="table-list-select">
                                 </tbody>
                             </table>