import{_ as e}from"./index-7266ee79.js";import{_ as a}from"./add.vue_vue_type_script_setup_true_lang-9cf41186.js";import{d as l,k as t,m as s,p as u,r,K as i,o as n,j as o,w as p,e as d,t as m,J as c,a as v,c as f,b as _,Z as y,f as b,$ as g,O as h,_ as w}from"./index-018fb6dd.js";import{a as x,b as k,d as j,e as V,f as C}from"./createGears-e9d05d0f.js";/* empty css             */import"./http-338d117f.js";/* empty css                   */import"./index-765bf96c.js";const q={class:"card-header"},N={class:"pt-5 pl-2"},O={key:0},S={key:1},T={class:"flex justify-start ml-9"},U=w(l({__name:"create",props:{primary:String|Number|Object,api:String},emits:["close"],setup(l,{emit:w}){const U=l,z=t(!1),B=t(!1),E=t(),J=t([]),R=t(),$=t({status:1}),A=s((()=>E.value?"编辑充值档位":"添加充值档位")),H=t([]),I=["MONTH","QUARTER","YEAR"],M=()=>{z.value=!1},G=(e,a)=>{if(a)E.value=a,E.value.index=e,z.value=!0;else{if(J.value.length>=6)return g.alert("当前充值档位位置已满");E.value=null,z.value=!0}},K=e=>{const a={...e,...e.typeObj,...e.sequenceObj};null!=e.index?J.value[e.index]=a:J.value.push(a)},Q=()=>{w("close")};return U.primary&&(U.primary,x(U.primary).then((e=>{$.value=e.data.template_info,J.value=e.data.template_item_list}))),u((()=>{k().then((e=>{H.value=e.data}))})),(l,t)=>{const s=r("el-input"),u=r("el-form-item"),x=a,k=r("el-table-column"),H=r("el-button"),W=r("el-table"),Y=r("el-card"),Z=r("el-switch"),D=r("el-form"),F=e,L=i("loading");return n(),o(Y,{shadow:"always","body-style":{padding:"20px"}},{header:p((()=>[d("div",q,[d("span",null,m(U.primary?"编辑":"添加")+"充值模板",1)])])),default:p((()=>[c((n(),o(D,{model:$.value,"label-width":"120px",ref_key:"form",ref:R,class:"pr-6"},{default:p((()=>[v(u,{label:"模板名称",prop:"name",rules:[{required:!0,message:"模板名称必须填写"},{max:20,message:"至多输入20个字符",trigger:"blur"}]},{default:p((()=>[v(s,{disabled:Boolean(U.primary),class:"item",modelValue:$.value.name,"onUpdate:modelValue":t[0]||(t[0]=e=>$.value.name=e),clearable:""},null,8,["disabled","modelValue"])])),_:1}),v(u,{label:"充值档位",prop:"options",rules:[{required:!0,message:"请添加充值档位"}]},{default:p((()=>[v(Y,{class:"w-full",shadow:"never"},{default:p((()=>[d("div",N,[v(x,{onClick:t[1]||(t[1]=e=>G(null,null))})]),c((n(),o(W,{data:J.value,class:"w-full mt-3"},{default:p((()=>[v(k,{prop:"price",label:"价格"},{default:p((e=>[d("span",null,m(e.row.price)+"元",1)])),_:1}),v(k,{prop:"sequence_text",label:"位置"}),v(k,{prop:"type_name",label:"挡位类型"}),v(k,{prop:"charge_coin",label:"充看币"},{default:p((e=>{return[(a=e.row,I.includes(a.type)?(n(),f("span",S,m(e.row.type_name),1)):(n(),f("span",O,m(Math.round(100*Number(e.row.price)))+"k币",1)))];var a})),_:1}),v(k,{prop:"given",label:"充看送币"},{default:p((e=>[d("span",null,m(e.row.given)+"k币",1)])),_:1}),v(k,{prop:"default_text",label:"默认项"},{default:p((e=>[d("span",null,m(e.row.is_default?"默认项":"非默认项"),1)])),_:1}),v(k,{label:"操作",width:"200"},{default:p((e=>[v(H,{link:"",type:"primary",size:"small",onClick:a=>G(e.$index,e.row)},{default:p((()=>[_("编辑")])),_:2},1032,["onClick"]),v(H,{link:"",type:"danger",size:"small",onClick:y((a=>{return l=e.$index,void g.confirm("确定要删除此条充值档位吗?","提示",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then((()=>{J.value.splice(l,1)})).catch((()=>{}));var l}),["prevent"])},{default:p((()=>[_("删除")])),_:2},1032,["onClick"])])),_:1})])),_:1},8,["data"])),[[L,B.value]])])),_:1})])),_:1}),v(u,{label:"启用状态",prop:"status",rules:[{required:!0,message:"请设置启用状态"}]},{default:p((()=>[v(Z,{modelValue:$.value.status,"onUpdate:modelValue":t[2]||(t[2]=e=>$.value.status=e),"active-value":1,"inactive-value":0},null,8,["modelValue"])])),_:1}),d("div",T,[v(H,{type:"primary",size:"default",onClick:Q},{default:p((()=>[_("取消")])),_:1}),v(H,{type:"primary",onClick:t[3]||(t[3]=e=>{var a;(a=R.value)&&($.value.options=J.value.map((e=>({price:Number(e.price),type:e.type,given:Number(e.given),sequence:e.sequence,is_default:e.is_default}))),B.value=!0,a.validate((e=>{if(e){const e={name:$.value.name,status:$.value.status,options:JSON.stringify($.value.options)};U.primary?V($.value.id,e).then((e=>{B.value=!1,h.success(e.message),w("close")})).catch((e=>{B.value=!1})):C(e).then((e=>{B.value=!1,h.success(e.message),w("close")})).catch((e=>{B.value=!1}))}else B.value=!1})).then((()=>{})))})},{default:p((()=>[_("确认")])),_:1})])])),_:1},8,["model"])),[[L,B.value]]),v(F,{modelValue:z.value,"onUpdate:modelValue":t[4]||(t[4]=e=>z.value=e),title:b(A),width:"40%","destroy-on-close":""},{default:p((()=>[v(j,{onClose:M,onSuccess:K,data:J.value,primary:E.value},null,8,["data","primary"])])),_:1},8,["modelValue","title"])])),_:1})}}}),[["__scopeId","data-v-9545fa1e"]]);export{U as default};
