import{d as q,aJ as H,aK as Q,aI as W,r as p,E as X,ai as n,o as f,c as g,U as a,O as t,u,S as h,D as O,a as A,F as D,a8 as M,M as B,P as Y,V as Z,T as ee}from"./vue.1RczIYhx.js";import{u as b}from"./useResponse.DqThFJSa.js";import{g as oe,a as le,p as ae}from"./api.D1vIUoIu.js";import{F as te,G as se,h as T}from"./elementPlus.CXoFsoPv.js";import{_ as ne}from"./_plugin-vue_export-helper.DlAUqK2U.js";import"./index.fM6cvGYs.js";const ie={class:"flex flex-wrap gap-1.5 min-h-14"},de=q({__name:"ShopAuthorize",props:H({rowData:Object},{modelValue:{default:!1},modelModifiers:{}}),emits:["update:modelValue"],setup(V){const U=V,{rowData:r}=U,y=Q(V,"modelValue"),z=W("noticeDialog"),i=p(""),m=p([]),s=p([]),C=p(!1),d=p("1");X(async()=>{await I(),await S()});function E(o){i.value="",s.value=[],o()}function F(){const o=m.value.find(e=>e.id===i.value);o&&!s.value.some(e=>e.id===o.id)&&s.value.push({id:o.id,name:o.name})}function N(o){return s.value.some(e=>e.id===o)}function R(o){s.value=s.value.filter(e=>e.id!==o.id),i.value=""}async function I(){const o=await b(le,{is_all:!0});m.value=o.data}async function S(){const o=await b(oe,{user_id:r==null?void 0:r.id}),e=(o.data.authorized_shops??[]).filter(c=>c!==null);o.data.is_authorized_all_shops?d.value="2":e.length>0&&(d.value="1",s.value=e.map(c=>{const _=m.value.find(v=>v.id===c);return{id:_.id,name:_.name}}))}async function j(){const o={...d.value==="2"?{}:{authorized_shops:s.value.map(e=>e.id)},user_id:r==null?void 0:r.id,is_authorized_all_shops:d.value==="2"};try{(await b(ae,o,C)).code===2e3&&(T.success("编辑成功！"),S())}catch{T.error("编辑失败！")}finally{i.value=""}}function G(){i.value="",s.value=[],z.value.visible=!1}function J(o){o==2&&(i.value="")}return(o,e)=>{const c=n("el-option"),_=n("el-select"),v=n("el-radio"),K=n("el-radio-group"),w=n("el-col"),x=n("el-row"),L=n("el-tag"),P=n("el-divider"),k=n("el-button"),$=n("el-dialog");return f(),g("div",null,[a($,{ref_key:"noticeDialog",ref:z,class:"authorize-dialog",modelValue:y.value,"onUpdate:modelValue":e[2]||(e[2]=l=>y.value=l),"before-close":E,"close-on-click-modal":!1,"close-on-press-escape":!1,title:"店铺授权",width:"40%"},{footer:t(()=>[a(k,{icon:u(te),onClick:G},{default:t(()=>e[5]||(e[5]=[h("取 消")])),_:1},8,["icon"]),a(k,{icon:u(se),loading:u(C),type:"primary",onClick:j},{default:t(()=>e[6]||(e[6]=[h("确 定")])),_:1},8,["icon","loading"])]),default:t(()=>[a(x,{class:"mb-2"},{default:t(()=>[a(w,null,{default:t(()=>[a(K,{modelValue:u(d),"onUpdate:modelValue":e[1]||(e[1]=l=>O(d)?d.value=l:null),onChange:J},{default:t(()=>[a(v,{value:"1"},{default:t(()=>[e[3]||(e[3]=A("span",{class:"mr-2 font-medium"},"店 铺",-1)),a(_,{modelValue:u(i),"onUpdate:modelValue":e[0]||(e[0]=l=>O(i)?i.value=l:null),disabled:u(d)=="2",filterable:"",placeholder:"输入搜索",style:{width:"200px"},onChange:F},{default:t(()=>[(f(!0),g(D,null,M(u(m),l=>(f(),B(c,{key:l.id,disabled:N(l.id),label:l.name,value:l.id},null,8,["disabled","label","value"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1}),a(v,{value:"2"},{default:t(()=>e[4]||(e[4]=[h("所有店铺")])),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1}),a(x,{gutter:20,class:"mb-4"},{default:t(()=>[a(w,{span:2})]),_:1}),A("div",ie,[(f(!0),g(D,null,M(u(s),l=>Y((f(),B(L,{key:l.id,closable:"",effect:"plain",round:"",onClose:ue=>R(l)},{default:t(()=>[h(ee(l.name),1)]),_:2},1032,["onClose"])),[[Z,u(d)=="1"]])),128))]),a(P,{style:{margin:"12px 0 20px 0"}})]),_:1},8,["modelValue"])])}}}),ve=ne(de,[["__scopeId","data-v-2289f50f"]]);export{ve as default};
