var e=(e,t,a)=>new Promise((i,r)=>{var l=e=>{try{s(a.next(e))}catch(t){r(t)}},o=e=>{try{s(a.throw(e))}catch(t){r(t)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(l,o);s((a=a.apply(e,t)).next())});import{d as t,r as a,k as i,A as r,h as l,e as o,w as s,g as d,b as n,I as m,J as p,f as u,v as c,j as v,K as f,E as y,O as _,T as j}from"./index-BoIUJTA2.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{f as g}from"./product-qKpGgPBm.js";import{a as h,E as b}from"./index-BcfO0-fK.js";import{E as x,a as k}from"./index-D2gD5Tn5.js";import{E as w}from"./index-ZsMdSUVI.js";import{E as q}from"./index-C_S0YbqD.js";import{E as P}from"./index-CjpBlozU.js";import{_ as V}from"./_plugin-vue_export-helper-BCo6x5W8.js";import"./castArray-nM8ho4U3.js";import"./_baseClone-Ct7RL6h5.js";import"./_initCloneObject-DRmC-q3t.js";import"./index-BMeOzN3u.js";import"./index-COyGylbk.js";import"./index-Bq8lawOo.js";import"./index-Cp4NEpJ7.js";import"./token-DWNpOE8r.js";import"./debounce-DQl5eUwG.js";import"./_baseIteratee-CtIat01j.js";import"./index-CXORCV4U.js";import"./index-BnK4BbY2.js";import"./use-dialog-FwJ-QdmW.js";import"./refs-Cw5r5QN8.js";const I={class:"flex items-center justify-between"},A={class:"font-medium"},C={class:"text-sm text-gray-500"},E=V(t({__name:"grant-reward-dialog",props:{visible:{type:Boolean},playerId:{}},emits:["update:visible","submit"],setup(t,{emit:V}){const E=t,U=V,M=a(),B=a(!1),z=a(!1),L=i({product_id:void 0,quantity:1,activity_id:void 0,reward_id:void 0,remark:""}),O=a([]);a([]),a([]);const T=a([]),F={product_id:[{required:!0,message:"请选择商品",trigger:"change"}],quantity:[{required:!0,message:"请输入发放数量",trigger:"blur"},{type:"number",min:1,max:100,message:"发放数量必须在1-100之间",trigger:"blur"}]},H=t=>e(this,null,function*(){z.value=!0;try{const e=(yield g({name:t||void 0,status:1,page:1,page_size:50})).list.map(e=>({id:e.id,name:e.name,price:e.price,stock:e.stock||0}));O.value=e,0===e.length?j.info(t?"未找到相关商品":"暂无可用商品"):j.success(`成功加载 ${e.length} 个商品`)}catch(e){const a=[{id:1,name:"iPhone 15 Pro",stock:100,price:9999},{id:2,name:"MacBook Air",stock:50,price:8999},{id:3,name:"AirPods Pro",stock:200,price:1999},{id:4,name:"iPad Air",stock:80,price:4399},{id:5,name:"Apple Watch",stock:150,price:2999},{id:6,name:"iPhone 15",stock:120,price:7999},{id:7,name:"MacBook Pro",stock:30,price:15999},{id:8,name:"AirPods Max",stock:75,price:4399}],i=t?a.filter(e=>e.name.toLowerCase().includes(t.toLowerCase())):a;O.value=i,j.warning("商品数据加载失败,使用演示数据")}finally{z.value=!1}}),J=()=>e(this,null,function*(){if(E.playerId)try{T.value=[]}catch(e){}}),K=()=>e(this,null,function*(){M.value&&E.playerId&&(yield M.value.validate(t=>e(this,null,function*(){if(t){B.value=!0;try{const e={product_id:L.product_id,quantity:L.quantity,activity_id:L.activity_id||void 0,reward_id:L.reward_id||void 0,remark:L.remark};U("submit",e),Q()}catch(e){j.error(e.message||"奖励发放失败")}finally{B.value=!1}}})))}),Q=()=>{U("update:visible",!1)},R=()=>{var e;null==(e=M.value)||e.resetFields(),L.quantity=1,L.activity_id=void 0,L.reward_id=void 0,L.remark="",O.value=[]};return r(()=>E.playerId,e=>{e&&(J(),H(""))},{immediate:!0}),r(()=>E.visible,e=>{e&&0===O.value.length&&H("")}),(e,a)=>{const i=w,r=k,j=x,g=b,V=q,E=f,T=h,J=y,S=P;return o(),l(S,{title:"给用户发放奖励","model-value":t.visible,"onUpdate:modelValue":a[3]||(a[3]=e=>U("update:visible",e)),width:"600px","close-on-click-modal":!1,onClosed:R},{footer:s(()=>[d(J,{onClick:_(Q,["prevent"])},{default:s(()=>[...a[5]||(a[5]=[v("取消",-1)])]),_:1}),d(J,{type:"primary",loading:B.value,onClick:_(K,["prevent"])},{default:s(()=>[...a[6]||(a[6]=[v(" 确认发放 ",-1)])]),_:1},8,["loading"])]),default:s(()=>[d(T,{ref_key:"formRef",ref:M,model:L,rules:F,"label-width":"100px",class:"reward-form"},{default:s(()=>[d(g,{label:"选择商品",prop:"product_id"},{default:s(()=>[d(j,{modelValue:L.product_id,"onUpdate:modelValue":a[0]||(a[0]=e=>L.product_id=e),placeholder:"请选择要发放的商品",filterable:"",remote:"","remote-method":H,loading:z.value,style:{width:"100%"}},{default:s(()=>[(o(!0),n(m,null,p(O.value,e=>(o(),l(r,{key:e.id,label:e.name,value:e.id},{default:s(()=>[u("div",I,[u("div",null,[u("div",A,c(e.name),1),u("div",C,"¥"+c(e.price),1)]),d(i,{size:"small",type:e.stock>0?"success":"danger"},{default:s(()=>[v(" 库存: "+c(e.stock||0),1)]),_:2},1032,["type"])])]),_:2},1032,["label","value"]))),128))]),_:1},8,["modelValue","loading"])]),_:1}),d(g,{label:"发放数量",prop:"quantity"},{default:s(()=>[d(V,{modelValue:L.quantity,"onUpdate:modelValue":a[1]||(a[1]=e=>L.quantity=e),min:1,max:100,"controls-position":"right",style:{width:"120px"}},null,8,["modelValue"]),a[4]||(a[4]=u("span",{class:"ml-2 text-sm text-gray-500"},"最多可发放100个",-1))]),_:1}),d(g,{label:"备注",prop:"remark"},{default:s(()=>[d(E,{modelValue:L.remark,"onUpdate:modelValue":a[2]||(a[2]=e=>L.remark=e),type:"textarea",rows:2,placeholder:"请输入发放备注(可选)",maxlength:"200","show-word-limit":""},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["model-value"])}}}),[["__scopeId","data-v-fca1fd3d"]]);export{E as default};