2 lines
5.8 KiB
JavaScript
2 lines
5.8 KiB
JavaScript
import{d as j,g as l,x as S,o as A,c as J,b as a,w as _,a as n,e as C,G as X,j as w,D as p,_ as q}from"./index-10f45eca.js";import{_ as G}from"./BasicModal.vue_vue_type_style_index_0_lang-c07380a4.js";import{_ as W}from"./BasicMainCard-06dad464.js";import{_ as z,u as H}from"./useBaseTable-89e367b0.js";import{_ as K}from"./button.vue_vue_type_style_index_0_lang-80cf0b72.js";import{g as B,a as Q}from"./competition-175262d4.js";import{t as Y,a as Z}from"./useDataTime-60875705.js";import{I as E}from"./Icon-e9a9d64e.js";import{_ as ee}from"./TextPreview.vue_vue_type_script_setup_true_lang-42c9e2e4.js";import{_ as te}from"./index-9601d570.js";import"./index-00f73089.js";import"./index-ceff8631.js";import"./vnode-b14d5532.js";import"./_plugin-vue_export-helper-2f157ef4.js";import"./Col-c6f28462.js";import"./index-5bc6b40d.js";import"./pickAttrs-2c86ae65.js";import"./FormItemContext-a11ae724.js";import"./index-ecb339ad.js";import"./index-1b352863.js";import"./useState-4f4a8c99.js";import"./isPlainObject-75024cd7.js";import"./index-db46c961.js";import"./toArray-45e57117.js";import"./index-cca2d62a.js";const oe=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:u=>u.record.index+1},{title:"نام مسابقه",dataIndex:"match_title",key:"match_title"},{title:"شرح مسابقه",dataIndex:"match_description",key:"match_description",slot:"match_description"},{title:"نام کاربر",dataIndex:"user_name",key:"user_name"},{title:"شماره همراه",dataIndex:"user_mobile",key:"user_mobile"},{title:"امتیاز کسب شده",dataIndex:"score",key:"score",align:"center",customRender:u=>u.record.score||0},{title:"زمان",dataIndex:"created_at",key:"created_at",customRender:u=>Y(u.record.created_at)}],ae={class:"flex justify-between items-center mb-4"},le=n("h2",null,"امتیازات و برندگان مسابقات",-1),ne={class:"flex gap-2"},se={class:"space-y-4"},ie=n("div",{class:"mb-1 text-sm text-gray-600"},"انتخاب مسابقه",-1),re={class:"space-y-4"},ce=n("div",{class:"mb-1 text-sm text-gray-600"},"انتخاب مسابقه",-1),De=j({__name:"index",setup(u){const I=te,$=l(null),[T,de]=H(),f=l(!1),g=l(!1),s=l(void 0),i=l(void 0),c=l([]),h=l(!1),b=l(!1),R=l(!1),F=l({columns:oe,api:B,defaultPageLimit:20});async function y(){try{h.value=!0;const t=await Q();c.value=(t||[]).map(e=>({label:e.title||`مسابقه ${e.id}`,value:e.id}))}catch(t){console.error("Error loading matchs:",t),p.error("خطا در بارگذاری لیست مسابقات")}finally{h.value=!1}}function N(){s.value=void 0,f.value=!0,c.value.length===0&&y()}function L(){f.value=!1,s.value=void 0}function P(){i.value=void 0,g.value=!0,c.value.length===0&&y()}function M(){g.value=!1,i.value=void 0}function U(){if(!i.value){p.warning("لطفاً مسابقه را انتخاب کنید");return}const t=c.value.find(v=>v.value===i.value),e=encodeURIComponent((t==null?void 0:t.label)||`مسابقه_${i.value}`),d=`/lottery?matchId=${i.value}&title=${e}`;window.open(d,"_blank","width=1200,height=800"),M()}async function D(){if(!s.value){p.warning("لطفاً مسابقه را انتخاب کنید");return}try{b.value=!0;const t={page:1,limit:1e4,filters:[{field:"match_id",op:"eq",value:s.value,cr:"and",hidden:!1,type:"number"}]},d=(await B(t)).rows||[];if(d.length===0){p.warning("برای این مسابقه برندهای یافت نشد");return}const v=d.map((r,V)=>({ردیف:V+1,"نام مسابقه":r.match_title||"","شرح مسابقه":r.match_description||"","نام کاربر":r.user_name||"","شماره همراه":r.user_mobile||"","امتیاز کسب شده":r.score||0,تاریخ:Z(r.created_at||"")})),m=await q(()=>import("./xlsx-6ed613d4.js"),[]),x=m.utils.json_to_sheet(v),o=m.utils.book_new();m.utils.book_append_sheet(o,x,"برندگان");const k=c.value.find(r=>r.value===s.value),O=`برندگان_${(k==null?void 0:k.label)||`مسابقه_${s.value}`}_${new Date().getTime()}.xlsx`;m.writeFile(o,O),p.success("فایل اکسل با موفقیت دانلود شد"),L()}catch(t){console.error("Error exporting to Excel:",t),p.error("خطا در تولید فایل اکسل")}finally{b.value=!1}}return S(()=>{y()}),(t,e)=>{const d=K,v=z,m=W,x=G;return A(),J("div",null,[a(m,null,{default:_(()=>[n("div",ae,[le,n("div",ne,[a(d,{onClick:P,style:{backgroundColor:"#FF6B35",borderColor:"#FF6B35",color:"#fff"},class:"lottery-btn"},{default:_(()=>[a(E,{icon:"vuesax-linear:gift",class:"mr-1"}),C(" قرعه کشی ")]),_:1}),a(d,{onClick:N,style:{backgroundColor:"#217346",borderColor:"#217346",color:"#fff"},class:"excel-export-btn"},{default:_(()=>[a(E,{icon:"vuesax-linear:document-download",class:"mr-1"}),C(" خروجی اکسل ")]),_:1})])]),a(v,X(F.value,{ref_key:"table",ref:$,onRegister:w(T)}),{match_description:_(({record:o})=>[a(ee,{text:o.match_description},null,8,["text"])]),_:1},16,["onRegister"])]),_:1}),a(x,{visible:f.value,"onUpdate:visible":e[1]||(e[1]=o=>f.value=o),title:"خروجی اکسل برندگان مسابقه",onOk:D,onCancel:L,confirmLoading:b.value},{default:_(()=>[n("div",se,[n("div",null,[ie,a(w(I),{value:s.value,"onUpdate:value":e[0]||(e[0]=o=>s.value=o),options:c.value,placeholder:"لطفاً مسابقه را انتخاب کنید",loading:h.value,class:"w-full","allow-clear":""},null,8,["value","options","loading"])])])]),_:1},8,["visible","confirmLoading"]),a(x,{visible:g.value,"onUpdate:visible":e[3]||(e[3]=o=>g.value=o),title:"قرعه کشی برندگان مسابقه",onOk:U,onCancel:M,confirmLoading:R.value},{default:_(()=>[n("div",re,[n("div",null,[ce,a(w(I),{value:i.value,"onUpdate:value":e[2]||(e[2]=o=>i.value=o),options:c.value,placeholder:"لطفاً مسابقه را انتخاب کنید",loading:h.value,class:"w-full","allow-clear":""},null,8,["value","options","loading"])])])]),_:1},8,["visible","confirmLoading"])])}}});export{De as default};
|