customerEdit.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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. // Validate and fetch customer data
  9. if (!empty($id) && is_numeric($id)) {
  10. // Fetch customer basic information
  11. $sql = "SELECT c.* FROM customer c WHERE c.cs_belong = ? AND c.id = ?";
  12. $stmt = $conn->prepare($sql);
  13. $stmt->bind_param("ii", $_SESSION['employee_id'], $id);
  14. $stmt->execute();
  15. $result = $stmt->get_result();
  16. if ($row = $result->fetch_assoc()) {
  17. $customer = [
  18. 'cs_company' => textUncode($row['cs_company']),
  19. 'cs_address' => textUncode($row['cs_address']),
  20. 'cs_code' => textUncode($row['cs_code']),
  21. 'cs_deal' => textUncode($row['cs_deal']),
  22. 'cs_addtime' => $row['cs_addtime'],
  23. 'cs_belongclient' => $row['cs_belongclient'],
  24. 'cs_updatetime' => $row['cs_updatetime'],
  25. 'cs_from' => $row['cs_from'],
  26. 'cs_country' => $row['cs_country'],
  27. 'cs_type' => $row['cs_type'],
  28. 'cs_note' => htmlUnCode($row['cs_note']),
  29. 'cs_claimFrom' => $row['cs_claimFrom'],
  30. 'allowedit' => $row['allowedit']
  31. ];
  32. // Fetch all contact records for this customer
  33. $contactSql = "SELECT cc.* FROM customer_contact cc WHERE cc.customer_id = ?";
  34. $contactStmt = $conn->prepare($contactSql);
  35. $contactStmt->bind_param("i", $id);
  36. $contactStmt->execute();
  37. $contactResult = $contactStmt->get_result();
  38. $contacts = [];
  39. while ($contactRow = $contactResult->fetch_assoc()) {
  40. $contact = [
  41. 'id' => $contactRow['id'],
  42. 'contact_name' => textUncode($contactRow['contact_name']),
  43. 'created_at' => $contactRow['created_at'],
  44. 'updated_at' => $contactRow['updated_at']
  45. ];
  46. // Process each contact method type (up to 3 entries each)
  47. $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
  48. foreach ($methodTypes as $type) {
  49. for ($i = 1; $i <= 3; $i++) {
  50. $fieldBase = $type . '_' . $i;
  51. $contact[$fieldBase] = textUncode($contactRow[$fieldBase]);
  52. if ($type == 'tel' || $type == 'whatsapp') {
  53. $contact[$fieldBase . '_format'] = textUncode($contactRow[$fieldBase . '_format']);
  54. }
  55. $contact[$fieldBase . '_bu'] = textUncode($contactRow[$fieldBase . '_bu']);
  56. }
  57. }
  58. $contacts[] = $contact;
  59. }
  60. } else {
  61. echo "<script>alert('客户不存在或你没权限查看!');history.back();</script>";
  62. exit;
  63. }
  64. } else {
  65. echo "<script>alert('客户不存在!');history.back();</script>";
  66. header("Location: $hrefstr");
  67. exit;
  68. }
  69. ?>
  70. <!DOCTYPE html>
  71. <html xmlns="http://www.w3.org/1999/xhtml">
  72. <head>
  73. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  74. <title>管理区域</title>
  75. <link rel="stylesheet" href="css/common.css" type="text/css" />
  76. <script src="system/js/jquery-1.7.2.min.js"></script>
  77. <script src="js/js.js"></script>
  78. <script src="js/xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  79. <script src="js/Hz2Py-szm-min.js"></script>
  80. <script src="js/ySearchSelect.js"></script>
  81. <script>
  82. $(document).ready(function(){
  83. $('.txt2').xheditor({
  84. tools:'full',
  85. hoverExecDelay:-1,
  86. urlBase:'system',
  87. upLinkUrl:"upload.php",
  88. upLinkExt:"zip,rar,txt,pdf",
  89. upImgUrl:"upload.php",
  90. upImgExt:"jpg,jpeg,gif,png",
  91. upFlashUrl:"upload.php",
  92. upFlashExt:"swf",
  93. upMediaUrl:"upload.php",
  94. upMediaExt:"wmv,avi,wma,mp3,mid"
  95. });
  96. // Remove contact
  97. $(document).on('click', '.remove-contact-btn', function() {
  98. var contactForm = $(this).closest('.contact-form');
  99. contactForm.remove();
  100. // Renumber remaining contacts
  101. $('#contacts-container .contact-form').each(function(index) {
  102. $(this).find('h3').text('联系人 #' + (index + 1));
  103. });
  104. });
  105. // Add contact form
  106. $('.add-contact-btn').click(function() {
  107. var contactsContainer = $('#contacts-container');
  108. var contactIndex = contactsContainer.children('.contact-form').length;
  109. var contactForm = `
  110. <div class="contact-form" id="contact-form-${contactIndex}">
  111. <div class="contact-header">
  112. <button type="button" class="remove-contact-btn" data-index="${contactIndex}">删除</button>
  113. <h3>联系人 #${contactIndex + 1}</h3>
  114. </div>
  115. <input type="hidden" name="contact[${contactIndex}][id]" value="">
  116. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  117. <tr>
  118. <th width="8%">联系人</th>
  119. <td><input type="text" name="contact[${contactIndex}][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  120. </tr>
  121. </table>
  122. <div class="contact-methods-container" id="contact-methods-${contactIndex}">
  123. <!-- Contact methods will be added here -->
  124. </div>
  125. <button type="button" class="add-method-btn" data-contact-index="${contactIndex}">添加联系方式</button>
  126. </div>
  127. `;
  128. contactsContainer.append(contactForm);
  129. });
  130. // Add contact method
  131. $(document).on('click', '.add-method-btn', function() {
  132. var contactIndex = $(this).data('contact-index');
  133. var methodsContainer = $('#contact-methods-' + contactIndex);
  134. // Count existing methods by type
  135. var methodCounts = {};
  136. methodsContainer.find('select.method-select').each(function() {
  137. var type = $(this).val();
  138. if (type) {
  139. methodCounts[type] = (methodCounts[type] || 0) + 1;
  140. }
  141. });
  142. var methodRow = `
  143. <div class="contact-method-row">
  144. <select class="method-select" onchange="updateMethodSelectAndPlaceholder(this)">
  145. <option value="">请选择联系方式</option>
  146. <option value="tel" ${(methodCounts.tel || 0) >= 3 ? 'disabled' : ''}>电话</option>
  147. <option value="wechat" ${(methodCounts.wechat || 0) >= 3 ? 'disabled' : ''}>微信</option>
  148. <option value="whatsapp" ${(methodCounts.whatsapp || 0) >= 3 ? 'disabled' : ''}>WhatsApp</option>
  149. <option value="email" ${(methodCounts.email || 0) >= 3 ? 'disabled' : ''}>邮箱</option>
  150. <option value="linkedin" ${(methodCounts.linkedin || 0) >= 3 ? 'disabled' : ''}>领英</option>
  151. <option value="facebook" ${(methodCounts.facebook || 0) >= 3 ? 'disabled' : ''}>Facebook</option>
  152. <option value="alibaba" ${(methodCounts.alibaba || 0) >= 3 ? 'disabled' : ''}>阿里巴巴</option>
  153. </select>
  154. <input type="text" class="txt1 method-input" style="width:60%;" placeholder="请选择联系方式类型">
  155. <button type="button" class="remove-method-btn">删除</button>
  156. </div>
  157. `;
  158. methodsContainer.append(methodRow);
  159. updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
  160. });
  161. // Remove contact method
  162. $(document).on('click', '.remove-method-btn', function() {
  163. var methodRow = $(this).closest('.contact-method-row');
  164. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  165. var type = methodRow.find('select.method-select').val();
  166. methodRow.remove();
  167. // Update available options in other selects
  168. updateAvailableMethodTypes(contactIndex);
  169. });
  170. });
  171. // Update method fields based on selection
  172. function updateMethodFields(methodRow) {
  173. var select = methodRow.find('select.method-select');
  174. var input = methodRow.find('input.method-input');
  175. var contactForm = methodRow.closest('.contact-form');
  176. var contactIndex = contactForm.attr('id').split('-')[2];
  177. var type = select.val();
  178. if (!type) return;
  179. // Count existing methods of this type
  180. var count = 1;
  181. contactForm.find('select.method-select').each(function() {
  182. if ($(this).val() === type && $(this)[0] !== select[0]) {
  183. count++;
  184. }
  185. });
  186. // Update field names
  187. select.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  188. input.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  189. // Add format field for tel and whatsapp
  190. if (type === 'tel' || type === 'whatsapp') {
  191. if (!methodRow.find('.format-input').length) {
  192. input.after(`<input type="hidden" class="format-input" name="contact[${contactIndex}][${type}_${count}_format]">`);
  193. }
  194. }
  195. // Add backup field
  196. if (!methodRow.find('.backup-input').length) {
  197. methodRow.append(`<input type="hidden" class="backup-input" name="contact[${contactIndex}][${type}_${count}_bu]">`);
  198. }
  199. }
  200. // Update available method types for a contact
  201. function updateAvailableMethodTypes(contactIndex) {
  202. var methodsContainer = $('#contact-methods-' + contactIndex);
  203. // Count methods by type
  204. var methodCounts = {};
  205. methodsContainer.find('select.method-select').each(function() {
  206. var type = $(this).val();
  207. if (type) {
  208. methodCounts[type] = (methodCounts[type] || 0) + 1;
  209. }
  210. });
  211. // Update all selects in this contact
  212. methodsContainer.find('select.method-select').each(function() {
  213. var currentValue = $(this).val();
  214. $(this).find('option').each(function() {
  215. var optionValue = $(this).val();
  216. if (optionValue && optionValue !== currentValue) {
  217. $(this).prop('disabled', (methodCounts[optionValue] || 0) >= 3);
  218. }
  219. });
  220. });
  221. }
  222. // Update placeholder and handle method fields
  223. function updateMethodSelectAndPlaceholder(selectElement) {
  224. var methodRow = $(selectElement).closest('.contact-method-row');
  225. updateMethodPlaceholder(selectElement);
  226. updateMethodFields(methodRow);
  227. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  228. updateAvailableMethodTypes(contactIndex);
  229. }
  230. // Look for the updateMethodPlaceholder function and replace it with this modified version
  231. function updateMethodPlaceholder(selectElement) {
  232. var placeholder = "";
  233. var value = $(selectElement).val();
  234. switch(value) {
  235. case "tel":
  236. placeholder = "电话格式必须为:区号+号码 如:+86 15012345678";
  237. break;
  238. case "wechat":
  239. placeholder = "微信";
  240. break;
  241. case "whatsapp":
  242. placeholder = "Whatsapp 格式必须为:区号+号码 如:+86 15012345678";
  243. break;
  244. case "email":
  245. placeholder = "邮箱格式必须正确,如: example@domain.com";
  246. break;
  247. case "linkedin":
  248. placeholder = "领英链接";
  249. break;
  250. case "facebook":
  251. placeholder = "Facebook";
  252. break;
  253. case "alibaba":
  254. placeholder = "阿里巴巴";
  255. break;
  256. default:
  257. placeholder = "请选择联系方式类型";
  258. }
  259. $(selectElement).next('.method-input').attr('placeholder', placeholder);
  260. }
  261. // Custom validation function for multiple contacts form with contact methods
  262. function validateMultipleContactsForm() {
  263. var clientCode = $("#cs_code").val();
  264. var clientCompany = $("#cs_company").val();
  265. var clientFrom = $("#cs_from").val();
  266. var clientCountry = $("#cs_country").val();
  267. // Validate basic customer info
  268. if (clientCode == "" || clientCode == null) {
  269. alert("客户代码不能为空!");
  270. $("#cs_code").focus();
  271. return false;
  272. }
  273. if (clientCountry == 0 || !clientCountry) {
  274. alert("这是哪个国家的客户?");
  275. $("#cs_country").focus();
  276. return false;
  277. }
  278. if (clientFrom == "0") {
  279. alert("请填写客户来源!");
  280. $("#cs_from").focus();
  281. return false;
  282. }
  283. // Get source text to check if it's from Alibaba platforms
  284. var clientFromText = $("#cs_from option:selected").text();
  285. var isAlibabaSource = clientFromText.indexOf("1688") >= 0 ||
  286. clientFromText.indexOf("阿里") >= 0 ||
  287. clientFromText.indexOf("alibaba") >= 0;
  288. // Validate that at least one contact has at least one contact method
  289. var hasContactMethod = false;
  290. var hasAlibabaContact = false;
  291. var allContactsValid = true;
  292. var phoneRegex = /^\+\d{1,4}\s\d{5,}$/; // Regex to validate phone format: +[country code] [number]
  293. var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; // Regex to validate email format
  294. $('.contact-form').each(function(contactIndex) {
  295. var $form = $(this);
  296. var contactName = $form.find('input[name*="[contact_name]"]').val();
  297. var hasMethodInThisContact = false;
  298. // Check if this contact has methods
  299. $form.find('.contact-method-row').each(function() {
  300. var methodType = $(this).find('select.method-select').val();
  301. var methodValue = $(this).find('input.method-input').val();
  302. if (methodValue) {
  303. hasMethodInThisContact = true;
  304. hasContactMethod = true;
  305. // Check if there's an Alibaba contact method
  306. if (methodType === 'alibaba') {
  307. hasAlibabaContact = true;
  308. }
  309. }
  310. // Check if method type is selected but value is empty
  311. if (methodType && !methodValue) {
  312. alert("联系方式类型已选择但值为空");
  313. allContactsValid = false;
  314. return false;
  315. }
  316. // Validate phone number format for tel and whatsapp
  317. if ((methodType === 'tel' || methodType === 'whatsapp') && methodValue) {
  318. if (!phoneRegex.test(methodValue)) {
  319. alert("电话格式不正确,请使用以下格式:区号+号码,如 +86 15012345678");
  320. $(this).find('input.method-input').focus();
  321. allContactsValid = false;
  322. return false;
  323. }
  324. }
  325. // Validate email format
  326. if (methodType === 'email' && methodValue) {
  327. if (!emailRegex.test(methodValue)) {
  328. alert("邮箱格式不正确,请输入有效的邮箱地址");
  329. $(this).find('input.method-input').focus();
  330. allContactsValid = false;
  331. return false;
  332. }
  333. }
  334. });
  335. // If contact has a name but no methods, or has methods but no name
  336. if ((contactName && !hasMethodInThisContact) || (!contactName && hasMethodInThisContact)) {
  337. alert("联系人 #" + (contactIndex + 1) + " 缺少联系人姓名或联系方式");
  338. allContactsValid = false;
  339. return false;
  340. }
  341. // If contact has neither name nor methods, it's an empty contact
  342. if (!contactName && !hasMethodInThisContact) {
  343. alert("联系人 #" + (contactIndex + 1) + " 是空的,请填写信息或删除此联系人");
  344. allContactsValid = false;
  345. return false;
  346. }
  347. });
  348. if (!allContactsValid) {
  349. return false;
  350. }
  351. if (!hasContactMethod) {
  352. alert("至少需要添加一个联系人,且联系人至少需要一种联系方式!");
  353. return false;
  354. }
  355. // If source is from Alibaba platforms, must have Alibaba contact method
  356. if (isAlibabaSource && !hasAlibabaContact) {
  357. alert("客户来源为1688或阿里国际站时,必须添加至少一个阿里巴巴联系方式!");
  358. return false;
  359. }
  360. // Set tag values
  361. $("input#mytag").val($(".taglist").html());
  362. // Convert the dynamic contact methods to the standard format expected by the server
  363. $('.contact-form').each(function(contactIndex) {
  364. var methodsData = {};
  365. $(this).find('.contact-method-row').each(function() {
  366. var type = $(this).find('select.method-select').val();
  367. var value = $(this).find('input.method-input').val();
  368. if (type && value) {
  369. methodsData[type] = value;
  370. }
  371. });
  372. // Create hidden inputs for each method
  373. for (var type in methodsData) {
  374. $('<input>').attr({
  375. type: 'hidden',
  376. name: 'contact[' + contactIndex + '][' + type + ']',
  377. value: methodsData[type]
  378. }).appendTo(this);
  379. }
  380. });
  381. return true;
  382. }
  383. // Modified submission function
  384. function submitCustomerForm() {
  385. if (validateMultipleContactsForm()) {
  386. $("#form1").submit();
  387. }
  388. }
  389. </script>
  390. <style>
  391. body {
  392. margin: 0;
  393. padding: 20px;
  394. background: #fff;
  395. }
  396. #man_zone {
  397. margin-left: 0;
  398. }
  399. .contact-form {
  400. margin-bottom: 10px;
  401. /*border: 1px solid #ddd;*/
  402. padding: 8px;
  403. background-color: #FFFFFF;
  404. }
  405. .contact-header {
  406. display: flex;
  407. align-items: center;
  408. margin-bottom: 8px;
  409. gap: 10px;
  410. }
  411. .contact-header h3 {
  412. margin: 0;
  413. order: 2;
  414. flex-grow: 1;
  415. }
  416. .remove-contact-btn {
  417. background-color: #f44336;
  418. color: white;
  419. border: none;
  420. padding: 4px 8px;
  421. cursor: pointer;
  422. order: 1;
  423. }
  424. .add-contact-btn {
  425. background-color: #4CAF50;
  426. color: white;
  427. border: none;
  428. padding: 6px 12px;
  429. margin-bottom: 10px;
  430. cursor: pointer;
  431. }
  432. .contact-methods-container {
  433. margin-top: 8px;
  434. }
  435. .contact-method-row {
  436. margin-bottom: 6px;
  437. padding: 6px;
  438. border: 1px solid #eee;
  439. /*background-color: #f5f5f5;*/
  440. display: flex;
  441. align-items: center;
  442. gap: 8px;
  443. }
  444. .add-method-btn {
  445. background-color: #2196F3;
  446. color: white;
  447. border: none;
  448. padding: 4px 8px;
  449. margin-top: 4px;
  450. cursor: pointer;
  451. }
  452. .remove-method-btn {
  453. background-color: #f44336;
  454. color: white;
  455. border: none;
  456. padding: 2px 4px;
  457. cursor: pointer;
  458. }
  459. .method-select {
  460. margin-right: 8px;
  461. padding: 3px;
  462. }
  463. .contact-table {
  464. margin-bottom: 6px;
  465. }
  466. .contact-table td, .contact-table th {
  467. padding: 4px 6px;
  468. }
  469. </style>
  470. </head>
  471. <body class="clear">
  472. <?php // require_once 'panel.php'; ?>
  473. <div id="man_zone">
  474. <form name="form1" id="form1" method="post" action="customerSave.php<?= $hrefstr ?>">
  475. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  476. <tbody>
  477. <tr>
  478. <th width="8%">客户编号</th>
  479. <td>
  480. <input type="text" id="cs_code" name="cs_code" value="<?= htmlspecialcharsFix($customer['cs_code']) ?>"
  481. <?= !empty($customer['cs_claimFrom']) ? 'readonly' : '' ?> class="txt1" />
  482. <input type="hidden" name="id" value="<?= $id ?>" />
  483. <input type="hidden" name="cs_addtime" value="<?= $customer['cs_addtime'] ?>" />
  484. <input type="hidden" name="Permissions" value="<?= $customer['allowedit'] ?>" />
  485. </td>
  486. </tr>
  487. <tr>
  488. <th width="8%">公司名称</th>
  489. <td><input type="text" id="cs_company" name="cs_company" value="<?= htmlspecialcharsFix($customer['cs_company']) ?>" class="txt1" /></td>
  490. </tr>
  491. <tr>
  492. <th width="8%">地区/国家</th>
  493. <td>
  494. <div class="layui-input-inline">
  495. <div class="layui-form-select ySearchSelect y1">
  496. <div class="layui-input">
  497. <?php
  498. $stmt = $conn->prepare("SELECT id, countryCode, countryName FROM country WHERE id = ?");
  499. $stmt->bind_param("i", $customer['cs_country']);
  500. $stmt->execute();
  501. $countryResult = $stmt->get_result();
  502. if ($countryRow = $countryResult->fetch_assoc()) {
  503. $countryId = $countryRow['id'];
  504. echo htmlspecialcharsFix($countryRow['countryName']);
  505. } else {
  506. echo "请选择";
  507. }
  508. ?>
  509. </div>
  510. <ul>
  511. <?php
  512. $result = $conn->query("SELECT id, countryCode, countryName FROM country");
  513. while ($row = $result->fetch_assoc()) {
  514. echo "<li class=\"on\" data-c=\"{$row['id']}\">(+{$row['countryCode']}){$row['countryName']}</li>";
  515. }
  516. ?>
  517. <p>无匹配项</p>
  518. </ul>
  519. <input name="cs_country" id="cs_country" value="<?= $countryId ?? '' ?>" type="hidden">
  520. </div>
  521. </div>
  522. <script>
  523. $(function () {
  524. $(".y1").ySearchSelect();
  525. })
  526. </script>
  527. </td>
  528. </tr>
  529. <tr>
  530. <th width="8%">客户来源</th>
  531. <td>
  532. <select id="cs_from" name="cs_from">
  533. <option value="0">请选择来源</option>
  534. <?php
  535. $result = $conn->query("SELECT id, ch_name FROM qudao");
  536. while ($row = $result->fetch_assoc()) {
  537. $selected = ($customer['cs_from'] == $row['id']) ? ' selected="selected"' : '';
  538. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  539. }
  540. ?>
  541. </select>
  542. </td>
  543. </tr>
  544. <tr>
  545. <th width="8%" valign="top">联系人信息</th>
  546. <td>
  547. <button type="button" class="add-contact-btn">添加联系人</button>
  548. <div id="contacts-container">
  549. <?php if (!empty($contacts)): ?>
  550. <?php foreach ($contacts as $index => $contact): ?>
  551. <div class="contact-form" id="contact-form-<?= $index ?>">
  552. <div class="contact-header">
  553. <button type="button" class="remove-contact-btn" data-index="<?= $index ?>">删除</button>
  554. <h3>联系人 #<?= $index + 1 ?></h3>
  555. </div>
  556. <input type="hidden" name="contact[<?= $index ?>][id]" value="<?= $contact['id'] ?>">
  557. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  558. <tr>
  559. <th width="8%">联系人</th>
  560. <td><input type="text" name="contact[<?= $index ?>][contact_name]" value="<?= htmlspecialcharsFix($contact['contact_name']) ?>" class="txt1" placeholder="联系人姓名"/></td>
  561. </tr>
  562. </table>
  563. <div class="contact-methods-container" id="contact-methods-<?= $index ?>">
  564. <?php
  565. $methodTypes = [
  566. 'tel' => '电话',
  567. 'wechat' => '微信',
  568. 'whatsapp' => 'WhatsApp',
  569. 'email' => '邮箱',
  570. 'linkedin' => '领英',
  571. 'facebook' => 'Facebook',
  572. 'alibaba' => '阿里巴巴'
  573. ];
  574. foreach ($methodTypes as $type => $label) {
  575. for ($i = 1; $i <= 3; $i++) {
  576. $fieldName = $type . '_' . $i;
  577. if (!empty($contact[$fieldName])) {
  578. echo '<div class="contact-method-row">';
  579. echo '<select class="method-select" name="contact[' . $index . '][' . $fieldName . ']" onchange="updateMethodSelectAndPlaceholder(this)">';
  580. echo '<option value="">请选择联系方式</option>';
  581. foreach ($methodTypes as $optionType => $optionLabel) {
  582. $selected = ($optionType === $type) ? 'selected' : '';
  583. echo '<option value="' . $optionType . '" ' . $selected . '>' . $optionLabel . '</option>';
  584. }
  585. echo '</select>';
  586. echo '<input type="text" class="txt1 method-input" style="width:60%;" name="contact[' . $index . '][' . $fieldName . ']" value="' . htmlspecialcharsFix($contact[$fieldName]) . '">';
  587. if ($type === 'tel' || $type === 'whatsapp') {
  588. echo '<input type="hidden" class="format-input" name="contact[' . $index . '][' . $fieldName . '_format]" value="' . htmlspecialcharsFix($contact[$fieldName . '_format']) . '">';
  589. }
  590. echo '<input type="hidden" class="backup-input" name="contact[' . $index . '][' . $fieldName . '_bu]" value="' . htmlspecialcharsFix($contact[$fieldName . '_bu']) . '">';
  591. echo '<button type="button" class="remove-method-btn">删除</button>';
  592. echo '</div>';
  593. }
  594. }
  595. }
  596. ?>
  597. </div>
  598. <button type="button" class="add-method-btn" data-contact-index="<?= $index ?>">添加联系方式</button>
  599. </div>
  600. <?php endforeach; ?>
  601. <?php else: ?>
  602. <div class="contact-form" id="contact-form-0">
  603. <div class="contact-header">
  604. <button type="button" class="remove-contact-btn" data-index="0">删除</button>
  605. <h3>联系人 #1</h3>
  606. </div>
  607. <input type="hidden" name="contact[0][id]" value="">
  608. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  609. <tr>
  610. <th width="8%">联系人</th>
  611. <td><input type="text" name="contact[0][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  612. </tr>
  613. </table>
  614. <div class="contact-methods-container" id="contact-methods-0">
  615. <!-- Contact methods will be added here -->
  616. </div>
  617. <button type="button" class="add-method-btn" data-contact-index="0">添加联系方式</button>
  618. </div>
  619. <?php endif; ?>
  620. </div>
  621. </td>
  622. </tr>
  623. <tr>
  624. <th width="8%">地址</th>
  625. <td><input type="text" id="cs_address" name="cs_address" value="<?= htmlspecialcharsFix($customer['cs_address']) ?>" class="txt1" /></td>
  626. </tr>
  627. <tr>
  628. <th>业务类型</th>
  629. <td>
  630. <?php
  631. $result = $conn->query("SELECT id, businessType FROM clienttype");
  632. while ($row = $result->fetch_assoc()) {
  633. $checked = ($row['id'] == $customer['cs_type']) ? ' checked="checked"' : '';
  634. echo "<input type=\"radio\" name=\"cs_type\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\"$checked>
  635. <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
  636. }
  637. ?>
  638. </td>
  639. </tr>
  640. <tr>
  641. <th>跟进阶段</th>
  642. <td>
  643. <?php
  644. $dealOptions = [
  645. ['id' => '0', 'label' => '无响应'],
  646. ['id' => '1', 'label' => '背景调查'],
  647. ['id' => '2', 'label' => '明确需求'],
  648. ['id' => '3', 'label' => '已成交']
  649. ];
  650. foreach ($dealOptions as $option) {
  651. $checked = ($customer['cs_deal'] == $option['id']) ? ' checked="checked"' : '';
  652. $disabled = ($customer['cs_deal'] == '3' && $option['id'] != '3') ? ' disabled="disabled"' : '';
  653. echo "<input type=\"radio\" id=\"fordeal{$option['id']}\" class=\"cs_deal\" name=\"cs_deal\"
  654. value=\"{$option['id']}\"$checked$disabled><label for=\"fordeal{$option['id']}\">{$option['label']}</label>";
  655. }
  656. ?>
  657. </td>
  658. </tr>
  659. <tr>
  660. <th>其他</th>
  661. <td>
  662. <input type="checkbox" id="belongClient" class="cs_belongClient" name="cs_belongClient"
  663. value="1"<?= $customer['cs_belongclient'] == 1 ? ' checked="checked"' : '' ?>>
  664. <label for="belongClient">客户的客户</label>
  665. </td>
  666. </tr>
  667. <tr>
  668. <th>自定义标签</th>
  669. <td>
  670. <div class="taglist">
  671. <?php
  672. $stmt = $conn->prepare("SELECT id, tagName FROM tagtable WHERE customerId = ?");
  673. $stmt->bind_param("i", $id);
  674. $stmt->execute();
  675. $result = $stmt->get_result();
  676. while ($row = $result->fetch_assoc()) {
  677. echo "<span>" . htmlspecialcharsFix($row['tagName']) . "</span>";
  678. }
  679. ?>
  680. </div>
  681. <div class="commontag">
  682. <i class="tag">美特柏品牌客户</i>,
  683. <i class="tag">OEM定制客户</i>,
  684. <i class="tag">小型B端客户</i>,
  685. <i class="tag">C端客户</i>,
  686. <i class="tag">贸易公司</i>,
  687. <i class="tag">档口客户</i>
  688. <?php
  689. $stmt = $conn->prepare("SELECT DISTINCT tagName FROM tagtable WHERE employeeId = ?");
  690. $stmt->bind_param("i", $_SESSION['employee_id']);
  691. $stmt->execute();
  692. $result = $stmt->get_result();
  693. while ($row = $result->fetch_assoc()) {
  694. echo "<i class=\"tag\">" . htmlspecialcharsFix(textUncode($row['tagName'])) . "</i>,";
  695. }
  696. ?>
  697. </div>
  698. <input type="text" id="tapinput" class="txt-short" placeholder="自定义标签,按Enter添加">
  699. <input type="hidden" id="mytag" name="mytag" value="">
  700. </td>
  701. </tr>
  702. <tr>
  703. <th width="8%">备注</th>
  704. <td><textarea name="cs_note" class="txt2"><?= htmlspecialcharsFix($customer['cs_note']) ?></textarea></td>
  705. </tr>
  706. </tbody>
  707. </table>
  708. <div class="form-actions">
  709. <input type="button" name="save" id="save" value="确定" class="btn1" onclick="submitCustomerForm();">
  710. <input type="button" value="返回" class="btn1" onClick="location.href='customers.php<?= $hrefstr ?>'" />
  711. </div>
  712. </form>
  713. </div>
  714. </body>
  715. </html>