import{d as j}from"./user-EiTTpYhZ.js";import{p as J}from"./config-J21_Zans.js";import{d as K,v as o,r as w,a as O,o as P,G as Q,g as u,z as W,k as X,w as n,e as r,b as p,x as m,t as f,S as Y,E as x,_ as Z}from"./index-CUnFTKV2.js";const ee={class:"current-value"},ae={class:"preview-info"},te={class:"operation-symbol"},le={class:"amount-value"},oe=K({__name:"MoneyChangeDialog",props:{modelValue:{type:Boolean},user:{},type:{},action:{default:"add"}},emits:["update:modelValue","success"],setup($,{emit:h}){const t=$,k=h,_=o({get:()=>t.modelValue,set:l=>k("update:modelValue",l)}),g=w(),y=w(!1),c=w(),a=O({type:1,amount:0,operation:1,remark:""}),U=async()=>{var l;try{const e=await J();(l=e.data)!=null&&l.value&&(c.value=e.data.value)}catch(e){console.error("获取应用设置失败:",e)}};P(()=>{U()});const B=o(()=>({operation:[{required:!0,message:"请选择操作类型",trigger:"change"}],amount:[{required:!0,message:"请输入金额",trigger:"blur"},{type:"number",min:.01,message:"金额必须大于0",trigger:"blur"},{validator:(l,e,s)=>{a.operation===2&&e>d.value?s(new Error(`扣除金额不能超过当前${v.value}`)):s()},trigger:"blur"}]})),v=o(()=>c.value?{1:c.value.balance_name||"钻石",2:c.value.currency1_name||"HH币",3:c.value.currency2_name||"哈尼券"}[t.type]||"钻石":{1:"钻石",2:"HH币",3:"哈尼券"}[t.type]||"钻石"),H=o(()=>`${v.value}变动`),C=o(()=>`当前${v.value}`),L=o(()=>`${v.value}数量`),d=o(()=>t.user&&{1:t.user.balance||0,2:t.user.integral||0,3:t.user.diamond||0}[t.type]||0),M=o(()=>t.type===1?`¥${d.value.toFixed(2)}`:d.value.toString()),E=o(()=>t.type===1?2:0),F=o(()=>(t.type===1,1)),b=o(()=>{const l=a.amount||0;return a.operation===1?d.value+l:Math.max(0,d.value-l)}),N=o(()=>t.type===1?`¥${b.value.toFixed(2)}`:b.value.toString()),R=o(()=>a.operation===1?"positive":b.value<d.value?"negative":"");Q(()=>t.modelValue,l=>{var e;l&&(a.type=t.type,a.operation=t.action==="add"?1:2,a.amount=0,a.remark="",(e=g.value)==null||e.resetFields())});const V=()=>{_.value=!1},q=async()=>{var e;if(!t.user){x.warning("用户信息不存在");return}if(await((e=g.value)==null?void 0:e.validate())){y.value=!0;try{await j(t.user.id,a),x.success("操作成功"),k("success"),V()}catch(s){x.error(s.message||"操作失败")}finally{y.value=!1}}};return(l,e)=>{const s=u("el-form-item"),S=u("el-radio"),z=u("el-radio-group"),A=u("el-input-number"),T=u("el-input"),G=u("el-form"),D=u("el-button"),I=u("el-dialog");return X(),W(I,{modelValue:_.value,"onUpdate:modelValue":e[3]||(e[3]=i=>_.value=i),title:H.value,width:"450px","close-on-click-modal":!1,onClose:V},{footer:n(()=>[r(D,{onClick:V},{default:n(()=>[...e[7]||(e[7]=[f("取消",-1)])]),_:1}),r(D,{type:"primary",onClick:q,loading:y.value},{default:n(()=>[...e[8]||(e[8]=[f("确定",-1)])]),_:1},8,["loading"])]),default:n(()=>[r(G,{ref_key:"formRef",ref:g,model:a,rules:B.value,"label-width":"100px"},{default:n(()=>[r(s,{label:C.value},{default:n(()=>[p("span",ee,m(M.value),1)]),_:1},8,["label"]),r(s,{label:"操作类型",prop:"operation"},{default:n(()=>[r(z,{modelValue:a.operation,"onUpdate:modelValue":e[0]||(e[0]=i=>a.operation=i)},{default:n(()=>[r(S,{value:1},{default:n(()=>[...e[4]||(e[4]=[f("充值（增加）",-1)])]),_:1}),r(S,{value:2},{default:n(()=>[...e[5]||(e[5]=[f("扣除（减少）",-1)])]),_:1})]),_:1},8,["modelValue"])]),_:1}),r(s,{label:L.value,prop:"amount"},{default:n(()=>[r(A,{modelValue:a.amount,"onUpdate:modelValue":e[1]||(e[1]=i=>a.amount=i),min:.01,max:999999999,precision:E.value,step:F.value,style:{width:"100%"},placeholder:"请输入金额"},null,8,["modelValue","precision","step"])]),_:1},8,["label"]),r(s,{label:"备注",prop:"remark"},{default:n(()=>[r(T,{modelValue:a.remark,"onUpdate:modelValue":e[2]||(e[2]=i=>a.remark=i),type:"textarea",rows:3,placeholder:"请输入操作备注（选填）",maxlength:"200","show-word-limit":""},null,8,["modelValue"])]),_:1}),r(s,{label:"操作预览"},{default:n(()=>[p("div",ae,[p("span",null,m(C.value)+"："+m(M.value),1),p("span",te,m(a.operation===1?"+":"-"),1),p("span",le,m(a.amount||0),1),e[6]||(e[6]=p("span",{class:"result-symbol"},"=",-1)),p("span",{class:Y(["result-value",R.value])},m(N.value),3)])]),_:1})]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])}}}),ue=Z(oe,[["__scopeId","data-v-6cc9c55d"]]);export{ue as default};
