order_edit.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. $id = $_GET['id'] ?? '';
  5. $page = $_GET['Page'] ?? '';
  6. $keys = urlencode($_GET['Keys'] ?? '');
  7. $hrefstr = "keys=$keys&Page=$page";
  8. // 验证并获取订单数据
  9. if (!empty($id) && is_numeric($id)) {
  10. // 获取订单基本信息
  11. $employee_id = $_SESSION['employee_id'];
  12. $sql = "SELECT o.*, c.cs_company, c.cs_code, cc.contact_name
  13. FROM orders o
  14. LEFT JOIN customer c ON o.customer_id = c.id
  15. LEFT JOIN customer_contact cc ON o.contact_id = cc.id
  16. WHERE o.id = $id AND o.employee_id = $employee_id";
  17. $result = mysqli_query($conn, $sql);
  18. if ($row = mysqli_fetch_assoc($result)) {
  19. $order = $row;
  20. } else {
  21. echo "<script>alert('订单不存在或您没有权限查看');history.back();</script>";
  22. exit;
  23. }
  24. // 获取订单项信息
  25. $sql = "SELECT oi.*, p.ProductName
  26. FROM order_items oi
  27. LEFT JOIN products p ON oi.product_id = p.id
  28. WHERE oi.order_id = $id";
  29. $itemsResult = mysqli_query($conn, $sql);
  30. $orderItems = [];
  31. while ($itemRow = mysqli_fetch_assoc($itemsResult)) {
  32. $orderItems[] = $itemRow;
  33. }
  34. } else {
  35. echo "<script>alert('订单不存在!');history.back();</script>";
  36. exit;
  37. }
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41. <head>
  42. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  43. <title>编辑订单</title>
  44. <link rel="stylesheet" href="css/common.css" type="text/css" />
  45. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  46. <script src="js/jquery-1.7.2.min.js"></script>
  47. <script src="js/js.js"></script>
  48. <style>
  49. body {
  50. margin: 0;
  51. padding: 20px;
  52. background: #fff;
  53. }
  54. #man_zone {
  55. margin-left: 0;
  56. }
  57. .product-row {
  58. border: 1px solid #ddd;
  59. padding: 10px;
  60. margin-bottom: 10px;
  61. background-color: #f9f9f9;
  62. position: relative;
  63. }
  64. .delete-product {
  65. position: absolute;
  66. right: 10px;
  67. top: 10px;
  68. color: red;
  69. cursor: pointer;
  70. }
  71. .add-product-btn {
  72. background-color: #4CAF50;
  73. color: white;
  74. padding: 8px 12px;
  75. border: none;
  76. cursor: pointer;
  77. margin-bottom: 15px;
  78. }
  79. .total-section {
  80. margin-top: 20px;
  81. padding: 10px;
  82. background-color: #eee;
  83. font-weight: bold;
  84. }
  85. #product-container {
  86. margin-bottom: 20px;
  87. }
  88. .productlist {
  89. display: none;
  90. position: absolute;
  91. background: white;
  92. border: 1px solid #ccc;
  93. max-height: 200px;
  94. overflow-y: auto;
  95. width: 100%;
  96. z-index: 1000;
  97. box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  98. }
  99. .productlist ul {
  100. list-style: none;
  101. padding: 0;
  102. margin: 0;
  103. }
  104. .productlist li {
  105. padding: 8px 10px;
  106. cursor: pointer;
  107. border-bottom: 1px solid #eee;
  108. }
  109. .productlist li:hover {
  110. background-color: #f5f5f5;
  111. }
  112. .productinput {
  113. position: relative;
  114. }
  115. .customerlist ul {
  116. list-style: none;
  117. padding: 0;
  118. margin: 0;
  119. }
  120. .customerlist li {
  121. padding: 8px 10px;
  122. cursor: pointer;
  123. border-bottom: 1px solid #eee;
  124. }
  125. .customerlist li:hover {
  126. background-color: #f5f5f5;
  127. }
  128. .productlist li .category-tag {
  129. color: #777;
  130. font-size: 12px;
  131. font-style: italic;
  132. margin-left: 5px;
  133. }
  134. </style>
  135. </head>
  136. <body>
  137. <div id="man_zone">
  138. <form name="form1" id="form1" method="post" action="order_save.php?<?= $hrefstr ?>" onsubmit="return validateOrderForm()">
  139. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  140. <tbody>
  141. <tr>
  142. <th width="8%">订单编号</th>
  143. <td>
  144. <input type="text" id="order_code" name="order_code" value="<?= htmlspecialcharsFix($order['order_code']) ?>" class="txt1" />
  145. <input type="hidden" name="id" value="<?= $id ?>" />
  146. </td>
  147. </tr>
  148. <tr>
  149. <th width="8%">客户选择</th>
  150. <td>
  151. <div style="display: inline-block; width: 60%;" class="customerinput">
  152. <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']) ?>">
  153. <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);">
  154. <ul style="list-style: none; padding: 0; margin: 0;"></ul>
  155. </div>
  156. <input type="hidden" name="customer_id" id="customer_id" value="<?= $order['customer_id'] ?>">
  157. <div class="selected-customer-info" style="margin-top: 5px; font-weight: bold;"></div>
  158. </div>
  159. </td>
  160. </tr>
  161. <tr>
  162. <th width="8%">联系人</th>
  163. <td>
  164. <select id="contact_id" name="contact_id">
  165. <option value="">请选择联系人</option>
  166. <?php
  167. if ($order['customer_id']) {
  168. $contactSql = "SELECT id, contact_name FROM customer_contact WHERE customer_id = " . $order['customer_id'];
  169. $contactResult = mysqli_query($conn, $contactSql);
  170. while ($contactRow = mysqli_fetch_assoc($contactResult)) {
  171. $selected = ($order['contact_id'] == $contactRow['id']) ? ' selected' : '';
  172. echo "<option value=\"{$contactRow['id']}\"$selected>" . htmlspecialcharsFix($contactRow['contact_name']) . "</option>";
  173. }
  174. }
  175. ?>
  176. </select>
  177. </td>
  178. </tr>
  179. <tr>
  180. <th width="8%">订单日期</th>
  181. <td>
  182. <input type="date" id="order_date" name="order_date" value="<?= substr($order['order_date'], 0, 10) ?>" class="txt1" />
  183. </td>
  184. </tr>
  185. <tr>
  186. <th width="8%" valign="top">产品列表</th>
  187. <td>
  188. <button type="button" id="add-product-btn" class="add-product-btn">添加产品</button>
  189. <div id="product-container">
  190. <?php foreach ($orderItems as $index => $item): ?>
  191. <div class="product-row" data-index="<?= $index ?>">
  192. <span class="delete-product">×</span>
  193. <div>
  194. <label>产品:</label>
  195. <div style="display: inline-block; width: 60%;" class="productinput">
  196. <input type="text" class="product-search fastsearch" placeholder="输入产品名称搜索..." style="width: 100%;" value="<?= htmlspecialcharsFix($item['ProductName'] ?? '') ?>">
  197. <div class="productlist"><ul></ul></div>
  198. <input type="hidden" name="items[<?= $index ?>][product_id]" class="product-id-input" value="<?= $item['product_id'] ?>">
  199. <div class="selected-product-info" style="margin-top: 5px; font-weight: bold;"><?= htmlspecialcharsFix($item['ProductName'] ?? '') ?></div>
  200. </div>
  201. </div>
  202. <div style="margin-top: 5px;">
  203. <label>数量:</label>
  204. <input type="number" name="items[<?= $index ?>][quantity]" value="<?= $item['quantity'] ?>" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
  205. <label style="margin-left: 10px;">单位:</label>
  206. <input type="text" name="items[<?= $index ?>][unit]" value="<?= htmlspecialcharsFix($item['unit']) ?>" class="unit-input">
  207. <label style="margin-left: 10px;">单价:</label>
  208. <input type="number" step="0.01" name="items[<?= $index ?>][unit_price]" value="<?= $item['unit_price'] ?>" class="price-input" onchange="calculateItemTotal(this)">
  209. </div>
  210. <div style="margin-top: 5px;">
  211. <label>折扣金额:</label>
  212. <input type="number" step="0.01" name="items[<?= $index ?>][discount_amount]" value="<?= $item['discount_amount'] ?>" class="discount-amount-input" onchange="calculateItemTotal(this)">
  213. <label style="margin-left: 10px;">折扣率:</label>
  214. <input type="number" step="0.01" name="items[<?= $index ?>][discount_percent]" value="<?= $item['discount_percent'] ?>" class="discount-percent-input" max="100" min="0">%
  215. <label style="margin-left: 10px;">总价:</label>
  216. <input type="number" step="0.01" name="items[<?= $index ?>][total_price]" value="<?= $item['total_price'] ?>" class="total-price-input" readonly>
  217. </div>
  218. <div style="margin-top: 5px;">
  219. <label>备注:</label>
  220. <input type="text" name="items[<?= $index ?>][notes]" value="<?= htmlspecialcharsFix($item['notes']) ?>" style="width: 80%;">
  221. </div>
  222. </div>
  223. <?php endforeach; ?>
  224. </div>
  225. <div class="total-section">
  226. <div>
  227. <label>订单小计:</label>
  228. <span id="subtotal"><?= number_format($order['subtotal'], 2) ?></span>
  229. <input type="hidden" name="subtotal" id="subtotal-input" value="<?= $order['subtotal'] ?>">
  230. </div>
  231. <div style="margin-top: 5px;">
  232. <label>订单折扣:</label>
  233. <input type="number" step="0.01" name="discount_amount" id="order-discount" value="<?= $order['discount_amount'] ?>" onchange="calculateOrderTotal()">
  234. </div>
  235. <div style="margin-top: 5px;">
  236. <label>订单总额:</label>
  237. <span id="total-amount"><?= number_format($order['total_amount'], 2) ?></span>
  238. <input type="hidden" name="total_amount" id="total-amount-input" value="<?= $order['total_amount'] ?>">
  239. </div>
  240. </div>
  241. </td>
  242. </tr>
  243. <tr>
  244. <th width="8%">订单备注</th>
  245. <td>
  246. <textarea name="notes" rows="3" style="width: 90%;"><?= htmlspecialcharsFix($order['notes']) ?></textarea>
  247. </td>
  248. </tr>
  249. <tr>
  250. <th></th>
  251. <td>
  252. <input type="submit" name="save" value="保存订单" class="btn1">
  253. <input type="button" value="返回" class="btn1" onClick="location.href='order.php?<?= $hrefstr ?>'" />
  254. </td>
  255. </tr>
  256. </tbody>
  257. </table>
  258. </form>
  259. <script>
  260. var productIndex = <?= count($orderItems) ?>;
  261. $(document).ready(function() {
  262. // 初始化计算
  263. calculateOrderTotal();
  264. // 添加产品行
  265. $('#add-product-btn').click(function() {
  266. addProductRow();
  267. });
  268. // 删除产品行
  269. $(document).on('click', '.delete-product', function() {
  270. if ($('.product-row').length > 1) {
  271. $(this).closest('.product-row').remove();
  272. reindexProductRows();
  273. calculateOrderTotal();
  274. } else {
  275. alert('订单至少需要一个产品');
  276. }
  277. });
  278. // 客户搜索功能
  279. var customerSearchTimeout = null;
  280. $(document).on('keyup', '.customer-search', function() {
  281. var $this = $(this);
  282. var searchTerm = $this.val().trim();
  283. var customerList = $('.customerlist');
  284. // 清除之前的超时
  285. clearTimeout(customerSearchTimeout);
  286. // 隐藏之前的结果
  287. customerList.hide();
  288. // 如果搜索词少于2个字符,不执行搜索
  289. if (searchTerm.length < 2) {
  290. return;
  291. }
  292. // 设置一个300毫秒的超时,以减少请求数量
  293. customerSearchTimeout = setTimeout(function() {
  294. $.ajax({
  295. url: 'get_customer_search.php',
  296. type: 'GET',
  297. data: {search: searchTerm},
  298. dataType: 'json',
  299. success: function(data) {
  300. var ul = customerList.find('ul');
  301. ul.empty();
  302. if (data && data.customers && data.customers.length > 0) {
  303. $.each(data.customers, function(i, customer) {
  304. var displayText = customer.cs_company;
  305. if (customer.cs_code) {
  306. displayText = customer.cs_code + ' - ' + displayText;
  307. }
  308. ul.append('<li data-id="' + customer.id + '" data-code="' + (customer.cs_code || '') + '">' +
  309. displayText + '</li>');
  310. });
  311. customerList.show();
  312. }
  313. },
  314. error: function() {
  315. console.log('搜索客户失败,请重试');
  316. }
  317. });
  318. }, 300);
  319. });
  320. // 点击选择客户
  321. $(document).on('click', '.customerlist li', function() {
  322. var $this = $(this);
  323. var customerId = $this.data('id');
  324. var customerName = $this.text();
  325. var customerCode = $this.data('code') || '';
  326. // 设置选中的客户ID和名称
  327. $('#customer_id').val(customerId);
  328. $('.customer-search').val(customerName);
  329. $('.selected-customer-info').text(customerName);
  330. $('.customerlist').hide();
  331. // 加载客户联系人
  332. loadCustomerContacts(customerId);
  333. });
  334. // 实时产品搜索功能 - 使用防抖动以减少请求数量
  335. var searchTimeout = null;
  336. $(document).on('keyup', '.product-search', function() {
  337. var $this = $(this);
  338. var row = $this.closest('.product-row');
  339. var searchTerm = $this.val().trim();
  340. var productList = row.find('.productlist');
  341. // 清除之前的超时
  342. clearTimeout(searchTimeout);
  343. // 隐藏之前的结果
  344. productList.hide();
  345. // 如果搜索词少于2个字符,不执行搜索
  346. if (searchTerm.length < 2) {
  347. return;
  348. }
  349. // 设置一个300毫秒的超时,以减少请求数量
  350. searchTimeout = setTimeout(function() {
  351. $.ajax({
  352. url: 'get_product_info.php',
  353. type: 'GET',
  354. data: {search: searchTerm},
  355. dataType: 'json',
  356. success: function(data) {
  357. var productList = row.find('.productlist');
  358. var ul = productList.find('ul');
  359. ul.empty();
  360. if (data && data.products && data.products.length > 0) {
  361. $.each(data.products, function(i, product) {
  362. ul.append('<li data-id="' + product.id + '">' +
  363. product.ProductName +
  364. (product.category_name ? ' <span class="category-tag">(' + product.category_name + ')</span>' : '') +
  365. '</li>');
  366. });
  367. productList.show();
  368. }
  369. },
  370. error: function() {
  371. console.log('搜索产品失败,请重试');
  372. }
  373. });
  374. }, 300);
  375. });
  376. // 点击选择产品
  377. $(document).on('click', '.productlist li', function() {
  378. var $this = $(this);
  379. var productId = $this.data('id');
  380. var productName = $this.text(); // 这会包含分类名,需要清理
  381. var categoryTag = $this.find('.category-tag').text();
  382. // 清理产品名称,移除分类信息
  383. if (categoryTag) {
  384. productName = productName.replace(categoryTag, '').trim();
  385. }
  386. var row = $this.closest('.product-row');
  387. // 设置选中的产品ID和名称
  388. row.find('.product-id-input').val(productId);
  389. row.find('.product-search').val(productName);
  390. // 显示包含分类的完整产品信息
  391. var displayName = productName;
  392. if (categoryTag) {
  393. displayName += ' <span class="category-tag">' + categoryTag + '</span>';
  394. }
  395. row.find('.selected-product-info').html(displayName);
  396. row.find('.productlist').hide();
  397. // 获取产品信息
  398. getProductInfo(productId, row);
  399. });
  400. // 点击其他地方隐藏下拉列表
  401. $(document).on('click', function(e) {
  402. if (!$(e.target).closest('.productinput').length) {
  403. $('.productlist').hide();
  404. }
  405. if (!$(e.target).closest('.customerinput').length) {
  406. $('.customerlist').hide();
  407. }
  408. });
  409. // 更新折扣率和折扣金额之间的关系
  410. $(document).on('change', '.discount-percent-input', function() {
  411. var row = $(this).closest('.product-row');
  412. var percent = parseFloat($(this).val()) || 0;
  413. var quantity = parseInt(row.find('.quantity-input').val()) || 0;
  414. var price = parseFloat(row.find('.price-input').val()) || 0;
  415. var subtotal = quantity * price;
  416. var discountAmount = (subtotal * percent / 100).toFixed(2);
  417. row.find('.discount-amount-input').val(discountAmount);
  418. calculateItemTotal(this);
  419. });
  420. $(document).on('change', '.discount-amount-input', function() {
  421. var row = $(this).closest('.product-row');
  422. var amount = parseFloat($(this).val()) || 0;
  423. var quantity = parseInt(row.find('.quantity-input').val()) || 0;
  424. var price = parseFloat(row.find('.price-input').val()) || 0;
  425. var subtotal = quantity * price;
  426. if (subtotal > 0) {
  427. var percent = ((amount / subtotal) * 100).toFixed(2);
  428. row.find('.discount-percent-input').val(percent);
  429. }
  430. calculateItemTotal(this);
  431. });
  432. });
  433. function addProductRow() {
  434. var html = `
  435. <div class="product-row" data-index="${productIndex}">
  436. <span class="delete-product">×</span>
  437. <div>
  438. <label>产品:</label>
  439. <div style="display: inline-block; width: 60%;" class="productinput">
  440. <input type="text" class="product-search fastsearch" placeholder="输入产品名称搜索..." style="width: 100%;">
  441. <div class="productlist"><ul></ul></div>
  442. <input type="hidden" name="items[${productIndex}][product_id]" class="product-id-input" value="">
  443. <div class="selected-product-info" style="margin-top: 5px; font-weight: bold;"></div>
  444. </div>
  445. </div>
  446. <div style="margin-top: 5px;">
  447. <label>数量:</label>
  448. <input type="number" name="items[${productIndex}][quantity]" value="1" min="1" class="quantity-input" onchange="calculateItemTotal(this)">
  449. <label style="margin-left: 10px;">单位:</label>
  450. <input type="text" name="items[${productIndex}][unit]" value="" class="unit-input">
  451. <label style="margin-left: 10px;">单价:</label>
  452. <input type="number" step="0.01" name="items[${productIndex}][unit_price]" value="0.00" class="price-input" onchange="calculateItemTotal(this)">
  453. </div>
  454. <div style="margin-top: 5px;">
  455. <label>折扣金额:</label>
  456. <input type="number" step="0.01" name="items[${productIndex}][discount_amount]" value="0.00" class="discount-amount-input" onchange="calculateItemTotal(this)">
  457. <label style="margin-left: 10px;">折扣率:</label>
  458. <input type="number" step="0.01" name="items[${productIndex}][discount_percent]" value="0" class="discount-percent-input" max="100" min="0">%
  459. <label style="margin-left: 10px;">总价:</label>
  460. <input type="number" step="0.01" name="items[${productIndex}][total_price]" value="0.00" class="total-price-input" readonly>
  461. </div>
  462. <div style="margin-top: 5px;">
  463. <label>备注:</label>
  464. <input type="text" name="items[${productIndex}][notes]" value="" style="width: 80%;">
  465. </div>
  466. </div>
  467. `;
  468. $('#product-container').append(html);
  469. productIndex++;
  470. }
  471. function reindexProductRows() {
  472. $('.product-row').each(function(index) {
  473. $(this).attr('data-index', index);
  474. $(this).find('select, input').each(function() {
  475. var name = $(this).attr('name');
  476. if (name) {
  477. name = name.replace(/items\[\d+\]/, 'items[' + index + ']');
  478. $(this).attr('name', name);
  479. }
  480. });
  481. });
  482. productIndex = $('.product-row').length;
  483. }
  484. function getProductInfo(productId, row) {
  485. if (!productId) return;
  486. $.ajax({
  487. url: 'get_product_info.php',
  488. type: 'GET',
  489. data: {id: productId},
  490. dataType: 'json',
  491. success: function(data) {
  492. if (data) {
  493. row.find('.unit-input').val(data.unit);
  494. row.find('.price-input').val(data.price);
  495. calculateItemTotal(row.find('.price-input')[0]);
  496. }
  497. }
  498. });
  499. }
  500. function calculateItemTotal(element) {
  501. var row = $(element).closest('.product-row');
  502. var quantity = parseInt(row.find('.quantity-input').val()) || 0;
  503. var price = parseFloat(row.find('.price-input').val()) || 0;
  504. var discountAmount = parseFloat(row.find('.discount-amount-input').val()) || 0;
  505. var subtotal = quantity * price;
  506. var total = subtotal - discountAmount;
  507. if (total < 0) total = 0;
  508. row.find('.total-price-input').val(total.toFixed(2));
  509. calculateOrderTotal();
  510. }
  511. function calculateOrderTotal() {
  512. var subtotal = 0;
  513. $('.total-price-input').each(function() {
  514. subtotal += parseFloat($(this).val()) || 0;
  515. });
  516. var orderDiscount = parseFloat($('#order-discount').val()) || 0;
  517. var total = subtotal - orderDiscount;
  518. if (total < 0) total = 0;
  519. $('#subtotal').text(subtotal.toFixed(2));
  520. $('#subtotal-input').val(subtotal.toFixed(2));
  521. $('#total-amount').text(total.toFixed(2));
  522. $('#total-amount-input').val(total.toFixed(2));
  523. }
  524. function loadCustomerContacts(customerId) {
  525. if (customerId) {
  526. $.ajax({
  527. url: 'get_customer_contacts.php',
  528. type: 'GET',
  529. data: {customer_id: customerId},
  530. dataType: 'json',
  531. success: function(data) {
  532. var options = '<option value="">请选择联系人</option>';
  533. if (data && data.length > 0) {
  534. for (var i = 0; i < data.length; i++) {
  535. options += '<option value="' + data[i].id + '">' + data[i].contact_name + '</option>';
  536. }
  537. }
  538. $('#contact_id').html(options);
  539. }
  540. });
  541. } else {
  542. $('#contact_id').html('<option value="">请选择联系人</option>');
  543. }
  544. }
  545. function validateOrderForm() {
  546. var orderCode = $('#order_code').val();
  547. var customerId = $('#customer_id').val();
  548. var customerName = $('.customer-search').val();
  549. var hasProducts = false;
  550. $('.product-id-input').each(function() {
  551. if ($(this).val()) {
  552. hasProducts = true;
  553. return false; // break the loop
  554. }
  555. });
  556. if (!orderCode) {
  557. alert('订单编号不能为空');
  558. $('#order_code').focus();
  559. return false;
  560. }
  561. if (!customerId || customerId <= 0) {
  562. alert('请选择客户');
  563. $('.customer-search').focus();
  564. return false;
  565. }
  566. if (!customerName) {
  567. alert('客户名称不能为空');
  568. $('.customer-search').focus();
  569. return false;
  570. }
  571. if (!hasProducts) {
  572. alert('订单必须包含至少一个产品');
  573. return false;
  574. }
  575. return true;
  576. }
  577. </script>
  578. </div>
  579. </body>
  580. </html>