Browse Source

fleat:order update

igb 4 weeks ago
parent
commit
d0fa955831
2 changed files with 54 additions and 30 deletions
  1. 1 0
      customers.php
  2. 53 30
      order_add.php

+ 1 - 0
customers.php

@@ -843,6 +843,7 @@ $hrefstr = "?keys=" . $keys;
                     <div class="col6"><?= $row['cs_addtime'] ?></div>
                     <div class="col9">
                         <a href="customerEdit.php?Keys=<?= $keys ?>&fliterDeal=<?= $filters['Deal'] ?>&fliterBusiness=<?= $filters['Business'] ?>&Page=<?= $page ?>&act=edit&id=<?= $row['id'] ?>" class="ico_edit ico">修改</a>
+                        <a href="order_add.php?customer_id=<?= $row['id'] ?>" class="ico_add ico">添加订单</a>
                     </div>
                 </div>
                 <div class="notepanel clear">

+ 53 - 30
order_add.php

@@ -4,7 +4,32 @@ checkLogin();
 
 $page = $_GET['Page'] ?? '';
 $keys = urlencode($_GET['Keys'] ?? '');
+$customerId = isset($_GET['customer_id']) ? intval($_GET['customer_id']) : 0; // 添加获取客户ID参数
 $hrefstr = "keys=$keys&Page=$page";
+
+// 如果有客户ID,获取客户信息
+$customerInfo = null;
+$contactOptions = '<option value="">请选择联系人</option>';
+
+if ($customerId > 0) {
+    $customerQuery = $conn->query("SELECT c.id, c.cs_code, c.cs_company 
+                                  FROM customer c 
+                                  WHERE c.id = " . $customerId);
+    if ($customerQuery && $customerQuery->num_rows > 0) {
+        $customerInfo = $customerQuery->fetch_assoc();
+        
+        // 获取该客户的联系人列表,不再自动选择第一个联系人
+        $contactsQuery = $conn->query("SELECT id, contact_name FROM customer_contact 
+                                      WHERE customer_id = " . $customerId);
+        if ($contactsQuery && $contactsQuery->num_rows > 0) {
+            // 移除自动选择联系人的逻辑
+            while ($contact = $contactsQuery->fetch_assoc()) {
+                $contactOptions .= '<option value="' . $contact['id'] . '">' . 
+                                  htmlspecialcharsFix($contact['contact_name']) . '</option>';
+            }
+        }
+    }
+}
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
@@ -102,22 +127,28 @@ $hrefstr = "keys=$keys&Page=$page";
             <tr>
                 <th width="8%">客户选择</th>
                 <td>
+                    <?php if ($customerInfo): ?>
+                    <!-- 已有客户ID,只显示客户信息 -->
+                    <div style="display: inline-block; width: 60%;">
+                        <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;">
+                            <?= htmlspecialcharsFix($customerInfo['cs_code'] . ' - ' . $customerInfo['cs_company']) ?>
+                        </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>
                         <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>
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">联系人</th>
-                <td>
-                    <select id="contact_id" name="contact_id">
-                        <option value="">请选择联系人</option>
-                    </select>
+                    <?php endif; ?>
                 </td>
             </tr>
             <tr>
@@ -369,17 +400,16 @@ $hrefstr = "keys=$keys&Page=$page";
                     <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
 
                     <label style="margin-left: 10px;">单位:</label>
-                    <input type="text" name="items[${productIndex}][unit]" value="" class="unit-input">
+                    <span class="unit-label" style="display: inline-block; padding: 2px 5px; min-width: 30px;"></span>
+                    <input type="hidden" name="items[${productIndex}][unit]" class="unit-input" value="">
 
                     <label style="margin-left: 10px;">单价:</label>
                     <input type="number" step="0.01" name="items[${productIndex}][unit_price]" value="" class="price-input" placeholder="请输入单价" onchange="calculateItemTotal(this)">
                     
                     <label style="margin-left: 10px;">总价:</label>
-                    <input type="number" step="0.01" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input" readonly>
-                </div>
-                <div style="margin-top: 5px;">
-                    <label>备注:</label>
-                    <input type="text" name="items[${productIndex}][notes]" value="" style="width: 90%;">
+                    <span class="total-price-display" style="display: inline-block; background-color: #f0f0f0; border: 1px solid #ddd; padding: 2px 8px; min-width: 60px; text-align: right; font-weight: bold;">0.00</span>
+
+                    <input type="hidden" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input">
                 </div>
             </div>
             `;
@@ -435,7 +465,9 @@ $hrefstr = "keys=$keys&Page=$page";
                 dataType: 'json',
                 success: function(data) {
                     if (data) {
+                        // 设置单位到隐藏输入框和显示标签
                         row.find('.unit-input').val(data.unit);
+                        row.find('.unit-label').text(data.unit || '');
 
                         // 只有当数据库中有价格信息时才设置价格
                         if (data.price && data.price !== '0' && data.price !== '0.00') {
@@ -459,6 +491,8 @@ $hrefstr = "keys=$keys&Page=$page";
             var total = quantity * price;
             if (total < 0) total = 0;
 
+            // 更新显示元素和隐藏输入框
+            row.find('.total-price-display').text(total.toFixed(2));
             row.find('.total-price-input').val(total.toFixed(2));
 
             calculateOrderTotal();
@@ -484,17 +518,12 @@ $hrefstr = "keys=$keys&Page=$page";
                     data: {customer_id: customerId},
                     dataType: 'json',
                     success: function(data) {
-                        var options = '<option value="">请选择联系人</option>';
-                        if (data && data.length > 0) {
-                            for (var i = 0; i < data.length; i++) {
-                                options += '<option value="' + data[i].id + '">' + data[i].contact_name + '</option>';
-                            }
-                        }
-                        $('#contact_id').html(options);
+                        // 不自动选择第一个联系人,让字段为空
+                        $('#contact_id').val('');
                     }
                 });
             } else {
-                $('#contact_id').html('<option value="">请选择联系人</option>');
+                $('#contact_id').val('');
             }
         }
 
@@ -502,7 +531,6 @@ $hrefstr = "keys=$keys&Page=$page";
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
             var customerName = $('.customer-search').val();
-            var contactId = $('#contact_id').val(); 
             var hasProducts = false;
             var allPricesValid = true;
             var firstEmptyPriceField = null;
@@ -537,18 +565,13 @@ $hrefstr = "keys=$keys&Page=$page";
                 return false;
             }
             
-            if (!customerName) {
+            // 只有当客户ID为0时才检查客户名称
+            if (customerId == '0' && !customerName) {
                 alert('请输入并选择有效的客户');
                 $('.customer-search').focus();
                 return false;
             }
             
-            if (!contactId) {
-                alert('请选择联系人');
-                $('#contact_id').focus();
-                return false;
-            }
-
             if (!hasProducts) {
                 alert('请至少添加一个产品');
                 $('#product-search-single').focus();