import{A as e,C as t,M as n,O as r,_ as i,a,b as o,f as s,g as c,k as l,l as u,m as d,o as f,s as p,w as m,x as h,y as g}from"./index-vhvNh9F8.js";var _={class:`page`},v={class:`tab-bar`},y={key:0,class:`coupon-list`},b={key:0,class:`empty-state`},x={class:`coupon-left`},S={key:0,class:`coupon-amount`},C={key:1,class:`coupon-amount`},w={class:`coupon-condition`},T={class:`coupon-right`},E={class:`coupon-name`},D={class:`coupon-info`},O={key:0,class:`coupon-time`},k=[`onClick`,`disabled`],A={key:1,class:`coupon-list`},j={key:0,class:`empty-state`},M={class:`coupon-left`},N={key:0,class:`coupon-amount`},P={key:1,class:`coupon-amount`},F={class:`coupon-condition`},I={class:`coupon-right`},L={class:`coupon-name`},R={class:`coupon-status-bar`},z={key:0,class:`coupon-time`},B=p({__name:`CouponList`,setup(p){let B=u(),V=r(`available`),H=r([]),U=r([]),W=r(null);function G(e){if(!e)return``;let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}async function K(){try{let e=await a.get(`/marketing/coupons`);e.code===0&&(H.value=e.data||[])}catch{}}async function q(){let e=localStorage.getItem(`token`);if(e)try{let t=await a.get(`/marketing/my-coupons`,{headers:{Authorization:`Bearer `+e}});t.code===0&&(U.value=t.data||[])}catch{}}async function J(e){let t=localStorage.getItem(`token`);if(!t){B.push(`/login`);return}W.value=e.id;try{let n=await a.post(`/marketing/coupon/receive`,{coupon_id:e.id},{headers:{Authorization:`Bearer `+t}});n.code===0?(alert(`🎉 领取成功！`),K(),q()):alert(n.message||`领取失败`)}catch{alert(`网络错误`)}finally{W.value=null}}return h(()=>{K(),q()}),(r,a)=>(t(),i(`div`,_,[o(f,{title:`领券中心`,onBack:a[0]||=e=>l(B).push(`/`)}),d(`div`,v,[d(`div`,{class:e([`tab-item`,{active:V.value===`available`}]),onClick:a[1]||=e=>V.value=`available`},`可领取`,2),d(`div`,{class:e([`tab-item`,{active:V.value===`mine`}]),onClick:a[2]||=e=>V.value=`mine`},`我的券`,2)]),V.value===`available`?(t(),i(`div`,y,[H.value.length===0?(t(),i(`div`,b,[...a[4]||=[d(`div`,{class:`empty-icon`},`🎫`,-1),d(`div`,{class:`empty-text`},`暂无可领取的优惠券`,-1)]])):c(``,!0),(t(!0),i(s,null,m(H.value,r=>(t(),i(`div`,{class:e([`coupon-card`,`type-`+r.type]),key:r.id},[d(`div`,x,[r.type===`discount`?(t(),i(`div`,C,[g(n(r.value),1),a[5]||=d(`span`,{class:`unit`},`折`,-1)])):(t(),i(`div`,S,`¥`+n(r.value),1)),d(`div`,w,`满`+n(r.min_amount)+`可用`,1)]),d(`div`,T,[d(`div`,E,n(r.name),1),d(`div`,D,` 已领 `+n(r.used_count||0)+` / `+n(r.total_count||`∞`),1),r.end_time?(t(),i(`div`,O,` 有效期至 `+n(G(r.end_time)),1)):c(``,!0),d(`button`,{class:`claim-btn`,onClick:e=>J(r),disabled:W.value===r.id},n(W.value===r.id?`领取中...`:`立即领取`),9,k)])],2))),128))])):c(``,!0),V.value===`mine`?(t(),i(`div`,A,[U.value.length===0?(t(),i(`div`,j,[...a[6]||=[d(`div`,{class:`empty-icon`},`📋`,-1),d(`div`,{class:`empty-text`},`还没有优惠券`,-1),d(`div`,{class:`empty-hint`},`去领取几张吧`,-1)]])):c(``,!0),(t(!0),i(s,null,m(U.value,r=>(t(),i(`div`,{class:e([`coupon-card mine`,`type-`+r.type+` `+r.status]),key:r.id},[d(`div`,M,[r.type===`discount`?(t(),i(`div`,P,[g(n(r.value),1),a[7]||=d(`span`,{class:`unit`},`折`,-1)])):(t(),i(`div`,N,`¥`+n(r.value),1)),d(`div`,F,`满`+n(r.min_amount)+`可用`,1)]),d(`div`,I,[d(`div`,L,n(r.name),1),d(`div`,R,[d(`span`,{class:e([`status-tag`,r.status])},n(r.status===`unused`?`未使用`:r.status===`used`?`已使用`:`已过期`),3)]),r.expired_time?(t(),i(`div`,z,` 有效期至 `+n(G(r.expired_time)),1)):c(``,!0),r.status===`unused`?(t(),i(`button`,{key:1,class:`use-btn`,onClick:a[3]||=e=>l(B).push(`/`)},`去使用`)):c(``,!0)])],2))),128))])):c(``,!0)]))}},[[`__scopeId`,`data-v-e0ea4f11`]]);export{B as default};