customerEdit.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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. // Validate that at least one contact has at least one contact method
  284. var hasContactMethod = false;
  285. var allContactsValid = true;
  286. var phoneRegex = /^\+\d{1,4}\s\d{5,}$/; // Regex to validate phone format: +[country code] [number]
  287. var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; // Regex to validate email format
  288. $('.contact-form').each(function(contactIndex) {
  289. var $form = $(this);
  290. var contactName = $form.find('input[name*="[contact_name]"]').val();
  291. var hasMethodInThisContact = false;
  292. // Check if this contact has methods
  293. $form.find('.contact-method-row').each(function() {
  294. var methodType = $(this).find('select.method-select').val();
  295. var methodValue = $(this).find('input.method-input').val();
  296. if (methodValue) {
  297. hasMethodInThisContact = true;
  298. hasContactMethod = true;
  299. }
  300. // Check if method type is selected but value is empty
  301. if (methodType && !methodValue) {
  302. alert("联系方式类型已选择但值为空");
  303. allContactsValid = false;
  304. return false;
  305. }
  306. // Validate phone number format for tel and whatsapp
  307. if ((methodType === 'tel' || methodType === 'whatsapp') && methodValue) {
  308. if (!phoneRegex.test(methodValue)) {
  309. alert("电话格式不正确,请使用以下格式:区号+号码,如 +86 15012345678");
  310. $(this).find('input.method-input').focus();
  311. allContactsValid = false;
  312. return false;
  313. }
  314. }
  315. // Validate email format
  316. if (methodType === 'email' && methodValue) {
  317. if (!emailRegex.test(methodValue)) {
  318. alert("邮箱格式不正确,请输入有效的邮箱地址");
  319. $(this).find('input.method-input').focus();
  320. allContactsValid = false;
  321. return false;
  322. }
  323. }
  324. });
  325. // If contact has a name but no methods, or has methods but no name
  326. if ((contactName && !hasMethodInThisContact) || (!contactName && hasMethodInThisContact)) {
  327. alert("联系人 #" + (contactIndex + 1) + " 缺少联系人姓名或联系方式");
  328. allContactsValid = false;
  329. return false;
  330. }
  331. // If contact has neither name nor methods, it's an empty contact
  332. if (!contactName && !hasMethodInThisContact) {
  333. alert("联系人 #" + (contactIndex + 1) + " 是空的,请填写信息或删除此联系人");
  334. allContactsValid = false;
  335. return false;
  336. }
  337. });
  338. if (!allContactsValid) {
  339. return false;
  340. }
  341. if (!hasContactMethod) {
  342. alert("至少需要添加一个联系人,且联系人至少需要一种联系方式!");
  343. return false;
  344. }
  345. // Set tag values
  346. $("input#mytag").val($(".taglist").html());
  347. // Convert the dynamic contact methods to the standard format expected by the server
  348. $('.contact-form').each(function(contactIndex) {
  349. var methodsData = {};
  350. $(this).find('.contact-method-row').each(function() {
  351. var type = $(this).find('select.method-select').val();
  352. var value = $(this).find('input.method-input').val();
  353. if (type && value) {
  354. methodsData[type] = value;
  355. }
  356. });
  357. // Create hidden inputs for each method
  358. for (var type in methodsData) {
  359. $('<input>').attr({
  360. type: 'hidden',
  361. name: 'contact[' + contactIndex + '][' + type + ']',
  362. value: methodsData[type]
  363. }).appendTo(this);
  364. }
  365. });
  366. return true;
  367. }
  368. // Modified submission function
  369. function submitCustomerForm() {
  370. if (validateMultipleContactsForm()) {
  371. $("#form1").submit();
  372. }
  373. }
  374. </script>
  375. <style>
  376. body {
  377. margin: 0;
  378. padding: 20px;
  379. background: #fff;
  380. }
  381. #man_zone {
  382. margin-left: 0;
  383. }
  384. .contact-form {
  385. margin-bottom: 10px;
  386. /*border: 1px solid #ddd;*/
  387. padding: 8px;
  388. background-color: #FFFFFF;
  389. }
  390. .contact-header {
  391. display: flex;
  392. align-items: center;
  393. margin-bottom: 8px;
  394. gap: 10px;
  395. }
  396. .contact-header h3 {
  397. margin: 0;
  398. order: 2;
  399. flex-grow: 1;
  400. }
  401. .remove-contact-btn {
  402. background-color: #f44336;
  403. color: white;
  404. border: none;
  405. padding: 4px 8px;
  406. cursor: pointer;
  407. order: 1;
  408. }
  409. .add-contact-btn {
  410. background-color: #4CAF50;
  411. color: white;
  412. border: none;
  413. padding: 6px 12px;
  414. margin-bottom: 10px;
  415. cursor: pointer;
  416. }
  417. .contact-methods-container {
  418. margin-top: 8px;
  419. }
  420. .contact-method-row {
  421. margin-bottom: 6px;
  422. padding: 6px;
  423. border: 1px solid #eee;
  424. /*background-color: #f5f5f5;*/
  425. display: flex;
  426. align-items: center;
  427. gap: 8px;
  428. }
  429. .add-method-btn {
  430. background-color: #2196F3;
  431. color: white;
  432. border: none;
  433. padding: 4px 8px;
  434. margin-top: 4px;
  435. cursor: pointer;
  436. }
  437. .remove-method-btn {
  438. background-color: #f44336;
  439. color: white;
  440. border: none;
  441. padding: 2px 4px;
  442. cursor: pointer;
  443. }
  444. .method-select {
  445. margin-right: 8px;
  446. padding: 3px;
  447. }
  448. .contact-table {
  449. margin-bottom: 6px;
  450. }
  451. .contact-table td, .contact-table th {
  452. padding: 4px 6px;
  453. }
  454. </style>
  455. </head>
  456. <body class="clear">
  457. <?php // require_once 'panel.php'; ?>
  458. <div id="man_zone">
  459. <form name="form1" id="form1" method="post" action="customerSave.php<?= $hrefstr ?>">
  460. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  461. <tbody>
  462. <tr>
  463. <th width="8%">客户编号</th>
  464. <td>
  465. <input type="text" id="cs_code" name="cs_code" value="<?= htmlspecialcharsFix($customer['cs_code']) ?>"
  466. <?= !empty($customer['cs_claimFrom']) ? 'readonly' : '' ?> class="txt1" />
  467. <input type="hidden" name="id" value="<?= $id ?>" />
  468. <input type="hidden" name="cs_addtime" value="<?= $customer['cs_addtime'] ?>" />
  469. <input type="hidden" name="Permissions" value="<?= $customer['allowedit'] ?>" />
  470. </td>
  471. </tr>
  472. <tr>
  473. <th width="8%">公司名称</th>
  474. <td><input type="text" id="cs_company" name="cs_company" value="<?= htmlspecialcharsFix($customer['cs_company']) ?>" class="txt1" /></td>
  475. </tr>
  476. <tr>
  477. <th width="8%">地区/国家</th>
  478. <td>
  479. <div class="layui-input-inline">
  480. <div class="layui-form-select ySearchSelect y1">
  481. <div class="layui-input">
  482. <?php
  483. $stmt = $conn->prepare("SELECT id, countryCode, countryName FROM country WHERE id = ?");
  484. $stmt->bind_param("i", $customer['cs_country']);
  485. $stmt->execute();
  486. $countryResult = $stmt->get_result();
  487. if ($countryRow = $countryResult->fetch_assoc()) {
  488. $countryId = $countryRow['id'];
  489. echo htmlspecialcharsFix($countryRow['countryName']);
  490. } else {
  491. echo "请选择";
  492. }
  493. ?>
  494. </div>
  495. <ul>
  496. <?php
  497. $result = $conn->query("SELECT id, countryCode, countryName FROM country");
  498. while ($row = $result->fetch_assoc()) {
  499. echo "<li class=\"on\" data-c=\"{$row['id']}\">(+{$row['countryCode']}){$row['countryName']}</li>";
  500. }
  501. ?>
  502. <p>无匹配项</p>
  503. </ul>
  504. <input name="cs_country" id="cs_country" value="<?= $countryId ?? '' ?>" type="hidden">
  505. </div>
  506. </div>
  507. <script>
  508. $(function () {
  509. $(".y1").ySearchSelect();
  510. })
  511. </script>
  512. </td>
  513. </tr>
  514. <tr>
  515. <th width="8%">客户来源</th>
  516. <td>
  517. <select id="cs_from" name="cs_from">
  518. <option value="0">请选择来源</option>
  519. <?php
  520. $result = $conn->query("SELECT id, ch_name FROM qudao");
  521. while ($row = $result->fetch_assoc()) {
  522. $selected = ($customer['cs_from'] == $row['id']) ? ' selected="selected"' : '';
  523. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  524. }
  525. ?>
  526. </select>
  527. </td>
  528. </tr>
  529. <tr>
  530. <th width="8%" valign="top">联系人信息</th>
  531. <td>
  532. <button type="button" class="add-contact-btn">添加联系人</button>
  533. <div id="contacts-container">
  534. <?php if (!empty($contacts)): ?>
  535. <?php foreach ($contacts as $index => $contact): ?>
  536. <div class="contact-form" id="contact-form-<?= $index ?>">
  537. <div class="contact-header">
  538. <button type="button" class="remove-contact-btn" data-index="<?= $index ?>">删除</button>
  539. <h3>联系人 #<?= $index + 1 ?></h3>
  540. </div>
  541. <input type="hidden" name="contact[<?= $index ?>][id]" value="<?= $contact['id'] ?>">
  542. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  543. <tr>
  544. <th width="8%">联系人</th>
  545. <td><input type="text" name="contact[<?= $index ?>][contact_name]" value="<?= htmlspecialcharsFix($contact['contact_name']) ?>" class="txt1" placeholder="联系人姓名"/></td>
  546. </tr>
  547. </table>
  548. <div class="contact-methods-container" id="contact-methods-<?= $index ?>">
  549. <?php
  550. $methodTypes = [
  551. 'tel' => '电话',
  552. 'wechat' => '微信',
  553. 'whatsapp' => 'WhatsApp',
  554. 'email' => '邮箱',
  555. 'linkedin' => '领英',
  556. 'facebook' => 'Facebook',
  557. 'alibaba' => '阿里巴巴'
  558. ];
  559. foreach ($methodTypes as $type => $label) {
  560. for ($i = 1; $i <= 3; $i++) {
  561. $fieldName = $type . '_' . $i;
  562. if (!empty($contact[$fieldName])) {
  563. echo '<div class="contact-method-row">';
  564. echo '<select class="method-select" name="contact[' . $index . '][' . $fieldName . ']" onchange="updateMethodSelectAndPlaceholder(this)">';
  565. echo '<option value="">请选择联系方式</option>';
  566. foreach ($methodTypes as $optionType => $optionLabel) {
  567. $selected = ($optionType === $type) ? 'selected' : '';
  568. echo '<option value="' . $optionType . '" ' . $selected . '>' . $optionLabel . '</option>';
  569. }
  570. echo '</select>';
  571. echo '<input type="text" class="txt1 method-input" style="width:60%;" name="contact[' . $index . '][' . $fieldName . ']" value="' . htmlspecialcharsFix($contact[$fieldName]) . '">';
  572. if ($type === 'tel' || $type === 'whatsapp') {
  573. echo '<input type="hidden" class="format-input" name="contact[' . $index . '][' . $fieldName . '_format]" value="' . htmlspecialcharsFix($contact[$fieldName . '_format']) . '">';
  574. }
  575. echo '<input type="hidden" class="backup-input" name="contact[' . $index . '][' . $fieldName . '_bu]" value="' . htmlspecialcharsFix($contact[$fieldName . '_bu']) . '">';
  576. echo '<button type="button" class="remove-method-btn">删除</button>';
  577. echo '</div>';
  578. }
  579. }
  580. }
  581. ?>
  582. </div>
  583. <button type="button" class="add-method-btn" data-contact-index="<?= $index ?>">添加联系方式</button>
  584. </div>
  585. <?php endforeach; ?>
  586. <?php else: ?>
  587. <div class="contact-form" id="contact-form-0">
  588. <div class="contact-header">
  589. <button type="button" class="remove-contact-btn" data-index="0">删除</button>
  590. <h3>联系人 #1</h3>
  591. </div>
  592. <input type="hidden" name="contact[0][id]" value="">
  593. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  594. <tr>
  595. <th width="8%">联系人</th>
  596. <td><input type="text" name="contact[0][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  597. </tr>
  598. </table>
  599. <div class="contact-methods-container" id="contact-methods-0">
  600. <!-- Contact methods will be added here -->
  601. </div>
  602. <button type="button" class="add-method-btn" data-contact-index="0">添加联系方式</button>
  603. </div>
  604. <?php endif; ?>
  605. </div>
  606. </td>
  607. </tr>
  608. <tr>
  609. <th width="8%">地址</th>
  610. <td><input type="text" id="cs_address" name="cs_address" value="<?= htmlspecialcharsFix($customer['cs_address']) ?>" class="txt1" /></td>
  611. </tr>
  612. <tr>
  613. <th>业务类型</th>
  614. <td>
  615. <?php
  616. $result = $conn->query("SELECT id, businessType FROM clienttype");
  617. while ($row = $result->fetch_assoc()) {
  618. $checked = ($row['id'] == $customer['cs_type']) ? ' checked="checked"' : '';
  619. echo "<input type=\"radio\" name=\"cs_type\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\"$checked>
  620. <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
  621. }
  622. ?>
  623. </td>
  624. </tr>
  625. <tr>
  626. <th>跟进阶段</th>
  627. <td>
  628. <?php
  629. $dealOptions = [
  630. ['id' => '0', 'label' => '无响应'],
  631. ['id' => '1', 'label' => '背景调查'],
  632. ['id' => '2', 'label' => '明确需求'],
  633. ['id' => '3', 'label' => '已成交']
  634. ];
  635. foreach ($dealOptions as $option) {
  636. $checked = ($customer['cs_deal'] == $option['id']) ? ' checked="checked"' : '';
  637. $disabled = ($customer['cs_deal'] == '3' && $option['id'] != '3') ? ' disabled="disabled"' : '';
  638. echo "<input type=\"radio\" id=\"fordeal{$option['id']}\" class=\"cs_deal\" name=\"cs_deal\"
  639. value=\"{$option['id']}\"$checked$disabled><label for=\"fordeal{$option['id']}\">{$option['label']}</label>";
  640. }
  641. ?>
  642. </td>
  643. </tr>
  644. <tr>
  645. <th>其他</th>
  646. <td>
  647. <input type="checkbox" id="belongClient" class="cs_belongClient" name="cs_belongClient"
  648. value="1"<?= $customer['cs_belongclient'] == 1 ? ' checked="checked"' : '' ?>>
  649. <label for="belongClient">客户的客户</label>
  650. </td>
  651. </tr>
  652. <tr>
  653. <th>自定义标签</th>
  654. <td>
  655. <div class="taglist">
  656. <?php
  657. $stmt = $conn->prepare("SELECT id, tagName FROM tagtable WHERE customerId = ?");
  658. $stmt->bind_param("i", $id);
  659. $stmt->execute();
  660. $result = $stmt->get_result();
  661. while ($row = $result->fetch_assoc()) {
  662. echo "<span>" . htmlspecialcharsFix($row['tagName']) . "</span>";
  663. }
  664. ?>
  665. </div>
  666. <div class="commontag">
  667. <i class="tag">美特柏品牌客户</i>,
  668. <i class="tag">OEM定制客户</i>,
  669. <i class="tag">小型B端客户</i>,
  670. <i class="tag">C端客户</i>,
  671. <i class="tag">贸易公司</i>,
  672. <i class="tag">档口客户</i>
  673. <?php
  674. $stmt = $conn->prepare("SELECT DISTINCT tagName FROM tagtable WHERE employeeId = ?");
  675. $stmt->bind_param("i", $_SESSION['employee_id']);
  676. $stmt->execute();
  677. $result = $stmt->get_result();
  678. while ($row = $result->fetch_assoc()) {
  679. echo "<i class=\"tag\">" . htmlspecialcharsFix(textUncode($row['tagName'])) . "</i>,";
  680. }
  681. ?>
  682. </div>
  683. <input type="text" id="tapinput" class="txt-short" placeholder="自定义标签,按Enter添加">
  684. <input type="hidden" id="mytag" name="mytag" value="">
  685. </td>
  686. </tr>
  687. <tr>
  688. <th width="8%">备注</th>
  689. <td><textarea name="cs_note" class="txt2"><?= htmlspecialcharsFix($customer['cs_note']) ?></textarea></td>
  690. </tr>
  691. </tbody>
  692. </table>
  693. <div class="form-actions">
  694. <input type="button" name="save" id="save" value="确定" class="btn1" onclick="submitCustomerForm();">
  695. <input type="button" value="返回" class="btn1" onClick="location.href='customers.php<?= $hrefstr ?>'" />
  696. </div>
  697. </form>
  698. </div>
  699. </body>
  700. </html>