智慧水务管理系统 - 精河县供水工程综合管理平台

crm-frontend-complete.html 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>中小企业 CRM 系统</title>
  7. <script src="https://cdn.tailwindcss.com"></script>
  8. </head>
  9. <body class="bg-gray-50 min-h-screen">
  10. <!-- 导航栏 -->
  11. <nav class="bg-indigo-600 text-white shadow-lg">
  12. <div class="container mx-auto px-4 py-4">
  13. <div class="flex justify-between items-center">
  14. <h1 class="text-2xl font-bold">📊 中小企业 CRM 系统</h1>
  15. <div class="flex gap-4">
  16. <button onclick="showListView()" class="text-white hover:text-indigo-200">📋 客户列表</button>
  17. <button onclick="showAddModal()" class="bg-white text-indigo-600 px-4 py-2 rounded-lg hover:bg-indigo-50 font-medium">
  18. ➕ 添加客户
  19. </button>
  20. </div>
  21. </div>
  22. </div>
  23. </nav>
  24. <!-- 主内容区 -->
  25. <div class="container mx-auto px-4 py-6">
  26. <!-- 列表视图 -->
  27. <div id="list-view">
  28. <!-- 统计卡片 -->
  29. <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
  30. <div class="bg-white p-4 rounded-lg shadow">
  31. <div class="text-gray-500 text-sm">总客户数</div>
  32. <div class="text-3xl font-bold text-indigo-600" id="stat-total">-</div>
  33. </div>
  34. <div class="bg-white p-4 rounded-lg shadow">
  35. <div class="text-gray-500 text-sm">潜在客户</div>
  36. <div class="text-3xl font-bold text-yellow-600" id="stat-potential">-</div>
  37. </div>
  38. <div class="bg-white p-4 rounded-lg shadow">
  39. <div class="text-gray-500 text-sm">跟进中</div>
  40. <div class="text-3xl font-bold text-blue-600" id="stat-contacting">-</div>
  41. </div>
  42. <div class="bg-white p-4 rounded-lg shadow">
  43. <div class="text-gray-500 text-sm">成交客户</div>
  44. <div class="text-3xl font-bold text-green-600" id="stat-customer">-</div>
  45. </div>
  46. </div>
  47. <!-- 搜索和筛选 -->
  48. <div class="bg-white p-4 rounded-lg shadow mb-6">
  49. <div class="flex gap-4">
  50. <input type="text" id="search-keyword" placeholder="搜索客户名称、公司、电话..."
  51. class="flex-1 border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500">
  52. <select id="filter-status" class="border border-gray-300 rounded-lg px-4 py-2">
  53. <option value="">全部状态</option>
  54. <option value="potential">潜在客户</option>
  55. <option value="contacting">跟进中</option>
  56. <option value="customer">成交客户</option>
  57. </select>
  58. <button onclick="loadCustomers()" class="bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700">
  59. 搜索
  60. </button>
  61. </div>
  62. </div>
  63. <!-- 客户列表 -->
  64. <div class="bg-white rounded-lg shadow overflow-hidden">
  65. <div class="px-6 py-4 border-b">
  66. <h2 class="text-lg font-semibold">客户列表</h2>
  67. </div>
  68. <div class="overflow-x-auto">
  69. <table class="w-full">
  70. <thead class="bg-gray-50">
  71. <tr>
  72. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">客户名称</th>
  73. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">公司</th>
  74. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">联系方式</th>
  75. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">来源</th>
  76. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">状态</th>
  77. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">操作</th>
  78. </tr>
  79. </thead>
  80. <tbody id="customer-list" class="divide-y divide-gray-200">
  81. <tr><td colspan="6" class="px-6 py-8 text-center text-gray-500">加载中...</td></tr>
  82. </tbody>
  83. </table>
  84. </div>
  85. </div>
  86. </div>
  87. <!-- 详情视图 -->
  88. <div id="detail-view" class="hidden">
  89. <button onclick="showListView()" class="mb-4 text-indigo-600 hover:text-indigo-800">← 返回列表</button>
  90. <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
  91. <!-- 客户信息 -->
  92. <div class="md:col-span-1">
  93. <div class="bg-white rounded-lg shadow p-6">
  94. <h3 class="text-xl font-bold mb-4" id="detail-name">-</h3>
  95. <div class="space-y-3 text-sm">
  96. <div>
  97. <span class="text-gray-500">公司</span>
  98. <p id="detail-company" class="font-medium">-</p>
  99. </div>
  100. <div>
  101. <span class="text-gray-500">电话</span>
  102. <p id="detail-phone" class="font-medium">-</p>
  103. </div>
  104. <div>
  105. <span class="text-gray-500">邮箱</span>
  106. <p id="detail-email" class="font-medium">-</p>
  107. </div>
  108. <div>
  109. <span class="text-gray-500">来源</span>
  110. <p id="detail-source" class="font-medium">-</p>
  111. </div>
  112. <div>
  113. <span class="text-gray-500">状态</span>
  114. <span id="detail-status" class="ml-2 px-2 py-1 rounded-full text-xs">-</span>
  115. </div>
  116. <div>
  117. <span class="text-gray-500">创建时间</span>
  118. <p id="detail-created" class="font-medium">-</p>
  119. </div>
  120. </div>
  121. <div class="mt-6 flex gap-2">
  122. <button onclick="showEditModal()" class="flex-1 bg-indigo-600 text-white py-2 rounded-lg hover:bg-indigo-700">编辑</button>
  123. <button onclick="deleteCurrentCustomer()" class="flex-1 bg-red-600 text-white py-2 rounded-lg hover:bg-red-700">删除</button>
  124. </div>
  125. </div>
  126. </div>
  127. <!-- 跟进记录 -->
  128. <div class="md:col-span-2">
  129. <div class="bg-white rounded-lg shadow p-6 mb-6">
  130. <h3 class="text-lg font-bold mb-4">添加跟进记录</h3>
  131. <form id="followup-form" class="space-y-4">
  132. <div>
  133. <label class="block text-sm font-medium text-gray-700 mb-1">跟进类型</label>
  134. <select name="type" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  135. <option value="电话">电话沟通</option>
  136. <option value="微信">微信联系</option>
  137. <option value="邮件">邮件往来</option>
  138. <option value="拜访">上门拜访</option>
  139. <option value="报价">发送报价</option>
  140. <option value="成交">成交签约</option>
  141. <option value="其他">其他</option>
  142. </select>
  143. </div>
  144. <div>
  145. <label class="block text-sm font-medium text-gray-700 mb-1">跟进内容</label>
  146. <textarea name="content" rows="3" required class="w-full border border-gray-300 rounded-lg px-4 py-2" placeholder="记录本次跟进的详细内容..."></textarea>
  147. </div>
  148. <div>
  149. <label class="block text-sm font-medium text-gray-700 mb-1">下次跟进日期</label>
  150. <input type="date" name="nextFollowup" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  151. </div>
  152. <button type="submit" class="bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700">添加记录</button>
  153. </form>
  154. </div>
  155. <div class="bg-white rounded-lg shadow p-6">
  156. <h3 class="text-lg font-bold mb-4">跟进记录</h3>
  157. <div id="followup-list" class="space-y-4">
  158. <p class="text-gray-500 text-center py-8">暂无跟进记录</p>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. <!-- 添加客户模态框 -->
  166. <div id="add-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center">
  167. <div class="bg-white rounded-lg p-6 w-full max-w-md mx-4">
  168. <h3 class="text-xl font-bold mb-4">添加客户</h3>
  169. <form id="add-form" class="space-y-4">
  170. <div>
  171. <label class="block text-sm font-medium text-gray-700 mb-1">客户名称 *</label>
  172. <input type="text" name="name" required class="w-full border border-gray-300 rounded-lg px-4 py-2">
  173. </div>
  174. <div>
  175. <label class="block text-sm font-medium text-gray-700 mb-1">公司</label>
  176. <input type="text" name="company" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  177. </div>
  178. <div>
  179. <label class="block text-sm font-medium text-gray-700 mb-1">电话</label>
  180. <input type="tel" name="phone" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  181. </div>
  182. <div>
  183. <label class="block text-sm font-medium text-gray-700 mb-1">邮箱</label>
  184. <input type="email" name="email" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  185. </div>
  186. <div>
  187. <label class="block text-sm font-medium text-gray-700 mb-1">来源</label>
  188. <select name="source" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  189. <option value="">请选择</option>
  190. <option value="官网">官网</option>
  191. <option value="电话">电话</option>
  192. <option value="朋友介绍">朋友介绍</option>
  193. <option value="展会">展会</option>
  194. <option value="其他">其他</option>
  195. </select>
  196. </div>
  197. <div>
  198. <label class="block text-sm font-medium text-gray-700 mb-1">备注</label>
  199. <textarea name="notes" rows="3" class="w-full border border-gray-300 rounded-lg px-4 py-2"></textarea>
  200. </div>
  201. <div class="flex gap-4 pt-4">
  202. <button type="submit" class="flex-1 bg-indigo-600 text-white py-2 rounded-lg hover:bg-indigo-700">保存</button>
  203. <button type="button" onclick="hideAddModal()" class="flex-1 bg-gray-200 text-gray-700 py-2 rounded-lg hover:bg-gray-300">取消</button>
  204. </div>
  205. </form>
  206. </div>
  207. </div>
  208. <!-- 编辑客户模态框 -->
  209. <div id="edit-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center">
  210. <div class="bg-white rounded-lg p-6 w-full max-w-md mx-4">
  211. <h3 class="text-xl font-bold mb-4">编辑客户</h3>
  212. <form id="edit-form" class="space-y-4">
  213. <input type="hidden" id="edit-id">
  214. <div>
  215. <label class="block text-sm font-medium text-gray-700 mb-1">客户名称 *</label>
  216. <input type="text" id="edit-name" required class="w-full border border-gray-300 rounded-lg px-4 py-2">
  217. </div>
  218. <div>
  219. <label class="block text-sm font-medium text-gray-700 mb-1">公司</label>
  220. <input type="text" id="edit-company" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  221. </div>
  222. <div>
  223. <label class="block text-sm font-medium text-gray-700 mb-1">电话</label>
  224. <input type="tel" id="edit-phone" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  225. </div>
  226. <div>
  227. <label class="block text-sm font-medium text-gray-700 mb-1">邮箱</label>
  228. <input type="email" id="edit-email" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  229. </div>
  230. <div>
  231. <label class="block text-sm font-medium text-gray-700 mb-1">来源</label>
  232. <select id="edit-source" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  233. <option value="">请选择</option>
  234. <option value="官网">官网</option>
  235. <option value="电话">电话</option>
  236. <option value="朋友介绍">朋友介绍</option>
  237. <option value="展会">展会</option>
  238. <option value="其他">其他</option>
  239. </select>
  240. </div>
  241. <div>
  242. <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
  243. <select id="edit-status" class="w-full border border-gray-300 rounded-lg px-4 py-2">
  244. <option value="potential">潜在客户</option>
  245. <option value="contacting">跟进中</option>
  246. <option value="customer">成交客户</option>
  247. </select>
  248. </div>
  249. <div>
  250. <label class="block text-sm font-medium text-gray-700 mb-1">备注</label>
  251. <textarea id="edit-notes" rows="3" class="w-full border border-gray-300 rounded-lg px-4 py-2"></textarea>
  252. </div>
  253. <div class="flex gap-4 pt-4">
  254. <button type="submit" class="flex-1 bg-indigo-600 text-white py-2 rounded-lg hover:bg-indigo-700">保存</button>
  255. <button type="button" onclick="hideEditModal()" class="flex-1 bg-gray-200 text-gray-700 py-2 rounded-lg hover:bg-gray-300">取消</button>
  256. </div>
  257. </form>
  258. </div>
  259. </div>
  260. <script>
  261. const API_BASE = window.location.hostname === 'localhost' ? 'http://localhost:3002/api' : '/api';
  262. let currentCustomerId = null;
  263. // 加载统计数据
  264. async function loadStats() {
  265. try {
  266. const res = await fetch(`${API_BASE}/stats`);
  267. const data = await res.json();
  268. if (data.success) {
  269. document.getElementById('stat-total').textContent = data.data.total;
  270. document.getElementById('stat-potential').textContent = data.data.potential;
  271. document.getElementById('stat-contacting').textContent = data.data.contacting;
  272. document.getElementById('stat-customer').textContent = data.data.customer;
  273. }
  274. } catch (error) {
  275. console.error('加载统计失败:', error);
  276. }
  277. }
  278. // 加载客户列表
  279. async function loadCustomers() {
  280. const keyword = document.getElementById('search-keyword').value;
  281. const status = document.getElementById('filter-status').value;
  282. let url = `${API_BASE}/customers?`;
  283. if (keyword) url += `keyword=${encodeURIComponent(keyword)}&`;
  284. if (status) url += `status=${status}&`;
  285. try {
  286. const res = await fetch(url);
  287. const data = await res.json();
  288. const tbody = document.getElementById('customer-list');
  289. if (data.success && data.data.length > 0) {
  290. tbody.innerHTML = data.data.map(c => `
  291. <tr class="hover:bg-gray-50">
  292. <td class="px-6 py-4 font-medium">${c.name}</td>
  293. <td class="px-6 py-4 text-gray-600">${c.company || '-'}</td>
  294. <td class="px-6 py-4">
  295. <div class="text-sm">${c.phone || '-'}</div>
  296. <div class="text-gray-500 text-xs">${c.email || ''}</div>
  297. </td>
  298. <td class="px-6 py-4 text-gray-600">${c.source || '-'}</td>
  299. <td class="px-6 py-4">
  300. <span class="px-2 py-1 rounded-full text-xs ${
  301. c.status === 'customer' ? 'bg-green-100 text-green-800' :
  302. c.status === 'contacting' ? 'bg-blue-100 text-blue-800' :
  303. 'bg-yellow-100 text-yellow-800'
  304. }">${
  305. c.status === 'customer' ? '成交客户' :
  306. c.status === 'contacting' ? '跟进中' : '潜在客户'
  307. }</span>
  308. </td>
  309. <td class="px-6 py-4">
  310. <button onclick="viewCustomer(${c.id})" class="text-indigo-600 hover:text-indigo-800 mr-3">详情</button>
  311. <button onclick="deleteCustomer(${c.id})" class="text-red-600 hover:text-red-800">删除</button>
  312. </td>
  313. </tr>
  314. `).join('');
  315. } else {
  316. tbody.innerHTML = '<tr><td colspan="6" class="px-6 py-8 text-center text-gray-500">暂无客户数据,点击右上角添加客户</td></tr>';
  317. }
  318. } catch (error) {
  319. console.error('加载客户失败:', error);
  320. }
  321. }
  322. // 查看客户详情
  323. async function viewCustomer(id) {
  324. currentCustomerId = id;
  325. try {
  326. const res = await fetch(`${API_BASE}/customers/${id}`);
  327. const data = await res.json();
  328. if (data.success) {
  329. const c = data.data;
  330. document.getElementById('detail-name').textContent = c.name;
  331. document.getElementById('detail-company').textContent = c.company || '-';
  332. document.getElementById('detail-phone').textContent = c.phone || '-';
  333. document.getElementById('detail-email').textContent = c.email || '-';
  334. document.getElementById('detail-source').textContent = c.source || '-';
  335. document.getElementById('detail-created').textContent = new Date(c.created_at).toLocaleString('zh-CN');
  336. const statusEl = document.getElementById('detail-status');
  337. statusEl.textContent = c.status === 'customer' ? '成交客户' : c.status === 'contacting' ? '跟进中' : '潜在客户';
  338. statusEl.className = `ml-2 px-2 py-1 rounded-full text-xs ${
  339. c.status === 'customer' ? 'bg-green-100 text-green-800' :
  340. c.status === 'contacting' ? 'bg-blue-100 text-blue-800' :
  341. 'bg-yellow-100 text-yellow-800'
  342. }`;
  343. // 加载跟进记录
  344. const followupList = document.getElementById('followup-list');
  345. if (c.followUps && c.followUps.length > 0) {
  346. followupList.innerHTML = c.followUps.map(f => `
  347. <div class="border-l-4 border-indigo-500 pl-4 py-2 bg-gray-50 rounded">
  348. <div class="flex justify-between items-start">
  349. <span class="font-medium text-indigo-600">${f.type || '跟进'}</span>
  350. <span class="text-xs text-gray-500">${new Date(f.created_at).toLocaleString('zh-CN')}</span>
  351. </div>
  352. <p class="text-gray-700 mt-1">${f.content || '-'}</p>
  353. ${f.next_followup ? `<p class="text-sm text-orange-600 mt-2">📅 下次跟进:${f.next_followup}</p>` : ''}
  354. </div>
  355. `).join('');
  356. } else {
  357. followupList.innerHTML = '<p class="text-gray-500 text-center py-8">暂无跟进记录</p>';
  358. }
  359. // 切换视图
  360. document.getElementById('list-view').classList.add('hidden');
  361. document.getElementById('detail-view').classList.remove('hidden');
  362. }
  363. } catch (error) {
  364. alert('加载详情失败:' + error.message);
  365. }
  366. }
  367. // 显示列表视图
  368. function showListView() {
  369. document.getElementById('detail-view').classList.add('hidden');
  370. document.getElementById('list-view').classList.remove('hidden');
  371. loadCustomers();
  372. loadStats();
  373. }
  374. // 显示添加模态框
  375. function showAddModal() {
  376. document.getElementById('add-modal').classList.remove('hidden');
  377. document.getElementById('add-modal').classList.add('flex');
  378. }
  379. // 隐藏添加模态框
  380. function hideAddModal() {
  381. document.getElementById('add-modal').classList.add('hidden');
  382. document.getElementById('add-modal').classList.remove('flex');
  383. document.getElementById('add-form').reset();
  384. }
  385. // 显示编辑模态框
  386. function showEditModal() {
  387. document.getElementById('edit-id').value = currentCustomerId;
  388. document.getElementById('edit-modal').classList.remove('hidden');
  389. document.getElementById('edit-modal').classList.add('flex');
  390. }
  391. // 隐藏编辑模态框
  392. function hideEditModal() {
  393. document.getElementById('edit-modal').classList.add('hidden');
  394. document.getElementById('edit-modal').classList.remove('flex');
  395. }
  396. // 删除客户
  397. async function deleteCustomer(id) {
  398. if (!confirm('确定要删除这个客户吗?')) return;
  399. try {
  400. const res = await fetch(`${API_BASE}/customers/${id}`, { method: 'DELETE' });
  401. const data = await res.json();
  402. if (data.success) {
  403. alert('客户已删除');
  404. loadCustomers();
  405. loadStats();
  406. }
  407. } catch (error) {
  408. alert('删除失败:' + error.message);
  409. }
  410. }
  411. // 删除当前客户
  412. function deleteCurrentCustomer() {
  413. if (currentCustomerId) deleteCustomer(currentCustomerId);
  414. }
  415. // 添加客户
  416. document.getElementById('add-form').addEventListener('submit', async (e) => {
  417. e.preventDefault();
  418. const formData = new FormData(e.target);
  419. const data = Object.fromEntries(formData);
  420. try {
  421. const res = await fetch(`${API_BASE}/customers`, {
  422. method: 'POST',
  423. headers: { 'Content-Type': 'application/json' },
  424. body: JSON.stringify(data)
  425. });
  426. const result = await res.json();
  427. if (result.success) {
  428. alert('客户添加成功!');
  429. hideAddModal();
  430. loadCustomers();
  431. loadStats();
  432. }
  433. } catch (error) {
  434. alert('添加失败:' + error.message);
  435. }
  436. });
  437. // 添加跟进记录
  438. document.getElementById('followup-form').addEventListener('submit', async (e) => {
  439. e.preventDefault();
  440. const formData = new FormData(e.target);
  441. const data = Object.fromEntries(formData);
  442. try {
  443. const res = await fetch(`${API_BASE}/customers/${currentCustomerId}/followups`, {
  444. method: 'POST',
  445. headers: { 'Content-Type': 'application/json' },
  446. body: JSON.stringify(data)
  447. });
  448. const result = await res.json();
  449. if (result.success) {
  450. alert('跟进记录添加成功!');
  451. document.getElementById('followup-form').reset();
  452. viewCustomer(currentCustomerId); // 刷新详情
  453. }
  454. } catch (error) {
  455. alert('添加失败:' + error.message);
  456. }
  457. });
  458. // 初始化
  459. loadStats();
  460. loadCustomers();
  461. </script>
  462. </body>
  463. </html>