import{r as v,d as de,u as se,a as ue,o as re,c as ce,b as t,w as l,e as x,f as r,g as O,h as fe,i as z,j as n,N as D,B as u,k as i,l as c,t as pe,m as me,n as b,_ as ge}from"./index-CkzfmDGw.js";import{S as ve}from"./SearchOutline-BKr0yDBJ.js";import{R as _e}from"./RefreshOutline-DXhpU5zO.js";import{A as ye}from"./AddOutline-BFgqErtO.js";import{C as E}from"./CloudUploadOutline-DMPKBx4X.js";import{D as I}from"./DownloadOutline-DvUGqON3.js";import{T as P}from"./TrashOutline-DHG1tVXU.js";import{C as we}from"./CreateOutline-bgrwmVxs.js";const _={page(a){return v({url:"/biz/code/page",method:"get",params:a})},detail(a){return v({url:`/biz/code/${a}`,method:"get"})},create(a){return v({url:"/biz/code",method:"post",data:a})},update(a){return v({url:"/biz/code",method:"put",data:a})},delete(a){return v({url:`/biz/code/${a.join(",")}`,method:"delete"})},export(a){var h;const d={};return(h=a==null?void 0:a.ids)!=null&&h.length&&(d.ids=a.ids.join(",")),(a==null?void 0:a.id)!==void 0&&(a==null?void 0:a.id)!==null&&(d.id=a.id),v({url:"/biz/code/export",method:"get",params:d,responseType:"blob"})},importData(a){const d=new FormData;return d.append("file",a),v({url:"/biz/code/import",method:"post",data:d,headers:{"Content-Type":"multipart/form-data"}})},downloadTemplate(){return v({url:"/biz/code/template",method:"get",responseType:"blob"})}},xe={class:"page-container"},be={class:"search-form"},he={class:"table-toolbar"},ke={style:{"margin-bottom":"12px"}},Ce=de({__name:"index",setup(a){const d=se(),h=ue(),y=O({id:null}),S=x([]),R=x(!1),f=x([]),m=O({page:1,pageSize:10,itemCount:0,showSizePicker:!0,pageSizes:[10,20,50]}),k=x(!1),T=x(""),U=x(!1),j=x(),$={code:""},C=O({...$}),V={},q=[{type:"selection"},{title:"id",key:"id"},{title:"邀请码",key:"code"},{title:"操作",key:"actions",width:140,fixed:"right",render(o){return b("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"nowrap"}},[b(u,{size:"small",quaternary:!0,onClick:()=>G(o)},{default:()=>[b(c,null,{default:()=>b(we)})," 编辑"]}),b(u,{size:"small",quaternary:!0,type:"error",onClick:()=>J(o)},{default:()=>[b(c,null,{default:()=>b(P)})," 删除"]})])}}];async function g(){R.value=!0;try{const o=await _.page({page:m.page,pageSize:m.pageSize,id:y.id||void 0});S.value=o.list,m.itemCount=o.total}finally{R.value=!1}}function L(){m.page=1,g()}function A(){y.id=null,L()}function F(o){m.page=o,g()}function M(o){m.pageSize=o,m.page=1,g()}function K(o){f.value=o}function W(){T.value="新增邀请码",Object.assign(C,$),k.value=!0}function G(o){T.value="编辑邀请码",Object.assign(C,o),k.value=!0}async function H(){var o;await((o=j.value)==null?void 0:o.validate());try{const e={...C};e.id?(await _.update(e),d.success("修改成功")):(await _.create(e),d.success("新增成功")),k.value=!1,g()}catch{}}function J(o){h.warning({title:"提示",content:"确定要删除该记录吗？",positiveText:"确定",negativeText:"取消",onPositiveClick:async()=>{try{await _.delete([o.id]),d.success("删除成功"),g()}catch{}}})}function Q(){h.warning({title:"提示",content:`确定要删除选中的 ${f.value.length} 条记录吗？`,positiveText:"确定",negativeText:"取消",onPositiveClick:async()=>{try{await _.delete(f.value),d.success("删除成功"),f.value=[],g()}catch{}}})}async function X(){try{const o={};f.value.length>0&&(o.ids=f.value),y.id!=null&&(o.id=y.id);const e=await _.export(o),p=window.URL.createObjectURL(e),w=document.createElement("a");w.href=p,w.download="邀请码数据.xlsx",w.click(),window.URL.revokeObjectURL(p)}catch{}}async function Y(){try{const o=await _.downloadTemplate(),e=window.URL.createObjectURL(o),p=document.createElement("a");p.href=e,p.download="邀请码导入模板.xlsx",p.click(),window.URL.revokeObjectURL(e)}catch{}}async function Z({file:o}){if(o.file)try{const e=await _.importData(o.file);e.fail>0?h.warning({title:"导入结果",content:`成功: ${e.success} 条，失败: ${e.fail} 条
错误信息: ${(e.errors||[]).join(`
`)||"无"}`,positiveText:"确定"}):(d.success(`导入成功，共 ${e.success} 条数据`),U.value=!1),g()}catch{}}async function ee(){}return re(()=>{g(),ee()}),(o,e)=>{const p=r("n-input"),w=r("n-form-item"),N=r("n-form"),te=r("n-data-table"),le=r("n-card"),B=r("n-modal"),ne=r("n-alert"),oe=r("n-text"),ae=r("n-p"),ie=r("n-upload-dragger");return fe(),ce("div",xe,[t(le,null,{default:l(()=>[z("div",be,[t(N,{inline:"",model:y,"label-placement":"left"},{default:l(()=>[t(w,{label:"id"},{default:l(()=>[t(p,{value:y.id,"onUpdate:value":e[0]||(e[0]=s=>y.id=s),placeholder:"请输入id",clearable:""},null,8,["value"])]),_:1}),t(w,null,{default:l(()=>[t(n(D),null,{default:l(()=>[t(n(u),{type:"primary",onClick:L},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(ve))]),_:1})]),default:l(()=>[e[7]||(e[7]=i(" 搜索 ",-1))]),_:1}),t(n(u),{onClick:A},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(_e))]),_:1})]),default:l(()=>[e[8]||(e[8]=i(" 重置 ",-1))]),_:1})]),_:1})]),_:1})]),_:1},8,["model"])]),z("div",he,[t(n(D),null,{default:l(()=>[t(n(u),{type:"primary",onClick:W},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(ye))]),_:1})]),default:l(()=>[e[9]||(e[9]=i(" 新增 ",-1))]),_:1}),t(n(u),{onClick:e[1]||(e[1]=s=>U.value=!0)},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(E))]),_:1})]),default:l(()=>[e[10]||(e[10]=i(" 导入 ",-1))]),_:1}),t(n(u),{onClick:X},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(I))]),_:1})]),default:l(()=>[i(" 导出"+pe(f.value.length>0?`(${f.value.length})`:""),1)]),_:1}),t(n(u),{type:"error",disabled:f.value.length===0,onClick:Q},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(P))]),_:1})]),default:l(()=>[e[11]||(e[11]=i(" 删除 ",-1))]),_:1},8,["disabled"])]),_:1})]),t(te,{columns:q,data:S.value,loading:R.value,pagination:m,"row-key":s=>s.id,"scroll-x":1200,"onUpdate:page":F,"onUpdate:pageSize":M,"onUpdate:checkedRowKeys":K},null,8,["data","loading","pagination","row-key"])]),_:1}),t(B,{show:k.value,"onUpdate:show":e[4]||(e[4]=s=>k.value=s),preset:"card",title:T.value,style:{width:"600px"}},{footer:l(()=>[t(n(D),{justify:"end"},{default:l(()=>[t(n(u),{onClick:e[3]||(e[3]=s=>k.value=!1)},{default:l(()=>[...e[12]||(e[12]=[i("取消",-1)])]),_:1}),t(n(u),{type:"primary",onClick:H},{default:l(()=>[...e[13]||(e[13]=[i("确定",-1)])]),_:1})]),_:1})]),default:l(()=>[t(N,{ref_key:"formRef",ref:j,model:C,rules:V,"label-placement":"left","label-width":"100px"},{default:l(()=>[t(w,{label:"邀请码",path:"code"},{default:l(()=>[t(p,{value:C.code,"onUpdate:value":e[2]||(e[2]=s=>C.code=s),placeholder:"请输入邀请码"},null,8,["value"])]),_:1})]),_:1},8,["model"])]),_:1},8,["show","title"]),t(B,{show:U.value,"onUpdate:show":e[6]||(e[6]=s=>U.value=s),preset:"card",title:"导入邀请码",style:{width:"500px"}},{footer:l(()=>[t(n(u),{onClick:e[5]||(e[5]=s=>U.value=!1)},{default:l(()=>[...e[19]||(e[19]=[i("关闭",-1)])]),_:1})]),default:l(()=>[t(n(D),{vertical:""},{default:l(()=>[t(ne,{type:"info"},{header:l(()=>[...e[14]||(e[14]=[i("导入说明",-1)])]),default:l(()=>[e[15]||(e[15]=z("ul",{style:{margin:"0","padding-left":"16px","line-height":"1.8"}},[z("li",null,"请先下载导入模板，按模板格式填写数据"),z("li",null,"支持 .xlsx 或 .xls 格式")],-1))]),_:1}),t(n(D),null,{default:l(()=>[t(n(u),{type:"primary",onClick:Y},{icon:l(()=>[t(n(c),null,{default:l(()=>[t(n(I))]),_:1})]),default:l(()=>[e[16]||(e[16]=i(" 下载模板 ",-1))]),_:1})]),_:1}),t(n(me),{max:1,accept:".xlsx,.xls","show-file-list":!0,"custom-request":Z},{default:l(()=>[t(ie,null,{default:l(()=>[z("div",ke,[t(n(c),{size:"48",depth:3},{default:l(()=>[t(n(E))]),_:1})]),t(oe,{style:{"font-size":"16px"}},{default:l(()=>[...e[17]||(e[17]=[i("点击或拖拽文件到此处上传",-1)])]),_:1}),t(ae,{depth:"3",style:{margin:"8px 0 0 0"}},{default:l(()=>[...e[18]||(e[18]=[i("支持 .xlsx 或 .xls 格式",-1)])]),_:1})]),_:1})]),_:1})]),_:1})]),_:1},8,["show"])])}}}),$e=ge(Ce,[["__scopeId","data-v-7a00e5d8"]]);export{$e as default};
