import{E as M}from"./index-CbmPSBt0.js";import{E as Z}from"./index-CCavIuTY.js";import{E as G}from"./el-card-BWcR1iD2.js";import{E as H}from"./el-pagination-DGQ0vO_O.js";import{E as J,a as O}from"./el-table-DkdQ6gPU.js";import{v as Q}from"./directive-vzjADwzS.js";import{E as w}from"./index-BMrs0kLP.js";import{d as W,y as m,D as _,c as D,s as p,w as r,o as u,q as n,h as x,e as g,g as v,x as y,aa as k,Z as X,K as Y,j as $,v as ee}from"./index-CGB0A5x_.js";import"./el-scrollbar-p6_f_LH2.js";import"./el-popper-DvBtRO32.js";import"./el-tag-C_D80BPW.js";import"./el-select-C59URVI0.js";import"./el-tooltip-l0sNRNKZ.js";import"./el-checkbox-Ci1DH0Aj.js";import{_ as te}from"./_plugin-vue_export-helper-DlAUqK2U.js";const ae={class:"data-table-page"},le={class:"table-toolbar"},oe={class:"table-title"},ne={class:"toolbar-actions"},se={key:0,class:"batch-bar"},re={class:"batch-info"},ie={class:"table-body"},ce={class:"table-pagination"},ue=W({__name:"DataTablePage",props:{title:{},data:{},loading:{type:Boolean,default:!1},searchable:{type:Boolean,default:!1},searchFields:{},multiSelect:{type:Boolean,default:!1},createText:{},createTo:{},deleteFn:{},rowKey:{default:"id"},emptyText:{default:"暂无数据"},pageSize:{default:10},pageSizes:{default:()=>[10,20,50,100]}},emits:["create","refresh","expandChange"],setup(l,{expose:F,emit:V}){const a=l,h=V,P=ee(),S=m(),o=m(new Set),d=m(""),f=m(1),b=m(a.pageSize);function z(t){return t[a.rowKey]??t.name??t.id}const C=$(()=>{var e;if(!d.value.trim()||!((e=a.searchFields)!=null&&e.length))return a.data;const t=d.value.toLowerCase().trim();return a.data.filter(i=>a.searchFields.some(s=>String(i[s]??"").toLowerCase().includes(t)))}),I=$(()=>{const t=(f.value-1)*b.value;return C.value.slice(t,t+b.value)});function K(t){o.value=new Set(t.map(z))}async function E(t,e="确定要删除这条记录吗？"){if(a.deleteFn)try{await w.confirm(e,"确认删除",{type:"warning",confirmButtonText:"确定",cancelButtonText:"取消"}),await a.deleteFn(t),h("refresh")}catch{}}async function N(){if(!(o.value.size===0||!a.deleteFn))try{await w.confirm(`确定要删除选中的 ${o.value.size} 条记录吗？`,"批量删除",{type:"warning"});const t=a.data.filter(s=>o.value.has(z(s)));let e=0,i=0;for(const s of t)try{await a.deleteFn(s),e++}catch{i++}o.value.clear(),h("refresh"),i===0?w.alert(`成功删除 ${e} 条记录`,"成功",{type:"success"}):w.alert(`成功 ${e} 条，失败 ${i} 条`,"部分失败",{type:"warning"})}catch{}}function T(){var t;o.value.clear(),(t=S.value)==null||t.clearSelection()}function L(){a.createTo?P.push(a.createTo):h("create")}function U(t,e){h("expandChange",t,Array.isArray(e)?e:[])}return _(()=>a.data,()=>{var t;o.value.clear(),f.value=1,(t=S.value)==null||t.clearSelection()}),_(()=>d.value,()=>{f.value=1}),F({handleDelete:E,clearSelection:T}),(t,e)=>{const i=M,s=Z,B=J,j=O,A=H,R=G,q=Q;return u(),D("div",ae,[p(R,{shadow:"never",class:"table-card"},{default:r(()=>[n("div",le,[x(t.$slots,"title",{},()=>[n("h2",oe,k(l.title),1)],!0),n("div",ne,[l.searchable?(u(),g(i,{key:0,modelValue:d.value,"onUpdate:modelValue":e[0]||(e[0]=c=>d.value=c),placeholder:`搜索${l.title}...`,clearable:"",class:"search-input"},{prefix:r(()=>[...e[3]||(e[3]=[n("i",{class:"fa fa-search"},null,-1)])]),_:1},8,["modelValue","placeholder"])):v("",!0),l.createText?(u(),g(s,{key:1,type:"primary",onClick:L},{default:r(()=>[e[4]||(e[4]=n("i",{class:"fa fa-plus",style:{"margin-right":"4px"}},null,-1)),y(" "+k(l.createText),1)]),_:1})):v("",!0),x(t.$slots,"toolbar-extra",{},void 0,!0)])]),p(X,{name:"el-zoom-in-top"},{default:r(()=>[l.multiSelect&&o.value.size>0?(u(),D("div",se,[n("span",re,[e[6]||(e[6]=y(" 已选择 ",-1)),n("strong",null,k(o.value.size),1),e[7]||(e[7]=y(" 项 ",-1)),p(s,{link:"",type:"primary",onClick:T},{default:r(()=>[...e[5]||(e[5]=[y("取消选择",-1)])]),_:1})]),p(s,{type:"danger",size:"small",onClick:N},{default:r(()=>[e[8]||(e[8]=n("i",{class:"fa fa-trash",style:{"margin-right":"4px"}},null,-1)),y(" 批量删除 ("+k(o.value.size)+") ",1)]),_:1})])):v("",!0)]),_:1}),n("div",ie,[Y((u(),g(j,{ref_key:"tableRef",ref:S,data:I.value,"row-key":l.rowKey,height:"100%",style:{width:"100%"},"empty-text":l.emptyText,onSelectionChange:K,onExpandChange:U},{default:r(()=>[l.multiSelect?(u(),g(B,{key:0,type:"selection",width:"50",align:"center","reserve-selection":"",fixed:"left"})):v("",!0),x(t.$slots,"columns",{},void 0,!0),t.$slots.actions?(u(),g(B,{key:1,label:"操作",align:"center",width:"220",fixed:"right"},{default:r(({row:c})=>[x(t.$slots,"actions",{row:c,handleDelete:E},void 0,!0)]),_:3})):v("",!0)]),_:3},8,["data","row-key","empty-text"])),[[q,l.loading]])]),n("div",ce,[p(A,{"current-page":f.value,"onUpdate:currentPage":e[1]||(e[1]=c=>f.value=c),"page-size":b.value,"onUpdate:pageSize":e[2]||(e[2]=c=>b.value=c),background:"",layout:"total, sizes, prev, pager, next, jumper","page-sizes":l.pageSizes,total:C.value.length},null,8,["current-page","page-size","page-sizes","total"])])]),_:3})])}}}),Ee=te(ue,[["__scopeId","data-v-19a2982f"]]);export{Ee as D};
