Sfoglia il codice sorgente

fix: 调整合同管理数据update逻辑

lanjianrong 8 mesi fa
parent
commit
a0e7226ed8

+ 0 - 3
app/controller/contract_controller.js

@@ -375,9 +375,6 @@ module.exports = app => {
                     case 'update':
                         responseData.data = await ctx.service.contractTree.updateCalc(options, data.postData);
                         break;
-                    case 'update-contract':
-                        responseData.data = await ctx.service.contract.updateCalc(options, data.postData);
-                        break;
                     case 'paste-block':
                         responseData.data = await this._pasteBlock(ctx, data.postData, options);
                         break;

+ 4 - 2
app/public/js/contract_detail.js

@@ -615,8 +615,7 @@ $(document).ready(function() {
                     data[col.field] = null;
                 }
                 // 更新至服务器
-
-                postData(window.location.pathname + '/update', {postType: (node && node.c_code) ? 'update-contract' : 'update', postData: data}, function (result) {
+                postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
                     const refreshNode = contractTree.loadPostData(result);
                     contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
                 });
@@ -714,10 +713,13 @@ $(document).ready(function() {
         deletePress: function (sheet) {
             if (!sheet.zh_setting) return;
             const sel = sheet.getSelections()[0], datas = [];
+
             for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
                 let bDel = false;
                 const node = sheet.zh_tree.nodes[iRow];
                 const data = sheet.zh_tree.getNodeKeyData(node);
+                if (node.c_code) data['c_code'] = node.c_code;
+
                 for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
                     const col = sheet.zh_setting.cols[iCol];
                     const style = sheet.getStyle(iRow, iCol);

+ 18 - 1
app/service/contract_tree.js

@@ -184,23 +184,40 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 const updateDatas = [];
+                const updateContractDatas = [];
                 for (const row of datas) {
                     const updateNode = await this.getDataById(row.id);
                     if (!updateNode) {
+                        const contractNode = await this.ctx.service.contract.getDataById(row.id);
+                        if (contractNode) {
+                          const updateContractData = this._filterUpdateInvalidField(contractNode.id, row)
+                          updateContractDatas.push(updateContractData);
+                          continue;
+                        }
                         throw '提交数据错误';
                     }
                     const updateData = this._filterUpdateInvalidField(updateNode.id, row);
                     // 如非子节点,需要更新底下所有已选清单的分部分项等数据
                     updateDatas.push(updateData);
                 }
+
                 if (updateDatas.length > 0) await transaction.updateRows(this.tableName, updateDatas);
+                if (updateContractDatas.length > 0) await transaction.updateRows(this.ctx.service.contract.tableName, updateContractDatas);
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();
                 throw err;
             }
 
-            return { update: await this.getDataById(ids) };
+            return { update: await this.getDataByIds(ids) };
+        }
+
+        async getDataByIds(ids) {
+          const resultData = []
+          for (const id of ids) {
+            resultData.push(await this.getDataByCondition({ id }) || await this.ctx.service.contract.getDataByCondition({ id }));
+          }
+          return resultData;
         }
 
         async getDataByKid(options, kid) {

+ 16 - 5
app/view/contract/col_set.ejs

@@ -7,10 +7,10 @@
             </div>
             <div class="modal-body">
                 <table class="table table-hover table-bordered">
-                    <thead><tr><th width="150px">列名</th><th width="50px">显示</th><th width="150px">别名</th><th width="80px">操作</th></tr></thead>
+                    <thead><tr><th width="150px" class="text-center">列名</th><th width="50px" class="text-center">显示</th><th width="150px" class="text-center">别名</th><th width="80px" class="text-center">操作</th></tr></thead>
                     <tbody class="text-center">
                     <% for (const cs of colSet) { %>
-                      <tr code="<%- cs.field %>"> 
+                      <tr code="<%- cs.field %>">
                           <td>
                               <%- cs.name %>
                               <% if (cs.hint) { %>
@@ -61,6 +61,9 @@
 // 立即获取表格 tbody 并绑定事件(确保脚本加载时即可初始化)
 const $tbody = $('#col-set').find('.modal-body table tbody');
 
+// 保存初始 HTML,在关闭时恢复(保证再次打开时为初始状态)
+const _initialColSetTbodyHtml = $tbody.html();
+
 // 更新上下移链接显示状态
 function updateMoveButtons() {
     const $currentRows = $tbody.find('tr');
@@ -95,12 +98,20 @@ $('#col-set').on('shown.bs.modal', function() {
     updateMoveButtons();
 });
 
+// 模态框隐藏时恢复到初始内容并重新绑定必要状态
+$('#col-set').on('hidden.bs.modal', function() {
+    // 恢复初始 tbody 内容
+    $tbody.html(_initialColSetTbodyHtml);
+    // 重新计算按钮显示状态
+    updateMoveButtons();
+});
+
 // 事件委托:从一开始就绑定上/下移事件
 $tbody.on('click', '.move-up', function(e) {
     e.preventDefault();
     const $currentRow = $(this).closest('tr');
     const $prevRow = $currentRow.prev('tr');
-    
+
     if ($prevRow.length) {
         $currentRow.insertBefore($prevRow);
         updateMoveButtons();
@@ -111,7 +122,7 @@ $tbody.on('click', '.move-down', function(e) {
     e.preventDefault();
     const $currentRow = $(this).closest('tr');
     const $nextRow = $currentRow.next('tr');
-    
+
     if ($nextRow.length) {
         $currentRow.insertAfter($nextRow);
         updateMoveButtons();
@@ -144,4 +155,4 @@ function onSetCol() {
     $('input[name=col_set]').val(JSON.stringify(colSet));
     return true;
 }
-</script>
+</script>