Procházet zdrojové kódy

feat: 添加用户选中状态同步功能,优化用户管理体验

caipin před 5 dny
rodič
revize
53353aa859
1 změnil soubory, kde provedl 22 přidání a 5 odebrání
  1. 22 5
      app/view/tender/detail_modal.ejs

+ 22 - 5
app/view/tender/detail_modal.ejs

@@ -2314,7 +2314,7 @@
             });
 
             // 选中用户
-            $('body').on('click', '#tourist_dropdownMenu dl dd', function () {
+            $('body').on('click', '#tourist_dropdownMenu dl dd', function (e) {
                 const id = parseInt($(this).data('id'));
                 if (id) {
                     const user = _.find(accountList, function (item) {
@@ -2326,6 +2326,7 @@
                     }
                     if (_.includes(saIdList, id)) {
                         toastr.error('该用户已存在列表中,无需重复添加');
+                        e.stopPropagation();
                         return;
                     }
 
@@ -2354,6 +2355,13 @@
                             '                                    <td><a href="javascript:void(0);" data-remove="'+ user.id +'" data-id="' + data.id + '" class="text-danger remove-tourist-user">移除</a></td>\n' +
                             '                                </tr>';
                         $('#tourist-users').append(html);
+                        const userIdToAddMark = id;
+                        const $targetMarkSpan = $('#tourist_dropdownMenu dl dd[data-id="' + userIdToAddMark + '"] .selected-mark');
+                        if ($targetMarkSpan.length > 0) {
+                            $targetMarkSpan.css('display', ''); 
+                        } else {
+                            console.warn('Warning: Could not find the selected-mark span for user ID:', userIdToAddMark);
+                        }
                         // 外面显示游客数量
                         const num = $('#tourist-users tr').length;
                         if (!$('#tourist-num').hasClass('badge')) {
@@ -2363,11 +2371,13 @@
                         }
                     });
                 }
+                e.stopPropagation();
             });
 
             // 移除用户
             $('body').on('click', '#tourist-users .remove-tourist-user', function () {
                 const id = parseInt($(this).data('id'));
+                const removeId = parseInt($(this).data('remove'));
                 if (id) {
                     const prop = {
                         id,
@@ -2376,6 +2386,16 @@
                     const _self = $(this);
                     postData('/tender/' + cur_tenderid + '/tourist/audit/save', prop, function (data) {
                         _self.parents('tr').remove();
+
+                        const userIdToRemoveMark = removeId;
+                        console.log('Removing mark for user ID:', userIdToRemoveMark);
+                        const $targetMarkSpanToRemove = $('#tourist_dropdownMenu dl dd[data-id="' + userIdToRemoveMark + '"] .selected-mark');
+                        if ($targetMarkSpanToRemove.length > 0) {
+                            $targetMarkSpanToRemove.css('display', 'none');
+                        } else {
+                            console.warn('Warning: Could not find the selected-mark span for user ID:', userIdToRemoveMark, 'to hide.');
+                        }
+
                         // 外面显示游客数量
                         const num = $('#tourist-users tr').length;
                         if (num == 0) {
@@ -3282,8 +3302,6 @@
                     postData('/tender/' + cur_tenderid + '/schedule/audit/save', prop, function (data) {
                         _self.parents('tr').remove();
 
-                        // --- 在此处添加新增代码 ---
-                        // 同步下拉菜单勾选状态 (移除勾选)
                         const userIdToRemoveMark = removeId;
                         console.log('Removing mark for user ID:', userIdToRemoveMark);
                         const $targetMarkSpanToRemove = $('#xxjd_dropdownMenu dl dd[data-id="' + userIdToRemoveMark + '"] .selected-mark');
@@ -3292,8 +3310,7 @@
                         } else {
                             console.warn('Warning: Could not find the selected-mark span for user ID:', userIdToRemoveMark, 'to hide.');
                         }
-                        // --- 新增代码结束 ---
-
+                       
                     });
                 }
             });