import{_ as e}from"./uv-image.e629c74e.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,B 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-d76b1e7a.js";import{r as j}from"./useRouter.2bdb47a0.js";import{_ as b}from"./uv-icon.5730d4d2.js";import{_ as A}from"./space.cecd0c54.js";import{_ as S}from"./uv-button.dcfcbf96.js";import{d as x}from"./product.b13622dd.js";import{u as h}from"./useInterface.5df3648b.js";import{P as y}from"./index.30cfb093.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 B=t(null),E=t(null),R=t(null),F=t(null),P=t(1),U=t(null),X=t(void 0);t(!1);const $=()=>{let e=z.value.join(",");V("submit",{store:F.value[e],num:P.value}),V("select",{store:F.value[e],num:P.value}),V("onSelect",{store:F.value[e],num:P.value})},{toast:q}=h();function D(e,t="plus"){if("plus"===t){if(P.value+1>e.stock)return q({title:"超出库存啦~"});P.value+=1}else{if(P.value-1<=0)return q({title:"至少选一件哦~"});P.value-=1}}return C({open:(e=1,t)=>{X.value=t,P.value=e,(async e=>{const t=await x(e);if(t)if(B.value=t,E.value=t.storeInfo,R.value=t.productAttr,F.value=t.productValue,X.value)z.value=k(X).split(","),U.value=F.value[X.value];else{let e=[];t.productAttr.forEach(((t,l)=>{e[l]=t.attrValueArr[0]})),z.value=e;let l=z.value.join(",");U.value=F.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),X=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((()=>[U.value?(l(),a(h,{key:0,class:"goodAttrSelect-goods"},{default:s((()=>[u(x,{class:"attr-image",src:U.value.image||B.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(E.value.storeName),1)])),_:1}),u(h,{class:"attr-info-bottom"},{default:s((()=>[u(h,{class:"price"},{default:s((()=>[o("¥"+r(U.value.price),1)])),_:1}),u(h,{class:"stock"},{default:s((()=>[o("库存："+r(U.value.stock),1)])),_:1})])),_:1})])),_:1})])),_:1})):c("",!0),n("div",{class:"line"}),U.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(U.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:P.value,"onUpdate:modelValue":k[1]||(k[1]=e=>P.value=e),onBlur:k[2]||(k[2]=e=>function(e,t){const l=Number(e.detail.value);l<=0&&(P.value=1,q({title:"至少选一件哦~"})),l>t.stock&&(P.value=t.stock,q({title:"超出库存啦~"})),P.value=l}(e,U.value))},null,8,["modelValue"])])),_:1}),u(h,{class:"button",onClick:k[3]||(k[3]=e=>D(U.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(",");U.value=F.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(X,{round:"",block:"",type:"primary",onClick:$},{default:s((()=>[o(" 确定 ")])),_:1})])),_:1})])),_:1})])),_:1},512)}}},[["__scopeId","data-v-444a2410"]]);export{C as _};
