Forráskód Böngészése

变更令编辑变成即时保存

ellisran 2 hete
szülő
commit
2c691f291b
2 módosított fájl, 137 hozzáadás és 54 törlés
  1. 132 50
      app/public/js/change_information.js
  2. 5 4
      app/view/change/information.ejs

+ 132 - 50
app/public/js/change_information.js

@@ -5791,35 +5791,96 @@ $(document).ready(() => {
         $('.reduction-code').click(function () {
             const code = $(this).attr('data-code');
             $('input[name="code"]').val(code);
-            changeInfo.code = $('input[name="code"]').val();
-            judgeChange();
+            updateInfo('code', code);
         });
-        // 记录变更信息操作
-        $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
-            changeInfo[$(this).attr('name')] = $(this).val();
-            judgeChange();
+
+        // 回车提交
+        $('#change_form input[type="text"]').on('keypress', function () {
+            if(window.event.keyCode === 13) {
+                $(this).blur();
+            }
+        });
+        $('#change_form textarea').on('keypress', function () {
+            if(window.event.keyCode === 13) {
+                $(this).blur();
+            }
         });
-        $('body').on('valuechange', '#change_form textarea', function (e, previous) {
-            changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
-            judgeChange();
+        $('#change_form input[type="text"]').blur(function () {
+            let val_name = $(this).attr('name');
+            let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
+            switch(val_name) {
+                case 'code':
+                    if(!val) {
+                        toastr.error('申请编号不能为空!');
+                        $(this).val(change[val_name]);
+                        return false;
+                    }
+                    break;
+                default:
+                    if(val && val.length > 255) {
+                        toastr.error('超出字段范围,请缩减');
+                        $(this).val(change[val_name]);
+                        return false;
+                    }
+                    break;
+            }
+            updateInfo(val_name, val);
         });
-        $('body').on('change', '#change_form select', function (e, previous) {
-            changeInfo[$(this).attr('name')] = $(this).val();
-            judgeChange();
+
+        $('#change_form textarea').blur(function () {
+            const val_name = $(this).attr('name');
+            let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
+            updateInfo(val_name, val);
         });
-        $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
-            changeInfo[$(this).attr('name')] = $(this).val();
-            judgeChange();
+
+        $('#change_form select').change(function () {
+            const val_name = $(this).attr('name');
+            let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
+            updateInfo(val_name, val);
         });
-        $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
+
+        $('#change_form input[type="radio"]').change(function () {
+            const val_name = $(this).attr('name');
+            let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
+            updateInfo(val_name, val);
+        });
+
+        $('#change_form input[type="checkbox"]').click(function () {
             const typecheck = [];
             $.each($('#change_form input[name="type[]"]:checked'), function () {
                 typecheck.push($(this).val());
             });
-            changeInfo.type = typecheck.join(',');
-            judgeChange();
+            const val_name = 'type';
+            const val = typecheck.join(',');
+            updateInfo(val_name, val);
         });
 
+        // 记录变更信息操作
+        // $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
+        //     changeInfo[$(this).attr('name')] = $(this).val();
+        //     judgeChange();
+        // });
+        // $('body').on('valuechange', '#change_form textarea', function (e, previous) {
+        //     changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
+        //     judgeChange();
+        // });
+        // $('body').on('change', '#change_form select', function (e, previous) {
+        //     changeInfo[$(this).attr('name')] = $(this).val();
+        //     judgeChange();
+        // });
+        // $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
+        //     changeInfo[$(this).attr('name')] = $(this).val();
+        //     judgeChange();
+        // });
+        // $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
+        //     const typecheck = [];
+        //     $.each($('#change_form input[name="type[]"]:checked'), function () {
+        //         typecheck.push($(this).val());
+        //     });
+        //     changeInfo.type = typecheck.join(',');
+        //     judgeChange();
+        // });
+
         // 保存修改ajax提交(不刷新页面)
         $('.save_change_btn').on('click', function () {
             // 保存修改modal
@@ -6117,42 +6178,51 @@ $(document).ready(() => {
     });
 
     if (readOnly && !shenpiPower) {
-        // 记录变更信息操作
-        $('body').on('valuechange', '#w_code', function (e, previous) {
-            const new_w_code = $(this).val();
-            if (new_w_code !== w_code) {
-                $('#show-save-btn').show();
-                $('#sp-btn').hide();
-                $('.title-main').addClass('bg-warning');
-            } else {
-                $('#show-save-btn').hide();
-                $('#sp-btn').show();
-                $('.title-main').removeClass('bg-warning');
+        $('input[id="w_code"]').on('keypress', function () {
+            if(window.event.keyCode === 13) {
+                $(this).blur();
             }
         });
-
-        // 保存修改ajax提交(不刷新页面)
-        $('.save_change_btn').on('click', function () {
-            const new_w_code = $('#w_code').val();
-            // 后改为br
-            // 更新至服务器
-            postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {
-                toastr.success(result ? result.msg : '');
-                $('#show-save-btn').hide();
-                $('#sp-btn').show();
-                $('.title-main').removeClass('bg-warning');
-                w_code = new_w_code;
-            });
-            return false;
+        $('input[id="w_code"]').blur(function () {
+            updateInfo('w_code', $('#w_code').val());
         });
 
-        $('#cancel_change').on('click', function () {
-            $('#show-save-btn').hide();
-            $('#sp-btn').show();
-            $('.title-main').removeClass('bg-warning');
-            $('#w_code').val(w_code);
-            // toastr.success('已还原到上次保存状态');
-        });
+        // 记录变更信息操作
+        // $('body').on('valuechange', '#w_code', function (e, previous) {
+        //     const new_w_code = $(this).val();
+        //     if (new_w_code !== w_code) {
+        //         $('#show-save-btn').show();
+        //         $('#sp-btn').hide();
+        //         $('.title-main').addClass('bg-warning');
+        //     } else {
+        //         $('#show-save-btn').hide();
+        //         $('#sp-btn').show();
+        //         $('.title-main').removeClass('bg-warning');
+        //     }
+        // });
+        //
+        // // 保存修改ajax提交(不刷新页面)
+        // $('.save_change_btn').on('click', function () {
+        //     const new_w_code = $('#w_code').val();
+        //     // 后改为br
+        //     // 更新至服务器
+        //     postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {
+        //         toastr.success(result ? result.msg : '');
+        //         $('#show-save-btn').hide();
+        //         $('#sp-btn').show();
+        //         $('.title-main').removeClass('bg-warning');
+        //         w_code = new_w_code;
+        //     });
+        //     return false;
+        // });
+        //
+        // $('#cancel_change').on('click', function () {
+        //     $('#show-save-btn').hide();
+        //     $('#sp-btn').show();
+        //     $('.title-main').removeClass('bg-warning');
+        //     $('#w_code').val(w_code);
+        //     // toastr.success('已还原到上次保存状态');
+        // });
     }
 });
 /**
@@ -6456,6 +6526,18 @@ function makePushBwmx(clinfo, listinfo, removeList, updateList, showTips = false
     }
     return info;
 }
+
+function updateInfo(val_name, val) {
+    if(change[val_name] !== val) {
+        // 更新至服务器
+        const updateData = {};
+        updateData[val_name] = val;
+        postData(window.location.pathname + '/save', { type:'info', updateData }, function (result) {
+            change[val_name] = val;
+        });
+    }
+}
+
 function makeWhiteList(clinfo) {
     clinfo.lid = 0;
     clinfo.xmj_code = null;

+ 5 - 4
app/view/change/information.ejs

@@ -109,7 +109,7 @@
                     <div class="tab-pane active" id="bgxinxi">
                         <div class="sjs-sh-1" style="overflow-y: auto;">
                             <% if (!change.readOnly || change.shenpiPower) { %>
-                            <form class="p-2" action="/tender/<%- change.tid %>/change/<%- change.cid %>/information/save?_csrf_j=<%= ctx.csrf %>" method="post" id="change_form">
+                            <div class="p-2" id="change_form">
                                 <% if (ctx.subProject.page_show.openChangeState) { %>
                                 <div class="form-group">
                                     <label>变更状态</label>
@@ -235,9 +235,9 @@
                                     <label>批复文号</label>
                                     <input class="form-control form-control-sm" id="w_code" name="w_code"  placeholder="" type="text" value="<%- change.w_code %>">
                                 </div>
-                            </form>
+                            </div>
                             <% } else { %>
-                            <form class="p-2">
+                            <div class="p-2">
                                 <% if (ctx.subProject.page_show.openChangeState) { %>
                                 <div class="form-group">
                                     <label>变更状态</label>
@@ -358,7 +358,7 @@
                                     <label>批复文号</label>
                                     <input class="form-control form-control-sm" id="w_code" placeholder="" type="text" value="<%- change.w_code %>" <% if (!(change.shenpiPower || (change.status === auditConst.status.checked && (ctx.session.sessionUser.is_admin || ctx.helper._.findIndex(change.auditors, { uid: ctx.session.sessionUser.accountId }) !== -1)))) { %>readonly<% } %>>
                                 </div>
-                            </form>
+                            </div>
                             <% } %>
                         </div>
                     </div>
@@ -619,6 +619,7 @@
     changeUnits = _.map(changeUnits, 'unit');
     changeUnits.push('');
     let changeUsedData = JSON.parse(unescape('<%- escape(JSON.stringify(changeUsedData)) %>'));
+    const change = JSON.parse(unescape('<%- escape(JSON.stringify(change)) %>'));
 </script>
 <% if (!change.readOnly || change.shenpiPower) { %>
 <script>