import{A as e,C as t,M as n,O as r,S as i,_ as a,a as o,b as s,d as c,f as l,g as u,j as d,k as f,l as p,m,o as h,p as g,s as _,w as v,x as y,y as b}from"./index-vhvNh9F8.js";var x={class:`page seckill-page`},S={key:0,class:`countdown-bar`},C={class:`countdown-label`},w={key:0},T={key:1},E={key:2},D={key:0,class:`countdown-timer`},O={class:`time-block`},k={class:`time-block`},A={class:`time-block`},j={key:1,class:`seckill-list`},M=[`onClick`],N={class:`seckill-img`},P=[`src`,`alt`],F={class:`seckill-info`},I={class:`seckill-name`},L={class:`seckill-prices`},R={class:`seckill-price`},ee={class:`original-price`},z={class:`seckill-progress`},B={class:`progress-bar`},V={class:`progress-text`},H=[`onClick`],U={key:2,class:`empty-state`},W=_({__name:`Seckill`,setup(_){let W=p(),G=r([]),K=r(null),q=r(Date.now()),J=null,Y=g(()=>{if(!K.value)return`ended`;let e=new Date(K.value.start_time).getTime(),t=new Date(K.value.end_time).getTime();return q.value<e?`upcoming`:q.value>=e&&q.value<t?`ongoing`:`ended`}),X=g(()=>K.value?Y.value===`upcoming`?new Date(K.value.start_time).getTime()-q.value:Y.value===`ongoing`?new Date(K.value.end_time).getTime()-q.value:0:0),Z=g(()=>String(Math.floor(X.value/36e5)).padStart(2,`0`)),Q=g(()=>String(Math.floor(X.value%36e5/6e4)).padStart(2,`0`)),$=g(()=>String(Math.floor(X.value%6e4/1e3)).padStart(2,`0`));function te(e){let t=e.stock+e.sales;return t<=0?0:Math.min(100,Math.round(e.sales/t*100))}function ne(e){let t=e.stock+e.sales;return t<=0?0:Math.min(100,Math.round(e.sales/t*100))}function re(e){W.push(`/product/`+e.product_id)}async function ie(e){if(e.stock<=0)return;let t=localStorage.getItem(`token`);if(!t){W.push(`/login`);return}try{let n=await o.post(`/marketing/seckill/buy`,{seckill_id:e.id},{headers:{Authorization:`Bearer `+t}});n.code===0?(alert(`🎉 秒杀成功！请在订单中完成支付`),W.push(`/orders`)):alert(n.message||`秒杀失败`)}catch{alert(`网络错误，请重试`)}}async function ae(){try{let e=await o.get(`/marketing/seckill/list`);e.code===0&&(G.value=e.data||[],G.value.length>0&&(K.value={start_time:G.value[0].start_time,end_time:G.value[0].end_time}))}catch{}}return y(()=>{ae(),J=setInterval(()=>{q.value=Date.now()},1e3)}),i(()=>{J&&clearInterval(J)}),(r,i)=>(t(),a(`div`,x,[s(h,{title:`限时秒杀`,onBack:i[0]||=e=>f(W).push(`/`)}),K.value?(t(),a(`div`,S,[m(`div`,C,[Y.value===`ongoing`?(t(),a(`span`,w,`🔥 秒杀进行中`)):Y.value===`upcoming`?(t(),a(`span`,T,`⏰ 即将开始`)):(t(),a(`span`,E,`已结束`))]),Y.value===`ongoing`||Y.value===`upcoming`?(t(),a(`div`,D,[m(`span`,O,n(Z.value),1),i[1]||=b(`:`,-1),m(`span`,k,n(Q.value),1),i[2]||=b(`:`,-1),m(`span`,A,n($.value),1)])):u(``,!0)])):u(``,!0),G.value.length>0?(t(),a(`div`,j,[(t(!0),a(l,null,v(G.value,r=>(t(),a(`div`,{class:`seckill-item`,key:r.id,onClick:e=>re(r)},[m(`div`,N,[m(`img`,{src:r.image||`/default-product.png`,alt:r.name},null,8,P),i[3]||=m(`div`,{class:`seckill-tag`},`秒杀`,-1)]),m(`div`,F,[m(`div`,I,n(r.name),1),m(`div`,L,[m(`span`,R,`¥`+n(r.seckill_price),1),m(`span`,ee,`¥`+n(r.original_price),1)]),m(`div`,z,[m(`div`,B,[m(`div`,{class:`progress-fill`,style:d({width:te(r)+`%`})},null,4)]),m(`span`,V,`已售 `+n(ne(r))+`%`,1)]),m(`button`,{class:e([`buy-btn`,{disabled:r.stock<=0}]),onClick:c(e=>ie(r),[`stop`])},n(r.stock<=0?`已抢光`:`立即抢购`),11,H)])],8,M))),128))])):(t(),a(`div`,U,[...i[4]||=[m(`div`,{class:`empty-icon`},`⚡`,-1),m(`div`,{class:`empty-text`},`暂无秒杀活动`,-1),m(`div`,{class:`empty-hint`},`关注商城，下次秒杀不错过`,-1)]]))]))}},[[`__scopeId`,`data-v-f9486c1e`]]);export{W as default};