import{_ as e}from"./uv-image.7b0e6bd2.js";import{f as t,o as l,c as a,w as s,a as u,h as o,t as r,m as c,k as n,p as i,b as v,r as d,F as f,g as m,d as p,I as _,n as g,u as k}from"./index-3714412c.js";import{r as j}from"./useRouter.f44141c1.js";import{_ as b}from"./uv-icon.c593f91d.js";import{_ as A}from"./space.57299547.js";import{_ as S}from"./uv-button.14a976f7.js";import{d as x}from"./product.d7200236.js";import{u as h}from"./useInterface.f3e95e31.js";import{P as y}from"./index.d0119d7e.js";import{_ as w}from"./_plugin-vue_export-helper.1b428a4d.js";const C=w({__name:"good-attr-select",props:["id"],emits:["onSelect","submit","close"],setup(w,{expose:C,emit:V}){const I=w,N=t(),z=t([]);t(!1);const E=t(null),P=t(null),R=t(null),B=t(null),F=t(1),M=t(null),U=t(void 0);t(!1);const Z=()=>{let e=z.value.join(",");V("submit",{store:B.value[e],num:F.value}),V("select",{store:B.value[e],num:F.value}),V("onSelect",{store:B.value[e],num:F.value})},{toast:q}=h();function D(e,t="plus"){if("plus"===t){if(F.value+1>e.stock)return q({title:"超出库存啦~"});F.value+=1}else{if(F.value-1<=0)return q({title:"至少选一件哦~"});F.value-=1}}return C({open:(e=1,t)=>{U.value=t,F.value=e,(async e=>{const t=await x(e);if(t)if(E.value=t,P.value=t.storeInfo,R.value=t.productAttr,B.value=t.productValue,U.value)z.value=k(U).split(","),M.value=B.value[U.value];else{let e=[];t.productAttr.forEach(((t,l)=>{e[l]=t.attrValueArr[0]})),z.value=e;let l=z.value.join(",");M.value=B.value[l]}})(I.id),N.value.show()},close:()=>{N.value.close(),V("close")}}),(t,k)=>{const x=j(m("uv-image"),e),h=p,w=j(m("uv-icon"),b),C=_,I=j(m("space"),A),U=j(m("uv-button"),S);return l(),a(y,{ref_key:"popupRef",ref:N,showCloseable:!1,onClose:k[5]||(k[5]=e=>V("close"))},{default:s((()=>[u(h,{class:"goodAttrSelect"},{default:s((()=>[M.value?(l(),a(h,{key:0,class:"goodAttrSelect-goods"},{default:s((()=>[u(x,{class:"attr-image",src:M.value.image||E.value.storeInfo.image,width:"150rpx",height:"150rpx"},null,8,["src"]),u(h,{class:"attr-info"},{default:s((()=>[u(h,{class:"name"},{default:s((()=>[o(r(P.value.storeName),1)])),_:1}),u(h,{class:"attr-info-bottom"},{default:s((()=>[u(h,{class:"price"},{default:s((()=>[o("¥"+r(M.value.price),1)])),_:1}),u(h,{class:"stock"},{default:s((()=>[o("库存："+r(M.value.stock),1)])),_:1})])),_:1})])),_:1})])),_:1})):c("",!0),n("div",{class:"line"}),M.value?(l(),a(h,{key:1,class:"goodAttrSelect-attr row"},{default:s((()=>[u(h,{class:"goodAttrSelect-attr-title"},{default:s((()=>[o(" 数量 ")])),_:1}),u(h,{class:"goodAttrSelect-attr-content"},{default:s((()=>[u(h,{class:"cart-num flex flex-ai__center flex-jc__sb",onClick:k[4]||(k[4]=i((()=>{}),["stop"]))},{default:s((()=>[u(h,{class:"button",onClick:k[0]||(k[0]=e=>D(M.value,"minus"))},{default:s((()=>[u(w,{name:"minus",color:"#333",size:"12"})])),_:1}),u(h,{class:"input"},{default:s((()=>[u(C,{type:"number",inputmode:"numeric",modelValue:F.value,"onUpdate:modelValue":k[1]||(k[1]=e=>F.value=e),onBlur:k[2]||(k[2]=e=>function(e,t){const l=Number(e.detail.value);l<=0&&(F.value=1,q({title:"至少选一件哦~"})),l>t.stock&&(F.value=t.stock,q({title:"超出库存啦~"})),F.value=l}(e,M.value))},null,8,["modelValue"])])),_:1}),u(h,{class:"button",onClick:k[3]||(k[3]=e=>D(M.value,"plus"))},{default:s((()=>[u(w,{name:"plus",color:"#333",size:"12"})])),_:1})])),_:1})])),_:1})])),_:1})):c("",!0),n("div",{class:"line"}),(l(!0),v(f,null,d(R.value,((e,t)=>(l(),a(h,{class:"goodAttrSelect-attr",key:t},{default:s((()=>[u(h,{class:"goodAttrSelect-attr-title"},{default:s((()=>[o(r(e.attrName),1)])),_:2},1024),u(h,{class:"goodAttrSelect-attr-content"},{default:s((()=>[u(I,{wrap:"warp"},{default:s((()=>[(l(!0),v(f,null,d(e.attrValueArr,((e,u)=>(l(),a(h,{class:g({attr:!0,check:z.value[t]===e}),key:u,onClick:l=>((e,t)=>{z.value[e]=t;let l=z.value.join(",");M.value=B.value[l]})(t,e)},{default:s((()=>[o(r(e),1)])),_:2},1032,["class","onClick"])))),128))])),_:2},1024)])),_:2},1024)])),_:2},1024)))),128)),u(h,{class:"goodAttrSelect-action"},{default:s((()=>[u(U,{round:"",block:"",type:"primary",onClick:Z},{default:s((()=>[o(" 确定 ")])),_:1})])),_:1})])),_:1})])),_:1},512)}}},[["__scopeId","data-v-444a2410"]]);export{C as _};
