import{$ as e,H as t,L as n,P as r,V as i,Wt as a,_ as o,d as s,et as c,i as l,lt as u,p as d,st as f,u as p,v as m,z as h}from"./runtime-core.esm-bundler-DbRZbT7v.js";import{l as g,o as _,s as v}from"./index-Mgun2LFs.js";import"./request-DG5cMCYw.js";import{t as y}from"./crm-COsPApQ4.js";var b={class:`p-6 space-y-4`},x={class:`bg-white rounded-2xl border border-gray-100 shadow-sm p-4 flex items-center flex-wrap gap-3`},S={class:`bg-white rounded-2xl border border-gray-100 shadow-sm`},C={class:`flex items-center justify-between px-5 py-4 border-b border-gray-50`},w={class:`px-2`},T={class:`px-5 py-3 border-t border-gray-50`},E={__name:`index`,setup(E){let D=u([]),O=u(0),k=u(!1),A=u(!1),j=u(!1),M=f({name:``,type:``}),N=f({page:1,per_page:20}),P=u(null),F=f({id:null,name:``,type:1,status:1}),I=u(!1),L={name:[{required:!0,message:`请输入渠道名称`,trigger:`blur`}]},R={1:`线上`,2:`线下`,3:`转介绍`};async function z(){k.value=!0;try{let e=await y.getList({...M,...N});D.value=e.data?.list||e.data?.data||[],O.value=e.data?.total||0}finally{k.value=!1}}function B(){N.page=1,z()}function V(){Object.assign(M,{name:``,type:``}),B()}function H(){I.value=!1,Object.assign(F,{id:null,name:``,type:1,status:1}),A.value=!0}async function U(e){I.value=!0,Object.assign(F,{...e}),A.value=!0}async function W(){P.value&&await P.value.validate(async e=>{if(e){j.value=!0;try{I.value?(await y.update(F.id,F),v.success(`更新成功`)):(await y.create(F),v.success(`创建成功`)),A.value=!1,z()}finally{j.value=!1}}})}async function G(e){await _.confirm(`确定删除渠道「${e.name}」吗？`,`删除确认`,{type:`warning`}),await y.delete(e.id),v.success(`删除成功`),z()}function K(e){N.page=e,z()}function q(e){N.per_page=e,N.page=1,z()}return r(()=>z()),(r,u)=>{let f=i(`el-input`),_=i(`el-option`),v=i(`el-select`),y=i(`el-button`),E=i(`el-table-column`),z=i(`el-tag`),J=i(`el-table`),Y=i(`el-pagination`),X=i(`el-form-item`),Z=i(`el-switch`),Q=i(`el-form`),$=i(`el-dialog`),ee=t(`loading`);return n(),d(`div`,b,[p(`div`,x,[m(f,{modelValue:M.name,"onUpdate:modelValue":u[0]||=e=>M.name=e,placeholder:`渠道名称`,style:{width:`180px`},clearable:``,onKeydown:g(B,[`enter`])},null,8,[`modelValue`]),m(v,{modelValue:M.type,"onUpdate:modelValue":u[1]||=e=>M.type=e,placeholder:`类型`,clearable:``,style:{width:`120px`}},{default:e(()=>[(n(),d(l,null,h(R,(e,t)=>m(_,{key:t,label:e,value:Number(t)},null,8,[`label`,`value`])),64))]),_:1},8,[`modelValue`]),m(y,{type:`primary`,onClick:B},{default:e(()=>[...u[9]||=[o(`查询`,-1)]]),_:1}),m(y,{onClick:V},{default:e(()=>[...u[10]||=[o(`重置`,-1)]]),_:1})]),p(`div`,S,[p(`div`,C,[u[12]||=p(`div`,{class:`flex items-center gap-3`},[p(`span`,{class:`font-medium text-gray-700`},`渠道列表`)],-1),m(y,{type:`primary`,onClick:H},{default:e(()=>[...u[11]||=[o(`新增渠道`,-1)]]),_:1})]),p(`div`,w,[c((n(),s(J,{data:D.value,style:{width:`100%`}},{default:e(()=>[m(E,{prop:`name`,label:`渠道名称`,"min-width":`150`}),m(E,{label:`类型`,width:`100`,align:`center`},{default:e(({row:e})=>[o(a(R[e.type]),1)]),_:1}),m(E,{label:`状态`,width:`80`,align:`center`},{default:e(({row:t})=>[m(z,{type:t.status?`success`:`danger`,size:`small`},{default:e(()=>[o(a(t.status?`启用`:`禁用`),1)]),_:2},1032,[`type`])]),_:1}),m(E,{prop:`created_at`,label:`创建时间`,"min-width":`160`}),m(E,{label:`操作`,width:`160`,fixed:`right`,align:`center`},{default:e(({row:t})=>[m(y,{size:`small`,type:`primary`,text:``,onClick:e=>U(t)},{default:e(()=>[...u[13]||=[o(`编辑`,-1)]]),_:1},8,[`onClick`]),m(y,{size:`small`,type:`danger`,text:``,onClick:e=>G(t)},{default:e(()=>[...u[14]||=[o(`删除`,-1)]]),_:1},8,[`onClick`])]),_:1})]),_:1},8,[`data`])),[[ee,k.value]])]),p(`div`,T,[m(Y,{"current-page":N.page,"onUpdate:currentPage":u[2]||=e=>N.page=e,"page-size":N.per_page,"onUpdate:pageSize":u[3]||=e=>N.per_page=e,total:O.value,"page-sizes":[10,20,50],layout:`total,sizes,prev,pager,next,jumper`,background:``,onCurrentChange:K,onSizeChange:q},null,8,[`current-page`,`page-size`,`total`])])]),m($,{modelValue:A.value,"onUpdate:modelValue":u[8]||=e=>A.value=e,title:I.value?`编辑渠道`:`新增渠道`,width:`450px`,"destroy-on-close":``},{footer:e(()=>[m(y,{onClick:u[7]||=e=>A.value=!1},{default:e(()=>[...u[15]||=[o(`取消`,-1)]]),_:1}),m(y,{type:`primary`,loading:j.value,onClick:W},{default:e(()=>[...u[16]||=[o(`确定`,-1)]]),_:1},8,[`loading`])]),default:e(()=>[m(Q,{ref_key:`formRef`,ref:P,model:F,rules:L,"label-width":`80px`},{default:e(()=>[m(X,{label:`渠道名称`,prop:`name`},{default:e(()=>[m(f,{modelValue:F.name,"onUpdate:modelValue":u[4]||=e=>F.name=e},null,8,[`modelValue`])]),_:1}),m(X,{label:`类型`},{default:e(()=>[m(v,{modelValue:F.type,"onUpdate:modelValue":u[5]||=e=>F.type=e,style:{width:`100%`}},{default:e(()=>[(n(),d(l,null,h(R,(e,t)=>m(_,{key:t,label:e,value:Number(t)},null,8,[`label`,`value`])),64))]),_:1},8,[`modelValue`])]),_:1}),m(X,{label:`状态`},{default:e(()=>[m(Z,{modelValue:F.status,"onUpdate:modelValue":u[6]||=e=>F.status=e,"active-value":1,"inactive-value":0},null,8,[`modelValue`])]),_:1})]),_:1},8,[`model`])]),_:1},8,[`modelValue`,`title`])])}}};export{E as default};