customerEdit.php 61 KB

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