customerAdd.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. ?>
  5. <!DOCTYPE html>
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>管理区域</title>
  10. <link rel="stylesheet" href="css/common.css" type="text/css" />
  11. <script src="js/jquery-1.7.2.min.js"></script>
  12. <script src="js/js.js"></script>
  13. <script src="js/xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  14. <script src="js/Hz2Py-szm-min.js"></script>
  15. <script src="js/ySearchSelect.js"></script>
  16. <script>
  17. $(document).ready(function(){
  18. $('.txt2').xheditor({
  19. tools:'full',
  20. hoverExecDelay:-1,
  21. urlBase:'system',
  22. upLinkUrl:"upload.php",
  23. upLinkExt:"zip,rar,txt,pdf",
  24. upImgUrl:"upload.php",
  25. upImgExt:"jpg,jpeg,gif,png",
  26. upFlashUrl:"upload.php",
  27. upFlashExt:"swf",
  28. upMediaUrl:"upload.php",
  29. upMediaExt:"wmv,avi,wma,mp3,mid"
  30. });
  31. // Add contact form
  32. $('.add-contact-btn').click(function() {
  33. var contactsContainer = $('#contacts-container');
  34. var contactIndex = contactsContainer.children('.contact-form').length;
  35. var contactForm = `
  36. <div class="contact-form" id="contact-form-${contactIndex}">
  37. <div class="contact-header">
  38. <button type="button" class="remove-contact-btn" data-index="${contactIndex}">删除</button>
  39. <h3>联系人 #${contactIndex + 1}</h3>
  40. </div>
  41. <input type="hidden" name="contact[${contactIndex}][id]" value="">
  42. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="contact-table">
  43. <tr>
  44. <th width="8%">联系人</th>
  45. <td><input type="text" name="contact[${contactIndex}][contact_name]" class="txt1" placeholder="联系人姓名"/></td>
  46. </tr>
  47. </table>
  48. <div class="contact-methods-container" id="contact-methods-${contactIndex}">
  49. <!-- Contact methods will be added here -->
  50. </div>
  51. <button type="button" class="add-method-btn" data-contact-index="${contactIndex}">添加联系方式</button>
  52. </div>
  53. `;
  54. contactsContainer.append(contactForm);
  55. });
  56. // Add contact method
  57. $(document).on('click', '.add-method-btn', function() {
  58. var contactIndex = $(this).data('contact-index');
  59. var methodsContainer = $('#contact-methods-' + contactIndex);
  60. // Count existing methods by type
  61. var methodCounts = {};
  62. methodsContainer.find('select.method-select').each(function() {
  63. var type = $(this).val();
  64. if (type) {
  65. methodCounts[type] = (methodCounts[type] || 0) + 1;
  66. }
  67. });
  68. var methodRow = `
  69. <div class="contact-method-row">
  70. <select class="method-select" onchange="updateMethodSelectAndPlaceholder(this)">
  71. <option value="">请选择联系方式</option>
  72. <option value="tel" ${(methodCounts.tel || 0) >= 3 ? 'disabled' : ''}>电话</option>
  73. <option value="wechat" ${(methodCounts.wechat || 0) >= 3 ? 'disabled' : ''}>微信</option>
  74. <option value="whatsapp" ${(methodCounts.whatsapp || 0) >= 3 ? 'disabled' : ''}>WhatsApp</option>
  75. <option value="email" ${(methodCounts.email || 0) >= 3 ? 'disabled' : ''}>邮箱</option>
  76. <option value="linkedin" ${(methodCounts.linkedin || 0) >= 3 ? 'disabled' : ''}>领英</option>
  77. <option value="facebook" ${(methodCounts.facebook || 0) >= 3 ? 'disabled' : ''}>Facebook</option>
  78. <option value="alibaba" ${(methodCounts.alibaba || 0) >= 3 ? 'disabled' : ''}>阿里巴巴</option>
  79. </select>
  80. <input type="text" class="txt1 method-input" style="width:60%;" placeholder="请选择联系方式类型">
  81. <button type="button" class="remove-method-btn">删除</button>
  82. </div>
  83. `;
  84. methodsContainer.append(methodRow);
  85. updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
  86. });
  87. // Remove contact method
  88. $(document).on('click', '.remove-method-btn', function() {
  89. var methodRow = $(this).closest('.contact-method-row');
  90. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  91. var type = methodRow.find('select.method-select').val();
  92. methodRow.remove();
  93. // Update available options in other selects
  94. updateAvailableMethodTypes(contactIndex);
  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 initial contact form if none exists
  106. if ($('#contacts-container').children().length === 0) {
  107. $('.add-contact-btn').click();
  108. }
  109. });
  110. // Update method fields based on selection
  111. function updateMethodFields(methodRow) {
  112. var select = methodRow.find('select.method-select');
  113. var input = methodRow.find('input.method-input');
  114. var contactForm = methodRow.closest('.contact-form');
  115. var contactIndex = contactForm.attr('id').split('-')[2];
  116. var type = select.val();
  117. if (!type) return;
  118. // Count existing methods of this type
  119. var count = 1;
  120. contactForm.find('select.method-select').each(function() {
  121. if ($(this).val() === type && $(this)[0] !== select[0]) {
  122. count++;
  123. }
  124. });
  125. // Update field names
  126. select.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  127. input.attr('name', `contact[${contactIndex}][${type}_${count}]`);
  128. // Add format field for tel and whatsapp
  129. if (type === 'tel' || type === 'whatsapp') {
  130. if (!methodRow.find('.format-input').length) {
  131. input.after(`<input type="hidden" class="format-input" name="contact[${contactIndex}][${type}_${count}_format]">`);
  132. }
  133. }
  134. // Add backup field
  135. if (!methodRow.find('.backup-input').length) {
  136. methodRow.append(`<input type="hidden" class="backup-input" name="contact[${contactIndex}][${type}_${count}_bu]">`);
  137. }
  138. }
  139. // Update available method types for a contact
  140. function updateAvailableMethodTypes(contactIndex) {
  141. var methodsContainer = $('#contact-methods-' + contactIndex);
  142. // Count methods by type
  143. var methodCounts = {};
  144. methodsContainer.find('select.method-select').each(function() {
  145. var type = $(this).val();
  146. if (type) {
  147. methodCounts[type] = (methodCounts[type] || 0) + 1;
  148. }
  149. });
  150. // Update all selects in this contact
  151. methodsContainer.find('select.method-select').each(function() {
  152. var currentValue = $(this).val();
  153. $(this).find('option').each(function() {
  154. var optionValue = $(this).val();
  155. if (optionValue && optionValue !== currentValue) {
  156. $(this).prop('disabled', (methodCounts[optionValue] || 0) >= 3);
  157. }
  158. });
  159. });
  160. }
  161. // Update placeholder and handle method fields
  162. function updateMethodSelectAndPlaceholder(selectElement) {
  163. var methodRow = $(selectElement).closest('.contact-method-row');
  164. updateMethodPlaceholder(selectElement);
  165. updateMethodFields(methodRow);
  166. var contactIndex = methodRow.closest('.contact-form').attr('id').split('-')[2];
  167. updateAvailableMethodTypes(contactIndex);
  168. }
  169. // Update method placeholder based on selected type
  170. function updateMethodPlaceholder(selectElement) {
  171. var placeholder = "";
  172. var value = $(selectElement).val();
  173. switch(value) {
  174. case "tel":
  175. placeholder = "电话格式:区号+号码 如:+86 15012345678";
  176. break;
  177. case "wechat":
  178. placeholder = "微信";
  179. break;
  180. case "whatsapp":
  181. placeholder = "Whatsapp 格式:区号+号码 如:+86 15012345678";
  182. break;
  183. case "email":
  184. placeholder = "邮件";
  185. break;
  186. case "linkedin":
  187. placeholder = "领英链接";
  188. break;
  189. case "facebook":
  190. placeholder = "Facebook";
  191. break;
  192. case "alibaba":
  193. placeholder = "阿里巴巴";
  194. break;
  195. default:
  196. placeholder = "请选择联系方式类型";
  197. }
  198. $(selectElement).next('.method-input').attr('placeholder', placeholder);
  199. }
  200. // Custom validation function for multiple contacts form with contact methods
  201. function validateMultipleContactsForm() {
  202. var clientCode = $("#cs_code").val();
  203. var clientCompany = $("#cs_company").val();
  204. var clientFrom = $("#cs_from").val();
  205. var clientCountry = $("#cs_country").val();
  206. // Validate basic customer info
  207. if (clientCode == "" || clientCode == null) {
  208. alert("客户代码不能为空!");
  209. $("#cs_code").focus();
  210. return false;
  211. }
  212. if (clientCountry == 0 || !clientCountry) {
  213. alert("这是哪个国家的客户?");
  214. return false;
  215. }
  216. if (clientFrom == "0") {
  217. alert("请填写客户来源!");
  218. return false;
  219. }
  220. // Validate that at least one contact has at least one contact method
  221. var hasContactMethod = false;
  222. var allContactsValid = true;
  223. $('.contact-form').each(function(contactIndex) {
  224. var $form = $(this);
  225. var contactName = $form.find('input[name*="[contact_name]"]').val();
  226. var hasMethodInThisContact = false;
  227. // Check if this contact has methods
  228. $form.find('.contact-method-row').each(function() {
  229. var methodType = $(this).find('select.method-select').val();
  230. var methodValue = $(this).find('input.method-input').val();
  231. if (methodValue) {
  232. hasMethodInThisContact = true;
  233. hasContactMethod = true;
  234. }
  235. // Check if method type is selected but value is empty
  236. if (methodType && !methodValue) {
  237. alert("联系方式类型已选择但值为空");
  238. allContactsValid = false;
  239. return false;
  240. }
  241. });
  242. // If contact has a name but no methods, or has methods but no name
  243. if ((contactName && !hasMethodInThisContact) || (!contactName && hasMethodInThisContact)) {
  244. alert("联系人 #" + (contactIndex + 1) + " 缺少联系人姓名或联系方式");
  245. allContactsValid = false;
  246. return false;
  247. }
  248. // If contact has neither name nor methods, it's an empty contact
  249. if (!contactName && !hasMethodInThisContact) {
  250. alert("联系人 #" + (contactIndex + 1) + " 是空的,请填写信息或删除此联系人");
  251. allContactsValid = false;
  252. return false;
  253. }
  254. });
  255. if (!allContactsValid) {
  256. return false;
  257. }
  258. if (!hasContactMethod) {
  259. alert("至少需要添加一个联系人,且联系人至少需要一种联系方式!");
  260. return false;
  261. }
  262. // Set tag values
  263. $("input#mytag").val($(".taglist").html());
  264. return true;
  265. }
  266. // Modified submission function
  267. function subform() {
  268. if (validateMultipleContactsForm()) {
  269. $("#form1").submit();
  270. }
  271. }
  272. </script>
  273. <style>
  274. body {
  275. margin: 0;
  276. padding: 20px;
  277. background: #fff;
  278. }
  279. #man_zone {
  280. margin-left: 0;
  281. }
  282. .contact-form {
  283. margin-bottom: 10px;
  284. /*border: 1px solid #ddd;*/
  285. padding: 8px;
  286. background-color: #FFFFFF;
  287. }
  288. .contact-header {
  289. display: flex;
  290. align-items: center;
  291. margin-bottom: 8px;
  292. gap: 10px;
  293. }
  294. .contact-header h3 {
  295. margin: 0;
  296. order: 2;
  297. flex-grow: 1;
  298. }
  299. .remove-contact-btn {
  300. background-color: #f44336;
  301. color: white;
  302. border: none;
  303. padding: 4px 8px;
  304. cursor: pointer;
  305. order: 1;
  306. }
  307. .add-contact-btn {
  308. background-color: #4CAF50;
  309. color: white;
  310. border: none;
  311. padding: 6px 12px;
  312. margin-bottom: 10px;
  313. cursor: pointer;
  314. }
  315. .contact-methods-container {
  316. margin-top: 8px;
  317. }
  318. .contact-method-row {
  319. margin-bottom: 6px;
  320. padding: 6px;
  321. border: 1px solid #eee;
  322. /*background-color: #f5f5f5;*/
  323. display: flex;
  324. align-items: center;
  325. gap: 8px;
  326. }
  327. .add-method-btn {
  328. background-color: #2196F3;
  329. color: white;
  330. border: none;
  331. padding: 4px 8px;
  332. margin-top: 4px;
  333. cursor: pointer;
  334. }
  335. .remove-method-btn {
  336. background-color: #f44336;
  337. color: white;
  338. border: none;
  339. padding: 2px 4px;
  340. cursor: pointer;
  341. }
  342. .method-select {
  343. margin-right: 8px;
  344. padding: 3px;
  345. }
  346. .contact-table {
  347. margin-bottom: 6px;
  348. }
  349. .contact-table td, .contact-table th {
  350. padding: 4px 6px;
  351. }
  352. </style>
  353. </head>
  354. <body class="clear">
  355. <?php // require_once 'panel.php'; ?>
  356. <div id="man_zone">
  357. <form name="form1" id="form1" method="post" action="customerSave.php<?= $hrefstr ?? '' ?>">
  358. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  359. <tbody>
  360. <tr>
  361. <th width="8%">客户编号</th>
  362. <td>
  363. <input type="text" id="cs_code" name="cs_code" value="" class="txt1" />
  364. <input type="hidden" name="cs_addtime" value="<?= date('Y-m-d H:i:s') ?>" />
  365. </td>
  366. </tr>
  367. <tr>
  368. <th width="8%">公司名称</th>
  369. <td><input type="text" id="cs_company" name="cs_company" value="" class="txt1" /></td>
  370. </tr>
  371. <tr>
  372. <th width="8%">地区</th>
  373. <td>
  374. <div class="layui-input-inline">
  375. <div class="layui-form-select ySearchSelect y1">
  376. <div class="layui-input">请选择客户区域</div>
  377. <input name="cs_country" id="cs_country" type="hidden">
  378. <i class="layui-edge"></i>
  379. <ul>
  380. <?php
  381. $result = $conn->query("SELECT id, countryCode, countryName FROM country");
  382. while ($row = $result->fetch_assoc()) {
  383. echo "<li class=\"on\" data-c=\"{$row['id']}\">(+{$row['countryCode']}){$row['countryName']}</li>";
  384. }
  385. ?>
  386. <p>无匹配项</p>
  387. </ul>
  388. </div>
  389. </div>
  390. <script>
  391. $(function () {
  392. $(".y1").ySearchSelect();
  393. })
  394. </script>
  395. </td>
  396. </tr>
  397. <tr>
  398. <th width="8%">来源</th>
  399. <td>
  400. <select id="cs_from" name="cs_from">
  401. <option value="0">请选择来源</option>
  402. <?php
  403. $result = $conn->query("SELECT id, ch_name FROM qudao");
  404. while ($row = $result->fetch_assoc()) {
  405. echo "<option value=\"{$row['id']}\">{$row['ch_name']}</option>";
  406. }
  407. ?>
  408. </select>
  409. </td>
  410. </tr>
  411. <tr>
  412. <th width="8%" valign="top">联系人信息</th>
  413. <td>
  414. <button type="button" class="add-contact-btn">添加联系人</button>
  415. <div id="contacts-container">
  416. <!-- Contact forms will be added here -->
  417. </div>
  418. </td>
  419. </tr>
  420. <tr>
  421. <th>地址</th>
  422. <td><input type="text" id="cs_address" name="cs_address" value="" class="txt1" /></td>
  423. </tr>
  424. <tr>
  425. <th>业务类型</th>
  426. <td>
  427. <?php
  428. $result = $conn->query("SELECT id, businessType FROM clienttype");
  429. while ($row = $result->fetch_assoc()) {
  430. echo "<input type=\"radio\" name=\"cs_type\" value=\"{$row['id']}\" id=\"fortype{$row['id']}\">
  431. <label for=\"fortype{$row['id']}\">{$row['businessType']}</label>";
  432. }
  433. ?>
  434. </td>
  435. </tr>
  436. <tr>
  437. <th>跟进阶段</th>
  438. <td>
  439. <input type="radio" id="fordeal1" class="cs_deal" name="cs_deal" value="0"><label for="fordeal1">无响应</label>
  440. <input type="radio" id="fordeal2" class="cs_deal" name="cs_deal" value="1" checked="checked"><label for="fordeal2">背景调查</label>
  441. <input type="radio" id="fordeal3" class="cs_deal" name="cs_deal" value="2"><label for="fordeal3">明确需求</label>
  442. <input type="radio" id="fordeal4" class="cs_deal" name="cs_deal" value="3"><label for="fordeal4">已成交</label>
  443. </td>
  444. </tr>
  445. <tr>
  446. <th>其他</th>
  447. <td>
  448. <input type="checkbox" id="belongClient" class="cs_belongClient" name="cs_belongClient" value="1">
  449. <label for="belongClient">客户的客户</label>
  450. </td>
  451. </tr>
  452. <tr>
  453. <th>自定义标签</th>
  454. <td>
  455. <div class="taglist"></div>
  456. <input type="hidden" id="mytag" name="mytag" value="">
  457. <div class="commontag clear">
  458. <i class="tag">美特柏品牌客户</i>,
  459. <i class="tag">OEM定制客户</i>,
  460. <i class="tag">小型B端客户</i>,
  461. <i class="tag">C端客户</i>,
  462. <i class="tag">贸易公司</i>,
  463. <i class="tag">档口客户</i>
  464. <?php
  465. // 将bind_param改为SQL拼接
  466. $employee_id = intval($_SESSION['employee_id']);
  467. $sql = "SELECT DISTINCT tagName FROM tagtable WHERE employeeId = ".$employee_id;
  468. $result = $conn->query($sql);
  469. while ($row = $result->fetch_assoc()) {
  470. echo "<i class=\"tag\">" . htmlspecialcharsFix(textUncode($row['tagName'])) . "</i>,";
  471. }
  472. ?>
  473. </div>
  474. <input type="text" id="tapinput" class="txt-short" placeholder="添加新标签,按Enter添加">
  475. </td>
  476. </tr>
  477. <tr>
  478. <th width="8%">备注</th>
  479. <td><textarea name="cs_note" class="txt2" placeholder=""></textarea></td>
  480. </tr>
  481. <tr>
  482. <th></th>
  483. <td>
  484. <input type="button" name="save" id="save" value="确定" class="btn1" onclick="subform();" />
  485. <input type="button" value="返回" class="btn1" onClick="location.href='customers.php'" />
  486. </td>
  487. </tr>
  488. </tbody>
  489. </table>
  490. </form>
  491. </div>
  492. </body>
  493. </html>