|
@@ -12,7 +12,7 @@ $hrefstr = "keys=$keys&Page=$page";
|
|
if (!empty($id) && is_numeric($id)) {
|
|
if (!empty($id) && is_numeric($id)) {
|
|
// 获取订单基本信息
|
|
// 获取订单基本信息
|
|
$employee_id = $_SESSION['employee_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
|
|
FROM orders o
|
|
LEFT JOIN customer c ON o.customer_id = c.id
|
|
LEFT JOIN customer c ON o.customer_id = c.id
|
|
LEFT JOIN customer_contact cc ON o.contact_id = cc.id
|
|
LEFT JOIN customer_contact cc ON o.contact_id = cc.id
|
|
@@ -93,6 +93,52 @@ if (!empty($id) && is_numeric($id)) {
|
|
#product-container {
|
|
#product-container {
|
|
margin-bottom: 20px;
|
|
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>
|
|
</style>
|
|
</head>
|
|
</head>
|
|
<body>
|
|
<body>
|
|
@@ -110,17 +156,14 @@ if (!empty($id) && is_numeric($id)) {
|
|
<tr>
|
|
<tr>
|
|
<th width="8%">客户选择</th>
|
|
<th width="8%">客户选择</th>
|
|
<td>
|
|
<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>
|
|
</td>
|
|
</tr>
|
|
</tr>
|
|
<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" />
|
|
<input type="date" id="order_date" name="order_date" value="<?= substr($order['order_date'], 0, 10) ?>" class="txt1" />
|
|
</td>
|
|
</td>
|
|
</tr>
|
|
</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>
|
|
<tr>
|
|
<th width="8%" valign="top">产品列表</th>
|
|
<th width="8%" valign="top">产品列表</th>
|
|
<td>
|
|
<td>
|
|
@@ -202,17 +200,12 @@ if (!empty($id) && is_numeric($id)) {
|
|
<span class="delete-product">×</span>
|
|
<span class="delete-product">×</span>
|
|
<div>
|
|
<div>
|
|
<label>产品:</label>
|
|
<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>
|
|
<div style="margin-top: 5px;">
|
|
<div style="margin-top: 5px;">
|
|
<label>数量:</label>
|
|
<label>数量:</label>
|
|
@@ -247,10 +240,6 @@ if (!empty($id) && is_numeric($id)) {
|
|
<span id="subtotal"><?= number_format($order['subtotal'], 2) ?></span>
|
|
<span id="subtotal"><?= number_format($order['subtotal'], 2) ?></span>
|
|
<input type="hidden" name="subtotal" id="subtotal-input" value="<?= $order['subtotal'] ?>">
|
|
<input type="hidden" name="subtotal" id="subtotal-input" value="<?= $order['subtotal'] ?>">
|
|
</div>
|
|
</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;">
|
|
<div style="margin-top: 5px;">
|
|
<label>订单折扣:</label>
|
|
<label>订单折扣:</label>
|
|
<input type="number" step="0.01" name="discount_amount" id="order-discount" value="<?= $order['discount_amount'] ?>" onchange="calculateOrderTotal()">
|
|
<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>
|
|
<textarea name="notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['notes']) ?></textarea>
|
|
</td>
|
|
</td>
|
|
</tr>
|
|
</tr>
|
|
- <tr>
|
|
|
|
- <th width="8%">内部备注</th>
|
|
|
|
- <td>
|
|
|
|
- <textarea name="internal_notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['internal_notes']) ?></textarea>
|
|
|
|
- </td>
|
|
|
|
- </tr>
|
|
|
|
<tr>
|
|
<tr>
|
|
<th></th>
|
|
<th></th>
|
|
<td>
|
|
<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() {
|
|
$(document).on('change', '.discount-percent-input', function() {
|
|
var row = $(this).closest('.product-row');
|
|
var row = $(this).closest('.product-row');
|
|
@@ -345,10 +481,12 @@ if (!empty($id) && is_numeric($id)) {
|
|
<span class="delete-product">×</span>
|
|
<span class="delete-product">×</span>
|
|
<div>
|
|
<div>
|
|
<label>产品:</label>
|
|
<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>
|
|
<div style="margin-top: 5px;">
|
|
<div style="margin-top: 5px;">
|
|
<label>数量:</label>
|
|
<label>数量:</label>
|
|
@@ -381,18 +519,6 @@ if (!empty($id) && is_numeric($id)) {
|
|
productIndex++;
|
|
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() {
|
|
function reindexProductRows() {
|
|
$('.product-row').each(function(index) {
|
|
$('.product-row').each(function(index) {
|
|
$(this).attr('data-index', index);
|
|
$(this).attr('data-index', index);
|
|
@@ -407,30 +533,22 @@ if (!empty($id) && is_numeric($id)) {
|
|
productIndex = $('.product-row').length;
|
|
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) {
|
|
function calculateItemTotal(element) {
|
|
@@ -454,9 +572,8 @@ if (!empty($id) && is_numeric($id)) {
|
|
subtotal += parseFloat($(this).val()) || 0;
|
|
subtotal += parseFloat($(this).val()) || 0;
|
|
});
|
|
});
|
|
|
|
|
|
- var shippingFee = parseFloat($('#shipping-fee').val()) || 0;
|
|
|
|
var orderDiscount = parseFloat($('#order-discount').val()) || 0;
|
|
var orderDiscount = parseFloat($('#order-discount').val()) || 0;
|
|
- var total = subtotal + shippingFee - orderDiscount;
|
|
|
|
|
|
+ var total = subtotal - orderDiscount;
|
|
|
|
|
|
if (total < 0) total = 0;
|
|
if (total < 0) total = 0;
|
|
|
|
|
|
@@ -491,9 +608,10 @@ if (!empty($id) && is_numeric($id)) {
|
|
function validateOrderForm() {
|
|
function validateOrderForm() {
|
|
var orderCode = $('#order_code').val();
|
|
var orderCode = $('#order_code').val();
|
|
var customerId = $('#customer_id').val();
|
|
var customerId = $('#customer_id').val();
|
|
|
|
+ var customerName = $('.customer-search').val();
|
|
var hasProducts = false;
|
|
var hasProducts = false;
|
|
|
|
|
|
- $('.product-select').each(function() {
|
|
|
|
|
|
+ $('.product-id-input').each(function() {
|
|
if ($(this).val()) {
|
|
if ($(this).val()) {
|
|
hasProducts = true;
|
|
hasProducts = true;
|
|
return false; // break the loop
|
|
return false; // break the loop
|
|
@@ -506,14 +624,20 @@ if (!empty($id) && is_numeric($id)) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!customerId || customerId == '0') {
|
|
|
|
|
|
+ if (!customerId || customerId <= 0) {
|
|
alert('请选择客户');
|
|
alert('请选择客户');
|
|
- $('#customer_id').focus();
|
|
|
|
|
|
+ $('.customer-search').focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!customerName) {
|
|
|
|
+ alert('客户名称不能为空');
|
|
|
|
+ $('.customer-search').focus();
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
if (!hasProducts) {
|
|
if (!hasProducts) {
|
|
- alert('请至少选择一个产品');
|
|
|
|
|
|
+ alert('订单必须包含至少一个产品');
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|