市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
5.7 KiB

import{u as B,e as L,a as E}from"./member.js";function r(){const n=localStorage.getItem("isLoggedIn")==="true",e=parseInt(localStorage.getItem("loginTime")),a=(new Date().getTime()-e)/(1e3*60*60);return!n||a>=24?(localStorage.removeItem("isLoggedIn"),localStorage.removeItem("loginTime"),!1):!0}function d(){const n=document.getElementById("loginCheckModal");n.style.display="flex"}function $(){window.location.href="login-management.html"}r()||d();document.getElementById("goToLoginBtn").addEventListener("click",$);let o={pageSize:20,currentPage:1,total:0,items:[]};const y=document.getElementById("tableBody"),w=document.getElementById("pagination"),v=document.getElementById("totalCount");document.getElementById("currentPage");document.getElementById("showingRange");const h=document.getElementById("pageSizeSelect"),x=document.getElementById("gotoInput"),b=document.getElementById("noteModal"),u=document.getElementById("noteTextarea"),M=document.getElementById("noteCancelBtn"),P=document.getElementById("noteSaveBtn"),f=document.getElementById("toast");let p=null;function I(n){f.textContent=n,f.classList.add("show"),setTimeout(()=>f.classList.remove("show"),1e3)}async function C(n,e){if(!r()){d();return}try{const t=await E({page:n,page_size:e});if(typeof t.code<"u"&&t.code!==200)throw new Error(t.msg||"接口返回错误");console.log(t);const a=t.data||{};o.items=a.list,o.total=a.total}catch{alert("获取数据失败"),o.total=0}}function S(){const n=(o.currentPage-1)*o.pageSize,e=o.items||[];y.innerHTML=e.map((t,a)=>{const s=n+a+1,c=t.isRelated?"status-1":"status-0",l=t.isRelated?"已联系":"未联系";return(t.code||"").replace(/\+/g,"")+(t.telephone||""),`
<tr>
<td>${s}</td>
<td>${i(t.name||"")}</td>
<td>
<button class="btn whatsapp" data-action="whatsapp" data-id="${t.id}">WhatsApp</button>
</td>
<td>${i(t.code||"")}</td>
<td>${i(t.telephone||"")}</td>
<td>${i(t.wechat||"")}</td>
<td>${i(t.email||"")}</td>
<td>${i(t.type===0?"其它":t.type===1?"视频":t.type===2?"直播":t.type===3?"帖子":"其它")}</td>
<td>${i(t.url||"")}</td>
<td>${i(t.createdAt||"")}</td>
<td>
<button class="status-btn ${c}" data-action="toggle" data-id="${t.id}">${l}</button>
</td>
<td>${i(t.note||"")}</td>
<td>
<button class="btn" data-action="editNote" data-id="${t.id}">编辑备注</button>
</td>
</tr>
`}).join(""),v.textContent=o.total}y.addEventListener("click",async n=>{if(!r()){d();return}const e=n.target.closest('[data-action="whatsapp"]');if(e){const s=e.getAttribute("data-id");T(s);return}const t=n.target.closest('[data-action="toggle"]');if(t){const s=t.getAttribute("data-id");await A(s,t);return}const a=n.target.closest('[data-action="editNote"]');if(a){const s=a.getAttribute("data-id");z(s);return}});function T(n){const e=o.items.find(c=>String(c.id)===String(n));if(!e)return;const a=(e.code||"").replace(/\+/g,"")+(e.telephone||""),s=`https://api.whatsapp.com/send?phone=${encodeURIComponent(a)}&text=${encodeURIComponent("hello欢迎来到赢在美股")}`;window.open(s,"_blank")}async function A(n,e){const t=o.items.find(c=>String(c.id)===String(n));if(!t)return;const a=t.isRelated,s=a?0:1;t.isRelated=s,e.textContent=s?"已联系":"未联系",e.classList.toggle("status-1",!!s),e.classList.toggle("status-0",!s);try{const c=await B({id:t.id,state:s});if(typeof c.code<"u"&&c.code!==200)throw new Error(c.msg||"更新失败");I("状态修改成功")}catch{t.isRelated=a,e.textContent=a?"已联系":"未联系",e.classList.toggle("status-1",!!a),e.classList.toggle("status-0",!a),alert("更新失败")}}function z(n){if(!r()){d();return}const e=o.items.find(t=>String(t.id)===String(n));e&&(p=n,u.value=e.note||"",b.style.display="flex",u.focus())}function g(){p=null,u.value="",b.style.display="none"}M.addEventListener("click",g);P.addEventListener("click",async()=>{if(!r()){d();return}if(!p)return g();const n=u.value.trim(),e=o.items.find(t=>String(t.id)===String(p));if(!e)return g();try{const t=await L({id:e.id,note:n});if(typeof t.code<"u"&&t.code!==200)throw new Error(t.msg||"保存失败");const a=e.note;e.note=n,S(),I("备注保存成功")}catch{alert("保存备注失败")}finally{g()}});function N(){const n=Math.max(1,Math.ceil(o.total/o.pageSize)),e=Math.min(Math.max(1,o.currentPage),n);o.currentPage=e;const t=k(e,n,2);let a="";a+=`<button class="btn" data-action="prev" ${e===1?"disabled":""}>上一页</button>`,t.forEach(s=>{s==="..."?a+='<span class="small" style="padding:6px 8px">...</span>':a+=`<button class="btn ${s===e?"active":""}" data-page="${s}">${s}</button>`}),a+=`<button class="btn" data-action="next" ${e===n?"disabled":""}>下一页</button>`,w.innerHTML=a}function k(n,e,t){const a=[],s=Math.max(1,n-t),c=Math.min(e,n+t);s>1&&(a.push(1),s>2&&a.push("..."));for(let l=s;l<=c;l++)a.push(l);return c<e&&(c<e-1&&a.push("..."),a.push(e)),a}w.addEventListener("click",n=>{if(!r()){d();return}const e=n.target.closest("button");if(!e)return;const t=e.getAttribute("data-action");if(t==="prev")o.currentPage>1&&o.currentPage--;else if(t==="next"){const a=Math.max(1,Math.ceil(o.total/o.pageSize));o.currentPage<a&&o.currentPage++}else{const a=Number(e.getAttribute("data-page"));isNaN(a)||(o.currentPage=a)}m()});h.addEventListener("change",()=>{if(!r()){d();return}const n=parseInt(h.value,10);o.pageSize=n,o.currentPage=1,m(),x.value=""});async function m(){if(!r()){d();return}const n=Math.max(1,o.currentPage);o.currentPage=n,await C(o.currentPage,o.pageSize),S(),N()}function i(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}r()?m():d();