5 Commits 656099771e ... 974df15168

Author SHA1 Message Date
  igb 974df15168 fleat: relationship 1 week ago
  igb b4476d0d41 fleat: relationship 1 week ago
  igb 7914110c1e fleat: relationship 1 week ago
  igb c12d216859 fleat: relationship 1 week ago
  igb 8c79936fb7 fleat: update function 1 week ago
10 changed files with 1448 additions and 108 deletions
  1. 52 0
      conn.php
  2. 0 8
      customers.php
  3. 2 2
      get_customer_search.php
  4. 1 6
      order.php
  5. 124 27
      order_add.php
  6. 162 65
      order_edit.php
  7. 1 0
      panel.php
  8. 434 0
      relationshipAdd.php
  9. 175 0
      relationshipSave.php
  10. 497 0
      relationships.php

+ 52 - 0
conn.php

@@ -90,6 +90,29 @@ function getIp() {
     return htmlspecialcharsFix($ip);
 }
 
+// 记录操作日志
+function logAction($action) {
+    global $conn;
+    
+    // 从SESSION获取当前用户名
+    $loginName = $_SESSION['employee_name'] ?? 'Unknown User';
+    
+    // 获取当前IP
+    $loginIp = getIp();
+    
+    // 当前时间
+    $loginTime = date('Y-m-d H:i:s');
+    
+    // 记录到日志表
+    $stmt = "INSERT INTO logrecord (loginName, loginIp, loginTime, loginAct) VALUES (
+            '" . mysqli_real_escape_string($conn, $loginName) . "', 
+            '" . mysqli_real_escape_string($conn, $loginIp) . "', 
+            '$loginTime', 
+            '" . mysqli_real_escape_string($conn, $action) . "')";
+    
+    $conn->query($stmt);
+}
+
 // 移除HTML
 function removeHTML($t0) {
     if (empty($t0)) {
@@ -364,9 +387,38 @@ function sitelink_replace($t0, $t1, $t2, $t3) {
     return $t4;
 }
 
+
+if(!function_exists('htmlspecialcharsFix')) {
 //处理特殊字符
 function htmlspecialcharsFix($input_str)
 {
     return $input_str;
 }
+}
+
+if(!function_exists('htmlspecialcharsAjaxFix')) {
+//处理特殊字符
+    function htmlspecialcharsAjaxFix($input_str)
+    {
+
+        return textUncode($input_str);
+    }
+}
+
+
+if(!function_exists('textDecode')) {
+    function textDecode($str) {
+        return textUncode($str);
+    }
+}
+
+
+if(!function_exists('htmlDecode')) {
+    function htmlDecode($str) {
+        return htmlspecialchars_decode($str, ENT_QUOTES);
+    }
+
+}
+
+
 

+ 0 - 8
customers.php

@@ -5,16 +5,8 @@ checkLogin();
 // 辅助函数
 
 
-function textDecode($str) {
-    return htmlspecialchars_decode($str, ENT_QUOTES);
-}
-
 
 
-function htmlDecode($str) {
-    return htmlspecialchars_decode($str, ENT_QUOTES);
-}
-
 $act = $_GET['act'] ?? '';
 $urlStr = '';
 

+ 2 - 2
get_customer_search.php

@@ -23,8 +23,8 @@ if (isset($_GET['search'])) {
     while ($row = mysqli_fetch_assoc($result)) {
         $customers[] = [
             'id' => $row['id'],
-            'cs_company' => htmlspecialcharsFix($row['cs_company']),
-            'cs_code' => htmlspecialcharsFix($row['cs_code'])
+            'cs_company' => htmlspecialcharsAjaxFix($row['cs_company']),
+            'cs_code' => htmlspecialcharsAjaxFix($row['cs_code'])
         ];
     }
     

+ 1 - 6
order.php

@@ -3,13 +3,8 @@ require_once 'conn.php';
 checkLogin();
 
 // 辅助函数
-function textDecode($str) {
-    return htmlspecialchars_decode($str, ENT_QUOTES);
-}
 
-function htmlDecode($str) {
-    return htmlspecialchars_decode($str, ENT_QUOTES);
-}
+
 
 $act = $_GET['act'] ?? '';
 $urlStr = '';

+ 124 - 27
order_add.php

@@ -242,6 +242,69 @@ if ($customerId > 0) {
             color: #d9534f;
         }
         /* 产品行样式优化 - 单行布局 */
+        
+        /* 客户选择样式 */
+        .customer-search-container {
+            display: flex;
+            align-items: center;
+            margin-bottom: 10px;
+            position: relative;
+            width: 60%;
+        }
+        .customer-dropdown {
+            display: none;
+            position: absolute;
+            background: white;
+            border: 1px solid #ccc;
+            max-height: 200px;
+            overflow-y: auto;
+            width: 100%;
+            z-index: 1000;
+            box-shadow: 0 3px 8px rgba(0,0,0,0.25);
+            border-radius: 0 0 4px 4px;
+            top: 100%;
+            left: 0;
+        }
+        .customer-item {
+            padding: 10px 12px;
+            cursor: pointer;
+            border-bottom: 1px solid #eee;
+            transition: background-color 0.2s;
+        }
+        .customer-item:hover {
+            background-color: #f0f0f0;
+        }
+        .customer-item:last-child {
+            border-bottom: none;
+        }
+        .selected-customer-info {
+            font-weight: bold;
+            padding: 8px 10px;
+            border: 1px solid #ddd;
+            background-color: #f9f9f9;
+            display: none;
+            width: 100%;
+            box-sizing: border-box;
+            word-break: break-all;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: normal;
+            min-height: 38px;
+            cursor: pointer;
+        }
+        .selected-customer-info:hover {
+            background-color: #f0f0f0;
+        }
+        .customer-clear-btn {
+            margin-left: 5px;
+            color: #e74c3c;
+            font-weight: bold;
+            cursor: pointer;
+            float: right;
+        }
+        .customer-clear-btn:hover {
+            color: #c0392b;
+        }
     </style>
 </head>
 <body>
@@ -258,24 +321,23 @@ if ($customerId > 0) {
                 <td>
                     <?php if ($customerInfo): ?>
                     <!-- 已有客户ID,只显示客户信息 -->
-                    <div style="display: inline-block; width: 60%;">
+                    <div class="customer-search-container">
                         <input type="hidden" name="customer_id" id="customer_id" value="<?= $customerId ?>">
                         <!-- 联系人字段设为空 -->
                         <input type="hidden" name="contact_id" id="contact_id" value="">
-                        <div class="selected-customer-info" style="font-weight: bold; padding: 8px 0; border: 1px solid #ddd; background-color: #f9f9f9; padding-left: 10px;">
+                        <div class="selected-customer-info" style="display: block;" title="<?= htmlspecialcharsFix($customerInfo['cs_code'] . ' - ' . $customerInfo['cs_company']) ?>">
                             <?= htmlspecialcharsFix($customerInfo['cs_code'] . ' - ' . $customerInfo['cs_company']) ?>
+                            <span class="customer-clear-btn" data-type="customer" style="display: none;">X</span>
                         </div>
                     </div>
                     <?php else: ?>
                     <!-- 无客户ID,显示搜索框 -->
-                    <div style="display: inline-block; width: 60%;" class="customerinput">
-                        <input type="text" class="customer-search fastsearch" placeholder="输入客户名称搜索..." style="width: 100%;">
-                        <div class="customerlist" style="display: none; position: absolute; background: white; border: 1px solid #ccc; max-height: 200px; overflow-y: auto; width: 100%; z-index: 1000; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
-                            <ul style="list-style: none; padding: 0; margin: 0;"></ul>
-                        </div>
+                    <div class="customer-search-container">
+                        <input type="text" id="customer_search" class="customer-search txt1" data-type="customer" placeholder="输入客户编码或名称搜索..." style="width: 100%;">
+                        <div id="customer_dropdown" class="customer-dropdown"></div>
+                        <div id="customer_selected" class="selected-customer-info" title=""></div>
                         <input type="hidden" name="customer_id" id="customer_id" value="0">
                         <input type="hidden" name="contact_id" id="contact_id" value="">
-                        <div class="selected-customer-info" style="margin-top: 5px; font-weight: bold;"></div>
                     </div>
                     <?php endif; ?>
                 </td>
@@ -382,21 +444,26 @@ if ($customerId > 0) {
                 $(this).trigger('input'); // 手动触发一次input事件
             });
             
-            $(document).on('input', '.customer-search', function() {
+            // 客户搜索输入处理
+            $(document).on('input', '#customer_search', function() {
                 // 如果是输入法正在组合中文,不处理
                 if (customerIsComposing) return;
                 
                 var $this = $(this);
                 var searchTerm = $this.val().trim();
-                var customerList = $('.customerlist');
+                var customerDropdown = $('#customer_dropdown');
                 
                 // 清除之前的超时
                 clearTimeout(customerSearchTimeout);
                 
                 // 隐藏之前的结果
-                customerList.hide();
+                customerDropdown.hide().empty();
                 
-                // 如果搜索词少于2个字符,不执行搜索
+                // 清除之前的选择
+                $('#customer_id').val('0');
+                $('#customer_selected').hide();
+                
+                // 如果搜索词少于1个字符,不执行搜索
                 if (searchTerm.length < 1) {
                     return;
                 }
@@ -409,8 +476,7 @@ if ($customerId > 0) {
                         data: {search: searchTerm},
                         dataType: 'json',
                         success: function(data) {
-                            var ul = customerList.find('ul');
-                            ul.empty();
+                            customerDropdown.empty();
                             
                             if (data && data.customers && data.customers.length > 0) {
                                 $.each(data.customers, function(i, customer) {
@@ -418,10 +484,16 @@ if ($customerId > 0) {
                                     if (customer.cs_code) {
                                         displayText = customer.cs_code + ' - ' + displayText;
                                     }
-                                    ul.append('<li data-id="' + customer.id + '" data-code="' + (customer.cs_code || '') + '">' + 
-                                              displayText + '</li>');
+                                    
+                                    var item = $('<div class="customer-item"></div>')
+                                        .attr('data-id', customer.id)
+                                        .attr('data-company', customer.cs_company)
+                                        .attr('data-display', displayText)
+                                        .text(displayText);
+                                    
+                                    customerDropdown.append(item);
                                 });
-                                customerList.show();
+                                customerDropdown.show();
                             }
                         },
                         error: function() {
@@ -432,22 +504,47 @@ if ($customerId > 0) {
             });
             
             // 点击选择客户
-            $(document).on('click', '.customerlist li', function() {
+            $(document).on('click', '.customer-item', function() {
                 var $this = $(this);
                 var customerId = $this.data('id');
-                var customerName = $this.text();
-                var customerCode = $this.data('code') || '';
+                var customerName = $this.data('company');
+                var displayText = $this.data('display');
                 
                 // 设置选中的客户ID和名称
                 $('#customer_id').val(customerId);
-                $('.customer-search').val(customerName);
-                $('.selected-customer-info').text(customerName);
-                $('.customerlist').hide();
+                $('#customer_search').hide();
+                $('#customer_selected').text(displayText).append('<span class="customer-clear-btn" data-type="customer">X</span>').show();
+                
+                // 添加标题属性,便于查看完整信息
+                $('#customer_selected').attr('title', displayText);
+                
+                // 隐藏下拉菜单
+                $('#customer_dropdown').hide();
                 
                 // 加载客户联系人
                 loadCustomerContacts(customerId);
             });
-
+            
+            // 点击X按钮清除选择的客户
+            $(document).on('click', '.customer-clear-btn', function(e) {
+                e.stopPropagation();
+                
+                // 显示搜索框,隐藏已选信息
+                $('#customer_search').val('').show();
+                $('#customer_selected').hide();
+                
+                // 清空客户ID和联系人ID
+                $('#customer_id').val('0');
+                $('#contact_id').val('');
+            });
+            
+            // 点击其他地方隐藏下拉列表
+            $(document).on('click', function(e) {
+                if (!$(e.target).closest('.customer-search-container').length) {
+                    $('#customer_dropdown').hide();
+                }
+            });
+            
             // 产品搜索框聚焦时显示搜索提示
             $(document).on('focus', '.product-search', function() {
                 // 隐藏所有已打开的产品搜索列表
@@ -865,7 +962,7 @@ if ($customerId > 0) {
         function validateOrderForm() {
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
-            var customerName = $('.customer-search').val();
+            var customerName = $('#customer_search').val();
             var hasProducts = false;
             var allSpecsSelected = true;
             var allPricesValid = true;
@@ -932,14 +1029,14 @@ if ($customerId > 0) {
 
             if (!customerId || customerId == '0') {
                 alert('请选择客户');
-                $('.customer-search').focus();
+                $('#customer_search').focus();
                 return false;
             }
             
             // 只有当客户ID为0时才检查客户名称
             if (customerId == '0' && !customerName) {
                 alert('请输入并选择有效的客户');
-                $('.customer-search').focus();
+                $('#customer_search').focus();
                 return false;
             }
             

+ 162 - 65
order_edit.php

@@ -260,6 +260,69 @@ if (!empty($id) && is_numeric($id)) {
             font-weight: bold;
             color: #d9534f;
         }
+        
+        /* 客户选择样式 */
+        .customer-search-container {
+            display: flex;
+            align-items: center;
+            margin-bottom: 10px;
+            position: relative;
+            width: 60%;
+        }
+        .customer-dropdown {
+            display: none;
+            position: absolute;
+            background: white;
+            border: 1px solid #ccc;
+            max-height: 200px;
+            overflow-y: auto;
+            width: 100%;
+            z-index: 1000;
+            box-shadow: 0 3px 8px rgba(0,0,0,0.25);
+            border-radius: 0 0 4px 4px;
+            top: 100%;
+            left: 0;
+        }
+        .customer-item {
+            padding: 10px 12px;
+            cursor: pointer;
+            border-bottom: 1px solid #eee;
+            transition: background-color 0.2s;
+        }
+        .customer-item:hover {
+            background-color: #f0f0f0;
+        }
+        .customer-item:last-child {
+            border-bottom: none;
+        }
+        .selected-customer-info {
+            font-weight: bold;
+            padding: 8px 10px;
+            border: 1px solid #ddd;
+            background-color: #f9f9f9;
+            display: none;
+            width: 100%;
+            box-sizing: border-box;
+            word-break: break-all;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: normal;
+            min-height: 38px;
+            cursor: pointer;
+        }
+        .selected-customer-info:hover {
+            background-color: #f0f0f0;
+        }
+        .customer-clear-btn {
+            margin-left: 5px;
+            color: #e74c3c;
+            font-weight: bold;
+            cursor: pointer;
+            float: right;
+        }
+        .customer-clear-btn:hover {
+            color: #c0392b;
+        }
     </style>
 </head>
 <body>
@@ -277,16 +340,14 @@ if (!empty($id) && is_numeric($id)) {
             <tr>
                 <th width="8%">客户选择</th>
                 <td>
-                    <div style="display: flex; width: 60%; position: relative; align-items: center;" class="customerinput">
-                        <div style="flex: 1; position: relative;">
-                            <input type="text" class="customer-search fastsearch" placeholder="输入客户编码或名称搜索..." style="width: 100%;" value="<?= htmlspecialcharsFix(isset($order['cs_code']) && $order['cs_code'] ? $order['cs_code'] . ' - ' . $order['cs_company'] : $order['cs_company']) ?>">
-                            <div class="customerlist" style="display: none; position: absolute; background: white; border: 1px solid #ccc; max-height: 200px; overflow-y: auto; width: 100%; z-index: 1000; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
-                                <ul style="list-style: none; padding: 0; margin: 0;"></ul>
-                            </div>
-                            <input type="hidden" name="customer_id" id="customer_id" value="<?= $order['customer_id'] ?>">
-                            <div class="selected-customer-info" style="margin-top: 5px; font-weight: bold;"></div>
+                    <div class="customer-search-container">
+                        <input type="text" id="customer_search" class="customer-search txt1" data-type="customer" placeholder="输入客户编码或名称搜索..." style="width: 100%;" value="<?= htmlspecialcharsFix(isset($order['cs_code']) && $order['cs_code'] ? $order['cs_code'] . ' - ' . $order['cs_company'] : $order['cs_company']) ?>">
+                        <div id="customer_dropdown" class="customer-dropdown"></div>
+                        <div id="customer_selected" class="selected-customer-info" style="display: block;" title="<?= htmlspecialcharsFix(isset($order['cs_code']) && $order['cs_code'] ? $order['cs_code'] . ' - ' . $order['cs_company'] : $order['cs_company']) ?>">
+                            <?= htmlspecialcharsFix(isset($order['cs_code']) && $order['cs_code'] ? $order['cs_code'] . ' - ' . $order['cs_company'] : $order['cs_company']) ?>
+                            <span class="customer-clear-btn" data-type="customer">X</span>
                         </div>
-                        <span class="delete-customer" style="margin-left: 10px; color: #e74c3c; font-weight: bold; font-size: 18px; cursor: pointer; width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 50%;">×</span>
+                        <input type="hidden" name="customer_id" id="customer_id" value="<?= $order['customer_id'] ?>">
                     </div>
                 </td>
             </tr>
@@ -428,58 +489,44 @@ if (!empty($id) && is_numeric($id)) {
                 }
             });
             
-            // 添加客户删除按钮事件
-            $('.delete-customer').on('click', function() {
-                // if(confirm('确定要清除当前选择的客户吗?')) {
-                    // 清空客户ID和客户名称
-                    $('#customer_id').val('');
-                    $('.customer-search').val('').focus();
-                    $('.selected-customer-info').text('');
-                // }
-            });
+            // 隐藏搜索框,因为已经选择了客户
+            $('#customer_search').hide();
             
-            // 添加样式到客户删除按钮
-            $('.delete-customer').hover(
-                function() { $(this).css('background-color', '#e74c3c').css('color', 'white'); },
-                function() { $(this).css('background-color', '').css('color', '#e74c3c'); }
-            );
-            
-            // 添加产品行按钮点击事件
-            $('#add-product-btn').on('click', function() {
-                addEmptyProductRow();
-                updateNoProductsMessage();
-            });
+            // 客户搜索功能
+            var customerSearchTimeout = null;
+            var customerIsComposing = false;
             
-            // 删除产品行
-            $(document).on('click', '.delete-product', function() {
-                if ($('.product-row').length > 1) {
-                    $(this).closest('.product-row').remove();
-                    reindexProductRows();
-                    calculateOrderTotal();
-                    updateNoProductsMessage();
-                } else {
-                    // 如果只剩最后一个产品行,则清空它而不是删除
-                    $(this).closest('.product-row').remove();
-                    updateNoProductsMessage();
-                    calculateOrderTotal(); // 确保在删除最后一个产品时也更新总额
-                }
+            // 监听输入法组合事件
+            $(document).on('compositionstart', '.customer-search', function() {
+                customerIsComposing = true;
             });
 
-            // 客户搜索功能
-            var customerSearchTimeout = null;
-            $(document).on('keyup', '.customer-search', function() {
+            $(document).on('compositionend', '.customer-search', function() {
+                customerIsComposing = false;
+                $(this).trigger('input'); // 手动触发一次input事件
+            });
+            
+            // 客户搜索输入处理
+            $(document).on('input', '#customer_search', function() {
+                // 如果是输入法正在组合中文,不处理
+                if (customerIsComposing) return;
+                
                 var $this = $(this);
                 var searchTerm = $this.val().trim();
-                var customerList = $('.customerlist');
+                var customerDropdown = $('#customer_dropdown');
                 
                 // 清除之前的超时
                 clearTimeout(customerSearchTimeout);
                 
                 // 隐藏之前的结果
-                customerList.hide();
+                customerDropdown.hide().empty();
                 
-                // 如果搜索词少于2个字符,不执行搜索
-                if (searchTerm.length < 2) {
+                // 清除之前的选择
+                $('#customer_id').val('0');
+                $('#customer_selected').hide();
+                
+                // 如果搜索词少于1个字符,不执行搜索
+                if (searchTerm.length < 1) {
                     return;
                 }
                 
@@ -491,8 +538,7 @@ if (!empty($id) && is_numeric($id)) {
                         data: {search: searchTerm},
                         dataType: 'json',
                         success: function(data) {
-                            var ul = customerList.find('ul');
-                            ul.empty();
+                            customerDropdown.empty();
                             
                             if (data && data.customers && data.customers.length > 0) {
                                 $.each(data.customers, function(i, customer) {
@@ -500,10 +546,16 @@ if (!empty($id) && is_numeric($id)) {
                                     if (customer.cs_code) {
                                         displayText = customer.cs_code + ' - ' + displayText;
                                     }
-                                    ul.append('<li data-id="' + customer.id + '" data-code="' + (customer.cs_code || '') + '">' + 
-                                              displayText + '</li>');
+                                    
+                                    var item = $('<div class="customer-item"></div>')
+                                        .attr('data-id', customer.id)
+                                        .attr('data-company', customer.cs_company)
+                                        .attr('data-display', displayText)
+                                        .text(displayText);
+                                    
+                                    customerDropdown.append(item);
                                 });
-                                customerList.show();
+                                customerDropdown.show();
                             }
                         },
                         error: function() {
@@ -514,17 +566,62 @@ if (!empty($id) && is_numeric($id)) {
             });
             
             // 点击选择客户
-            $(document).on('click', '.customerlist li', function() {
+            $(document).on('click', '.customer-item', function() {
                 var $this = $(this);
                 var customerId = $this.data('id');
-                var customerName = $this.text();
-                var customerCode = $this.data('code') || '';
+                var customerName = $this.data('company');
+                var displayText = $this.data('display');
                 
                 // 设置选中的客户ID和名称
                 $('#customer_id').val(customerId);
-                $('.customer-search').val(customerName);
-                $('.selected-customer-info').text(customerName);
-                $('.customerlist').hide();
+                $('#customer_search').hide();
+                $('#customer_selected').text(displayText).append('<span class="customer-clear-btn" data-type="customer">X</span>').show();
+                
+                // 添加标题属性,便于查看完整信息
+                $('#customer_selected').attr('title', displayText);
+                
+                // 隐藏下拉菜单
+                $('#customer_dropdown').hide();
+            });
+            
+            // 点击X按钮清除选择的客户
+            $(document).on('click', '.customer-clear-btn', function(e) {
+                e.stopPropagation();
+                
+                // 显示搜索框,隐藏已选信息
+                $('#customer_search').val('').show();
+                $('#customer_selected').hide();
+                
+                // 清空客户ID
+                $('#customer_id').val('0');
+            });
+            
+            // 点击其他地方隐藏下拉列表
+            $(document).on('click', function(e) {
+                if (!$(e.target).closest('.customer-search-container').length) {
+                    $('#customer_dropdown').hide();
+                }
+            });
+            
+            // 添加产品行按钮点击事件
+            $('#add-product-btn').on('click', function() {
+                addEmptyProductRow();
+                updateNoProductsMessage();
+            });
+            
+            // 删除产品行
+            $(document).on('click', '.delete-product', function() {
+                if ($('.product-row').length > 1) {
+                    $(this).closest('.product-row').remove();
+                    reindexProductRows();
+                    calculateOrderTotal();
+                    updateNoProductsMessage();
+                } else {
+                    // 如果只剩最后一个产品行,则清空它而不是删除
+                    $(this).closest('.product-row').remove();
+                    updateNoProductsMessage();
+                    calculateOrderTotal(); // 确保在删除最后一个产品时也更新总额
+                }
             });
 
             // 产品搜索框聚焦时显示搜索提示
@@ -685,8 +782,8 @@ if (!empty($id) && is_numeric($id)) {
                 if (!$(e.target).closest('.product-search').length && !$(e.target).closest('.productlist').length) {
                     $('.productlist').hide();
                 }
-                if (!$(e.target).closest('.customerinput').length) {
-                    $('.customerlist').hide();
+                if (!$(e.target).closest('.customer-search-container').length) {
+                    $('#customer_dropdown').hide();
                 }
             });
             
@@ -1004,7 +1101,7 @@ if (!empty($id) && is_numeric($id)) {
         function validateOrderForm() {
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
-            var customerName = $('.customer-search').val();
+            var customerName = $('#customer_search').val() || $('#customer_selected').text().trim();
             var hasProducts = false;
             var allSpecsSelected = true;
             var allPricesValid = true;
@@ -1071,13 +1168,13 @@ if (!empty($id) && is_numeric($id)) {
 
             if (!customerId || customerId == '0') {
                 alert('请选择客户');
-                $('.customer-search').focus();
+                $('#customer_search').focus();
                 return false;
             }
 
             if (!customerName) {
                 alert('客户名称不能为空');
-                $('.customer-search').focus();
+                $('#customer_search').focus();
                 return false;
             }
             

+ 1 - 0
panel.php

@@ -43,6 +43,7 @@ $stmt->close();
                 <dt><a href="../home.php" target="contentFrame">客户查找</a></dt>
             <?php endif; ?>
             <dt><a href="../customerAdd.php" target="contentFrame">客户录入</a></dt>
+            <dt><a href="relationships.php" target="contentFrame">客户关系</a></dt>
             <dt><a href="../order.php" target="contentFrame">订单管理</a></dt>
             <dt id="myCustomer" class="subnav">我的客户
                 <div class="list-wraper">

+ 434 - 0
relationshipAdd.php

@@ -0,0 +1,434 @@
+<?php
+require_once 'conn.php';
+checkLogin();
+
+// 检查是否为编辑模式
+$isEdit = false;
+$relationshipData = null;
+
+if (isset($_GET['id']) && is_numeric($_GET['id'])) {
+    $id = intval($_GET['id']);
+    $query = "SELECT * FROM customer_relationship WHERE id = ?";
+    $stmt = $conn->prepare($query);
+    $stmt->bind_param('i', $id);
+    $stmt->execute();
+    $result = $stmt->get_result();
+    
+    if ($result->num_rows > 0) {
+        $relationshipData = $result->fetch_assoc();
+        $isEdit = true;
+    } else {
+        echo "<script>alert('未找到指定的客户关系记录!'); window.location.href='relationships.php';</script>";
+        exit;
+    }
+}
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <title><?= $isEdit ? '编辑' : '新增' ?>客户关系</title>
+    <link rel="stylesheet" href="css/common.css" type="text/css" />
+    <script src="js/jquery-1.7.2.min.js"></script>
+    <script src="js/js.js"></script>
+    <script src="js/ySearchSelect.js"></script>
+    <style>
+        body {
+            margin: a;
+            padding: 20px;
+            background: #fff;
+        }
+        #man_zone {
+            margin-left: 0;
+        }
+        .relationship-form-container {
+            margin-bottom: 20px;
+        }
+        .customer-search-container {
+            display: flex;
+            align-items: center;
+            margin-bottom: 10px;
+            position: relative;
+            width: 60%;
+        }
+        .customer-info {
+            margin-top: 5px;
+            padding: 5px;
+            background-color: #f5f5f5;
+            border: 1px solid #ddd;
+            border-radius: 3px;
+            display: none;
+        }
+        .customer-dropdown {
+            display: none;
+            position: absolute;
+            background: white;
+            border: 1px solid #ccc;
+            max-height: 200px;
+            overflow-y: auto;
+            width: 100%;
+            z-index: 1000;
+            box-shadow: 0 3px 8px rgba(0,0,0,0.25);
+            border-radius: 0 0 4px 4px;
+            top: 100%;
+            left: 0;
+        }
+        .customer-item {
+            padding: 10px 12px;
+            cursor: pointer;
+            border-bottom: 1px solid #eee;
+            transition: background-color 0.2s;
+        }
+        .customer-item:hover {
+            background-color: #f0f0f0;
+        }
+        .customer-item:last-child {
+            border-bottom: none;
+        }
+        .selected-customer-info {
+            font-weight: bold;
+            padding: 8px 10px;
+            border: 1px solid #ddd;
+            background-color: #f9f9f9;
+            display: none;
+            width: 100%;
+            box-sizing: border-box;
+            word-break: break-all;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: normal;
+            min-height: 38px;
+            cursor: pointer;
+        }
+        .selected-customer-info:hover {
+            background-color: #f0f0f0;
+        }
+        .customer-clear-btn {
+            margin-left: 5px;
+            color: #e74c3c;
+            font-weight: bold;
+            cursor: pointer;
+            float: right;
+        }
+        .customer-clear-btn:hover {
+            color: #c0392b;
+        }
+    </style>
+    <script>
+        $(document).ready(function() {
+            // 处理表单提交前的验证
+            $('#save').click(function() {
+                if (validateForm()) {
+                    $('#form1').submit();
+                }
+            });
+            
+            // 客户搜索功能
+            var customerSearchTimeouts = {
+                source: null,
+                target: null
+            };
+            var customerIsComposing = false;
+            
+            // 监听输入法组合事件
+            $(document).on('compositionstart', '.customer-search', function() {
+                customerIsComposing = true;
+            });
+
+            $(document).on('compositionend', '.customer-search', function() {
+                customerIsComposing = false;
+                $(this).trigger('input'); // 手动触发一次input事件
+            });
+            
+            // 客户搜索输入
+            $(document).on('input', '.customer-search', function() {
+                // 如果是输入法正在组合中文,不处理
+                if (customerIsComposing) return;
+                
+                var $this = $(this);
+                var searchType = $this.data('type'); // source 或 target
+                var searchTerm = $this.val().trim();
+                var customerDropdown = $('#' + searchType + '_customer_dropdown');
+                
+                // 清除之前的超时
+                clearTimeout(customerSearchTimeouts[searchType]);
+                
+                // 隐藏之前的结果
+                customerDropdown.hide();
+                
+                // 清除之前的选择
+                $('#' + searchType + '_customer_id').val('');
+                $('#' + searchType + '_customer_selected').hide();
+                
+                // 如果搜索词少于1个字符,不执行搜索
+                if (searchTerm.length < 1) {
+                    return;
+                }
+                
+                // 设置一个300毫秒的超时,以减少请求数量
+                customerSearchTimeouts[searchType] = setTimeout(function() {
+                    $.ajax({
+                        url: 'get_customer_search.php',
+                        type: 'GET',
+                        data: {search: searchTerm},
+                        dataType: 'json',
+                        success: function(data) {
+                            customerDropdown.empty();
+                            
+                            if (data && data.customers && data.customers.length > 0) {
+                                $.each(data.customers, function(i, customer) {
+                                    var displayText = customer.cs_company;
+                                    if (customer.cs_code) {
+                                        displayText = customer.cs_code + ' - ' + displayText;
+                                    }
+                                    
+                                    var item = $('<div class="customer-item"></div>')
+                                        .attr('data-id', customer.id)
+                                        .attr('data-company', customer.cs_company)
+                                        .attr('data-display', displayText)
+                                        .text(displayText);
+                                    
+                                    customerDropdown.append(item);
+                                });
+                                customerDropdown.show();
+                            }
+                        },
+                        error: function() {
+                            console.log('搜索客户失败,请重试');
+                        }
+                    });
+                }, 300);
+            });
+            
+            // 点击选择客户
+            $(document).on('click', '.customer-item', function() {
+                var $this = $(this);
+                var customerId = $this.data('id');
+                var customerName = $this.data('company');
+                var displayText = $this.data('display');
+                var parentContainer = $this.parent();
+                var searchType = parentContainer.attr('id').replace('_customer_dropdown', '');
+                
+                // 设置选中的客户ID和名称
+                $('#' + searchType + '_customer_id').val(customerId);
+                $('#' + searchType + '_customer_search').hide();
+                $('#' + searchType + '_customer_selected').text(displayText).append('<span class="customer-clear-btn" data-type="' + searchType + '">X</span>').show();
+                $('#' + searchType + '_customer_company').val(customerName);
+                
+                // 添加标题属性,便于查看完整信息
+                $('#' + searchType + '_customer_selected').attr('title', displayText);
+                
+                // 隐藏下拉菜单
+                parentContainer.hide();
+            });
+            
+            // 点击已选客户可以重新选择
+            $(document).on('click', '.selected-customer-info', function() {
+                // 点击整个已选区域不再执行任何操作
+            });
+            
+            // 点击X按钮清除选择的客户
+            $(document).on('click', '.customer-clear-btn', function(e) {
+                e.stopPropagation();
+                var searchType = $(this).data('type');
+                
+                // 显示搜索框,隐藏已选信息
+                $('#' + searchType + '_customer_search').val('').show();
+                $('#' + searchType + '_customer_selected').hide();
+                
+                // 清空客户ID
+                $('#' + searchType + '_customer_id').val('');
+            });
+            
+            // 点击其他地方隐藏下拉列表
+            $(document).on('click', function(e) {
+                if (!$(e.target).closest('.customer-search-container').length) {
+                    $('.customer-dropdown').hide();
+                }
+            });
+            
+            // 如果编辑模式下已有选中客户,显示客户信息
+            <?php if ($isEdit): ?>
+            $('#source_customer_selected').show();
+            $('#target_customer_selected').show();
+            $('#source_customer_search').hide();
+            $('#target_customer_search').hide();
+            <?php endif; ?>
+        });
+        
+        // 表单验证函数
+        function validateForm() {
+            // 验证源客户和目标客户
+            var sourceCustomerId = $('#source_customer_id').val();
+            var targetCustomerId = $('#target_customer_id').val();
+            var relationshipType = $('#relationship_type').val();
+            
+            if (!sourceCustomerId) {
+                alert('请选择源客户');
+                $('#source_customer_search').show().focus();
+                $('#source_customer_selected').hide();
+                return false;
+            }
+            
+            if (!targetCustomerId) {
+                alert('请选择目标客户');
+                $('#target_customer_search').show().focus();
+                $('#target_customer_selected').hide();
+                return false;
+            }
+            
+            if (sourceCustomerId === targetCustomerId) {
+                alert('源客户和目标客户不能是同一个客户');
+                return false;
+            }
+            
+            if (!relationshipType) {
+                alert('请选择关系类型');
+                $('#relationship_type').focus();
+                return false;
+            }
+            
+            return true;
+        }
+    </script>
+</head>
+<body class="clear">
+<?php // require_once 'panel.php'; ?>
+<div id="man_zone">
+    <form name="form1" id="form1" method="post" action="relationshipSave.php">
+        <?php if ($isEdit): ?>
+        <input type="hidden" name="id" value="<?= $relationshipData['id'] ?>">
+        <?php endif; ?>
+        
+        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
+            <tbody>
+                <tr>
+                    <th width="15%">源客户</th>
+                    <td>
+                        <div class="customer-search-container">
+                            <input type="text" id="source_customer_search" class="customer-search txt1" data-type="source" placeholder="输入客户名称搜索..." value="" />
+                            <div id="source_customer_selected" class="selected-customer-info" title="<?php 
+                            if ($isEdit) {
+                                $sourceCustQuery = "SELECT cs_company, cs_code FROM customer WHERE id = ?";
+                                $stmt = $conn->prepare($sourceCustQuery);
+                                $stmt->bind_param('i', $relationshipData['source_customer_id']);
+                                $stmt->execute();
+                                $result = $stmt->get_result();
+                                if ($row = $result->fetch_assoc()) {
+                                    $displayText = $row['cs_company'];
+                                    if ($row['cs_code']) {
+                                        $displayText = $row['cs_code'] . ' - ' . $displayText;
+                                    }
+                                    echo textDecode($displayText);
+                                }
+                            }
+                            ?>"><?php 
+                            if ($isEdit) {
+                                $sourceCustQuery = "SELECT cs_company, cs_code FROM customer WHERE id = ?";
+                                $stmt = $conn->prepare($sourceCustQuery);
+                                $stmt->bind_param('i', $relationshipData['source_customer_id']);
+                                $stmt->execute();
+                                $result = $stmt->get_result();
+                                if ($row = $result->fetch_assoc()) {
+                                    $displayText = $row['cs_company'];
+                                    if ($row['cs_code']) {
+                                        $displayText = $row['cs_code'] . ' - ' . $displayText;
+                                    }
+                                    echo textDecode($displayText);
+                                }
+                            }
+                            ?><span class="customer-clear-btn" data-type="source">X</span></div>
+                            <div id="source_customer_dropdown" class="customer-dropdown"></div>
+                        </div>
+                        <input type="hidden" id="source_customer_id" name="source_customer_id" value="<?= $isEdit ? $relationshipData['source_customer_id'] : '' ?>" />
+                        <input type="hidden" id="source_customer_company" name="source_customer_company" value="" />
+                    </td>
+                </tr>
+                <tr>
+                    <th>目标客户</th>
+                    <td>
+                        <div class="customer-search-container">
+                            <input type="text" id="target_customer_search" class="customer-search txt1" data-type="target" placeholder="输入客户名称搜索..." value="" />
+                            <div id="target_customer_selected" class="selected-customer-info" title="<?php 
+                            if ($isEdit) {
+                                $targetCustQuery = "SELECT cs_company, cs_code FROM customer WHERE id = ?";
+                                $stmt = $conn->prepare($targetCustQuery);
+                                $stmt->bind_param('i', $relationshipData['target_customer_id']);
+                                $stmt->execute();
+                                $result = $stmt->get_result();
+                                if ($row = $result->fetch_assoc()) {
+                                    $displayText = $row['cs_company'];
+                                    if ($row['cs_code']) {
+                                        $displayText = $row['cs_code'] . ' - ' . $displayText;
+                                    }
+                                    echo textDecode($displayText);
+                                }
+                            }
+                            ?>"><?php 
+                            if ($isEdit) {
+                                $targetCustQuery = "SELECT cs_company, cs_code FROM customer WHERE id = ?";
+                                $stmt = $conn->prepare($targetCustQuery);
+                                $stmt->bind_param('i', $relationshipData['target_customer_id']);
+                                $stmt->execute();
+                                $result = $stmt->get_result();
+                                if ($row = $result->fetch_assoc()) {
+                                    $displayText = $row['cs_company'];
+                                    if ($row['cs_code']) {
+                                        $displayText = $row['cs_code'] . ' - ' . $displayText;
+                                    }
+                                    echo textDecode($displayText);
+                                }
+                            }
+                            ?><span class="customer-clear-btn" data-type="target">X</span></div>
+                            <div id="target_customer_dropdown" class="customer-dropdown"></div>
+                        </div>
+                        <input type="hidden" id="target_customer_id" name="target_customer_id" value="<?= $isEdit ? $relationshipData['target_customer_id'] : '' ?>" />
+                        <input type="hidden" id="target_customer_company" name="target_customer_company" value="" />
+                    </td>
+                </tr>
+                <tr>
+                    <th>关系类型</th>
+                    <td>
+                        <select id="relationship_type" name="relationship_type" class="txt1">
+                            <option value="">请选择关系类型</option>
+                            <option value="1" <?= $isEdit && $relationshipData['relationship_type'] == 1 ? 'selected' : '' ?>>母公司-子公司</option>
+                            <option value="2" <?= $isEdit && $relationshipData['relationship_type'] == 2 ? 'selected' : '' ?>>供应商-客户</option>
+                            <option value="3" <?= $isEdit && $relationshipData['relationship_type'] == 3 ? 'selected' : '' ?>>合作伙伴</option>
+                            <option value="4" <?= $isEdit && $relationshipData['relationship_type'] == 4 ? 'selected' : '' ?>>竞争对手</option>
+                            <option value="5" <?= $isEdit && $relationshipData['relationship_type'] == 5 ? 'selected' : '' ?>>推荐人</option>
+                            <option value="6" <?= $isEdit && $relationshipData['relationship_type'] == 6 ? 'selected' : '' ?>>其他</option>
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th>关系状态</th>
+                    <td>
+                        <label>
+                            <input type="radio" name="relationship_status" value="1" <?= (!$isEdit || ($isEdit && $relationshipData['relationship_status'] == 1)) ? 'checked' : '' ?>>
+                            启用
+                        </label>
+                        <label>
+                            <input type="radio" name="relationship_status" value="0" <?= ($isEdit && $relationshipData['relationship_status'] == 0) ? 'checked' : '' ?>>
+                            停用
+                        </label>
+                    </td>
+                </tr>
+                <tr>
+                    <th>关系描述</th>
+                    <td>
+                        <textarea name="description" class="txt1" style="width:80%; height:100px;"><?= $isEdit ? htmlspecialchars(textDecode($relationshipData['description'])) : '' ?></textarea>
+                    </td>
+                </tr>
+                <tr>
+                    <th></th>
+                    <td>
+                        <input type="button" name="save" id="save" value="保存" class="btn1" />
+                        <input type="button" value="返回" class="btn1" onClick="location.href='relationships.php'" />
+                    </td>
+                </tr>
+            </tbody>
+        </table>
+    </form>
+</div>
+</body>
+</html> 

+ 175 - 0
relationshipSave.php

@@ -0,0 +1,175 @@
+<?php
+require_once 'conn.php';
+checkLogin();
+
+// 获取操作类型
+$act = $_GET['act'] ?? '';
+
+// 获取表单数据
+$id = isset($_POST['id']) ? intval($_POST['id']) : (isset($_GET['id']) ? intval($_GET['id']) : 0);
+$source_customer_id = isset($_POST['source_customer_id']) ? intval($_POST['source_customer_id']) : 0;
+$target_customer_id = isset($_POST['target_customer_id']) ? intval($_POST['target_customer_id']) : 0;
+$relationship_type = isset($_POST['relationship_type']) ? intval($_POST['relationship_type']) : 0;
+$relationship_status = isset($_POST['relationship_status']) ? intval($_POST['relationship_status']) : 1;
+$description = isset($_POST['description']) ? textEncode($_POST['description']) : '';
+
+// 当前员工ID
+$employee_id = $_SESSION['employee_id'];
+
+// 删除操作
+if ($act == 'delete' && $id > 0) {
+    // 验证关系记录是否存在
+    $checkQuery = "SELECT * FROM customer_relationship WHERE id = $id";
+    $result = $conn->query($checkQuery);
+    
+    if ($result->num_rows == 0) {
+        echo "<script>alert('未找到指定的客户关系记录!'); window.location.href='relationships.php';</script>";
+        exit;
+    }
+    
+    // 记录删除操作到日志
+    $row = $result->fetch_assoc();
+    $source_company_query = "SELECT cs_company FROM customer WHERE id = ".$row['source_customer_id'];
+    $target_company_query = "SELECT cs_company FROM customer WHERE id = ".$row['target_customer_id'];
+    
+    $source_result = $conn->query($source_company_query);
+    $source_company = '';
+    if ($source_row = $source_result->fetch_assoc()) {
+        $source_company = textDecode($source_row['cs_company']);
+    }
+    
+    $target_result = $conn->query($target_company_query);
+    $target_company = '';
+    if ($target_row = $target_result->fetch_assoc()) {
+        $target_company = textDecode($target_row['cs_company']);
+    }
+    
+    $log_message = $_SESSION['employee_name'] . " 删除了客户关系记录:" . 
+                   $source_company . " 和 " . $target_company . " 之间的关系";
+    
+    logAction($log_message);
+    
+    // 执行删除操作
+    $deleteQuery = "DELETE FROM customer_relationship WHERE id = $id";
+    $conn->query($deleteQuery);
+    
+    echo "<script>alert('客户关系记录已成功删除!'); window.location.href='relationships.php';</script>";
+    exit;
+}
+
+// 表单数据验证
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+    // 验证源客户和目标客户
+    if ($source_customer_id <= 0 || $target_customer_id <= 0) {
+        echo "<script>alert('请选择有效的源客户和目标客户!'); history.back();</script>";
+        exit;
+    }
+    
+    if ($source_customer_id == $target_customer_id) {
+        echo "<script>alert('源客户和目标客户不能是同一个客户!'); history.back();</script>";
+        exit;
+    }
+    
+    // 验证关系类型
+    if ($relationship_type <= 0 || $relationship_type > 6) {
+        echo "<script>alert('请选择有效的关系类型!'); history.back();</script>";
+        exit;
+    }
+    
+    // 检查相同的关系是否已存在
+    $checkDuplicateQuery = "SELECT * FROM customer_relationship 
+                           WHERE source_customer_id = $source_customer_id 
+                           AND target_customer_id = $target_customer_id 
+                           AND relationship_type = $relationship_type";
+    
+    if ($id > 0) {
+        $checkDuplicateQuery .= " AND id != $id";
+    }
+    
+    $result = $conn->query($checkDuplicateQuery);
+    
+    if ($result->num_rows > 0) {
+        echo "<script>alert('相同的客户关系记录已存在!'); history.back();</script>";
+        exit;
+    }
+    
+    // 根据是否有ID决定是更新还是新增
+    if ($id > 0) {
+        // 更新操作
+        $updateQuery = "UPDATE customer_relationship SET 
+                        source_customer_id = $source_customer_id,
+                        target_customer_id = $target_customer_id,
+                        relationship_type = $relationship_type,
+                        relationship_status = $relationship_status,
+                        description = '$description',
+                        updated_by = $employee_id,
+                        updated_at = NOW()
+                        WHERE id = $id";
+        
+        if ($conn->query($updateQuery)) {
+            // 获取源客户和目标客户名称
+            $source_company_query = "SELECT cs_company FROM customer WHERE id = $source_customer_id";
+            $target_company_query = "SELECT cs_company FROM customer WHERE id = $target_customer_id";
+            
+            $source_result = $conn->query($source_company_query);
+            $source_company = '';
+            if ($source_row = $source_result->fetch_assoc()) {
+                $source_company = textDecode($source_row['cs_company']);
+            }
+            
+            $target_result = $conn->query($target_company_query);
+            $target_company = '';
+            if ($target_row = $target_result->fetch_assoc()) {
+                $target_company = textDecode($target_row['cs_company']);
+            }
+            
+            // 记录日志
+            $log_message = $_SESSION['employee_name'] . " 更新了客户关系记录:" . 
+                          $source_company . " 和 " . $target_company . " 之间的关系";
+            
+            logAction($log_message);
+            
+            echo "<script>alert('客户关系记录已成功更新!'); window.location.href='relationships.php';</script>";
+        } else {
+            echo "<script>alert('更新客户关系记录失败:" . $conn->error . "'); history.back();</script>";
+        }
+    } else {
+        // 新增操作
+        $insertQuery = "INSERT INTO customer_relationship 
+                        (source_customer_id, target_customer_id, relationship_type, relationship_status, 
+                         description, employee_id, updated_by, created_at, updated_at)
+                        VALUES ($source_customer_id, $target_customer_id, $relationship_type, $relationship_status, 
+                         '$description', $employee_id, $employee_id, NOW(), NOW())";
+        
+        if ($conn->query($insertQuery)) {
+            // 获取源客户和目标客户名称
+            $source_company_query = "SELECT cs_company FROM customer WHERE id = $source_customer_id";
+            $target_company_query = "SELECT cs_company FROM customer WHERE id = $target_customer_id";
+            
+            $source_result = $conn->query($source_company_query);
+            $source_company = '';
+            if ($source_row = $source_result->fetch_assoc()) {
+                $source_company = textDecode($source_row['cs_company']);
+            }
+            
+            $target_result = $conn->query($target_company_query);
+            $target_company = '';
+            if ($target_row = $target_result->fetch_assoc()) {
+                $target_company = textDecode($target_row['cs_company']);
+            }
+            
+            // 记录日志
+            $log_message = $_SESSION['employee_name'] . " 新增了客户关系记录:" . 
+                          $source_company . " 和 " . $target_company . " 之间的关系";
+            
+            logAction($log_message);
+            
+            echo "<script>alert('客户关系记录已成功添加!'); window.location.href='relationships.php';</script>";
+        } else {
+            echo "<script>alert('添加客户关系记录失败:" . $conn->error . "'); history.back();</script>";
+        }
+    }
+} else {
+    echo "<script>alert('无效的请求!'); window.location.href='relationships.php';</script>";
+}
+?> 

+ 497 - 0
relationships.php

@@ -0,0 +1,497 @@
+<?php
+require_once 'conn.php';
+checkLogin();
+
+ 
+$keys = $_GET['Keys'] ?? '';
+$fliterRelationType = $_GET['FliterRelationType'] ?? '';
+$fliterStatus = $_GET['FliterStatus'] ?? '';
+$page = $_GET['Page'] ?? 1;
+$urlStr = '';
+
+if (!empty($fliterRelationType)) {
+    $urlStr .= "&FliterRelationType=" . urlencode($fliterRelationType);
+}
+
+if (isset($fliterStatus) && $fliterStatus !== '') {
+    $urlStr .= "&FliterStatus=" . urlencode($fliterStatus);
+}
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <title>客户关系管理</title>
+    <link rel="stylesheet" href="css/common.css" type="text/css" />
+    <link rel="stylesheet" href="css/alert.css" type="text/css" />
+    <script src="js/jquery-1.7.2.min.js"></script>
+    <script src="js/js.js"></script>
+    <style>
+        body {
+            margin: 0;
+            padding: 20px;
+            background: #fff;
+        }
+        #man_zone {
+            margin-left: 0;
+        }
+        
+        /* 表格布局 */
+        .table2 {
+            width: 100%;
+        }
+        
+        .theader, .tline {
+            display: flex;
+            flex-direction: row;
+            align-items: center;
+            width: 100%;
+            border-bottom: 1px solid #ddd;
+        }
+        
+        .theader {
+            background-color: #f2f2f2;
+            font-weight: bold;
+            height: 40px;
+        }
+        
+        .tline {
+            height: 45px;
+        }
+        
+        .tline:hover {
+            background-color: #f5f5f5;
+        }
+        
+        /* 列宽定义 */
+        .col2 { width: 5%; text-align: center; }
+        .col3 { width: 20%; }
+        .col4 { width: 20%; }
+        .col5 { width: 10%; }
+        .col6 { width: 8%; text-align: center; }
+        .col7 { width: 8%; }
+        .col8 { width: 14%; }
+        .col9 { width: 15%; text-align: center; }
+        
+        /* 表格布局修复 */
+        .table2 .col2 { width: 5%; text-align: center; }
+        .table2 .col3 { width: 20%; }
+        .table2 .col4 { width: 20%; }
+        .table2 .col5 { width: 10%; }
+        .table2 .col6 { width: 8%; text-align: center; }
+        .table2 .col7 { width: 8%; }
+        .table2 .col8 { width: 14%; }
+        .table2 .col9 { width: 15%; text-align: center; }
+        
+        .theader > div, .tline > div {
+            padding: 0 5px;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: nowrap;
+        }
+        
+        /* 搜索栏样式 */
+        .fastSelect {
+            margin-bottom: 20px;
+            background-color: #f9f9f9;
+            padding: 15px;
+            border-radius: 3px;
+            border: 1px solid #eee;
+        }
+        
+        .fastSelect H1 {
+            font-size: 16px;
+            margin-top: 0;
+            margin-bottom: 10px;
+            color: #333;
+        }
+        
+        .selectItem {
+            margin-bottom: 10px;
+            display: flex;
+            align-items: center;
+            gap: 10px;
+        }
+        
+        .selectItem label {
+            font-weight: bold;
+            font-size: 13px;
+            color: #555;
+        }
+        
+        .inputSearch {
+            display: flex;
+            align-items: center;
+            margin-top: 0px;
+        }
+
+
+
+        .inputSearch .inputTxt {
+            padding:1px 5px;
+            border: 1px solid #ccc;
+
+            width: 300px;
+            height: 30px;
+        }
+        
+        .searchgo {
+            margin-left: 5px;
+            padding: 0 15px;
+            background: #337ab7;
+            color: white;
+            border: none;
+            border-radius: 3px;
+            cursor: pointer;
+            height: 32px;
+            line-height: 32px;
+        }
+        
+        /* 按钮容器 */
+        .search-button-container {
+            display: flex;
+            align-items: flex-end;
+        }
+        
+        /* 状态颜色 */
+        .status-active {
+            color: green;
+        }
+        
+        .status-inactive {
+            color: red;
+        }
+        
+        /* 按钮样式 */
+        .ico {
+            margin: 0 5px;
+            text-decoration: none;
+        }
+        
+        .ico_edit {
+            color: #3498db;
+        }
+        
+        .ico_del {
+            color: #e74c3c;
+        }
+        
+        .ico:hover {
+            text-decoration: underline;
+        }
+        
+        /* 详情样式 */
+        .detail-row {
+            display: none;
+            background-color: #f8f8f8;
+            border-bottom: 1px solid #ddd;
+            padding: 15px;
+        }
+        
+        .detail-container {
+            display: flex;
+            flex-wrap: wrap;
+        }
+        
+        .detail-item {
+            width: 33%;
+            margin-bottom: 10px;
+        }
+        
+        .detail-item label {
+            font-weight: bold;
+            display: block;
+            margin-bottom: 3px;
+            color: #555;
+        }
+        
+        .detail-item-full {
+            width: 100%;
+            margin-bottom: 10px;
+        }
+        
+        .detail-content {
+            margin-top: 5px;
+        }
+        
+        .clickable-row {
+            cursor: pointer;
+        }
+    </style>
+</head>
+<body>
+<div id="man_zone">
+    <div class="fastSelect clear">
+        <H1>筛选条件</H1>
+        <div class="selectItem">
+            <label>关系类型</label>
+            <select name="FliterRelationType" class="filterSearch">
+                <option value="">所有关系类型</option>
+                <option value="1" <?= $fliterRelationType == '1' ? 'selected' : '' ?>>母公司-子公司</option>
+                <option value="2" <?= $fliterRelationType == '2' ? 'selected' : '' ?>>供应商-客户</option>
+                <option value="3" <?= $fliterRelationType == '3' ? 'selected' : '' ?>>合作伙伴</option>
+                <option value="4" <?= $fliterRelationType == '4' ? 'selected' : '' ?>>竞争对手</option>
+                <option value="5" <?= $fliterRelationType == '5' ? 'selected' : '' ?>>推荐人</option>
+                <option value="6" <?= $fliterRelationType == '6' ? 'selected' : '' ?>>其他</option>
+            </select>
+        </div>
+        <div class="selectItem">
+            <label>状态</label>
+            <select name="FliterStatus" class="filterSearch">
+                <option value="">全部状态</option>
+                <option value="1" <?= $fliterStatus == '1' ? 'selected' : '' ?>>启用</option>
+                <option value="0" <?= $fliterStatus == '0' ? 'selected' : '' ?>>停用</option>
+            </select>
+        </div>
+        <div class="inputSearch">
+            <input type="text" id="keys" class="inputTxt" placeholder="请输入搜索关键词"
+                value="<?= empty($keys) ? '' : htmlspecialchars($keys) ?>" />
+            <input type="button" id="searchgo" class="searchgo" value="搜索"
+                onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
+        </div>
+    </div>
+
+    <div align="right" style="margin-bottom: 10px;">
+        <input type="button" value="新增客户关系" class="btn1" onClick="location.href='relationshipAdd.php'" />
+    </div>
+
+    <div class="table2">
+        <div class="theader">
+            <div class="col2">序号</div>
+            <div class="col3">源客户</div>
+            <div class="col4">目标客户</div>
+            <div class="col5">关系类型</div>
+            <div class="col6">状态</div>
+            <div class="col7">创建人</div>
+            <div class="col8">更新时间</div>
+            <div class="col9">操作</div>
+        </div>
+
+        <?php
+        // 构建查询条件
+        $whereClause = "WHERE 1=1";
+        $params = [];
+        
+        if (!empty($keys)) {
+            $searchKeys = '%' . $conn->real_escape_string($keys) . '%';
+            $whereClause .= " AND (c1.cs_code LIKE '$searchKeys' OR c1.cs_company LIKE '$searchKeys' OR c2.cs_code LIKE '$searchKeys' OR c2.cs_company LIKE '$searchKeys' OR cr.description LIKE '$searchKeys')";
+        }
+        
+        if (!empty($fliterRelationType)) {
+            $whereClause .= " AND cr.relationship_type = '" . $conn->real_escape_string($fliterRelationType) . "'";
+        }
+        
+        if (isset($fliterStatus) && $fliterStatus !== '') {
+            $whereClause .= " AND cr.relationship_status = '" . $conn->real_escape_string($fliterStatus) . "'";
+        }
+        
+        // 分页设置
+        $page = (int)$page;
+        $perpage = 20; // 每页显示条数
+        $start = ($page - 1) * $perpage;
+        
+        // 计算总记录数
+        $countQuery = "SELECT COUNT(*) as total 
+                       FROM customer_relationship cr
+                       JOIN customer c1 ON cr.source_customer_id = c1.id
+                       JOIN customer c2 ON cr.target_customer_id = c2.id
+                       $whereClause";
+        
+        $result = $conn->query($countQuery);
+        $row = $result->fetch_assoc();
+        $totalRecords = $row['total'];
+        $totalPages = ceil($totalRecords / $perpage);
+        if ($totalPages < 1) $totalPages = 1;
+        
+        // 验证当前页码
+        if ($page < 1) $page = 1;
+        if ($page > $totalPages) $page = $totalPages;
+        
+        // 获取关系列表
+        $query = "SELECT cr.*, 
+                  c1.cs_code as source_code,
+                  c1.cs_company as source_company, 
+                  c2.cs_code as target_code,
+                  c2.cs_company as target_company,
+                  e.em_user as creator
+                  FROM customer_relationship cr
+                  JOIN customer c1 ON cr.source_customer_id = c1.id
+                  JOIN customer c2 ON cr.target_customer_id = c2.id
+                  LEFT JOIN employee e ON cr.employee_id = e.id
+                  $whereClause
+                  ORDER BY cr.updated_at DESC
+                  LIMIT $start, $perpage";
+        
+        $result = $conn->query($query);
+        
+        if ($result->num_rows > 0) {
+            $tempNum = ($page - 1) * $perpage;
+            while ($row = $result->fetch_assoc()) {
+                $tempNum++;
+                // 获取关系类型描述
+                $relationType = '';
+                switch ($row['relationship_type']) {
+                    case 1: $relationType = '母公司-子公司'; break;
+                    case 2: $relationType = '供应商-客户'; break;
+                    case 3: $relationType = '合作伙伴'; break;
+                    case 4: $relationType = '竞争对手'; break;
+                    case 5: $relationType = '推荐人'; break;
+                    case 6: $relationType = '其他'; break;
+                }
+                
+                $status = $row['relationship_status'] == 1 ? 
+                    '<span class="status-active">启用</span>' : 
+                    '<span class="status-inactive">停用</span>';
+                
+                ?>
+                <div class="tline clickable-row" data-id="<?= $row['id'] ?>">
+                    <div class="col2"><?= $tempNum ?></div>
+                    <div class="col3"><?= htmlspecialcharsFix($row['source_code'].' - '.$row['source_company']) ?></div>
+                    <div class="col4"><?= htmlspecialcharsFix($row['target_code'].' - '.$row['target_company']) ?></div>
+                    <div class="col5"><?= $relationType ?></div>
+                    <div class="col6"><?= $status ?></div>
+                    <div class="col7"><?= htmlspecialcharsFix($row['creator']) ?></div>
+                    <div class="col8"><?= $row['updated_at'] ?></div>
+                    <div class="col9">
+                        <a href="relationshipAdd.php?id=<?= $row['id'] ?>" class="ico_edit ico">编辑</a>
+                        <a href="javascript:void(0)" onclick="confirmDelete(<?= $row['id'] ?>); event.stopPropagation();" class="ico_del ico">删除</a>
+                    </div>
+                </div>
+                <div id="detail-<?= $row['id'] ?>" class="detail-row">
+                    <div class="detail-container">
+                        <div class="detail-item">
+                            <label>源客户</label>
+                            <div><?= htmlspecialcharsFix($row['source_code'].' - '.$row['source_company']) ?></div>
+                        </div>
+                        <div class="detail-item">
+                            <label>目标客户</label>
+                            <div><?= htmlspecialcharsFix($row['target_code'].' - '.$row['target_company']) ?></div>
+                        </div>
+                        <div class="detail-item">
+                            <label>关系类型</label>
+                            <div><?= $relationType ?></div>
+                        </div>
+                        <div class="detail-item">
+                            <label>状态</label>
+                            <div><?= $row['relationship_status'] == 1 ? '启用' : '停用' ?></div>
+                        </div>
+                        <div class="detail-item">
+                            <label>创建人</label>
+                            <div><?= htmlspecialcharsFix($row['creator']) ?></div>
+                        </div>
+                        <div class="detail-item">
+                            <label>创建时间</label>
+                            <div><?= $row['created_at'] ?></div>
+                        </div>
+                        <div class="detail-item">
+                            <label>更新时间</label>
+                            <div><?= $row['updated_at'] ?></div>
+                        </div>
+                        <div class="detail-item-full">
+                            <label>关系描述</label>
+                            <div><?= nl2br(htmlspecialcharsFix($row['description'] ?? '无')) ?></div>
+                        </div>
+                    </div>
+                </div>
+                <?php
+            }
+        } else {
+            if (empty($keys) && empty($fliterRelationType) && $fliterStatus === '') {
+                echo '<div class="tline"><div style="text-align:center; width:100%;">当前暂无客户关系记录</div></div>';
+            } else {
+                echo '<div class="tline"><div style="text-align:center; width:100%;"><a href="?">没有找到匹配的客户关系记录,点击返回</a></div></div>';
+            }
+        }
+        ?>
+
+        <div class="showpagebox">
+            <?php
+            if ($totalPages > 1) {
+                $pageName = "?Keys=$keys$urlStr&";
+                $pageLen = 3;
+
+                if ($page > 1) {
+                    echo "<a href=\"{$pageName}Page=1\">首页</a>";
+                    echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
+                }
+
+                if ($pageLen * 2 + 1 >= $totalPages) {
+                    $startPage = 1;
+                    $endPage = $totalPages;
+                } else {
+                    if ($page <= $pageLen + 1) {
+                        $startPage = 1;
+                        $endPage = $pageLen * 2 + 1;
+                    } else {
+                        $startPage = $page - $pageLen;
+                        $endPage = $page + $pageLen;
+                    }
+                    if ($page + $pageLen > $totalPages) {
+                        $startPage = $totalPages - $pageLen * 2;
+                        $endPage = $totalPages;
+                    }
+                }
+
+                for ($i = $startPage; $i <= $endPage; $i++) {
+                    if ($i == $page) {
+                        echo "<a class=\"current\">$i</a>";
+                    } else {
+                        echo "<a href=\"{$pageName}Page=$i\">$i</a>";
+                    }
+                }
+
+                if ($page < $totalPages) {
+                    if ($totalPages - $page > $pageLen) {
+                        echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
+                    }
+                    echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
+                    echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
+                }
+            }
+            ?>
+        </div>
+    </div>
+    
+    <script>
+    $(document).ready(function() {
+        // 处理筛选条件改变
+        $('.filterSearch').change(function() {
+            var url = '?';
+            var keys = $('#keys').val();
+            if (keys && keys != '请输入搜索关键词') {
+                url += 'Keys=' + encodeURIComponent(keys) + '&';
+            }
+
+            // 获取所有筛选条件
+            $('select.filterSearch').each(function() {
+                var name = $(this).attr('name');
+                var value = $(this).val();
+                if (value) {
+                    url += name + '=' + encodeURIComponent(value) + '&';
+                }
+            });
+
+            // 移除末尾的&
+            if (url.endsWith('&')) {
+                url = url.substring(0, url.length - 1);
+            }
+
+            location.href = url;
+        });
+        
+        // 点击行显示详情
+        $('.clickable-row').click(function() {
+            var id = $(this).data('id');
+            $('#detail-' + id).slideToggle();
+        });
+    });
+    
+    function confirmDelete(id) {
+        if (confirm("确定要删除此关系记录吗?此操作不可恢复!")) {
+            window.location.href = "relationshipSave.php?act=delete&id=" + id + "&keys=<?= urlencode($keys) ?>&page=<?= $page ?>";
+        }
+    }
+    </script>
+</div>
+</body>
+</html>