import{h as B,a as X,_ as x}from"./http-CGjljVXL.js";import{_ as ee}from"./PageHeader.vue_vue_type_script_setup_true_lang-ClDoYPHj.js";import{A as L}from"./AdminNumberInput-BCSDw1QF.js";import{d as te,u as le,q as ae,c as z,e as t,w as a,a as q,x as oe,y as N,p as j,k as p,j as A,r as s,z as ne,o as _,i as u,t as v}from"./index-CcdGGfCj.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";const se={class:"page-stack management-page"},ie={class:"panel filter-bar"},ue={class:"panel table-panel"},de={class:"code-cell"},re={class:"form-grid"},ye=te({__name:"RedemptionsView",setup(pe){const m=le(),b=p(!1),y=p(!1),c=p(!1),k=p(!1),V=p([]),f=p([]),C=p(0);async function I(o){await navigator.clipboard.writeText(o),m.success("兑换码已复制")}const d=A({keyword:"",status:"",page:1,page_size:15}),i=A({name:"",points:10,quantity:1,expires_at:""});async function g(){b.value=!0;try{const{data:o}=await B.get("/redemption-codes",{params:d});V.value=o.data.items,C.value=o.data.total}catch(o){T(o)}finally{b.value=!1}}function M(){Object.assign(i,{name:"",points:10,quantity:1,expires_at:""}),c.value=!0}async function S(){const o=Number(i.points),e=Number(i.quantity);if(!Number.isFinite(o)||o<1||o>100){m.warning("单码积分数量必须为 1 至 100");return}if(!Number.isInteger(e)||e<1||e>10){m.warning("生成数量必须为 1 至 10");return}y.value=!0;try{const{data:n}=await B.post("/redemption-batches",i);f.value=n.data.codes,c.value=!1,k.value=!0,m.success("兑换码批次生成成功"),g()}catch(n){T(n)}finally{y.value=!1}}async function Y(){await navigator.clipboard.writeText(f.value.join(`
`)),m.success("完整兑换码已复制")}function h(){const o=new Blob([f.value.join(`\r
`)],{type:"text/plain;charset=utf-8"}),e=URL.createObjectURL(o),n=document.createElement("a");n.href=e,n.download=`redemption-codes-${Date.now()}.txt`,n.click(),URL.revokeObjectURL(e)}function E(){f.value=[],k.value=!1}function T(o){const e=X(o);m.error(e.message,e.copyText)}const O=o=>({unused:"未使用",used:"已使用",expired:"已过期"})[o]||o,R=o=>o?new Date(o).toLocaleString("zh-CN",{timeZone:"Asia/Shanghai",hour12:!1}):"长期有效";return ae(g),(o,e)=>{const n=s("el-button"),U=s("el-input"),D=s("el-option"),F=s("el-select"),r=s("el-table-column"),H=s("el-tag"),P=s("el-table"),Z=s("el-empty"),G=s("el-pagination"),w=s("el-form-item"),J=s("el-date-picker"),K=s("el-form"),$=s("el-dialog"),Q=s("el-alert"),W=ne("loading");return _(),z("div",se,[t(ee,{title:"兑换码管理",description:"完整兑换码可在列表中直接查看并复制"},{default:a(()=>[t(n,{type:"primary",onClick:M},{default:a(()=>[t(x,{name:"Plus"}),e[10]||(e[10]=u("生成兑换码 ",-1))]),_:1})]),_:1}),q("section",ie,[t(U,{modelValue:d.keyword,"onUpdate:modelValue":e[0]||(e[0]=l=>d.keyword=l),clearable:"",placeholder:"批次、兑换码或用户 UID"},null,8,["modelValue"]),t(F,{modelValue:d.status,"onUpdate:modelValue":e[1]||(e[1]=l=>d.status=l),clearable:"",placeholder:"状态"},{default:a(()=>[t(D,{label:"未使用",value:"unused"}),t(D,{label:"已使用",value:"used"}),t(D,{label:"已过期",value:"expired"})]),_:1},8,["modelValue"]),t(n,{type:"primary",onClick:e[2]||(e[2]=l=>{d.page=1,g()})},{default:a(()=>[...e[11]||(e[11]=[u("查询",-1)])]),_:1})]),oe((_(),z("section",ue,[t(P,{data:V.value},{default:a(()=>[t(r,{prop:"code",label:"兑换码","min-width":"230","show-overflow-tooltip":""},{default:a(({row:l})=>[q("span",de,v(l.code||"--"),1)]),_:1}),t(r,{label:"操作",width:"90",fixed:"right"},{default:a(({row:l})=>[l.code?(_(),N(n,{key:0,link:"",type:"primary",onClick:me=>I(l.code)},{default:a(()=>[t(x,{name:"CopyDocument"}),e[12]||(e[12]=u("复制",-1))]),_:1},8,["onClick"])):j("",!0)]),_:1}),t(r,{prop:"batch_name",label:"所属批次","min-width":"140"}),t(r,{label:"积分数量",width:"110"},{default:a(({row:l})=>[u(v(Number(l.points).toFixed(2)),1)]),_:1}),t(r,{label:"状态",width:"100"},{default:a(({row:l})=>[t(H,{effect:"plain"},{default:a(()=>[u(v(O(l.status)),1)]),_:2},1024)]),_:1}),t(r,{prop:"redeemed_uid",label:"兑换用户 UID",width:"130"}),t(r,{label:"兑换时间","min-width":"180"},{default:a(({row:l})=>[u(v(l.redeemed_at?R(l.redeemed_at):"--"),1)]),_:1}),t(r,{label:"失效时间","min-width":"180"},{default:a(({row:l})=>[u(v(l.status==="used"?"--":R(l.expires_at)),1)]),_:1}),t(r,{prop:"created_by",label:"创建管理员",width:"130"})]),_:1},8,["data"]),!b.value&&!V.value.length?(_(),N(Z,{key:0,description:"暂无兑换码"})):j("",!0),C.value>d.page_size?(_(),N(G,{key:1,"current-page":d.page,"onUpdate:currentPage":e[3]||(e[3]=l=>d.page=l),background:"",layout:"total,prev,pager,next",total:C.value,onCurrentChange:g},null,8,["current-page","total"])):j("",!0)])),[[W,b.value]]),t($,{modelValue:c.value,"onUpdate:modelValue":e[9]||(e[9]=l=>c.value=l),title:"按批次生成兑换码",width:"min(560px, calc(100vw - 32px))"},{footer:a(()=>[t(n,{onClick:e[8]||(e[8]=l=>c.value=!1)},{default:a(()=>[...e[13]||(e[13]=[u("取消",-1)])]),_:1}),t(n,{type:"primary",loading:y.value,disabled:y.value,onClick:S},{default:a(()=>[...e[14]||(e[14]=[u("生成",-1)])]),_:1},8,["loading","disabled"])]),default:a(()=>[t(K,{model:i,"label-position":"top"},{default:a(()=>[t(w,{label:"批次名称",required:""},{default:a(()=>[t(U,{modelValue:i.name,"onUpdate:modelValue":e[4]||(e[4]=l=>i.name=l),modelModifiers:{trim:!0}},null,8,["modelValue"])]),_:1}),q("div",re,[t(w,{label:"单码积分数量",required:""},{default:a(()=>[t(L,{modelValue:i.points,"onUpdate:modelValue":e[5]||(e[5]=l=>i.points=l),min:1,max:100,precision:2},null,8,["modelValue"])]),_:1}),t(w,{label:"生成数量",required:""},{default:a(()=>[t(L,{modelValue:i.quantity,"onUpdate:modelValue":e[6]||(e[6]=l=>i.quantity=l),min:1,max:10,precision:0},null,8,["modelValue"])]),_:1})]),t(w,{label:"有效期"},{default:a(()=>[t(J,{modelValue:i.expires_at,"onUpdate:modelValue":e[7]||(e[7]=l=>i.expires_at=l),type:"datetime","value-format":"YYYY-MM-DDTHH:mm:ssZ",class:"field-full"},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue"]),t($,{"model-value":k.value,title:"完整兑换码（仅展示一次）",width:"min(720px, calc(100vw - 32px))","close-on-click-modal":!1,"close-on-press-escape":!1,"show-close":!1},{footer:a(()=>[t(n,{onClick:Y},{default:a(()=>[t(x,{name:"CopyDocument"}),e[15]||(e[15]=u("复制全部 ",-1))]),_:1}),t(n,{onClick:h},{default:a(()=>[t(x,{name:"Download"}),e[16]||(e[16]=u("导出文件 ",-1))]),_:1}),t(n,{type:"primary",onClick:E},{default:a(()=>[...e[17]||(e[17]=[u("我已保存，关闭",-1)])]),_:1})]),default:a(()=>[t(Q,{type:"warning",closable:!1,title:"关闭后系统无法再次查看完整兑换码，请立即复制或导出。"}),t(U,{class:"code-output","model-value":f.value.join(`
`),type:"textarea",rows:12,readonly:""},null,8,["model-value"])]),_:1},8,["model-value"])])}}});export{ye as default};
