customerEdit.php 63 KB

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