customerEdit.php 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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. 'cs_dealdate' => $row['cs_dealdate']
  32. ];
  33. // Fetch all contact records for this customer
  34. $contactSql = "SELECT cc.* FROM customer_contact cc WHERE cc.customer_id = ?";
  35. $contactStmt = $conn->prepare($contactSql);
  36. $contactStmt->bind_param("i", $id);
  37. $contactStmt->execute();
  38. $contactResult = $contactStmt->get_result();
  39. $contacts = [];
  40. while ($contactRow = $contactResult->fetch_assoc()) {
  41. $contact = [
  42. 'id' => $contactRow['id'],
  43. 'contact_name' => textUncode($contactRow['contact_name']),
  44. 'created_at' => $contactRow['created_at'],
  45. 'updated_at' => $contactRow['updated_at']
  46. ];
  47. // Process each contact method type (up to 3 entries each)
  48. $methodTypes = ['tel', 'email', 'whatsapp', 'wechat', 'linkedin', 'facebook', 'alibaba'];
  49. foreach ($methodTypes as $type) {
  50. for ($i = 1; $i <= 3; $i++) {
  51. $fieldBase = $type . '_' . $i;
  52. $contact[$fieldBase] = textUncode($contactRow[$fieldBase]);
  53. if ($type == 'tel' || $type == 'whatsapp') {
  54. $contact[$fieldBase . '_format'] = textUncode($contactRow[$fieldBase . '_format']);
  55. }
  56. $contact[$fieldBase . '_bu'] = textUncode($contactRow[$fieldBase . '_bu']);
  57. }
  58. }
  59. $contacts[] = $contact;
  60. }
  61. } else {
  62. echo "<script>alert('客户不存在或你没权限查看!');history.back();</script>";
  63. exit;
  64. }
  65. } else {
  66. echo "<script>alert('客户不存在!');history.back();</script>";
  67. header("Location: $hrefstr");
  68. exit;
  69. }
  70. ?>
  71. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  72. <html xmlns="http://www.w3.org/1999/xhtml">
  73. <head>
  74. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  75. <title>管理区域</title>
  76. <link rel="stylesheet" href="css/common.css" type="text/css" />
  77. <script src="system/js/jquery-1.7.2.min.js"></script>
  78. <script src="js/js.js"></script>
  79. <script src="js/xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  80. <script src="js/Hz2Py-szm-min.js"></script>
  81. <script src="js/ySearchSelect.js"></script>
  82. <script>
  83. $(document).ready(function(){
  84. $('.txt2').xheditor({
  85. tools:'simple',
  86. hoverExecDelay:-1
  87. });
  88. // 失去焦点时执行格式化
  89. $(document).on('blur', '.method-input', function() {
  90. var methodType = $(this).prev('.method-select').val();
  91. if (methodType === 'tel' || methodType === 'whatsapp') {
  92. var formattedValue = formatPhoneNumber($(this).val(), true);
  93. $(this).val(formattedValue);
  94. }
  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. <div class="contact-method-row">
  117. <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
  118. <input type="text" name="contact[${contactIndex}][contact_name]" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
  119. </div>
  120. <div class="contact-methods-container" id="contact-methods-${contactIndex}">
  121. <!-- Contact methods will be added here -->
  122. </div>
  123. <button type="button" class="add-method-btn" data-contact-index="${contactIndex}">添加联系方式</button>
  124. </div>
  125. `;
  126. contactsContainer.append(contactForm);
  127. });
  128. // Add contact method
  129. $(document).on('click', '.add-method-btn', function() {
  130. var contactIndex = $(this).data('contact-index');
  131. var methodsContainer = $('#contact-methods-' + contactIndex);
  132. // Count existing methods by type
  133. var methodCounts = {};
  134. methodsContainer.find('select.method-select').each(function() {
  135. var type = $(this).val();
  136. if (type) {
  137. methodCounts[type] = (methodCounts[type] || 0) + 1;
  138. }
  139. });
  140. var methodRow = `
  141. <div class="contact-method-row">
  142. <select class="method-select" onchange="updateMethodSelectAndPlaceholder(this)">
  143. <option value="">请选择联系方式</option>
  144. <option value="tel" ${(methodCounts.tel || 0) >= 3 ? 'disabled' : ''}>电话</option>
  145. <option value="wechat" ${(methodCounts.wechat || 0) >= 3 ? 'disabled' : ''}>微信</option>
  146. <option value="whatsapp" ${(methodCounts.whatsapp || 0) >= 3 ? 'disabled' : ''}>WhatsApp</option>
  147. <option value="email" ${(methodCounts.email || 0) >= 3 ? 'disabled' : ''}>邮箱</option>
  148. <option value="linkedin" ${(methodCounts.linkedin || 0) >= 3 ? 'disabled' : ''}>领英</option>
  149. <option value="facebook" ${(methodCounts.facebook || 0) >= 3 ? 'disabled' : ''}>Facebook</option>
  150. <option value="alibaba" ${(methodCounts.alibaba || 0) >= 3 ? 'disabled' : ''}>阿里巴巴</option>
  151. </select>
  152. <input type="text" class="txt1 method-input" style="width:60%;" placeholder="请选择联系方式类型">
  153. <button type="button" class="remove-method-btn">删除</button>
  154. </div>
  155. `;
  156. methodsContainer.append(methodRow);
  157. updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
  158. });
  159. // Remove contact method
  160. $(document).on('click', '.remove-method-btn', function() {
  161. var methodRow = $(this).closest('.contact-method-row');
  162. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  163. var type = methodRow.find('select.method-select').val();
  164. methodRow.remove();
  165. // Update available options in other selects
  166. updateAvailableMethodTypes(contactIndex);
  167. });
  168. // 客户关系相关JS代码
  169. // 显示添加关系弹窗
  170. $('#add-relationship-btn').click(function() {
  171. $('#relationship-modal-title').text('添加客户关系');
  172. $('#relationship_id').val('');
  173. $('#related_customer_id').val('');
  174. $('#related_customer_search').val('').show();
  175. $('#related_customer_selected').hide();
  176. $('#relationship_type').val('');
  177. $('input[name="relationship_status"][value="1"]').prop('checked', true);
  178. $('#relationship_description').val('');
  179. $('<div class="modal-backdrop"></div>').appendTo('body');
  180. $('#relationship-modal').show();
  181. });
  182. // 关闭弹窗
  183. $('#cancel-relationship-btn').click(function() {
  184. $('#relationship-modal').hide();
  185. $('.modal-backdrop').remove();
  186. });
  187. // 编辑关系
  188. $(document).on('click', '.edit-relationship-btn', function() {
  189. var relationshipId = $(this).data('id');
  190. // AJAX获取关系详情
  191. $.ajax({
  192. url: 'get_relationship.php',
  193. type: 'GET',
  194. data: {id: relationshipId},
  195. dataType: 'json',
  196. success: function(data) {
  197. if (data && data.success) {
  198. var relationship = data.relationship;
  199. $('#relationship_id').val(relationship.id);
  200. // 确定关联的客户(不是当前客户的那一方)
  201. var currentCustomerId = $('#current_customer_id').val();
  202. var relatedCustomerId = relationship.source_customer_id == currentCustomerId
  203. ? relationship.target_customer_id
  204. : relationship.source_customer_id;
  205. var relatedCustomerName = relationship.source_customer_id == currentCustomerId
  206. ? relationship.target_company
  207. : relationship.source_company;
  208. var relatedCustomerCode = relationship.source_customer_id == currentCustomerId
  209. ? relationship.target_code
  210. : relationship.source_code;
  211. var displayText = relatedCustomerName;
  212. if (relatedCustomerCode) {
  213. displayText = relatedCustomerCode + ' - ' + relatedCustomerName;
  214. }
  215. $('#related_customer_id').val(relatedCustomerId);
  216. $('#related_customer_search').hide();
  217. $('#related_customer_selected')
  218. .text(displayText)
  219. .append('<span class="customer-clear-btn" title="清除选择">X</span>')
  220. .show()
  221. .attr('title', displayText);
  222. $('#relationship_type').val(relationship.relationship_type);
  223. $('input[name="relationship_status"][value="' + relationship.relationship_status + '"]').prop('checked', true);
  224. $('#relationship_description').val(relationship.description);
  225. $('#relationship-modal-title').text('编辑客户关系');
  226. $('<div class="modal-backdrop"></div>').appendTo('body');
  227. $('#relationship-modal').show();
  228. } else {
  229. alert('获取关系信息失败');
  230. }
  231. },
  232. error: function() {
  233. alert('获取关系信息失败,请稍后重试');
  234. }
  235. });
  236. });
  237. // 删除关系
  238. $(document).on('click', '.delete-relationship-btn', function() {
  239. if (confirm('确定要删除此客户关系吗?')) {
  240. var relationshipId = $(this).data('id');
  241. $.ajax({
  242. url: 'delete_relationship.php',
  243. type: 'POST',
  244. data: {id: relationshipId},
  245. dataType: 'json',
  246. success: function(data) {
  247. if (data && data.success) {
  248. alert('删除成功');
  249. location.reload();
  250. } else {
  251. alert(data.message || '删除失败');
  252. }
  253. },
  254. error: function() {
  255. alert('操作失败,请稍后重试');
  256. }
  257. });
  258. }
  259. });
  260. // 保存关系
  261. $('#save-relationship-btn').click(function() {
  262. var relationshipId = $('#relationship_id').val();
  263. var currentCustomerId = $('#current_customer_id').val();
  264. var relatedCustomerId = $('#related_customer_id').val();
  265. var relationshipType = $('#relationship_type').val();
  266. var relationshipStatus = $('input[name="relationship_status"]:checked').val();
  267. var description = $('#relationship_description').val();
  268. // 验证
  269. if (!relatedCustomerId) {
  270. alert('请选择关联客户');
  271. return;
  272. }
  273. if (!relationshipType) {
  274. alert('请选择关系类型');
  275. return;
  276. }
  277. var data = {
  278. id: relationshipId,
  279. source_customer_id: currentCustomerId,
  280. target_customer_id: relatedCustomerId,
  281. relationship_type: relationshipType,
  282. relationship_status: relationshipStatus,
  283. description: description
  284. };
  285. $.ajax({
  286. url: 'save_relationship.php',
  287. type: 'POST',
  288. data: data,
  289. dataType: 'json',
  290. success: function(response) {
  291. if (response && response.success) {
  292. alert('保存成功');
  293. $('#relationship-modal').hide();
  294. $('.modal-backdrop').remove();
  295. location.reload();
  296. } else {
  297. alert(response.message || '保存失败');
  298. }
  299. },
  300. error: function() {
  301. alert('操作失败,请稍后重试');
  302. }
  303. });
  304. });
  305. // 客户搜索功能
  306. var customerSearchTimeout = null;
  307. var customerIsComposing = false;
  308. // 监听输入法组合事件
  309. $(document).on('compositionstart', '#related_customer_search', function() {
  310. customerIsComposing = true;
  311. });
  312. $(document).on('compositionend', '#related_customer_search', function() {
  313. customerIsComposing = false;
  314. $(this).trigger('input'); // 手动触发一次input事件
  315. });
  316. // 客户搜索输入
  317. $(document).on('input', '#related_customer_search', function() {
  318. // 如果是输入法正在组合中文,不处理
  319. if (customerIsComposing) return;
  320. var searchTerm = $(this).val().trim();
  321. var customerDropdown = $('#related_customer_dropdown');
  322. var currentCustomerId = $('#current_customer_id').val();
  323. // 清除之前的超时
  324. clearTimeout(customerSearchTimeout);
  325. // 隐藏之前的结果
  326. customerDropdown.hide();
  327. // 清除之前的选择
  328. $('#related_customer_id').val('');
  329. $('#related_customer_selected').hide();
  330. // 如果搜索词少于1个字符,不执行搜索
  331. if (searchTerm.length < 1) {
  332. return;
  333. }
  334. // 设置一个300毫秒的超时,以减少请求数量
  335. customerSearchTimeout = setTimeout(function() {
  336. $.ajax({
  337. url: 'get_customer_search.php',
  338. type: 'GET',
  339. data: {
  340. search: searchTerm,
  341. exclude_id: currentCustomerId // 排除当前客户
  342. },
  343. dataType: 'json',
  344. success: function(data) {
  345. customerDropdown.empty();
  346. if (data && data.customers && data.customers.length > 0) {
  347. $.each(data.customers, function(i, customer) {
  348. var displayText = customer.cs_company;
  349. if (customer.cs_code) {
  350. displayText = customer.cs_code + ' - ' + displayText;
  351. }
  352. var item = $('<div class="customer-item"></div>')
  353. .attr('data-id', customer.id)
  354. .attr('data-display', displayText)
  355. .text(displayText);
  356. customerDropdown.append(item);
  357. });
  358. customerDropdown.show();
  359. }
  360. },
  361. error: function() {
  362. console.log('搜索客户失败,请重试');
  363. }
  364. });
  365. }, 300);
  366. });
  367. // 点击选择客户
  368. $(document).on('click', '.customer-item', function() {
  369. var customerId = $(this).data('id');
  370. var displayText = $(this).data('display');
  371. // 设置选中的客户ID和显示
  372. $('#related_customer_id').val(customerId);
  373. $('#related_customer_search').hide();
  374. $('#related_customer_selected')
  375. .text(displayText)
  376. .append('<span class="customer-clear-btn" title="清除选择">X</span>')
  377. .show()
  378. .attr('title', displayText);
  379. // 隐藏下拉菜单
  380. $('#related_customer_dropdown').hide();
  381. });
  382. // 点击X按钮清除选择的客户
  383. $(document).on('click', '.customer-clear-btn', function(e) {
  384. e.stopPropagation();
  385. // 显示搜索框,隐藏已选信息
  386. $('#related_customer_search').val('').show();
  387. $('#related_customer_selected').hide();
  388. // 清空客户ID
  389. $('#related_customer_id').val('');
  390. });
  391. // 点击其他地方隐藏下拉列表
  392. $(document).on('click', function(e) {
  393. if (!$(e.target).closest('.customer-search-container').length) {
  394. $('.customer-dropdown').hide();
  395. }
  396. });
  397. // 处理跟进阶段变化时显示/隐藏成交时间字段
  398. $('input[name="cs_deal"]').change(function() {
  399. if($(this).val() == '3') {
  400. $('#deal_date_row').show();
  401. } else {
  402. $('#deal_date_row').hide();
  403. }
  404. });
  405. });
  406. // Update method fields based on selection
  407. function updateMethodFields(methodRow) {
  408. var select = methodRow.find('select.method-select');
  409. var input = methodRow.find('input.method-input');
  410. var contactForm = methodRow.closest('.contact-form');
  411. var contactIndex = contactForm.attr('id').split('-')[2];
  412. var type = select.val();
  413. if (!type) return;
  414. // Count existing methods of this type
  415. var count = 1;
  416. contactForm.find('select.method-select').each(function() {
  417. if ($(this).val() === type && $(this)[0] !== select[0]) {
  418. count++;
  419. }
  420. });
  421. // Update field names
  422. select.attr('name', `contact[${contactIndex}][method_type_${count}]`);
  423. input.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  424. // Add format field for tel and whatsapp
  425. if (type === 'tel' || type === 'whatsapp') {
  426. if (!methodRow.find('.format-input').length) {
  427. input.after(`<input type="hidden" class="format-input" name="contact[${contactIndex}][${type}_${count}_format]">`);
  428. }
  429. }
  430. // Add backup field
  431. if (!methodRow.find('.backup-input').length) {
  432. methodRow.append(`<input type="hidden" class="backup-input" name="contact[${contactIndex}][${type}_${count}_bu]">`);
  433. }
  434. }
  435. // Update available method types for a contact
  436. function updateAvailableMethodTypes(contactIndex) {
  437. var methodsContainer = $('#contact-methods-' + contactIndex);
  438. // Count methods by type
  439. var methodCounts = {};
  440. methodsContainer.find('select.method-select').each(function() {
  441. var type = $(this).val();
  442. if (type) {
  443. methodCounts[type] = (methodCounts[type] || 0) + 1;
  444. }
  445. });
  446. // Update all selects in this contact
  447. methodsContainer.find('select.method-select').each(function() {
  448. var currentValue = $(this).val();
  449. $(this).find('option').each(function() {
  450. var optionValue = $(this).val();
  451. if (optionValue && optionValue !== currentValue) {
  452. $(this).prop('disabled', (methodCounts[optionValue] || 0) >= 3);
  453. }
  454. });
  455. });
  456. }
  457. // Update placeholder and handle method fields
  458. function updateMethodSelectAndPlaceholder(selectElement) {
  459. var methodRow = $(selectElement).closest('.contact-method-row');
  460. updateMethodPlaceholder(selectElement);
  461. updateMethodFields(methodRow);
  462. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  463. updateAvailableMethodTypes(contactIndex);
  464. }
  465. // Look for the updateMethodPlaceholder function and replace it with this modified version
  466. function updateMethodPlaceholder(selectElement) {
  467. var placeholder = "";
  468. var value = $(selectElement).val();
  469. switch(value) {
  470. case "tel":
  471. placeholder = "电话格式必须为:区号+号码 如:+86 15012345678";
  472. break;
  473. case "wechat":
  474. placeholder = "微信";
  475. break;
  476. case "whatsapp":
  477. placeholder = "Whatsapp 格式必须为:区号+号码 如:+86 15012345678";
  478. break;
  479. case "email":
  480. placeholder = "邮箱格式必须正确,如: example@domain.com";
  481. break;
  482. case "linkedin":
  483. placeholder = "领英链接";
  484. break;
  485. case "facebook":
  486. placeholder = "Facebook";
  487. break;
  488. case "alibaba":
  489. placeholder = "阿里巴巴";
  490. break;
  491. default:
  492. placeholder = "请选择联系方式类型";
  493. }
  494. $(selectElement).next('.method-input').attr('placeholder', placeholder);
  495. }
  496. // 格式化电话号码函数
  497. function formatPhoneNumber(phone, finalFormat = false) {
  498. if (!phone) return phone;
  499. // 去除所有非数字、加号和空格
  500. phone = phone.replace(/[^\d\s+]/g, '');
  501. // 去除开头和结尾的空格
  502. phone = phone.trim();
  503. // 确保以加号开头
  504. if (!phone.startsWith('+')) {
  505. // 如果第一个字符是数字,添加加号
  506. if (/^\d/.test(phone)) {
  507. phone = '+' + phone;
  508. } else {
  509. // 如果不是以数字开头,检查是否有数字并添加加号
  510. var firstDigitIndex = phone.search(/\d/);
  511. if (firstDigitIndex >= 0) {
  512. phone = '+' + phone.substring(firstDigitIndex);
  513. } else {
  514. // 如果没有数字,返回原始输入
  515. return phone;
  516. }
  517. }
  518. }
  519. return phone;
  520. }
  521. // Custom validation function for multiple contacts form with contact methods
  522. function validateMultipleContactsForm() {
  523. var clientCode = $("#cs_code").val();
  524. var clientCompany = $("#cs_company").val();
  525. var clientFrom = $("#cs_from").val();
  526. var clientCountry = $("#cs_country").val();
  527. // Validate basic customer info
  528. if (clientCode == "" || clientCode == null) {
  529. alert("客户代码不能为空!");
  530. $("#cs_code").focus();
  531. return false;
  532. }
  533. if (clientCountry == 0 || !clientCountry) {
  534. alert("这是哪个国家的客户?");
  535. $("#cs_country").focus();
  536. return false;
  537. }
  538. if (clientFrom == "0") {
  539. alert("请填写客户来源!");
  540. $("#cs_from").focus();
  541. return false;
  542. }
  543. // Validate that at least one business type is selected
  544. if (!$('input[name="cs_type[]"]:checked').length) {
  545. alert("请至少选择一种业务类型!");
  546. return false;
  547. }
  548. // Get source text to check if it's from Alibaba platforms
  549. var clientFromText = $("#cs_from option:selected").text();
  550. var isAlibabaSource = clientFromText.indexOf("1688") >= 0 ||
  551. clientFromText.indexOf("阿里") >= 0 ||
  552. clientFromText.indexOf("alibaba") >= 0;
  553. // Validate that at least one contact has at least one contact method
  554. var hasContactMethod = false;
  555. var hasAlibabaContact = false;
  556. var allContactsValid = true;
  557. var phoneRegex = /^\+\d{1,4}\s\d+$/; // 区号后必须有空格,号码中不能有空格
  558. var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; // Regex to validate email format
  559. $('.contact-form').each(function(contactIndex) {
  560. var $form = $(this);
  561. var contactName = $form.find('input[name*="[contact_name]"]').val();
  562. var hasMethodInThisContact = false;
  563. // Check if this contact has methods
  564. $form.find('.contact-method-row').each(function() {
  565. var methodType = $(this).find('select.method-select').val();
  566. var methodValue = $(this).find('input.method-input').val();
  567. if (methodValue) {
  568. hasMethodInThisContact = true;
  569. hasContactMethod = true;
  570. // Check if there's an Alibaba contact method
  571. if (methodType === 'alibaba') {
  572. hasAlibabaContact = true;
  573. }
  574. }
  575. // Check if method type is selected but value is empty
  576. if (methodType && !methodValue) {
  577. alert("联系方式类型已选择但值为空");
  578. allContactsValid = false;
  579. return false;
  580. }
  581. // Validate phone number format for tel and whatsapp
  582. if ((methodType === 'tel' || methodType === 'whatsapp') && methodValue) {
  583. if (!phoneRegex.test(methodValue)) {
  584. // 检查具体的错误原因
  585. if (!methodValue.startsWith('+')) {
  586. alert("电话号码必须以'+'开头");
  587. } else if (methodValue.indexOf(' ') === -1) {
  588. alert("区号后必须有空格,例如: +86 15012345678");
  589. } else if (methodValue.split(' ').length > 2 || methodValue.split(' ')[1].indexOf(' ') !== -1) {
  590. alert("号码部分不能包含空格");
  591. } else {
  592. alert("电话格式不正确,正确格式为: +区号 号码,例如 +86 15012345678");
  593. }
  594. $(this).find('input.method-input').focus();
  595. allContactsValid = false;
  596. return false;
  597. }
  598. }
  599. // Validate email format
  600. if (methodType === 'email' && methodValue) {
  601. if (!emailRegex.test(methodValue)) {
  602. alert("邮箱格式不正确,请输入有效的邮箱地址");
  603. $(this).find('input.method-input').focus();
  604. allContactsValid = false;
  605. return false;
  606. }
  607. }
  608. });
  609. // If contact has a name but no methods, or has methods but no name
  610. if ((contactName && !hasMethodInThisContact) || (!contactName && hasMethodInThisContact)) {
  611. alert("联系人 #" + (contactIndex + 1) + " 缺少联系人姓名或联系方式");
  612. allContactsValid = false;
  613. return false;
  614. }
  615. // If contact has neither name nor methods, it's an empty contact
  616. if (!contactName && !hasMethodInThisContact) {
  617. alert("联系人 #" + (contactIndex + 1) + " 是空的,请填写信息或删除此联系人");
  618. allContactsValid = false;
  619. return false;
  620. }
  621. });
  622. if (!allContactsValid) {
  623. return false;
  624. }
  625. if (!hasContactMethod) {
  626. alert("至少需要添加一个联系人,且联系人至少需要一种联系方式!");
  627. return false;
  628. }
  629. // If source is from Alibaba platforms, must have Alibaba contact method
  630. if (isAlibabaSource && !hasAlibabaContact) {
  631. alert("客户来源为1688或阿里国际站时,必须添加至少一个阿里巴巴联系方式!");
  632. return false;
  633. }
  634. // Set tag values
  635. $("input#mytag").val($(".taglist").html());
  636. // Convert the dynamic contact methods to the standard format expected by the server
  637. $('.contact-form').each(function(contactIndex) {
  638. var methodsData = {};
  639. $(this).find('.contact-method-row').each(function() {
  640. var type = $(this).find('select.method-select').val();
  641. var value = $(this).find('input.method-input').val();
  642. if (type && value) {
  643. methodsData[type] = value;
  644. }
  645. });
  646. // Create hidden inputs for each method
  647. for (var type in methodsData) {
  648. $('<input>').attr({
  649. type: 'hidden',
  650. name: 'contact[' + contactIndex + '][' + type + ']',
  651. value: methodsData[type]
  652. }).appendTo(this);
  653. }
  654. });
  655. return true;
  656. }
  657. // Modified submission function
  658. function submitCustomerForm() {
  659. if (validateMultipleContactsForm()) {
  660. $("#form1").submit();
  661. }
  662. }
  663. </script>
  664. <style>
  665. body {
  666. margin: 0;
  667. padding: 20px;
  668. background: #fff;
  669. }
  670. #man_zone {
  671. margin-left: 0;
  672. }
  673. .contact-form {
  674. margin-bottom: 10px;
  675. /*border: 1px solid #ddd;*/
  676. padding: 8px;
  677. background-color: #FFFFFF;
  678. }
  679. .contact-header {
  680. display: flex;
  681. align-items: center;
  682. margin-bottom: 8px;
  683. gap: 10px;
  684. }
  685. .contact-header h3 {
  686. margin: 0;
  687. order: 2;
  688. flex-grow: 1;
  689. }
  690. .remove-contact-btn {
  691. background-color: #f44336;
  692. color: white;
  693. border: none;
  694. padding: 4px 8px;
  695. cursor: pointer;
  696. order: 1;
  697. }
  698. .add-contact-btn {
  699. background-color: #4CAF50;
  700. color: white;
  701. border: none;
  702. padding: 6px 12px;
  703. margin-bottom: 10px;
  704. cursor: pointer;
  705. }
  706. .contact-methods-container {
  707. margin-top: 8px;
  708. }
  709. .contact-method-row {
  710. margin-bottom: 6px;
  711. padding: 6px;
  712. border: 0px solid #eee;
  713. /*background-color: #f5f5f5;*/
  714. display: flex;
  715. align-items: center;
  716. gap: 8px;
  717. }
  718. .add-method-btn {
  719. background-color: #2196F3;
  720. color: white;
  721. border: none;
  722. padding: 4px 8px;
  723. margin-top: 4px;
  724. cursor: pointer;
  725. }
  726. .remove-method-btn {
  727. background-color: #f44336;
  728. color: white;
  729. border: none;
  730. padding: 2px 4px;
  731. cursor: pointer;
  732. }
  733. .method-select {
  734. margin-right: 8px;
  735. padding: 3px;
  736. }
  737. .contact-table {
  738. margin-bottom: 6px;
  739. }
  740. .contact-table td, .contact-table th {
  741. padding: 4px 6px;
  742. }
  743. /* 客户关系样式 */
  744. .relationships-table {
  745. width: 100%;
  746. border-collapse: collapse;
  747. margin-bottom: 10px;
  748. }
  749. .relationships-table th, .relationships-table td {
  750. border: 1px solid #ddd;
  751. padding: 8px;
  752. text-align: left;
  753. }
  754. .relationships-table th {
  755. background-color: #f2f2f2;
  756. }
  757. .btn-add-relationship {
  758. background-color: #4CAF50;
  759. color: white;
  760. border: none;
  761. padding: 6px 12px;
  762. margin-bottom: 10px;
  763. cursor: pointer;
  764. }
  765. .edit-relationship-btn, .delete-relationship-btn {
  766. margin-right: 5px;
  767. cursor: pointer;
  768. padding: 3px 8px;
  769. border: none;
  770. }
  771. .edit-relationship-btn {
  772. background-color: #2196F3;
  773. color: white;
  774. }
  775. .delete-relationship-btn {
  776. background-color: #f44336;
  777. color: white;
  778. }
  779. #relationship-modal {
  780. position: fixed;
  781. top: 50%;
  782. left: 50%;
  783. transform: translate(-50%, -50%);
  784. background-color: white;
  785. padding: 20px;
  786. border: 1px solid #ddd;
  787. box-shadow: 0 0 10px rgba(0,0,0,0.3);
  788. z-index: 1000;
  789. width: 600px;
  790. max-width: 90%;
  791. }
  792. /* 弹窗内表格样式修复 */
  793. #relationship-modal table.table1 {
  794. width: 100%;
  795. border-collapse: collapse;
  796. table-layout: fixed;
  797. }
  798. #relationship-modal table.table1 th {
  799. width: 120px;
  800. text-align: right;
  801. padding-right: 10px;
  802. vertical-align: middle;
  803. white-space: nowrap;
  804. }
  805. #relationship-modal table.table1 td {
  806. padding: 6px 8px;
  807. }
  808. #relationship-modal .txt1 {
  809. width: 90%;
  810. }
  811. #relationship-modal select.txt1 {
  812. max-width: 300px;
  813. }
  814. .modal-backdrop {
  815. position: fixed;
  816. top: 0;
  817. left: 0;
  818. width: 100%;
  819. height: 100%;
  820. background-color: rgba(0,0,0,0.5);
  821. z-index: 999;
  822. }
  823. .modal-actions {
  824. text-align: right;
  825. margin-top: 15px;
  826. }
  827. .modal-actions button {
  828. padding: 5px 15px;
  829. margin-left: 10px;
  830. cursor: pointer;
  831. }
  832. /* 弹窗按钮样式 */
  833. .modal-actions .btn1 {
  834. border: 1px solid #ccc;
  835. background: #f5f5f5;
  836. border-radius: 3px;
  837. color: #333;
  838. font-size: 12px;
  839. height: 26px;
  840. padding: 0 15px;
  841. transition: all 0.3s;
  842. }
  843. .modal-actions .btn1:hover {
  844. background: #e6e6e6;
  845. border-color: #adadad;
  846. }
  847. #save-relationship-btn {
  848. background-color: #428bca;
  849. color: white;
  850. border-color: #357ebd;
  851. }
  852. #save-relationship-btn:hover {
  853. background-color: #3071a9;
  854. border-color: #285e8e;
  855. }
  856. .customer-search-container {
  857. display: flex;
  858. align-items: center;
  859. margin-bottom: 10px;
  860. position: relative;
  861. width: 80%;
  862. }
  863. .customer-dropdown {
  864. display: none;
  865. position: absolute;
  866. background: white;
  867. border: 1px solid #ccc;
  868. max-height: 200px;
  869. overflow-y: auto;
  870. width: 100%;
  871. z-index: 1000;
  872. box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  873. border-radius: 0 0 4px 4px;
  874. top: 100%;
  875. left: 0;
  876. }
  877. .customer-item {
  878. padding: 10px 12px;
  879. cursor: pointer;
  880. border-bottom: 1px solid #eee;
  881. transition: background-color 0.2s;
  882. }
  883. .customer-item:hover {
  884. background-color: #f0f0f0;
  885. }
  886. .selected-customer-info {
  887. font-weight: bold;
  888. padding: 8px 10px;
  889. border: 1px solid #ddd;
  890. background-color: #f9f9f9;
  891. display: none;
  892. width: 100%;
  893. box-sizing: border-box;
  894. word-break: break-all;
  895. overflow: hidden;
  896. text-overflow: ellipsis;
  897. white-space: normal;
  898. min-height: 38px;
  899. position: relative;
  900. padding-right: 25px;
  901. }
  902. .customer-clear-btn {
  903. position: absolute;
  904. right: 5px;
  905. top: 50%;
  906. transform: translateY(-50%);
  907. color: #e74c3c;
  908. font-weight: bold;
  909. cursor: pointer;
  910. width: 16px;
  911. height: 16px;
  912. text-align: center;
  913. line-height: 16px;
  914. background: #f5f5f5;
  915. border-radius: 50%;
  916. }
  917. .customer-clear-btn:hover {
  918. background: #e74c3c;
  919. color: white;
  920. }
  921. </style>
  922. </head>
  923. <body class="clear">
  924. <?php // require_once 'panel.php'; ?>
  925. <div id="man_zone">
  926. <form name="form1" id="form1" method="post" action="customerSave.php<?= $hrefstr ?>">
  927. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  928. <tbody>
  929. <tr>
  930. <th width="8%">客户编号</th>
  931. <td>
  932. <input type="text" id="cs_code" name="cs_code" value="<?= htmlspecialcharsFix($customer['cs_code']) ?>"
  933. <?= !empty($customer['cs_claimFrom']) ? 'readonly' : '' ?> class="txt1" />
  934. <input type="hidden" name="id" value="<?= $id ?>" />
  935. <input type="hidden" name="cs_addtime" value="<?= $customer['cs_addtime'] ?>" />
  936. <input type="hidden" name="Permissions" value="<?= $customer['allowedit'] ?>" />
  937. </td>
  938. </tr>
  939. <tr>
  940. <th width="8%">公司名称</th>
  941. <td><input type="text" id="cs_company" name="cs_company" value="<?= htmlspecialcharsFix($customer['cs_company']) ?>" class="txt1" /></td>
  942. </tr>
  943. <!-- 客户关系管理部分 -->
  944. <tr>
  945. <th width="8%" valign="top">客户关系</th>
  946. <td>
  947. <div id="relationships-container">
  948. <?php
  949. // 获取当前客户的所有关系
  950. $relationshipSql = "SELECT cr.*,
  951. c1.cs_company as source_company, c1.cs_code as source_code,
  952. c2.cs_company as target_company, c2.cs_code as target_code
  953. FROM customer_relationship cr
  954. LEFT JOIN customer c1 ON cr.source_customer_id = c1.id
  955. LEFT JOIN customer c2 ON cr.target_customer_id = c2.id
  956. WHERE cr.source_customer_id = ? OR cr.target_customer_id = ?";
  957. $relationshipStmt = $conn->prepare($relationshipSql);
  958. $relationshipStmt->bind_param("ii", $id, $id);
  959. $relationshipStmt->execute();
  960. $relationshipResult = $relationshipStmt->get_result();
  961. $hasRelationships = false;
  962. if ($relationshipResult->num_rows > 0) {
  963. $hasRelationships = true;
  964. echo '<table width="100%" border="0" cellpadding="3" cellspacing="1" class="relationships-table">';
  965. echo '<tr><th>关系类型</th><th>相关客户</th><th>关系状态</th><th>关系描述</th><th>操作</th></tr>';
  966. while ($relationship = $relationshipResult->fetch_assoc()) {
  967. $relationType = '';
  968. switch ($relationship['relationship_type']) {
  969. case 1: $relationType = '母公司-子公司'; break;
  970. case 2: $relationType = '供应商-客户'; break;
  971. case 3: $relationType = '合作伙伴'; break;
  972. case 4: $relationType = '竞争对手'; break;
  973. case 5: $relationType = '推荐人'; break;
  974. case 6: $relationType = '其他'; break;
  975. }
  976. $relationStatus = $relationship['relationship_status'] == 1 ? '启用' : '停用';
  977. // 确定关联的客户(不是当前客户的那一方)
  978. $relatedCustomerId = $relationship['source_customer_id'] == $id
  979. ? $relationship['target_customer_id']
  980. : $relationship['source_customer_id'];
  981. $relatedCustomerName = $relationship['source_customer_id'] == $id
  982. ? textUncode($relationship['target_company'])
  983. : textUncode($relationship['source_company']);
  984. $relatedCustomerCode = $relationship['source_customer_id'] == $id
  985. ? textUncode($relationship['target_code'])
  986. : textUncode($relationship['source_code']);
  987. $displayText = $relatedCustomerName;
  988. if ($relatedCustomerCode) {
  989. $displayText = $relatedCustomerCode . ' - ' . $relatedCustomerName;
  990. }
  991. echo '<tr>';
  992. echo '<td>' . $relationType . '</td>';
  993. echo '<td>' . htmlspecialchars($displayText) . '</td>';
  994. echo '<td>' . $relationStatus . '</td>';
  995. echo '<td>' . htmlspecialchars(textUncode($relationship['description'])) . '</td>';
  996. echo '<td>';
  997. echo '<button type="button" class="edit-relationship-btn" data-id="' . $relationship['id'] . '">编辑</button>';
  998. echo '<button type="button" class="delete-relationship-btn" data-id="' . $relationship['id'] . '">删除</button>';
  999. echo '</td>';
  1000. echo '</tr>';
  1001. }
  1002. echo '</table>';
  1003. } else {
  1004. echo '<p>暂无关联客户关系。</p>';
  1005. }
  1006. ?>
  1007. <button type="button" id="add-relationship-btn" class="btn-add-relationship">添加客户关系</button>
  1008. </div>
  1009. <!-- 添加/编辑关系的弹出框 -->
  1010. <div id="relationship-modal" style="display: none;">
  1011. <h3 id="relationship-modal-title" style="margin-top: 0; margin-bottom: 15px;">添加客户关系</h3>
  1012. <input type="hidden" id="relationship_id" value="">
  1013. <input type="hidden" id="current_customer_id" value="<?= $id ?>">
  1014. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1 relationship-modal-table">
  1015. <tr>
  1016. <th width="120">关联客户</th>
  1017. <td>
  1018. <div class="customer-search-container" style="width: 90%; position: relative;">
  1019. <input type="text" id="related_customer_search" class="customer-search txt1" placeholder="输入客户编码或名称搜索..." value="" style="width: 100%; box-sizing: border-box;" />
  1020. <div id="related_customer_selected" class="selected-customer-info"></div>
  1021. <div id="related_customer_dropdown" class="customer-dropdown"></div>
  1022. </div>
  1023. <input type="hidden" id="related_customer_id" value="" />
  1024. </td>
  1025. </tr>
  1026. <tr>
  1027. <th>关系类型</th>
  1028. <td>
  1029. <select id="relationship_type" class="txt1" style="width: auto; min-width: 200px;">
  1030. <option value="">请选择关系类型</option>
  1031. <option value="1">母公司-子公司</option>
  1032. <option value="2">供应商-客户</option>
  1033. <option value="3">合作伙伴</option>
  1034. <option value="4">竞争对手</option>
  1035. <option value="5">推荐人</option>
  1036. <option value="6">其他</option>
  1037. </select>
  1038. </td>
  1039. </tr>
  1040. <tr>
  1041. <th>关系状态</th>
  1042. <td>
  1043. <label style="margin-right: 15px;">
  1044. <input type="radio" name="relationship_status" value="1" checked>
  1045. 启用
  1046. </label>
  1047. <label>
  1048. <input type="radio" name="relationship_status" value="0">
  1049. 停用
  1050. </label>
  1051. </td>
  1052. </tr>
  1053. <tr>
  1054. <th>关系描述</th>
  1055. <td>
  1056. <textarea id="relationship_description" class="txt1" style="width: 90%; height: 100px; resize: vertical;"></textarea>
  1057. </td>
  1058. </tr>
  1059. </table>
  1060. <div class="modal-actions">
  1061. <button type="button" id="save-relationship-btn" class="btn1">保存</button>
  1062. <button type="button" id="cancel-relationship-btn" class="btn1">取消</button>
  1063. </div>
  1064. </div>
  1065. </td>
  1066. </tr>
  1067. <tr>
  1068. <th width="8%">地区/国家</th>
  1069. <td>
  1070. <div class="layui-input-inline">
  1071. <div class="layui-form-select ySearchSelect y1">
  1072. <div class="layui-input">
  1073. <?php
  1074. $stmt = $conn->prepare("SELECT id, countryCode, countryName FROM country WHERE id = ?");
  1075. $stmt->bind_param("i", $customer['cs_country']);
  1076. $stmt->execute();
  1077. $countryResult = $stmt->get_result();
  1078. if ($countryRow = $countryResult->fetch_assoc()) {
  1079. $countryId = $countryRow['id'];
  1080. echo htmlspecialcharsFix($countryRow['countryName']);
  1081. } else {
  1082. echo "请选择";
  1083. }
  1084. ?>
  1085. </div>
  1086. <ul>
  1087. <?php
  1088. $result = $conn->query("SELECT id, countryCode, countryName FROM country");
  1089. while ($row = $result->fetch_assoc()) {
  1090. echo "<li class=\"on\" data-c=\"{$row['id']}\">(+{$row['countryCode']}){$row['countryName']}</li>";
  1091. }
  1092. ?>
  1093. <p>无匹配项</p>
  1094. </ul>
  1095. <input name="cs_country" id="cs_country" value="<?= $countryId ?? '' ?>" type="hidden">
  1096. </div>
  1097. </div>
  1098. <script>
  1099. $(function () {
  1100. $(".y1").ySearchSelect();
  1101. })
  1102. </script>
  1103. </td>
  1104. </tr>
  1105. <tr>
  1106. <th width="8%">客户来源</th>
  1107. <td>
  1108. <select id="cs_from" name="cs_from">
  1109. <option value="0">请选择来源</option>
  1110. <?php
  1111. $result = $conn->query("SELECT id, ch_name FROM qudao");
  1112. while ($row = $result->fetch_assoc()) {
  1113. $selected = ($customer['cs_from'] == $row['id']) ? ' selected="selected"' : '';
  1114. echo "<option value=\"{$row['id']}\"$selected>{$row['ch_name']}</option>";
  1115. }
  1116. ?>
  1117. </select>
  1118. </td>
  1119. </tr>
  1120. <tr>
  1121. <th width="8%" valign="top">联系人信息</th>
  1122. <td>
  1123. <button type="button" class="add-contact-btn">添加联系人</button>
  1124. <div id="contacts-container">
  1125. <?php if (!empty($contacts)): ?>
  1126. <?php foreach ($contacts as $index => $contact): ?>
  1127. <div class="contact-form" id="contact-form-<?= $index ?>">
  1128. <div class="contact-header">
  1129. <button type="button" class="remove-contact-btn" data-index="<?= $index ?>">删除</button>
  1130. <h3>联系人 #<?= $index + 1 ?></h3>
  1131. </div>
  1132. <input type="hidden" name="contact[<?= $index ?>][id]" value="<?= $contact['id'] ?>">
  1133. <div class="contact-method-row">
  1134. <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
  1135. <input type="text" name="contact[<?= $index ?>][contact_name]" value="<?= htmlspecialcharsFix($contact['contact_name']) ?>" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
  1136. </div>
  1137. <div class="contact-methods-container" id="contact-methods-<?= $index ?>">
  1138. <?php
  1139. $methodTypes = [
  1140. 'tel' => '电话',
  1141. 'wechat' => '微信',
  1142. 'whatsapp' => 'WhatsApp',
  1143. 'email' => '邮箱',
  1144. 'linkedin' => '领英',
  1145. 'facebook' => 'Facebook',
  1146. 'alibaba' => '阿里巴巴'
  1147. ];
  1148. foreach ($methodTypes as $type => $label) {
  1149. for ($i = 1; $i <= 3; $i++) {
  1150. $fieldName = $type . '_' . $i;
  1151. if (!empty($contact[$fieldName])) {
  1152. echo '<div class="contact-method-row">';
  1153. echo '<select class="method-select" name="contact[' . $index . '][method_type_' . $i . ']" onchange="updateMethodSelectAndPlaceholder(this)">';
  1154. echo '<option value="">请选择联系方式</option>';
  1155. foreach ($methodTypes as $optionType => $optionLabel) {
  1156. $selected = ($optionType === $type) ? 'selected' : '';
  1157. echo '<option value="' . $optionType . '" ' . $selected . '>' . $optionLabel . '</option>';
  1158. }
  1159. echo '</select>';
  1160. echo '<input type="text" class="txt1 method-input" style="width:60%;" name="contact[' . $index . '][' . $fieldName . ']" value="' . htmlspecialcharsFix($contact[$fieldName]) . '">';
  1161. if ($type === 'tel' || $type === 'whatsapp') {
  1162. echo '<input type="hidden" class="format-input" name="contact[' . $index . '][' . $fieldName . '_format]" value="' . htmlspecialcharsFix($contact[$fieldName . '_format']) . '">';
  1163. }
  1164. echo '<input type="hidden" class="backup-input" name="contact[' . $index . '][' . $fieldName . '_bu]" value="' . htmlspecialcharsFix($contact[$fieldName . '_bu']) . '">';
  1165. echo '<button type="button" class="remove-method-btn">删除</button>';
  1166. echo '</div>';
  1167. }
  1168. }
  1169. }
  1170. ?>
  1171. </div>
  1172. <button type="button" class="add-method-btn" data-contact-index="<?= $index ?>">添加联系方式</button>
  1173. </div>
  1174. <?php endforeach; ?>
  1175. <?php else: ?>
  1176. <div class="contact-form" id="contact-form-0"">
  1177. <div class="contact-header">
  1178. <button type="button" class="remove-contact-btn" data-index="0">删除</button>
  1179. <h3>联系人 #1</h3>
  1180. </div>
  1181. <input type="hidden" name="contact[0][id]" value="">
  1182. <div class="contact-method-row">
  1183. <span style="width:80px;display:inline-block;font-weight:bold;" class="method-select">联系人姓名</span>
  1184. <input type="text" name="contact[0][contact_name]" class="txt1 method-input" style="width:60%;" placeholder="联系人姓名"/>
  1185. </div>
  1186. <div class="contact-methods-container" id="contact-methods-0">
  1187. <!-- Contact methods will be added here -->
  1188. </div>
  1189. <button type="button" class="add-method-btn" data-contact-index="0">添加联系方式</button>
  1190. </div>
  1191. <?php endif; ?>
  1192. </div>
  1193. </td>
  1194. </tr>
  1195. <tr>
  1196. <th width="8%">地址</th>
  1197. <td><input type="text" id="cs_address" name="cs_address" value="<?= htmlspecialcharsFix($customer['cs_address']) ?>" class="txt1" /></td>
  1198. </tr>
  1199. <tr>
  1200. <th>业务类型</th>
  1201. <td>
  1202. <?php
  1203. // 获取当前客户的业务类型
  1204. $selected_types = [];
  1205. $type_result = $conn->query("SELECT business_type_id FROM customer_business_type WHERE customer_id = " . intval($id));
  1206. while ($type_row = $type_result->fetch_assoc()) {
  1207. $selected_types[] = $type_row['business_type_id'];
  1208. }
  1209. $result = $conn->query("SELECT id, businessType FROM clienttype");
  1210. while ($row = $result->fetch_assoc()) {
  1211. $checked = in_array($row['id'], $selected_types) ? ' checked="checked"' : '';
  1212. echo "<input type=\"checkbox\" name=\"cs_type[]\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\"$checked>
  1213. <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
  1214. }
  1215. ?>
  1216. </td>
  1217. </tr>
  1218. <tr>
  1219. <th>跟进阶段</th>
  1220. <td>
  1221. <?php
  1222. $dealOptions = [
  1223. ['id' => '0', 'label' => '无响应'],
  1224. ['id' => '1', 'label' => '背景调查'],
  1225. ['id' => '2', 'label' => '明确需求'],
  1226. ['id' => '3', 'label' => '已成交']
  1227. ];
  1228. foreach ($dealOptions as $option) {
  1229. $checked = ($customer['cs_deal'] == $option['id']) ? ' checked="checked"' : '';
  1230. $disabled = ($customer['cs_deal'] == '3' && $option['id'] != '3') ? ' disabled="disabled"' : '';
  1231. echo "<input type=\"radio\" id=\"fordeal{$option['id']}\" class=\"cs_deal\" name=\"cs_deal\"
  1232. value=\"{$option['id']}\"$checked$disabled><label for=\"fordeal{$option['id']}\">{$option['label']}</label>";
  1233. }
  1234. ?>
  1235. </td>
  1236. </tr>
  1237. <tr id="deal_date_row" <?= $customer['cs_deal'] != '3' ? 'style="display:none;"' : '' ?>>
  1238. <th>成交时间</th>
  1239. <td>
  1240. <input type="date" id="cs_dealdate" name="cs_dealdate" class="txt1"
  1241. value="<?= !empty($customer['cs_dealdate']) ? date('Y-m-d', strtotime($customer['cs_dealdate'])) : '' ?>" />
  1242. <span style="color:#999; font-size:12px;">若不填写,系统将自动记录为成交状态变更日期</span>
  1243. </td>
  1244. </tr>
  1245. <tr>
  1246. <th>其他</th>
  1247. <td>
  1248. <input type="checkbox" id="belongClient" class="cs_belongClient" name="cs_belongClient"
  1249. value="1"<?= $customer['cs_belongclient'] == 1 ? ' checked="checked"' : '' ?>>
  1250. <label for="belongClient">客户的客户</label>
  1251. </td>
  1252. </tr>
  1253. <tr>
  1254. <th>自定义标签</th>
  1255. <td>
  1256. <div class="taglist">
  1257. <?php
  1258. $stmt = $conn->prepare("SELECT id, tagName FROM tagtable WHERE customerId = ?");
  1259. $stmt->bind_param("i", $id);
  1260. $stmt->execute();
  1261. $result = $stmt->get_result();
  1262. while ($row = $result->fetch_assoc()) {
  1263. echo "<span>" . htmlspecialcharsFix($row['tagName']) . "</span>";
  1264. }
  1265. ?>
  1266. </div>
  1267. <div class="commontag">
  1268. <i class="tag">美特柏品牌客户</i>,
  1269. <i class="tag">OEM定制客户</i>,
  1270. <i class="tag">小型B端客户</i>,
  1271. <i class="tag">C端客户</i>,
  1272. <i class="tag">贸易公司</i>,
  1273. <i class="tag">档口客户</i>
  1274. <?php
  1275. $stmt = $conn->prepare("SELECT DISTINCT tagName FROM tagtable WHERE employeeId = ?");
  1276. $stmt->bind_param("i", $_SESSION['employee_id']);
  1277. $stmt->execute();
  1278. $result = $stmt->get_result();
  1279. while ($row = $result->fetch_assoc()) {
  1280. echo "<i class=\"tag\">" . htmlspecialcharsFix(textUncode($row['tagName'])) . "</i>,";
  1281. }
  1282. ?>
  1283. </div>
  1284. <input type="text" id="tapinput" class="txt-short" placeholder="自定义标签,按Enter添加">
  1285. <input type="hidden" id="mytag" name="mytag" value="">
  1286. </td>
  1287. </tr>
  1288. <tr>
  1289. <th width="8%">备注</th>
  1290. <td><textarea name="cs_note" class="txt2"><?= htmlspecialcharsFix($customer['cs_note']) ?></textarea></td>
  1291. </tr>
  1292. </tbody>
  1293. </table>
  1294. <div class="form-actions">
  1295. <input type="button" name="save" id="save" value="确定" class="btn1" onclick="submitCustomerForm();">
  1296. <input type="button" value="返回" class="btn1" onClick="location.href='customers.php<?= $hrefstr ?>'" />
  1297. </div>
  1298. </form>
  1299. </div>
  1300. </body>
  1301. </html>