customerEdit.php 62 KB

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