customerEdit.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. // Add contact form
  97. $('.add-contact-btn').click(function() {
  98. var contactsContainer = $('#contacts-container');
  99. var contactIndex = contactsContainer.children('.contact-form').length;
  100. var contactForm = `
  101. <div class="contact-form" id="contact-form-${contactIndex}">
  102. <div class="contact-header">
  103. <button type="button" class="remove-contact-btn" data-index="${contactIndex}">删除</button>
  104. <h3>联系人 #${contactIndex + 1}</h3>
  105. </div>
  106. <input type="hidden" name="contact[${contactIndex}][id]" value="">
  107. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  108. <tr>
  109. <th width="8%">联系人</th>
  110. <td><input type="text" name="contact[${contactIndex}][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  111. </tr>
  112. </table>
  113. <div class="contact-methods-container" id="contact-methods-${contactIndex}">
  114. <!-- Contact methods will be added here -->
  115. </div>
  116. <button type="button" class="add-method-btn" data-contact-index="${contactIndex}">添加联系方式</button>
  117. </div>
  118. `;
  119. contactsContainer.append(contactForm);
  120. });
  121. // Add contact method
  122. $(document).on('click', '.add-method-btn', function() {
  123. var contactIndex = $(this).data('contact-index');
  124. var methodsContainer = $('#contact-methods-' + contactIndex);
  125. // Count existing methods by type
  126. var methodCounts = {};
  127. methodsContainer.find('select.method-select').each(function() {
  128. var type = $(this).val();
  129. if (type) {
  130. methodCounts[type] = (methodCounts[type] || 0) + 1;
  131. }
  132. });
  133. var methodRow = `
  134. <div class="contact-method-row">
  135. <select class="method-select" onchange="updateMethodSelectAndPlaceholder(this)">
  136. <option value="">请选择联系方式</option>
  137. <option value="tel" ${(methodCounts.tel || 0) >= 3 ? 'disabled' : ''}>电话</option>
  138. <option value="wechat" ${(methodCounts.wechat || 0) >= 3 ? 'disabled' : ''}>微信</option>
  139. <option value="whatsapp" ${(methodCounts.whatsapp || 0) >= 3 ? 'disabled' : ''}>WhatsApp</option>
  140. <option value="email" ${(methodCounts.email || 0) >= 3 ? 'disabled' : ''}>邮箱</option>
  141. <option value="linkedin" ${(methodCounts.linkedin || 0) >= 3 ? 'disabled' : ''}>领英</option>
  142. <option value="facebook" ${(methodCounts.facebook || 0) >= 3 ? 'disabled' : ''}>Facebook</option>
  143. <option value="alibaba" ${(methodCounts.alibaba || 0) >= 3 ? 'disabled' : ''}>阿里巴巴</option>
  144. </select>
  145. <input type="text" class="txt1 method-input" style="width:60%;" placeholder="请选择联系方式类型">
  146. <button type="button" class="remove-method-btn">删除</button>
  147. </div>
  148. `;
  149. methodsContainer.append(methodRow);
  150. updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
  151. });
  152. // Remove contact method
  153. $(document).on('click', '.remove-method-btn', function() {
  154. var methodRow = $(this).closest('.contact-method-row');
  155. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  156. var type = methodRow.find('select.method-select').val();
  157. methodRow.remove();
  158. // Update available options in other selects
  159. updateAvailableMethodTypes(contactIndex);
  160. });
  161. });
  162. // Update method fields based on selection
  163. function updateMethodFields(methodRow) {
  164. var select = methodRow.find('select.method-select');
  165. var input = methodRow.find('input.method-input');
  166. var contactForm = methodRow.closest('.contact-form');
  167. var contactIndex = contactForm.attr('id').split('-')[2];
  168. var type = select.val();
  169. if (!type) return;
  170. // Count existing methods of this type
  171. var count = 1;
  172. contactForm.find('select.method-select').each(function() {
  173. if ($(this).val() === type && $(this)[0] !== select[0]) {
  174. count++;
  175. }
  176. });
  177. // Update field names
  178. select.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  179. input.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  180. // Add format field for tel and whatsapp
  181. if (type === 'tel' || type === 'whatsapp') {
  182. if (!methodRow.find('.format-input').length) {
  183. input.after(`<input type="hidden" class="format-input" name="contact[${contactIndex}][${type}_${count}_format]">`);
  184. }
  185. }
  186. // Add backup field
  187. if (!methodRow.find('.backup-input').length) {
  188. methodRow.append(`<input type="hidden" class="backup-input" name="contact[${contactIndex}][${type}_${count}_bu]">`);
  189. }
  190. }
  191. // Update available method types for a contact
  192. function updateAvailableMethodTypes(contactIndex) {
  193. var methodsContainer = $('#contact-methods-' + contactIndex);
  194. // Count methods by type
  195. var methodCounts = {};
  196. methodsContainer.find('select.method-select').each(function() {
  197. var type = $(this).val();
  198. if (type) {
  199. methodCounts[type] = (methodCounts[type] || 0) + 1;
  200. }
  201. });
  202. // Update all selects in this contact
  203. methodsContainer.find('select.method-select').each(function() {
  204. var currentValue = $(this).val();
  205. $(this).find('option').each(function() {
  206. var optionValue = $(this).val();
  207. if (optionValue && optionValue !== currentValue) {
  208. $(this).prop('disabled', (methodCounts[optionValue] || 0) >= 3);
  209. }
  210. });
  211. });
  212. }
  213. // Update placeholder and handle method fields
  214. function updateMethodSelectAndPlaceholder(selectElement) {
  215. var methodRow = $(selectElement).closest('.contact-method-row');
  216. updateMethodPlaceholder(selectElement);
  217. updateMethodFields(methodRow);
  218. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  219. updateAvailableMethodTypes(contactIndex);
  220. }
  221. // Look for the updateMethodPlaceholder function and replace it with this modified version
  222. function updateMethodPlaceholder(selectElement) {
  223. var placeholder = "";
  224. var value = $(selectElement).val();
  225. switch(value) {
  226. case "tel":
  227. placeholder = "电话格式:区号+号码 如:+86 15012345678";
  228. break;
  229. case "wechat":
  230. placeholder = "微信";
  231. break;
  232. case "whatsapp":
  233. placeholder = "Whatsapp 格式:区号+号码 如:+86 15012345678";
  234. break;
  235. case "email":
  236. placeholder = "邮件";
  237. break;
  238. case "linkedin":
  239. placeholder = "领英链接";
  240. break;
  241. case "facebook":
  242. placeholder = "Facebook";
  243. break;
  244. case "alibaba":
  245. placeholder = "阿里巴巴";
  246. break;
  247. default:
  248. placeholder = "请选择联系方式类型";
  249. }
  250. $(selectElement).next('.method-input').attr('placeholder', placeholder);
  251. }
  252. // Custom validation function for multiple contacts form with contact methods
  253. function validateMultipleContactsForm() {
  254. var clientCode = $("#cs_code").val();
  255. var clientCompany = $("#cs_company").val();
  256. var clientFrom = $("#cs_from").val();
  257. var clientCountry = $("#cs_country").val();
  258. // Validate basic customer info
  259. if (clientCode == "" || clientCode == null) {
  260. alert("客户代码不能为空!");
  261. $("#cs_code").focus();
  262. return false;
  263. }
  264. if (clientCountry == 0) {
  265. alert("这是哪个国家的客户?");
  266. return false;
  267. }
  268. if (clientFrom == "0") {
  269. alert("请填写客户来源!");
  270. return false;
  271. }
  272. // Validate that at least one contact has at least one contact method
  273. var hasContactMethod = false;
  274. var allContactsValid = true;
  275. $('.contact-form').each(function(contactIndex) {
  276. var $form = $(this);
  277. var contactName = $form.find('input[name*="[contact_name]"]').val();
  278. var hasMethodInThisContact = false;
  279. // Check if this contact has methods
  280. $form.find('.contact-method-row').each(function() {
  281. var methodType = $(this).find('select.method-select').val();
  282. var methodValue = $(this).find('input.method-input').val();
  283. if (methodValue) {
  284. hasMethodInThisContact = true;
  285. hasContactMethod = true;
  286. }
  287. // Check if method type is selected but value is empty
  288. if (methodType && !methodValue) {
  289. alert("联系方式类型已选择但值为空");
  290. allContactsValid = false;
  291. return false;
  292. }
  293. });
  294. // If contact has a name but no methods, or has methods but no name
  295. if ((contactName && !hasMethodInThisContact) || (!contactName && hasMethodInThisContact)) {
  296. alert("联系人 #" + (contactIndex + 1) + " 缺少联系人姓名或联系方式");
  297. allContactsValid = false;
  298. return false;
  299. }
  300. // If contact has neither name nor methods, it's an empty contact
  301. if (!contactName && !hasMethodInThisContact) {
  302. alert("联系人 #" + (contactIndex + 1) + " 是空的,请填写信息或删除此联系人");
  303. allContactsValid = false;
  304. return false;
  305. }
  306. });
  307. if (!allContactsValid) {
  308. return false;
  309. }
  310. if (!hasContactMethod) {
  311. alert("至少需要添加一个联系人,且联系人至少需要一种联系方式!");
  312. return false;
  313. }
  314. // Set tag values
  315. $("input#mytag").val($(".taglist").html());
  316. // Convert the dynamic contact methods to the standard format expected by the server
  317. $('.contact-form').each(function(contactIndex) {
  318. var methodsData = {};
  319. $(this).find('.contact-method-row').each(function() {
  320. var type = $(this).find('select.method-select').val();
  321. var value = $(this).find('input.method-input').val();
  322. if (type && value) {
  323. methodsData[type] = value;
  324. }
  325. });
  326. // Create hidden inputs for each method
  327. for (var type in methodsData) {
  328. $('<input>').attr({
  329. type: 'hidden',
  330. name: 'contact[' + contactIndex + '][' + type + ']',
  331. value: methodsData[type]
  332. }).appendTo(this);
  333. }
  334. });
  335. return true;
  336. }
  337. // Modified submission function
  338. function submitCustomerForm() {
  339. if (validateMultipleContactsForm()) {
  340. $("#form1").submit();
  341. }
  342. }
  343. </script>
  344. <style>
  345. body {
  346. margin: 0;
  347. padding: 20px;
  348. background: #fff;
  349. }
  350. #man_zone {
  351. margin-left: 0;
  352. }
  353. .contact-form {
  354. margin-bottom: 10px;
  355. /*border: 1px solid #ddd;*/
  356. padding: 8px;
  357. background-color: #FFFFFF;
  358. }
  359. .contact-header {
  360. display: flex;
  361. align-items: center;
  362. margin-bottom: 8px;
  363. gap: 10px;
  364. }
  365. .contact-header h3 {
  366. margin: 0;
  367. order: 2;
  368. flex-grow: 1;
  369. }
  370. .remove-contact-btn {
  371. background-color: #f44336;
  372. color: white;
  373. border: none;
  374. padding: 4px 8px;
  375. cursor: pointer;
  376. order: 1;
  377. }
  378. .add-contact-btn {
  379. background-color: #4CAF50;
  380. color: white;
  381. border: none;
  382. padding: 6px 12px;
  383. margin-bottom: 10px;
  384. cursor: pointer;
  385. }
  386. .contact-methods-container {
  387. margin-top: 8px;
  388. }
  389. .contact-method-row {
  390. margin-bottom: 6px;
  391. padding: 6px;
  392. border: 1px solid #eee;
  393. /*background-color: #f5f5f5;*/
  394. display: flex;
  395. align-items: center;
  396. gap: 8px;
  397. }
  398. .add-method-btn {
  399. background-color: #2196F3;
  400. color: white;
  401. border: none;
  402. padding: 4px 8px;
  403. margin-top: 4px;
  404. cursor: pointer;
  405. }
  406. .remove-method-btn {
  407. background-color: #f44336;
  408. color: white;
  409. border: none;
  410. padding: 2px 4px;
  411. cursor: pointer;
  412. }
  413. .method-select {
  414. margin-right: 8px;
  415. padding: 3px;
  416. }
  417. .contact-table {
  418. margin-bottom: 6px;
  419. }
  420. .contact-table td, .contact-table th {
  421. padding: 4px 6px;
  422. }
  423. </style>
  424. </head>
  425. <body class="clear">
  426. <?php // require_once 'panel.php'; ?>
  427. <div id="man_zone">
  428. <form name="form1" id="form1" method="post" action="customerSave.php<?= $hrefstr ?>">
  429. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  430. <tbody>
  431. <tr>
  432. <th width="8%">客户编号</th>
  433. <td>
  434. <input type="text" id="cs_code" name="cs_code" value="<?= htmlspecialcharsFix($customer['cs_code']) ?>"
  435. <?= !empty($customer['cs_claimFrom']) ? 'readonly' : '' ?> class="txt1" />
  436. <input type="hidden" name="id" value="<?= $id ?>" />
  437. <input type="hidden" name="cs_addtime" value="<?= $customer['cs_addtime'] ?>" />
  438. <input type="hidden" name="Permissions" value="<?= $customer['allowedit'] ?>" />
  439. </td>
  440. </tr>
  441. <tr>
  442. <th width="8%">公司名称</th>
  443. <td><input type="text" id="cs_company" name="cs_company" value="<?= htmlspecialcharsFix($customer['cs_company']) ?>" class="txt1" /></td>
  444. </tr>
  445. <tr>
  446. <th width="8%">地区</th>
  447. <td>
  448. <div class="layui-input-inline">
  449. <div class="layui-form-select ySearchSelect y1">
  450. <div class="layui-input">
  451. <?php
  452. $stmt = $conn->prepare("SELECT id, countryCode, countryName FROM country WHERE id = ?");
  453. $stmt->bind_param("i", $customer['cs_country']);
  454. $stmt->execute();
  455. $countryResult = $stmt->get_result();
  456. if ($countryRow = $countryResult->fetch_assoc()) {
  457. $countryId = $countryRow['id'];
  458. echo htmlspecialcharsFix($countryRow['countryName']);
  459. } else {
  460. echo "请选择";
  461. }
  462. ?>
  463. </div>
  464. <ul>
  465. <?php
  466. $result = $conn->query("SELECT id, countryCode, countryName FROM country");
  467. while ($row = $result->fetch_assoc()) {
  468. echo "<li class=\"on\" data-c=\"{$row['id']}\">(+{$row['countryCode']}){$row['countryName']}</li>";
  469. }
  470. ?>
  471. <p>无匹配项</p>
  472. </ul>
  473. <input name="cs_country" id="cs_country" value="<?= $countryId ?? '' ?>" type="hidden">
  474. </div>
  475. </div>
  476. <script>
  477. $(function () {
  478. $(".y1").ySearchSelect();
  479. })
  480. </script>
  481. </td>
  482. </tr>
  483. <tr>
  484. <th width="8%">客户来源</th>
  485. <td>
  486. <select id="cs_from" name="cs_from">
  487. <option value="0">请选择来源</option>
  488. <?php
  489. $result = $conn->query("SELECT id, ch_name FROM qudao");
  490. while ($row = $result->fetch_assoc()) {
  491. $selected = ($customer['cs_from'] == $row['id']) ? ' selected="selected"' : '';
  492. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  493. }
  494. ?>
  495. </select>
  496. </td>
  497. </tr>
  498. <tr>
  499. <th width="8%" valign="top">联系人信息</th>
  500. <td>
  501. <button type="button" class="add-contact-btn">添加联系人</button>
  502. <div id="contacts-container">
  503. <?php if (!empty($contacts)): ?>
  504. <?php foreach ($contacts as $index => $contact): ?>
  505. <div class="contact-form" id="contact-form-<?= $index ?>">
  506. <div class="contact-header">
  507. <button type="button" class="remove-contact-btn" data-index="<?= $index ?>">删除</button>
  508. <h3>联系人 #<?= $index + 1 ?></h3>
  509. </div>
  510. <input type="hidden" name="contact[<?= $index ?>][id]" value="<?= $contact['id'] ?>">
  511. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  512. <tr>
  513. <th width="8%">联系人</th>
  514. <td><input type="text" name="contact[<?= $index ?>][contact_name]" value="<?= htmlspecialcharsFix($contact['contact_name']) ?>" class="txt1" placeholder="联系人姓名"/></td>
  515. </tr>
  516. </table>
  517. <div class="contact-methods-container" id="contact-methods-<?= $index ?>">
  518. <?php
  519. $methodTypes = [
  520. 'tel' => '电话',
  521. 'wechat' => '微信',
  522. 'whatsapp' => 'WhatsApp',
  523. 'email' => '邮箱',
  524. 'linkedin' => '领英',
  525. 'facebook' => 'Facebook',
  526. 'alibaba' => '阿里巴巴'
  527. ];
  528. foreach ($methodTypes as $type => $label) {
  529. for ($i = 1; $i <= 3; $i++) {
  530. $fieldName = $type . '_' . $i;
  531. if (!empty($contact[$fieldName])) {
  532. echo '<div class="contact-method-row">';
  533. echo '<select class="method-select" name="contact[' . $index . '][' . $fieldName . ']" onchange="updateMethodSelectAndPlaceholder(this)">';
  534. echo '<option value="">请选择联系方式</option>';
  535. foreach ($methodTypes as $optionType => $optionLabel) {
  536. $selected = ($optionType === $type) ? 'selected' : '';
  537. echo '<option value="' . $optionType . '" ' . $selected . '>' . $optionLabel . '</option>';
  538. }
  539. echo '</select>';
  540. echo '<input type="text" class="txt1 method-input" style="width:60%;" name="contact[' . $index . '][' . $fieldName . ']" value="' . htmlspecialcharsFix($contact[$fieldName]) . '">';
  541. if ($type === 'tel' || $type === 'whatsapp') {
  542. echo '<input type="hidden" class="format-input" name="contact[' . $index . '][' . $fieldName . '_format]" value="' . htmlspecialcharsFix($contact[$fieldName . '_format']) . '">';
  543. }
  544. echo '<input type="hidden" class="backup-input" name="contact[' . $index . '][' . $fieldName . '_bu]" value="' . htmlspecialcharsFix($contact[$fieldName . '_bu']) . '">';
  545. echo '<button type="button" class="remove-method-btn">删除</button>';
  546. echo '</div>';
  547. }
  548. }
  549. }
  550. ?>
  551. </div>
  552. <button type="button" class="add-method-btn" data-contact-index="<?= $index ?>">添加联系方式</button>
  553. </div>
  554. <?php endforeach; ?>
  555. <?php else: ?>
  556. <div class="contact-form" id="contact-form-0">
  557. <div class="contact-header">
  558. <button type="button" class="remove-contact-btn" data-index="0">删除</button>
  559. <h3>联系人 #1</h3>
  560. </div>
  561. <input type="hidden" name="contact[0][id]" value="">
  562. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  563. <tr>
  564. <th width="8%">联系人</th>
  565. <td><input type="text" name="contact[0][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  566. </tr>
  567. </table>
  568. <div class="contact-methods-container" id="contact-methods-0">
  569. <!-- Contact methods will be added here -->
  570. </div>
  571. <button type="button" class="add-method-btn" data-contact-index="0">添加联系方式</button>
  572. </div>
  573. <?php endif; ?>
  574. </div>
  575. </td>
  576. </tr>
  577. <tr>
  578. <th width="8%">地址</th>
  579. <td><input type="text" id="cs_address" name="cs_address" value="<?= htmlspecialcharsFix($customer['cs_address']) ?>" class="txt1" /></td>
  580. </tr>
  581. <tr>
  582. <th>业务类型</th>
  583. <td>
  584. <?php
  585. $result = $conn->query("SELECT id, businessType FROM clienttype");
  586. while ($row = $result->fetch_assoc()) {
  587. $checked = ($row['id'] == $customer['cs_type']) ? ' checked="checked"' : '';
  588. echo "<input type=\"radio\" name=\"cs_type\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\"$checked>
  589. <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
  590. }
  591. ?>
  592. </td>
  593. </tr>
  594. <tr>
  595. <th>跟进阶段</th>
  596. <td>
  597. <?php
  598. $dealOptions = [
  599. ['id' => '0', 'label' => '无响应'],
  600. ['id' => '1', 'label' => '背景调查'],
  601. ['id' => '2', 'label' => '明确需求'],
  602. ['id' => '3', 'label' => '已成交']
  603. ];
  604. foreach ($dealOptions as $option) {
  605. $checked = ($customer['cs_deal'] == $option['id']) ? ' checked="checked"' : '';
  606. $disabled = ($customer['cs_deal'] == '3' && $option['id'] != '3') ? ' disabled="disabled"' : '';
  607. echo "<input type=\"radio\" id=\"fordeal{$option['id']}\" class=\"cs_deal\" name=\"cs_deal\"
  608. value=\"{$option['id']}\"$checked$disabled><label for=\"fordeal{$option['id']}\">{$option['label']}</label>";
  609. }
  610. ?>
  611. </td>
  612. </tr>
  613. <tr>
  614. <th>其他</th>
  615. <td>
  616. <input type="checkbox" id="belongClient" class="cs_belongClient" name="cs_belongClient"
  617. value="1"<?= $customer['cs_belongclient'] == 1 ? ' checked="checked"' : '' ?>>
  618. <label for="belongClient">客户的客户</label>
  619. </td>
  620. </tr>
  621. <tr>
  622. <th>自定义标签</th>
  623. <td>
  624. <div class="taglist">
  625. <?php
  626. $stmt = $conn->prepare("SELECT id, tagName FROM tagtable WHERE customerId = ?");
  627. $stmt->bind_param("i", $id);
  628. $stmt->execute();
  629. $result = $stmt->get_result();
  630. while ($row = $result->fetch_assoc()) {
  631. echo "<span>" . htmlspecialcharsFix($row['tagName']) . "</span>";
  632. }
  633. ?>
  634. </div>
  635. <div class="commontag">
  636. <i class="tag">美特柏品牌客户</i>,
  637. <i class="tag">OEM定制客户</i>,
  638. <i class="tag">小型B端客户</i>,
  639. <i class="tag">C端客户</i>,
  640. <i class="tag">贸易公司</i>,
  641. <i class="tag">档口客户</i>
  642. <?php
  643. $stmt = $conn->prepare("SELECT DISTINCT tagName FROM tagtable WHERE employeeId = ?");
  644. $stmt->bind_param("i", $_SESSION['employee_id']);
  645. $stmt->execute();
  646. $result = $stmt->get_result();
  647. while ($row = $result->fetch_assoc()) {
  648. echo "<i class=\"tag\">" . htmlspecialcharsFix(textUncode($row['tagName'])) . "</i>,";
  649. }
  650. ?>
  651. </div>
  652. <input type="text" id="tapinput" class="txt-short" placeholder="自定义标签,按Enter添加">
  653. <input type="hidden" id="mytag" name="mytag" value="">
  654. </td>
  655. </tr>
  656. <tr>
  657. <th width="8%">备注</th>
  658. <td><textarea name="cs_note" class="txt2"><?= htmlspecialcharsFix($customer['cs_note']) ?></textarea></td>
  659. </tr>
  660. </tbody>
  661. </table>
  662. <div class="form-actions">
  663. <input type="button" name="save" id="save" value="确定" class="btn1" onclick="submitCustomerForm();">
  664. <input type="button" value="返回" class="btn1" onClick="location.href='customers.php<?= $hrefstr ?>'" />
  665. </div>
  666. </form>
  667. </div>
  668. </body>
  669. </html>