import{d as A,v as f,r as v,a as J,G as K,g as n,z as q,k as r,w as e,c as w,H as I,e as t,b as d,l as W,m as X,x as u,F as Y,y as Z,t as c,E as D,N as $,_ as ee}from"./index-CUnFTKV2.js";import{b as te}from"./user-EiTTpYhZ.js";const ae={key:0,class:"user-info"},oe={class:"user-detail"},le={class:"nickname"},se={class:"uid"},ne={class:"coupon-option"},ue={class:"coupon-title"},ie={class:"coupon-value"},re={key:0,class:"quantity-tip"},de=A({__name:"GiftCouponDialog",props:{modelValue:{type:Boolean},user:{}},emits:["update:modelValue","success"],setup(m,{emit:N}){const y=m,B=N,g=f({get:()=>y.modelValue,set:a=>B("update:modelValue",a)}),b=v(),V=v(!1),k=v(!1),p=v([]),s=J({couponId:0,quantity:1}),P={couponId:[{required:!0,message:"请选择优惠券",trigger:"change"}],quantity:[{required:!0,message:"请输入赠送数量",trigger:"blur"},{type:"number",min:1,message:"数量必须大于0",trigger:"blur"}]},i=f(()=>p.value.find(a=>a.id===s.couponId)),U=f(()=>i.value?{1:"新人优惠券",2:"权益优惠券",3:"满减优惠券"}[i.value.type]||"未知":""),z=f(()=>999),E=async()=>{k.value=!0;try{const a=await $({url:"/admin/business/coupons/templates",method:"get",params:{status:0}});p.value=a.data||[]}catch(a){console.error("加载优惠券列表失败",a),p.value=[]}finally{k.value=!1}},F=()=>{var a;s.couponId=0,s.quantity=1,(a=b.value)==null||a.resetFields(),E()},h=()=>{g.value=!1},G=async()=>{var o;if(!y.user){D.warning("用户信息不存在");return}if(await((o=b.value)==null?void 0:o.validate())){V.value=!0;try{await te(y.user.id,s),D.success("赠送成功"),B("success"),h()}catch(x){D.error(x.message||"赠送失败")}finally{V.value=!1}}};return K(()=>s.couponId,()=>{s.quantity=1}),(a,o)=>{const x=n("el-icon"),R=n("el-avatar"),T=n("el-option"),O=n("el-select"),C=n("el-form-item"),_=n("el-descriptions-item"),S=n("el-descriptions"),H=n("el-input-number"),M=n("el-form"),L=n("el-button"),Q=n("el-dialog");return r(),q(Q,{modelValue:g.value,"onUpdate:modelValue":o[2]||(o[2]=l=>g.value=l),title:"赠送优惠券",width:"600px","close-on-click-modal":!1,onClose:h,onOpen:F},{footer:e(()=>[t(L,{onClick:h},{default:e(()=>[...o[3]||(o[3]=[c("取消",-1)])]),_:1}),t(L,{type:"primary",onClick:G,loading:V.value},{default:e(()=>[...o[4]||(o[4]=[c("确定赠送",-1)])]),_:1},8,["loading"])]),default:e(()=>[m.user?(r(),w("div",ae,[t(R,{src:m.user.avatar,size:40},{default:e(()=>[t(x,null,{default:e(()=>[t(W(X))]),_:1})]),_:1},8,["src"]),d("div",oe,[d("div",le,u(m.user.nickname||"-"),1),d("div",se,"UID: "+u(m.user.uid),1)])])):I("",!0),t(M,{ref_key:"formRef",ref:b,model:s,rules:P,"label-width":"100px"},{default:e(()=>[t(C,{label:"选择优惠券",prop:"couponId"},{default:e(()=>[t(O,{modelValue:s.couponId,"onUpdate:modelValue":o[0]||(o[0]=l=>s.couponId=l),placeholder:"请选择优惠券",style:{width:"100%"},filterable:"",loading:k.value},{default:e(()=>[(r(!0),w(Y,null,Z(p.value,l=>(r(),q(T,{key:l.id,label:l.title,value:l.id},{default:e(()=>[d("div",ne,[d("span",ue,u(l.title),1),d("span",ie," 满"+u(l.minPrice)+"减"+u(l.discountPrice),1)])]),_:2},1032,["label","value"]))),128))]),_:1},8,["modelValue","loading"])]),_:1}),i.value?(r(),q(C,{key:0,label:"优惠券详情"},{default:e(()=>[t(S,{column:2,border:"",size:"small"},{default:e(()=>[t(_,{label:"名称"},{default:e(()=>[c(u(i.value.title),1)]),_:1}),t(_,{label:"类型"},{default:e(()=>[c(u(U.value),1)]),_:1}),t(_,{label:"面值"},{default:e(()=>[c(" 满"+u(i.value.minPrice)+"减"+u(i.value.discountPrice),1)]),_:1}),t(_,{label:"有效期"},{default:e(()=>[c(u(i.value.validDays)+"天",1)]),_:1})]),_:1})]),_:1})):I("",!0),t(C,{label:"赠送数量",prop:"quantity"},{default:e(()=>{var l;return[t(H,{modelValue:s.quantity,"onUpdate:modelValue":o[1]||(o[1]=j=>s.quantity=j),min:1,max:z.value,style:{width:"200px"}},null,8,["modelValue","max"]),(l=i.value)!=null&&l.stock?(r(),w("span",re," （最多可赠送 "+u(i.value.stock)+" 张） ",1)):I("",!0)]}),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue"])}}}),pe=ee(de,[["__scopeId","data-v-ce01a32f"]]);export{pe as default};
