Parcourir la source

fleat: order update

igb il y a 3 semaines
Parent
commit
04ee628ecc
6 fichiers modifiés avec 557 ajouts et 524 suppressions
  1. 200 255
      order.php
  2. 85 59
      order_add.php
  3. 16 79
      order_details.php
  4. 247 123
      order_edit.php
  5. 8 7
      order_save.php
  6. 1 1
      panel.php

+ 200 - 255
order.php

@@ -15,29 +15,11 @@ $act = $_GET['act'] ?? '';
 $urlStr = '';
 
 // 处理筛选条件
-$fliterStatus = $_GET['fliterStatus'] ?? '';
-$fliterPayment = $_GET['fliterPayment'] ?? '';
-$fliterCustomer = $_GET['fliterCustomer'] ?? '';
 $fliterFromDate = $_GET['fliterFromDate'] ?? '';
 $fliterToDate = $_GET['fliterToDate'] ?? '';
 
 $fliterStr = "";
 
-if (!empty($fliterStatus)) {
-    $fliterStr .= " AND o.order_status = " . intval($fliterStatus);
-    $urlStr .= "&fliterStatus=" . $fliterStatus;
-}
-
-if (!empty($fliterPayment)) {
-    $fliterStr .= " AND o.payment_status = " . intval($fliterPayment);
-    $urlStr .= "&fliterPayment=" . $fliterPayment;
-}
-
-if (!empty($fliterCustomer)) {
-    $fliterStr .= " AND o.customer_id = " . intval($fliterCustomer);
-    $urlStr .= "&fliterCustomer=" . $fliterCustomer;
-}
-
 if (!empty($fliterFromDate)) {
     $fliterStr .= " AND o.order_date >= '" . mysqli_real_escape_string($conn, $fliterFromDate) . "'";
     $urlStr .= "&fliterFromDate=" . urlencode($fliterFromDate);
@@ -58,7 +40,7 @@ $ordStr = !empty($ord) ? "$ord," : "";
 
 // 构建查询SQL
 $employee_id = $_SESSION['employee_id'];
-$sqlStr = "SELECT o.*, c.cs_company, cc.contact_name
+$sqlStr = "SELECT o.*, c.cs_company, c.cs_code, cc.contact_name
            FROM orders o
            LEFT JOIN customer c ON o.customer_id = c.id
            LEFT JOIN customer_contact cc ON o.contact_id = cc.id
@@ -67,6 +49,7 @@ $sqlStr = "SELECT o.*, c.cs_company, cc.contact_name
 if (!empty($keyscode)) {
     $sqlStr .= " AND (o.order_code LIKE '%$keyscode%'
            OR c.cs_company LIKE '%$keyscode%'
+           OR c.cs_code LIKE '%$keyscode%'
            OR cc.contact_name LIKE '%$keyscode%')";
 }
 
@@ -91,85 +74,98 @@ $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
         #man_zone {
             margin-left: 0;
         }
-        .status-badge {
-            display: inline-block;
-            padding: 3px 8px;
-            border-radius: 3px;
-            font-size: 12px;
-            color: white;
+        
+        /* 表格布局修复 */
+        .table2 {
+            width: 100%;
         }
-        .status-0 { background-color: #999; }
-        .status-1 { background-color: #5bc0de; }
-        .status-2 { background-color: #337ab7; }
-        .status-3 { background-color: #f0ad4e; }
-        .status-4 { background-color: #5cb85c; }
-        .status-5 { background-color: #28a745; }
-
-        .payment-badge {
-            display: inline-block;
-            padding: 3px 8px;
-            border-radius: 3px;
-            font-size: 12px;
-            color: white;
+        
+        .theader, .tline {
+            display: flex;
+            flex-direction: row;
+            align-items: center;
+            width: 100%;
+            border-bottom: 1px solid #ddd;
         }
-        .payment-0 { background-color: #d9534f; }
-        .payment-1 { background-color: #f0ad4e; }
-        .payment-2 { background-color: #5cb85c; }
-
-        /* Date picker styling */
+        
+        .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: 15%; }
+        .col4 { width: 12%; }
+        .col5 { width: 18%; }
+        .col6 { width: 12%; }
+        .col7 { width: 12%; }
+        .col9 { width: 10%; text-align: right; }
+        .col10 { width: 16%; text-align: center; }
+        
+        .theader > div, .tline > div {
+            padding: 0 5px;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: nowrap;
+        }
+        
+        /* 日期选择器样式 */
         .date-input {
             padding: 5px;
             border: 1px solid #ccc;
             border-radius: 3px;
         }
         
-        /* 新的表格样式 */
-        .order-table {
-            width: 100%;
-            border-collapse: collapse;
-            margin-bottom: 20px;
+        /* 滑动面板样式 */
+        .slidepanel {
+            cursor: pointer;
         }
         
-        .order-table th {
-            background-color: #f2f2f2;
-            padding: 10px;
-            text-align: left;
-            border-bottom: 2px solid #ddd;
+        .slidepanel.open {
             font-weight: bold;
+            color: #3366cc;
         }
         
-        .order-table td {
-            padding: 8px 10px;
-            border-bottom: 1px solid #ddd;
-            vertical-align: middle;
+        .notepanel {
+            display: none;
+            background: #f9f9f9;
+            padding: 10px;
+            border: 1px solid #eee;
+            margin-bottom: 10px;
         }
         
-        .order-table tr:hover {
-            background-color: #f5f5f5;
+        .notepanel .noteItem {
+            font-weight: bold;
+            margin-bottom: 5px;
         }
         
-        .pagination {
-            text-align: center;
-            margin: 20px 0;
+        .notepanel .noteItem2 {
+            font-weight: bold;
+            margin-top: 10px;
+            margin-bottom: 5px;
         }
         
-        .pagination a {
-            display: inline-block;
-            padding: 5px 10px;
-            margin: 0 3px;
-            border: 1px solid #ddd;
-            text-decoration: none;
-            color: #337ab7;
+        .lx {
+            display: flex;
+            flex-wrap: wrap;
+            gap: 15px;
         }
         
-        .pagination a.current {
-            background-color: #337ab7;
-            color: white;
-            border-color: #337ab7;
+        .lx > div {
+            margin-bottom: 10px;
         }
         
-        .pagination a:hover:not(.current) {
-            background-color: #ddd;
+        .lx > div > div {
+            margin-bottom: 5px;
         }
     </style>
 </head>
@@ -178,54 +174,15 @@ $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
     <div class="fastSelect clear">
         <H1>筛选条件</H1>
         <div class="selectItem">
-            <label>订单状态</label>
-            <select name="fliterStatus" class="filterSearch">
-                <option value="">全部状态</option>
-                <option value="0"<?= $fliterStatus == "0" ? ' selected' : '' ?>>已取消</option>
-                <option value="1"<?= $fliterStatus == "1" ? ' selected' : '' ?>>待确认</option>
-                <option value="2"<?= $fliterStatus == "2" ? ' selected' : '' ?>>已确认</option>
-                <option value="3"<?= $fliterStatus == "3" ? ' selected' : '' ?>>生产中</option>
-                <option value="4"<?= $fliterStatus == "4" ? ' selected' : '' ?>>已发货</option>
-                <option value="5"<?= $fliterStatus == "5" ? ' selected' : '' ?>>已完成</option>
-            </select>
-        </div>
-        <div class="selectItem">
-            <label>付款状态</label>
-            <select name="fliterPayment" class="filterSearch">
-                <option value="">全部付款状态</option>
-                <option value="0"<?= $fliterPayment == "0" ? ' selected' : '' ?>>未付款</option>
-                <option value="1"<?= $fliterPayment == "1" ? ' selected' : '' ?>>部分付款</option>
-                <option value="2"<?= $fliterPayment == "2" ? ' selected' : '' ?>>已付清</option>
-            </select>
-        </div>
-        <div class="selectItem">
-            <label>客户筛选</label>
-            <select name="fliterCustomer" class="filterSearch">
-                <option value="">全部客户</option>
-                <?php
-                $employee_id = $_SESSION['employee_id'];
-                $customerSql = "SELECT id, cs_company FROM customer WHERE cs_belong = $employee_id ORDER BY cs_company";
-                $customerResult = mysqli_query($conn, $customerSql);
-                while ($customerRow = mysqli_fetch_assoc($customerResult)) {
-                    $selected = ($fliterCustomer == $customerRow['id']) ? ' selected' : '';
-                    echo "<option value=\"{$customerRow['id']}\"$selected>" . htmlspecialcharsFix($customerRow['cs_company']) . "</option>";
-                }
-                ?>
-            </select>
-        </div>
-        <div class="selectItem">
-            <label>订单日期 从</label>
+            <label>订单日期</label>
             <input type="date" name="fliterFromDate" class="date-input filterSearch" value="<?= $fliterFromDate ?>">
             <label>到</label>
             <input type="date" name="fliterToDate" class="date-input filterSearch" value="<?= $fliterToDate ?>">
         </div>
-        <div class="inputSearch">
-            <input type="text" id="keys" class="inputTxt"
-                value="<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>"
-                onFocus="if(this.value == '<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>'){this.value='';}"
-                onBlur="if(this.value == ''){this.value='<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>';}"
-                onKeyDown="if(event.keyCode==13){location.href='?Keys='+escape(document.getElementById('keys').value)}" />
-            <input type="button" id="searchgo" class="searchgo" value="go"
+        <div class="inputSearch" >
+            <input type="text" id="keys" class="inputTxt" placeholder="请输入搜索关键词"
+                value="<?= empty($keyscode) ? '' : $keyscode ?>" />
+            <input type="button" id="searchgo" class="searchgo" value="搜索"
                 onClick="location.href='?Keys='+escape(document.getElementById('keys').value)" />
         </div>
     </div>
@@ -234,156 +191,144 @@ $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
         <input type="button" value="新增订单" class="btn1" onClick="location.href='order_add.php'" />
     </div>
 
-    <table class="order-table">
-        <thead>
-            <tr>
-                <th>序号</th>
-                <th>订单编号</th>
-                <th>客户</th>
-                <th>联系人</th>
-                <th>订单日期</th>
-                <th>订单状态</th>
-                <th>付款状态</th>
-                <th>订单金额</th>
-                <th>操作</th>
-            </tr>
-        </thead>
-        <tbody>
-            <?php
-            // 设置每页显示记录数
-            $pageSize = 20;
-
-            // 获取总记录数
-            $employee_id = $_SESSION['employee_id'];
-            $countSql = "SELECT COUNT(*) AS total FROM orders o
-                         WHERE o.employee_id = $employee_id";
-            if (!empty($keyscode)) {
-                $countSql .= " AND (o.order_code LIKE '%$keyscode%'
-                             OR o.customer_id IN (SELECT id FROM customer WHERE cs_company LIKE '%$keyscode%'))";
+    <div class="table2 em<?= $_SESSION['employee_id'] ?>">
+        <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="col9">订单金额</div>
+            <div class="col10">操作</div>
+        </div>
+
+        <?php
+        // 设置每页显示记录数
+        $pageSize = 20;
+
+        // 获取总记录数
+        $employee_id = $_SESSION['employee_id'];
+        $countSql = "SELECT COUNT(*) AS total FROM orders o
+                     LEFT JOIN customer c ON o.customer_id = c.id
+                     LEFT JOIN customer_contact cc ON o.contact_id = cc.id
+                     WHERE o.employee_id = $employee_id";
+        if (!empty($keyscode)) {
+            $countSql .= " AND (o.order_code LIKE '%$keyscode%'
+                         OR c.cs_company LIKE '%$keyscode%'
+                         OR c.cs_code LIKE '%$keyscode%'
+                         OR cc.contact_name LIKE '%$keyscode%')";
+        }
+        $countSql .= $fliterStr;
+
+        $countResult = mysqli_query($conn, $countSql);
+        $countRow = mysqli_fetch_assoc($countResult);
+        $totalRecords = $countRow['total'];
+
+        // 计算总页数
+        $totalPages = ceil($totalRecords / $pageSize);
+        if ($totalPages < 1) $totalPages = 1;
+
+        // 验证当前页码
+        $page = (int)$page;
+        if ($page < 1) $page = 1;
+        if ($page > $totalPages) $page = $totalPages;
+
+        // 计算起始记录
+        $offset = ($page - 1) * $pageSize;
+
+        // 添加分页条件
+        $sqlStr .= " LIMIT $offset, $pageSize";
+
+        $result = mysqli_query($conn, $sqlStr);
+
+        if (mysqli_num_rows($result) > 0) {
+            $tempNum = ($page - 1) * $pageSize;
+            while ($row = mysqli_fetch_assoc($result)) {
+                $tempNum++;
+                ?>
+                <div class="tline">
+                    <div class="col2"><?= $tempNum ?></div>
+                    <div class="col3 slidepanel"><?= htmlspecialcharsFix($row['order_code']) ?></div>
+                    <div class="col4"><?= htmlspecialcharsFix($row['cs_code']) ?></div>
+                    <div class="col5"><?= htmlspecialcharsFix($row['cs_company']) ?></div>
+                    <div class="col6"><?= htmlspecialcharsFix($row['contact_name']) ?></div>
+                    <div class="col7"><?= date('Y-m-d', strtotime($row['order_date'])) ?></div>
+                    <div class="col9"><?= number_format($row['total_amount'], 2) ?></div>
+                    <div class="col10">
+                        <a href="order_edit.php?id=<?= $row['id'] ?>&keys=<?= $keys ?>&page=<?= $page ?>" class="ico_edit ico">修改</a>
+                        <a href="order_details.php?id=<?= $row['id'] ?>" class="ico_view ico">查看详情</a>
+                    </div>
+                </div>
+                <div class="notepanel clear">
+                    <div class="noteItem">订单详情</div>
+                    <div class="lx">
+                        <div class="price-details">
+                            <div><strong>小计:</strong> <?= number_format($row['subtotal'], 2) ?></div>
+                            <div><strong>折扣金额:</strong> <?= number_format($row['discount_amount'], 2) ?></div>
+                            <div><strong>总金额:</strong> <?= number_format($row['total_amount'], 2) ?></div>
+                        </div>
+                    </div>
+                    <div class="noteItem2">备注</div>
+                    <div class="notecontent"><?= htmlspecialcharsFix($row['notes']) ?></div>
+                </div>
+                <?php
             }
-            $countSql .= $fliterStr;
-
-            $countResult = mysqli_query($conn, $countSql);
-            $countRow = mysqli_fetch_assoc($countResult);
-            $totalRecords = $countRow['total'];
-
-            // 计算总页数
-            $totalPages = ceil($totalRecords / $pageSize);
-            if ($totalPages < 1) $totalPages = 1;
-
-            // 验证当前页码
-            $page = (int)$page;
-            if ($page < 1) $page = 1;
-            if ($page > $totalPages) $page = $totalPages;
-
-            // 计算起始记录
-            $offset = ($page - 1) * $pageSize;
-
-            // 添加分页条件
-            $sqlStr .= " LIMIT $offset, $pageSize";
-
-            $result = mysqli_query($conn, $sqlStr);
-
-            if (mysqli_num_rows($result) > 0) {
-                $tempNum = ($page - 1) * $pageSize;
-                while ($row = mysqli_fetch_assoc($result)) {
-                    $tempNum++;
-                    ?>
-                    <tr>
-                        <td><?= $tempNum ?></td>
-                        <td><?= htmlspecialcharsFix($row['order_code']) ?></td>
-                        <td><?= htmlspecialcharsFix($row['cs_company']) ?></td>
-                        <td><?= htmlspecialcharsFix($row['contact_name']) ?></td>
-                        <td><?= date('Y-m-d', strtotime($row['order_date'])) ?></td>
-                        <td>
-                            <?php
-                            $statusMap = [
-                                0 => '已取消',
-                                1 => '待确认',
-                                2 => '已确认',
-                                3 => '生产中',
-                                4 => '已发货',
-                                5 => '已完成'
-                            ];
-                            echo '<span class="status-badge status-' . $row['order_status'] . '">' .
-                                 $statusMap[$row['order_status']] . '</span>';
-                            ?>
-                        </td>
-                        <td>
-                            <?php
-                            $paymentMap = [
-                                0 => '未付款',
-                                1 => '部分付款',
-                                2 => '已付清'
-                            ];
-                            echo '<span class="payment-badge payment-' . $row['payment_status'] . '">' .
-                                 $paymentMap[$row['payment_status']] . '</span>';
-                            ?>
-                        </td>
-                        <td><?= number_format($row['total_amount'], 2) . ' ' . $row['currency'] ?></td>
-                        <td>
-                            <a href="order_edit.php?id=<?= $row['id'] ?>&keys=<?= $keys ?>&page=<?= $page ?>" class="ico_edit ico">修改</a>
-                            <a href="order_details.php?id=<?= $row['id'] ?>" class="ico_view ico">查看详情</a>
-                        </td>
-                    </tr>
-                    <?php
-                }
+        } else {
+            if (empty($keys) && empty($fliterStr)) {
+                echo '<div class="tline"><div align="center" colspan="9">当前暂无订单记录</div></div>';
             } else {
-                if (empty($keys) && empty($fliterStr)) {
-                    echo '<tr><td colspan="9" align="center">当前暂无订单记录</td></tr>';
-                } else {
-                    echo '<tr><td colspan="9" align="center"><a href="?">没有找到匹配的订单记录,点击返回</a></td></tr>';
-                }
+                echo '<div class="tline"><div align="center" colspan="9"><a href="?">没有找到匹配的订单记录,点击返回</a></div></div>';
             }
-            ?>
-        </tbody>
-    </table>
+        }
+        ?>
 
-    <div class="pagination">
-        <?php
-        if ($totalPages > 1) {
-            $pageName = "?Keys=$keys$urlStr&";
-            $pageLen = 3;
+        <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 ($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) {
+                if ($pageLen * 2 + 1 >= $totalPages) {
                     $startPage = 1;
-                    $endPage = $pageLen * 2 + 1;
-                } else {
-                    $startPage = $page - $pageLen;
-                    $endPage = $page + $pageLen;
-                }
-                if ($page + $pageLen > $totalPages) {
-                    $startPage = $totalPages - $pageLen * 2;
                     $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>";
+                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>";
+                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>";
                 }
-                echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
-                echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
             }
-        }
-        ?>
+            ?>
+        </div>
     </div>
 
     <script>

+ 85 - 59
order_add.php

@@ -105,16 +105,14 @@ $hrefstr = "keys=$keys&Page=$page";
             <tr>
                 <th width="8%">客户选择</th>
                 <td>
-                    <select id="customer_id" name="customer_id" onchange="loadCustomerContacts(this.value)">
-                        <option value="0">请选择客户</option>
-                        <?php
-                        $customerSql = "SELECT id, cs_company FROM customer WHERE cs_belong = " . $_SESSION['employee_id'] . " ORDER BY cs_company";
-                        $customerResult = mysqli_query($conn, $customerSql);
-                        while ($customerRow = mysqli_fetch_assoc($customerResult)) {
-                            echo "<option value=\"{$customerRow['id']}\">" . htmlspecialcharsFix($customerRow['cs_company']) . "</option>";
-                        }
-                        ?>
-                    </select>
+                    <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">
+                        <div class="selected-customer-info" style="margin-top: 5px; font-weight: bold;"></div>
+                    </div>
                 </td>
             </tr>
             <tr>
@@ -129,47 +127,6 @@ $hrefstr = "keys=$keys&Page=$page";
                 <th width="8%">订单日期</th>
                 <td><input type="date" id="order_date" name="order_date" value="<?= date('Y-m-d') ?>" class="txt1" /></td>
             </tr>
-            <tr>
-                <th width="8%">预计交付日期</th>
-                <td><input type="date" id="delivery_date" name="delivery_date" value="" class="txt1" /></td>
-            </tr>
-            <tr>
-                <th width="8%">实际交付日期</th>
-                <td><input type="date" id="actual_delivery_date" name="actual_delivery_date" value="" class="txt1" /></td>
-            </tr>
-            <tr>
-                <th width="8%">订单状态</th>
-                <td>
-                    <select id="order_status" name="order_status">
-                        <option value="0">已取消</option>
-                        <option value="1" selected>待确认</option>
-                        <option value="2">已确认</option>
-                        <option value="3">生产中</option>
-                        <option value="4">已发货</option>
-                        <option value="5">已完成</option>
-                    </select>
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">付款状态</th>
-                <td>
-                    <select id="payment_status" name="payment_status">
-                        <option value="0" selected>未付款</option>
-                        <option value="1">部分付款</option>
-                        <option value="2">已付清</option>
-                    </select>
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">币种</th>
-                <td>
-                    <select id="currency" name="currency">
-                        <option value="CNY" selected>人民币 (CNY)</option>
-<!--                        <option value="USD">美元 (USD)</option>-->
-<!--                        <option value="EUR">欧元 (EUR)</option>-->
-                    </select>
-                </td>
-            </tr>
             <tr>
                 <th width="8%" valign="top">产品列表</th>
                 <td>
@@ -229,12 +186,6 @@ $hrefstr = "keys=$keys&Page=$page";
                     <textarea name="notes" rows="3" style="width: 90%;"></textarea>
                 </td>
             </tr>
-            <tr>
-                <th width="8%">内部备注</th>
-                <td>
-                    <textarea name="internal_notes" rows="3" style="width: 90%;"></textarea>
-                </td>
-            </tr>
             <tr>
                 <th></th>
                 <td>
@@ -268,6 +219,71 @@ $hrefstr = "keys=$keys&Page=$page";
                     alert('订单至少需要一个产品');
                 }
             });
+            
+            // 客户搜索功能
+            var customerSearchTimeout = null;
+            $(document).on('keyup', '.customer-search', function() {
+                var $this = $(this);
+                var searchTerm = $this.val().trim();
+                var customerList = $('.customerlist');
+                
+                // 清除之前的超时
+                clearTimeout(customerSearchTimeout);
+                
+                // 隐藏之前的结果
+                customerList.hide();
+                
+                // 如果搜索词少于2个字符,不执行搜索
+                if (searchTerm.length < 2) {
+                    return;
+                }
+                
+                // 设置一个300毫秒的超时,以减少请求数量
+                customerSearchTimeout = setTimeout(function() {
+                    $.ajax({
+                        url: 'get_customer_search.php',
+                        type: 'GET',
+                        data: {search: searchTerm},
+                        dataType: 'json',
+                        success: function(data) {
+                            var ul = customerList.find('ul');
+                            ul.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;
+                                    }
+                                    ul.append('<li data-id="' + customer.id + '" data-code="' + (customer.cs_code || '') + '">' + 
+                                              displayText + '</li>');
+                                });
+                                customerList.show();
+                            }
+                        },
+                        error: function() {
+                            console.log('搜索客户失败,请重试');
+                        }
+                    });
+                }, 300);
+            });
+            
+            // 点击选择客户
+            $(document).on('click', '.customerlist li', function() {
+                var $this = $(this);
+                var customerId = $this.data('id');
+                var customerName = $this.text();
+                var customerCode = $this.data('code') || '';
+                
+                // 设置选中的客户ID和名称
+                $('#customer_id').val(customerId);
+                $('.customer-search').val(customerName);
+                $('.selected-customer-info').text(customerName);
+                $('.customerlist').hide();
+                
+                // 加载客户联系人
+                loadCustomerContacts(customerId);
+            });
 
             // 实时产品搜索功能 - 使用防抖动以减少请求数量
             var searchTimeout = null;
@@ -347,11 +363,14 @@ $hrefstr = "keys=$keys&Page=$page";
                 getProductInfo(productId, row);
             });
             
-            // 点击其他地方隐藏产品列表
+            // 点击其他地方隐藏下拉列表
             $(document).on('click', function(e) {
                 if (!$(e.target).closest('.productinput').length) {
                     $('.productlist').hide();
                 }
+                if (!$(e.target).closest('.customerinput').length) {
+                    $('.customerlist').hide();
+                }
             });
         });
 
@@ -479,6 +498,7 @@ $hrefstr = "keys=$keys&Page=$page";
         function validateOrderForm() {
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
+            var customerName = $('.customer-search').val();
             var hasProducts = false;
 
             $('.product-id-input').each(function() {
@@ -496,7 +516,13 @@ $hrefstr = "keys=$keys&Page=$page";
 
             if (!customerId || customerId == '0') {
                 alert('请选择客户');
-                $('#customer_id').focus();
+                $('.customer-search').focus();
+                return false;
+            }
+            
+            if (!customerName) {
+                alert('请输入并选择有效的客户');
+                $('.customer-search').focus();
                 return false;
             }
 

+ 16 - 79
order_details.php

@@ -8,7 +8,7 @@ $id = $_GET['id'] ?? '';
 if (!empty($id) && is_numeric($id)) {
     // 获取订单基本信息
     $employee_id = $_SESSION['employee_id'];
-    $sql = "SELECT o.*, c.cs_company, cc.contact_name, e.employee_name 
+    $sql = "SELECT o.*, c.cs_company, cc.contact_name, e.em_user as employee_name 
             FROM orders o 
             LEFT JOIN customer c ON o.customer_id = c.id 
             LEFT JOIN customer_contact cc ON o.contact_id = cc.id 
@@ -91,30 +91,13 @@ if (!empty($id) && is_numeric($id)) {
         .products-table th {
             background-color: #f2f2f2;
         }
-        .status-badge {
-            display: inline-block;
-            padding: 3px 8px;
-            border-radius: 3px;
-            font-size: 12px;
-            color: white;
+        /* 移除徽章式样,使用普通文本显示 */
+        .order-status {
+            font-weight: bold;
         }
-        .status-0 { background-color: #999; }
-        .status-1 { background-color: #5bc0de; }
-        .status-2 { background-color: #337ab7; }
-        .status-3 { background-color: #f0ad4e; }
-        .status-4 { background-color: #5cb85c; }
-        .status-5 { background-color: #28a745; }
-
-        .payment-badge {
-            display: inline-block;
-            padding: 3px 8px;
-            border-radius: 3px;
-            font-size: 12px;
-            color: white;
+        .payment-status {
+            font-weight: bold;
         }
-        .payment-0 { background-color: #d9534f; }
-        .payment-1 { background-color: #f0ad4e; }
-        .payment-2 { background-color: #5cb85c; }
 
         .notes-section {
             border: 1px solid #ddd;
@@ -151,42 +134,6 @@ if (!empty($id) && is_numeric($id)) {
         <div class="info-row">
             <span class="info-label">订单日期:</span> <?= date('Y-m-d', strtotime($order['order_date'])) ?>
         </div>
-        <div class="info-row">
-            <span class="info-label">预计交付日期:</span> <?= $order['delivery_date'] ? date('Y-m-d', strtotime($order['delivery_date'])) : '未设置' ?>
-        </div>
-        <div class="info-row">
-            <span class="info-label">实际交付日期:</span> <?= $order['actual_delivery_date'] ? date('Y-m-d', strtotime($order['actual_delivery_date'])) : '未完成' ?>
-        </div>
-        <div class="info-row">
-            <span class="info-label">订单状态:</span>
-            <?php
-            $statusMap = [
-                0 => '已取消',
-                1 => '待确认',
-                2 => '已确认',
-                3 => '生产中',
-                4 => '已发货',
-                5 => '已完成'
-            ];
-            echo '<span class="status-badge status-' . $order['order_status'] . '">' .
-                $statusMap[$order['order_status']] . '</span>';
-            ?>
-        </div>
-        <div class="info-row">
-            <span class="info-label">付款状态:</span>
-            <?php
-            $paymentMap = [
-                0 => '未付款',
-                1 => '部分付款',
-                2 => '已付清'
-            ];
-            echo '<span class="payment-badge payment-' . $order['payment_status'] . '">' .
-                $paymentMap[$order['payment_status']] . '</span>';
-            ?>
-        </div>
-        <div class="info-row">
-            <span class="info-label">币种:</span> <?= $order['currency'] ?>
-        </div>
         <div class="info-row">
             <span class="info-label">创建时间:</span> <?= $order['created_at'] ?>
         </div>
@@ -237,35 +184,25 @@ if (!empty($id) && is_numeric($id)) {
 
     <div class="total-section">
         <div>
-            <strong>订单小计:</strong> <?= number_format($order['subtotal'], 2) ?> <?= $order['currency'] ?>
-        </div>
-        <div>
-            <strong>运费:</strong> <?= number_format($order['shipping_fee'], 2) ?> <?= $order['currency'] ?>
+            <strong>订单小计:</strong> <?= number_format($order['subtotal'], 2) ?>
         </div>
+        <?php if(isset($order['discount_amount']) && $order['discount_amount'] > 0): ?>
         <div>
-            <strong>订单折扣:</strong> <?= number_format($order['discount_amount'], 2) ?> <?= $order['currency'] ?>
+            <strong>订单折扣:</strong> <?= number_format($order['discount_amount'], 2) ?>
         </div>
+        <?php endif; ?>
         <div style="font-size: 1.2em; margin-top: 5px;">
-            <strong>订单总额:</strong> <?= number_format($order['total_amount'], 2) ?> <?= $order['currency'] ?>
+            <strong>订单总额:</strong> <?= number_format($order['total_amount'], 2) ?>
         </div>
     </div>
 
-    <?php if (!empty($order['notes']) || !empty($order['internal_notes'])): ?>
+    <?php if (!empty($order['notes'])): ?>
         <div class="notes-section">
             <h2>备注信息</h2>
-            <?php if (!empty($order['notes'])): ?>
-                <div>
-                    <strong>订单备注:</strong>
-                    <p><?= nl2br(htmlspecialcharsFix($order['notes'])) ?></p>
-                </div>
-            <?php endif; ?>
-
-            <?php if (!empty($order['internal_notes'])): ?>
-                <div>
-                    <strong>内部备注:</strong>
-                    <p><?= nl2br(htmlspecialcharsFix($order['internal_notes'])) ?></p>
-                </div>
-            <?php endif; ?>
+            <div>
+                <strong>订单备注:</strong>
+                <p><?= nl2br(htmlspecialcharsFix($order['notes'])) ?></p>
+            </div>
         </div>
     <?php endif; ?>
 </div>

+ 247 - 123
order_edit.php

@@ -12,7 +12,7 @@ $hrefstr = "keys=$keys&Page=$page";
 if (!empty($id) && is_numeric($id)) {
     // 获取订单基本信息
     $employee_id = $_SESSION['employee_id'];
-    $sql = "SELECT o.*, c.cs_company, cc.contact_name 
+    $sql = "SELECT o.*, c.cs_company, c.cs_code, cc.contact_name 
             FROM orders o 
             LEFT JOIN customer c ON o.customer_id = c.id 
             LEFT JOIN customer_contact cc ON o.contact_id = cc.id 
@@ -93,6 +93,52 @@ if (!empty($id) && is_numeric($id)) {
         #product-container {
             margin-bottom: 20px;
         }
+        .productlist {
+            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);
+        }
+        .productlist ul {
+            list-style: none;
+            padding: 0;
+            margin: 0;
+        }
+        .productlist li {
+            padding: 8px 10px;
+            cursor: pointer;
+            border-bottom: 1px solid #eee;
+        }
+        .productlist li:hover {
+            background-color: #f5f5f5;
+        }
+        .productinput {
+            position: relative;
+        }
+        .customerlist ul {
+            list-style: none;
+            padding: 0;
+            margin: 0;
+        }
+        .customerlist li {
+            padding: 8px 10px;
+            cursor: pointer;
+            border-bottom: 1px solid #eee;
+        }
+        .customerlist li:hover {
+            background-color: #f5f5f5;
+        }
+        .productlist li .category-tag {
+            color: #777;
+            font-size: 12px;
+            font-style: italic;
+            margin-left: 5px;
+        }
     </style>
 </head>
 <body>
@@ -110,17 +156,14 @@ if (!empty($id) && is_numeric($id)) {
             <tr>
                 <th width="8%">客户选择</th>
                 <td>
-                    <select id="customer_id" name="customer_id" onchange="loadCustomerContacts(this.value)">
-                        <option value="0">请选择客户</option>
-                        <?php
-                        $customerSql = "SELECT id, cs_company FROM customer WHERE cs_belong = " . $_SESSION['employee_id'] . " ORDER BY cs_company";
-                        $customerResult = mysqli_query($conn, $customerSql);
-                        while ($customerRow = mysqli_fetch_assoc($customerResult)) {
-                            $selected = ($order['customer_id'] == $customerRow['id']) ? ' selected' : '';
-                            echo "<option value=\"{$customerRow['id']}\"$selected>" . htmlspecialcharsFix($customerRow['cs_company']) . "</option>";
-                        }
-                        ?>
-                    </select>
+                    <div style="display: inline-block; width: 60%;" class="customerinput">
+                        <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>
                 </td>
             </tr>
             <tr>
@@ -147,51 +190,6 @@ if (!empty($id) && is_numeric($id)) {
                     <input type="date" id="order_date" name="order_date" value="<?= substr($order['order_date'], 0, 10) ?>" class="txt1" />
                 </td>
             </tr>
-            <tr>
-                <th width="8%">预计交付日期</th>
-                <td>
-                    <input type="date" id="delivery_date" name="delivery_date" value="<?= $order['delivery_date'] ? substr($order['delivery_date'], 0, 10) : '' ?>" class="txt1" />
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">实际交付日期</th>
-                <td>
-                    <input type="date" id="actual_delivery_date" name="actual_delivery_date" value="<?= $order['actual_delivery_date'] ? substr($order['actual_delivery_date'], 0, 10) : '' ?>" class="txt1" />
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">订单状态</th>
-                <td>
-                    <select id="order_status" name="order_status">
-                        <option value="0" <?= $order['order_status'] == 0 ? 'selected' : '' ?>>已取消</option>
-                        <option value="1" <?= $order['order_status'] == 1 ? 'selected' : '' ?>>待确认</option>
-                        <option value="2" <?= $order['order_status'] == 2 ? 'selected' : '' ?>>已确认</option>
-                        <option value="3" <?= $order['order_status'] == 3 ? 'selected' : '' ?>>生产中</option>
-                        <option value="4" <?= $order['order_status'] == 4 ? 'selected' : '' ?>>已发货</option>
-                        <option value="5" <?= $order['order_status'] == 5 ? 'selected' : '' ?>>已完成</option>
-                    </select>
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">付款状态</th>
-                <td>
-                    <select id="payment_status" name="payment_status">
-                        <option value="0" <?= $order['payment_status'] == 0 ? 'selected' : '' ?>>未付款</option>
-                        <option value="1" <?= $order['payment_status'] == 1 ? 'selected' : '' ?>>部分付款</option>
-                        <option value="2" <?= $order['payment_status'] == 2 ? 'selected' : '' ?>>已付清</option>
-                    </select>
-                </td>
-            </tr>
-            <tr>
-                <th width="8%">币种</th>
-                <td>
-                    <select id="currency" name="currency">
-                        <option value="CNY" <?= $order['currency'] == 'CNY' ? 'selected' : '' ?>>人民币 (CNY)</option>
-                        <option value="USD" <?= $order['currency'] == 'USD' ? 'selected' : '' ?>>美元 (USD)</option>
-                        <option value="EUR" <?= $order['currency'] == 'EUR' ? 'selected' : '' ?>>欧元 (EUR)</option>
-                    </select>
-                </td>
-            </tr>
             <tr>
                 <th width="8%" valign="top">产品列表</th>
                 <td>
@@ -202,17 +200,12 @@ if (!empty($id) && is_numeric($id)) {
                                 <span class="delete-product">×</span>
                                 <div>
                                     <label>产品:</label>
-                                    <select name="items[<?= $index ?>][product_id]" class="product-select" onchange="updateProductInfo(this)">
-                                        <option value="">请选择产品</option>
-                                        <?php
-                                        $productSql = "SELECT id, ProductName FROM products ORDER BY ProductName";
-                                        $productResult = mysqli_query($conn, $productSql);
-                                        while ($productRow = mysqli_fetch_assoc($productResult)) {
-                                            $selected = ($item['product_id'] == $productRow['id']) ? ' selected' : '';
-                                            echo "<option value=\"{$productRow['id']}\"$selected>" . htmlspecialcharsFix($productRow['ProductName']) . "</option>";
-                                        }
-                                        ?>
-                                    </select>
+                                    <div style="display: inline-block; width: 60%;" class="productinput">
+                                        <input type="text" class="product-search fastsearch" placeholder="输入产品名称搜索..." style="width: 100%;" value="<?= htmlspecialcharsFix($item['ProductName'] ?? '') ?>">
+                                        <div class="productlist"><ul></ul></div>
+                                        <input type="hidden" name="items[<?= $index ?>][product_id]" class="product-id-input" value="<?= $item['product_id'] ?>">
+                                        <div class="selected-product-info" style="margin-top: 5px; font-weight: bold;"><?= htmlspecialcharsFix($item['ProductName'] ?? '') ?></div>
+                                    </div>
                                 </div>
                                 <div style="margin-top: 5px;">
                                     <label>数量:</label>
@@ -247,10 +240,6 @@ if (!empty($id) && is_numeric($id)) {
                             <span id="subtotal"><?= number_format($order['subtotal'], 2) ?></span>
                             <input type="hidden" name="subtotal" id="subtotal-input" value="<?= $order['subtotal'] ?>">
                         </div>
-                        <div style="margin-top: 5px;">
-                            <label>运费:</label>
-                            <input type="number" step="0.01" name="shipping_fee" id="shipping-fee" value="<?= $order['shipping_fee'] ?>" onchange="calculateOrderTotal()">
-                        </div>
                         <div style="margin-top: 5px;">
                             <label>订单折扣:</label>
                             <input type="number" step="0.01" name="discount_amount" id="order-discount" value="<?= $order['discount_amount'] ?>" onchange="calculateOrderTotal()">
@@ -269,12 +258,6 @@ if (!empty($id) && is_numeric($id)) {
                     <textarea name="notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['notes']) ?></textarea>
                 </td>
             </tr>
-            <tr>
-                <th width="8%">内部备注</th>
-                <td>
-                    <textarea name="internal_notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['internal_notes']) ?></textarea>
-                </td>
-            </tr>
             <tr>
                 <th></th>
                 <td>
@@ -309,6 +292,159 @@ if (!empty($id) && is_numeric($id)) {
                 }
             });
 
+            // 客户搜索功能
+            var customerSearchTimeout = null;
+            $(document).on('keyup', '.customer-search', function() {
+                var $this = $(this);
+                var searchTerm = $this.val().trim();
+                var customerList = $('.customerlist');
+                
+                // 清除之前的超时
+                clearTimeout(customerSearchTimeout);
+                
+                // 隐藏之前的结果
+                customerList.hide();
+                
+                // 如果搜索词少于2个字符,不执行搜索
+                if (searchTerm.length < 2) {
+                    return;
+                }
+                
+                // 设置一个300毫秒的超时,以减少请求数量
+                customerSearchTimeout = setTimeout(function() {
+                    $.ajax({
+                        url: 'get_customer_search.php',
+                        type: 'GET',
+                        data: {search: searchTerm},
+                        dataType: 'json',
+                        success: function(data) {
+                            var ul = customerList.find('ul');
+                            ul.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;
+                                    }
+                                    ul.append('<li data-id="' + customer.id + '" data-code="' + (customer.cs_code || '') + '">' + 
+                                              displayText + '</li>');
+                                });
+                                customerList.show();
+                            }
+                        },
+                        error: function() {
+                            console.log('搜索客户失败,请重试');
+                        }
+                    });
+                }, 300);
+            });
+            
+            // 点击选择客户
+            $(document).on('click', '.customerlist li', function() {
+                var $this = $(this);
+                var customerId = $this.data('id');
+                var customerName = $this.text();
+                var customerCode = $this.data('code') || '';
+                
+                // 设置选中的客户ID和名称
+                $('#customer_id').val(customerId);
+                $('.customer-search').val(customerName);
+                $('.selected-customer-info').text(customerName);
+                $('.customerlist').hide();
+                
+                // 加载客户联系人
+                loadCustomerContacts(customerId);
+            });
+            
+            // 实时产品搜索功能 - 使用防抖动以减少请求数量
+            var searchTimeout = null;
+            $(document).on('keyup', '.product-search', function() {
+                var $this = $(this);
+                var row = $this.closest('.product-row');
+                var searchTerm = $this.val().trim();
+                var productList = row.find('.productlist');
+                
+                // 清除之前的超时
+                clearTimeout(searchTimeout);
+                
+                // 隐藏之前的结果
+                productList.hide();
+                
+                // 如果搜索词少于2个字符,不执行搜索
+                if (searchTerm.length < 2) {
+                    return;
+                }
+                
+                // 设置一个300毫秒的超时,以减少请求数量
+                searchTimeout = setTimeout(function() {
+                    $.ajax({
+                        url: 'get_product_info.php',
+                        type: 'GET',
+                        data: {search: searchTerm},
+                        dataType: 'json',
+                        success: function(data) {
+                            var productList = row.find('.productlist');
+                            var ul = productList.find('ul');
+                            ul.empty();
+                            
+                            if (data && data.products && data.products.length > 0) {
+                                $.each(data.products, function(i, product) {
+                                    ul.append('<li data-id="' + product.id + '">' + 
+                                              product.ProductName + 
+                                              (product.category_name ? ' <span class="category-tag">(' + product.category_name + ')</span>' : '') + 
+                                              '</li>');
+                                });
+                                productList.show();
+                            }
+                        },
+                        error: function() {
+                            console.log('搜索产品失败,请重试');
+                        }
+                    });
+                }, 300);
+            });
+            
+            // 点击选择产品
+            $(document).on('click', '.productlist li', function() {
+                var $this = $(this);
+                var productId = $this.data('id');
+                var productName = $this.text(); // 这会包含分类名,需要清理
+                var categoryTag = $this.find('.category-tag').text();
+                
+                // 清理产品名称,移除分类信息
+                if (categoryTag) {
+                    productName = productName.replace(categoryTag, '').trim();
+                }
+                
+                var row = $this.closest('.product-row');
+                
+                // 设置选中的产品ID和名称
+                row.find('.product-id-input').val(productId);
+                row.find('.product-search').val(productName);
+                
+                // 显示包含分类的完整产品信息
+                var displayName = productName;
+                if (categoryTag) {
+                    displayName += ' <span class="category-tag">' + categoryTag + '</span>';
+                }
+                row.find('.selected-product-info').html(displayName);
+                row.find('.productlist').hide();
+                
+                // 获取产品信息
+                getProductInfo(productId, row);
+            });
+            
+            // 点击其他地方隐藏下拉列表
+            $(document).on('click', function(e) {
+                if (!$(e.target).closest('.productinput').length) {
+                    $('.productlist').hide();
+                }
+                if (!$(e.target).closest('.customerinput').length) {
+                    $('.customerlist').hide();
+                }
+            });
+
             // 更新折扣率和折扣金额之间的关系
             $(document).on('change', '.discount-percent-input', function() {
                 var row = $(this).closest('.product-row');
@@ -345,10 +481,12 @@ if (!empty($id) && is_numeric($id)) {
                 <span class="delete-product">×</span>
                 <div>
                     <label>产品:</label>
-                    <select name="items[${productIndex}][product_id]" class="product-select" onchange="updateProductInfo(this)">
-                        <option value="">请选择产品</option>
-                        ${getProductOptions()}
-                    </select>
+                    <div style="display: inline-block; width: 60%;" class="productinput">
+                        <input type="text" class="product-search fastsearch" placeholder="输入产品名称搜索..." style="width: 100%;">
+                        <div class="productlist"><ul></ul></div>
+                        <input type="hidden" name="items[${productIndex}][product_id]" class="product-id-input" value="">
+                        <div class="selected-product-info" style="margin-top: 5px; font-weight: bold;"></div>
+                    </div>
                 </div>
                 <div style="margin-top: 5px;">
                     <label>数量:</label>
@@ -381,18 +519,6 @@ if (!empty($id) && is_numeric($id)) {
             productIndex++;
         }
 
-        function getProductOptions() {
-            var options = '';
-            <?php
-            $productSql = "SELECT id, ProductName FROM products ORDER BY ProductName";
-            $productResult = mysqli_query($conn, $productSql);
-            while ($productRow = mysqli_fetch_assoc($productResult)) {
-                echo "options += '<option value=\"{$productRow['id']}\">" . addslashes(htmlspecialcharsFix($productRow['ProductName'])) . "</option>';\n";
-            }
-            ?>
-            return options;
-        }
-
         function reindexProductRows() {
             $('.product-row').each(function(index) {
                 $(this).attr('data-index', index);
@@ -407,30 +533,22 @@ if (!empty($id) && is_numeric($id)) {
             productIndex = $('.product-row').length;
         }
 
-        function updateProductInfo(selectElement) {
-            var productId = $(selectElement).val();
-            var row = $(selectElement).closest('.product-row');
-
-            if (productId) {
-                // 使用AJAX获取产品信息
-                $.ajax({
-                    url: 'get_product_info.php',
-                    type: 'GET',
-                    data: {id: productId},
-                    dataType: 'json',
-                    success: function(data) {
-                        if (data) {
-                            row.find('.unit-input').val(data.unit);
-                            row.find('.price-input').val(data.price);
-                            calculateItemTotal(selectElement);
-                        }
+        function getProductInfo(productId, row) {
+            if (!productId) return;
+            
+            $.ajax({
+                url: 'get_product_info.php',
+                type: 'GET',
+                data: {id: productId},
+                dataType: 'json',
+                success: function(data) {
+                    if (data) {
+                        row.find('.unit-input').val(data.unit);
+                        row.find('.price-input').val(data.price);
+                        calculateItemTotal(row.find('.price-input')[0]);
                     }
-                });
-            } else {
-                row.find('.unit-input').val('');
-                row.find('.price-input').val('0.00');
-                calculateItemTotal(selectElement);
-            }
+                }
+            });
         }
 
         function calculateItemTotal(element) {
@@ -454,9 +572,8 @@ if (!empty($id) && is_numeric($id)) {
                 subtotal += parseFloat($(this).val()) || 0;
             });
 
-            var shippingFee = parseFloat($('#shipping-fee').val()) || 0;
             var orderDiscount = parseFloat($('#order-discount').val()) || 0;
-            var total = subtotal + shippingFee - orderDiscount;
+            var total = subtotal - orderDiscount;
 
             if (total < 0) total = 0;
 
@@ -491,9 +608,10 @@ if (!empty($id) && is_numeric($id)) {
         function validateOrderForm() {
             var orderCode = $('#order_code').val();
             var customerId = $('#customer_id').val();
+            var customerName = $('.customer-search').val();
             var hasProducts = false;
 
-            $('.product-select').each(function() {
+            $('.product-id-input').each(function() {
                 if ($(this).val()) {
                     hasProducts = true;
                     return false; // break the loop
@@ -506,14 +624,20 @@ if (!empty($id) && is_numeric($id)) {
                 return false;
             }
 
-            if (!customerId || customerId == '0') {
+            if (!customerId || customerId <= 0) {
                 alert('请选择客户');
-                $('#customer_id').focus();
+                $('.customer-search').focus();
+                return false;
+            }
+
+            if (!customerName) {
+                alert('客户名称不能为空');
+                $('.customer-search').focus();
                 return false;
             }
 
             if (!hasProducts) {
-                alert('请至少选择一个产品');
+                alert('订单必须包含至少一个产品');
                 return false;
             }
 

+ 8 - 7
order_save.php

@@ -14,20 +14,21 @@ $customer_id = (int)$_POST['customer_id'];
 $contact_id = !empty($_POST['contact_id']) ? (int)$_POST['contact_id'] : "NULL";
 $employee_id = $_SESSION['employee_id'];
 $order_date = mysqli_real_escape_string($conn, $_POST['order_date']);
-$delivery_date = !empty($_POST['delivery_date']) ? "'" . mysqli_real_escape_string($conn, $_POST['delivery_date']) . "'" : "NULL";
-$actual_delivery_date = !empty($_POST['actual_delivery_date']) ? "'" . mysqli_real_escape_string($conn, $_POST['actual_delivery_date']) . "'" : "NULL";
-$order_status = (int)$_POST['order_status'];
-$payment_status = (int)$_POST['payment_status'];
-$currency = mysqli_real_escape_string($conn, htmlspecialchars($_POST['currency'], ENT_QUOTES, 'UTF-8'));
+
+// 设置已删除字段的默认值
+$delivery_date = "NULL";
+$actual_delivery_date = "NULL";
+$order_status = 1; // 默认为"待确认"
+$payment_status = 0; // 默认为"未付款"
+$currency = "CNY"; // 默认为人民币
 $notes = mysqli_real_escape_string($conn, htmlspecialchars($_POST['notes'], ENT_QUOTES, 'UTF-8'));
-$internal_notes = mysqli_real_escape_string($conn, htmlspecialchars($_POST['internal_notes'], ENT_QUOTES, 'UTF-8'));
+$internal_notes = ""; // 默认为空
 
 // 获取订单项信息
 $items = $_POST['items'] ?? [];
 
 // 计算订单总额
 $subtotal = 0;
-$shipping_fee = !empty($_POST['shipping_fee']) ? (float)$_POST['shipping_fee'] : 0;
 $discount_amount = !empty($_POST['discount_amount']) ? (float)$_POST['discount_amount'] : 0;
 
 foreach ($items as $item) {

+ 1 - 1
panel.php

@@ -35,7 +35,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="../order.php" target="contentFrame">订单录入</a></dt>
+            <dt><a href="../order.php" target="contentFrame">订单管理</a></dt>
             <dt id="myCustomer" class="subnav">我的客户
                 <div class="list-wraper">
                     <a href="../customers.php" target="contentFrame">全部客户  (<?= $_SESSION['t'] ?>)</a>