import{C as e,E as t,M as n,O as r,T as i,_ as a,a as o,b as s,f as c,g as l,k as u,l as d,m as f,o as p,s as m,t as h,w as g,x as _,y as v}from"./index-vhvNh9F8.js";var y={class:`page`},b={key:0,style:{"text-align":`center`,padding:`40px`,color:`#999`}},x={key:1,style:{"text-align":`center`,padding:`40px`,color:`#999`,"font-size":`14px`}},S=[`onClick`],C={class:`card-body`,style:{display:`flex`,gap:`10px`}},w={style:{flex:`1`,"min-width":`0`}},T={style:{"font-size":`14px`,"font-weight":`600`}},E={style:{"font-size":`12px`,color:`#999`,"margin-top":`4px`}},D={style:{"margin-top":`4px`,"font-size":`12px`}},O={style:{padding:`20px`}},k={key:0,style:{display:`flex`,gap:`12px`,"margin-bottom":`16px`}},A={style:{flex:`1`,"min-width":`0`}},j={style:{"font-size":`15px`,"font-weight":`600`}},M={style:{"font-size":`12px`,color:`#999`,"margin-top":`2px`}},N={style:{"margin-bottom":`12px`}},P={style:{color:`var(--danger)`,"font-weight":`700`}},F={style:{"margin-bottom":`12px`}},I={key:0,style:{"margin-top":`8px`,"font-size":`14px`,color:`var(--danger)`,"font-weight":`700`}},L=m({__name:`BulkGroup`,setup(m){let L=d(),R=r(localStorage.getItem(`token`)||``),z=r([]),B=r(!1),V=r(!1),H=r(null),U=r(1),W=r(!1);function G(e,t){if(!e||!e.tiers||!e.tiers.length)return 0;let n=e.tiers[0].price;for(let r of e.tiers)t>=r.min_qty&&(n=r.price);return+(n*t).toFixed(2)}function K(e){H.value=e,U.value=1,V.value=!0}async function q(){if(!R.value){L.push(`/login`);return}let e=H.value;if(e){W.value=!0;try{let t=await o.post(`/bulk-group/order`,{bulk_id:e.id,product_id:e.product_id,quantity:U.value},{headers:{Authorization:`Bearer `+R.value}});t.code===0?(alert(`团购下单成功！`),V.value=!1):alert(t.message||`下单失败`)}catch{alert(`网络错误`)}W.value=!1}}return _(async()=>{B.value=!0;try{let e=await o.get(`/bulk-group/list`);if(e.code===0){let t=e.data.list||[];t.forEach(e=>{e.tiers=JSON.parse(e.tiers||`[]`)}),z.value=t}}catch{}B.value=!1}),(r,o)=>{let d=i(`van-image`),m=i(`van-stepper`),_=i(`van-button`),J=i(`van-action-sheet`);return e(),a(`div`,y,[s(p,{title:`阶梯团购`,onBack:o[0]||=e=>u(L).push(`/`)}),B.value?(e(),a(`div`,b,`加载中...`)):z.value.length===0?(e(),a(`div`,x,`暂无团购活动`)):l(``,!0),(e(!0),a(c,null,g(z.value,r=>(e(),a(`div`,{key:r.id,class:`card`,onClick:e=>K(r)},[f(`div`,C,[s(d,{src:r.product_image,style:{width:`80px`,height:`80px`,"border-radius":`6px`,"object-fit":`cover`,"flex-shrink":`0`},"lazy-load":``},{error:t(()=>[...o[3]||=[f(`div`,{class:`img-placeholder`,style:{width:`80px`,height:`80px`,"border-radius":`6px`,"font-size":`16px`}},`📷`,-1)]]),_:1},8,[`src`]),f(`div`,w,[f(`div`,T,n(r.name),1),f(`div`,E,n(r.product_name),1),f(`div`,D,[(e(!0),a(c,null,g(r.tiers||[],t=>(e(),a(`span`,{key:t.min_qty,style:{display:`inline-block`,background:`#fef0f0`,color:`var(--danger)`,padding:`1px 6px`,"border-radius":`4px`,"margin-right":`4px`,"margin-bottom":`4px`}},`≥`+n(t.min_qty)+`件 ¥`+n(t.price),1))),128))])])])],8,S))),128)),s(J,{show:V.value,"onUpdate:show":o[2]||=e=>V.value=e,title:`团购详情`},{default:t(()=>[f(`div`,O,[H.value?(e(),a(`div`,k,[s(d,{src:H.value.product_image,style:{width:`72px`,height:`72px`,"border-radius":`6px`,"object-fit":`cover`,"flex-shrink":`0`},"lazy-load":``},{error:t(()=>[...o[4]||=[f(`div`,{class:`img-placeholder`,style:{width:`72px`,height:`72px`,"border-radius":`6px`,"font-size":`14px`}},`📷`,-1)]]),_:1},8,[`src`]),f(`div`,A,[f(`div`,j,n(H.value.name),1),f(`div`,M,n(H.value.product_name),1)])])):l(``,!0),f(`div`,N,[o[5]||=f(`div`,{style:{"font-size":`13px`,"font-weight":`600`,"margin-bottom":`8px`}},`阶梯价格`,-1),(e(!0),a(c,null,g(H.value?.tiers||[],t=>(e(),a(`div`,{key:t.min_qty,style:{display:`flex`,"justify-content":`space-between`,padding:`8px`,"margin-bottom":`6px`,background:`#f9f9f9`,"border-radius":`6px`,"font-size":`13px`}},[f(`span`,null,`≥ `+n(t.min_qty)+` 件`,1),f(`span`,P,`¥`+n(u(h)(t.price))+` / 件`,1)]))),128))]),f(`div`,F,[o[6]||=f(`div`,{style:{"font-size":`13px`,color:`#666`,"margin-bottom":`4px`}},`购买数量`,-1),s(m,{modelValue:U.value,"onUpdate:modelValue":o[1]||=e=>U.value=e,min:`1`,max:99,size:`28`},null,8,[`modelValue`]),H.value?.tiers?(e(),a(`div`,I,`预计总价: ¥`+n(u(h)(G(H.value,U.value))),1)):l(``,!0)]),s(_,{round:``,block:``,class:`primary-btn`,style:{height:`44px`},onClick:q,loading:W.value,disabled:!R.value},{default:t(()=>[...o[7]||=[v(`立即下单`,-1)]]),_:1},8,[`loading`,`disabled`])])]),_:1},8,[`show`])])}}},[[`__scopeId`,`data-v-6db44e1d`]]);export{L as default};