import{G as y,H as M,I as w,J as C,K as x}from"./index.DLhCD1Qz.js";import{_ as U}from"./yb_admin_plugin.DNFUAscl.js";import{aZ as r,aL as p,s as _,bJ as a,I as d,u as v,F as B,aX as D,H as i,bb as m}from"./@vue.Da0bZ210.js";import"./vue.Bj6dTZYa.js";import"./@element-plus.pQhr8KT1.js";import"./echarts.Dms41JYJ.js";import"./tslib.BDyQ-Jie.js";import"./zrender.BueMfJu3.js";import"./axios.BjtuyMK1.js";import"./pinia.Tngw-S_5.js";import"./vue-router.DaVMGKLh.js";import"./element-plus.DC208N5p.js";import"./lodash-es.DVGGNlzX.js";import"./@vueuse.BhH-hw9p.js";import"./async-validator.9PlIezaS.js";import"./@popperjs.C5az9QE8.js";import"./@ctrl.C4Rzlq_k.js";import"./dayjs.BLMYetss.js";import"./memoize-one.BdPwpGay.js";import"./normalize-wheel-es.BQoi3Ox2.js";import"./@floating-ui.DCXYYTka.js";import"./vue-i18n.C7BagGww.js";import"./@intlify.TnaUIxGf.js";import"./moment.C5S46NFB.js";const E={title:"添加/编辑套餐",name:"Add",components:{},props:{edit:{type:Object,default:()=>({id:0})}},data(){return{app_list:[],checkedAll:!1,showAll:!1,menuData:[],expandedIds:[],checkedIds:[],form:{name:"",addons_id:"",module_ids:"",storage_size:0,traffic_size:0,remark:"",is_custom_config:0}}},computed:{rules(){return{name:[{required:!0,trigger:"blur",message:"请输入套餐名称"}],addons_id:[{required:!0,trigger:"blur",message:"请选择应用"}]}}},watch:{showAll(e){let t=this.$refs.tree.store.nodesMap;for(let s in t)t.hasOwnProperty(s)&&(t[s].expanded=e)},checkedAll(e){let t=this.$refs.tree.store.nodesMap;for(let s in t)t.hasOwnProperty(s)&&(t[s].checked=e)}},created(){C().then(e=>{this.app_list=e.data,e.data.length>0&&(this.edit.id||(this.form.addons_id=e.data[0].id,this.getAddonsMenu()))}),this.edit.id&&x({id:this.edit.id}).then(e=>{this.form=e.data.info,this.form.id=this.edit.id,this.menuData=e.data.menu_data,this.getExpandedAndChecked(e.data.module_ids)})},methods:{handleAddon(e){this.form.addons_id=e,this.getAddonsMenu()},getAddonsMenu(){w({addons_id:this.form.addons_id}).then(e=>{this.menuData=e.data.tree})},getExpandedAndChecked(e){for(let t of e)t.state.selected&&(this.checkedIds.push(t.id),this.expandedIds.push(t.id)),t.children&&this.getExpandedAndChecked(t.children)},onSubmit(){this.$refs.form.validate(async e=>{if(e){let t=this.$refs.tree.getCheckedKeys(),s=this.$refs.tree.getHalfCheckedKeys();s.push(...t),s=s.join(),this.form.module_ids=s,(this.edit.id?y:M)(this.form).then(l=>{this.$baseMessage("保存成功"),this.callBack&&this.callBack()})}else return!1})}}};function H(e,t,s,k,l,u){const f=r("el-input"),n=r("el-form-item"),g=r("el-option"),b=r("el-select"),h=r("el-checkbox"),I=r("el-tree"),c=r("el-radio"),V=r("el-radio-group"),A=r("el-form");return p(),_(A,{ref:"form",model:l.form,rules:u.rules,"label-width":"80px"},{default:a(()=>[d(n,{label:e.translateI18n("套餐名称"),prop:"name"},{default:a(()=>[d(f,{modelValue:l.form.name,"onUpdate:modelValue":t[0]||(t[0]=o=>l.form.name=o),modelModifiers:{trim:!0},placeholder:e.translateI18n("套餐名称"),autocomplete:"off"},null,8,["modelValue","placeholder"])]),_:1},8,["label"]),d(n,{label:e.translateI18n("解决方案"),prop:"addons_id"},{default:a(()=>[d(b,{modelValue:l.form.addons_id,"onUpdate:modelValue":t[1]||(t[1]=o=>l.form.addons_id=o),onChange:u.handleAddon},{default:a(()=>[(p(!0),v(B,null,D(l.app_list,o=>(p(),_(g,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","onChange"])]),_:1},8,["label"]),d(n,{label:e.translateI18n("应用权限")},{default:a(()=>[d(h,{modelValue:l.checkedAll,"onUpdate:modelValue":t[2]||(t[2]=o=>l.checkedAll=o)},{default:a(()=>[i(m(e.translateI18n("选中全部")),1)]),_:1},8,["modelValue"]),d(h,{modelValue:l.showAll,"onUpdate:modelValue":t[3]||(t[3]=o=>l.showAll=o)},{default:a(()=>[i(m(e.translateI18n("显示全部")),1)]),_:1},8,["modelValue"])]),_:1},8,["label"]),d(n,{label:"",class:"role-tree-class"},{default:a(()=>[d(I,{ref:"tree",data:l.menuData,"show-checkbox":"","node-key":"id",props:{label:"label"},"highlight-current":!0,"default-expanded-keys":l.expandedIds,"default-checked-keys":l.checkedIds},null,8,["data","default-expanded-keys","default-checked-keys"])]),_:1}),d(n,{label:e.translateI18n("用户配置"),prop:"is_custom_config"},{default:a(()=>[d(V,{modelValue:l.form.is_custom_config,"onUpdate:modelValue":t[4]||(t[4]=o=>l.form.is_custom_config=o)},{default:a(()=>[d(c,{label:0},{default:a(()=>[i(m(e.translateI18n("不支持")),1)]),_:1}),d(c,{label:1},{default:a(()=>[i(m(e.translateI18n("支持")),1)]),_:1})]),_:1},8,["modelValue"])]),_:1},8,["label"]),d(n,{label:e.translateI18n("套餐说明"),prop:"remark"},{default:a(()=>[d(f,{modelValue:l.form.remark,"onUpdate:modelValue":t[5]||(t[5]=o=>l.form.remark=o),modelModifiers:{trim:!0},placeholder:e.translateI18n("套餐说明"),type:"textarea",style:{width:"70%"}},null,8,["modelValue","placeholder"])]),_:1},8,["label"])]),_:1},8,["model","rules"])}const de=U(E,[["render",H],["__scopeId","data-v-81e69063"]]);export{de as default};
