2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
import{d as j,r as a,i as A,o as X,c as q,b as l,w as f,a as n,e as C,a2 as J,L as I,a0 as _,a3 as W}from"./index-c822befc.js";import{_ as z}from"./BasicModal.vue_vue_type_style_index_0_lang-fa4544ee.js";import{_ as G}from"./BasicMainCard-b6310d06.js";import{_ as H}from"./BaseTable.vue_vue_type_style_index_0_lang-f9e383e0.js";import{_ as K}from"./button.vue_vue_type_style_index_0_lang-5b65d3cd.js";import{g as B,a as Q}from"./competition-fa304f49.js";import{t as T}from"./useDataTime-a731f50b.js";import{u as Y}from"./useBaseTable-3aeb2499.js";import{I as E}from"./Icon-ff3adddf.js";import{_ as Z}from"./index-976673f9.js";import"./styleChecker-cf4483ca.js";import"./index-16f734d6.js";import"./index-81ddbbad.js";import"./colors-b3e52159.js";import"./raf-e9e40ecb.js";import"./index-69ae13da.js";import"./debounce-89f3cd70.js";import"./index-1f56a36b.js";import"./index-71609388.js";import"./pickAttrs-6fdf7ff0.js";import"./objectDestructuringEmpty-24e23e90.js";import"./_plugin-vue_export-helper-c27b6911.js";import"./index-48058786.js";import"./index-122c3910.js";import"./useState-3b1f4886.js";import"./Col-25b75183.js";import"./usePrefix-93de78a0.js";import"./index-d11abaf6.js";import"./index-b00d1c6a.js";import"./SearchOutlined-8e71a0af.js";import"./EyeOutlined-b57fa33c.js";import"./eagerComputed-7892359b.js";import"./CheckOutlined-af96a0f7.js";const ee=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:s=>s.record.index+1},{title:"نام مسابقه",dataIndex:"match_title",key:"match_title"},{title:"شرح مسابقه",dataIndex:"match_description",key:"match_description",customRender:s=>{const d=s.record.match_description;return d?d.length>50?d.substring(0,50)+"...":d:"-"}},{title:"نام کاربر",dataIndex:"user_name",key:"user_name"},{title:"شماره همراه",dataIndex:"user_mobile",key:"user_mobile"},{title:"امتیاز کسب شده",dataIndex:"score",key:"score",align:"center",customRender:s=>s.record.score||0},{title:"تاریخ",dataIndex:"created_at",key:"created_at",customRender:s=>T(s.record.created_at)}],te={class:"flex justify-between items-center mb-4"},oe=n("h2",null,"امتیازات و برندگان مسابقات",-1),ae={class:"flex gap-2"},le={class:"space-y-4"},ne=n("div",{class:"mb-1 text-sm text-gray-600"},"انتخاب مسابقه",-1),se={class:"space-y-4"},re=n("div",{class:"mb-1 text-sm text-gray-600"},"انتخاب مسابقه",-1),Xe=j({__name:"index",setup(s){const d=Z,$=a(null),[R,ie]=Y(),g=a(!1),h=a(!1),r=a(void 0),i=a(void 0),u=a([]),b=a(!1),y=a(!1),F=a(!1),N=a({columns:ee,api:B,defaultPageLimit:20});async function k(){try{b.value=!0;const t=await Q();u.value=(t||[]).map(e=>({label:e.title||`مسابقه ${e.id}`,value:e.id}))}catch(t){console.error("Error loading matchs:",t),_.error("خطا در بارگذاری لیست مسابقات")}finally{b.value=!1}}function P(){r.value=void 0,g.value=!0,u.value.length===0&&k()}function L(){g.value=!1,r.value=void 0}function U(){i.value=void 0,h.value=!0,u.value.length===0&&k()}function M(){h.value=!1,i.value=void 0}function O(){if(!i.value){_.warning("لطفاً مسابقه را انتخاب کنید");return}const t=u.value.find(v=>v.value===i.value),e=encodeURIComponent((t==null?void 0:t.label)||`مسابقه_${i.value}`),m=`/lottery?matchId=${i.value}&title=${e}`;window.open(m,"_blank","width=1200,height=800"),M()}async function V(){if(!r.value){_.warning("لطفاً مسابقه را انتخاب کنید");return}try{y.value=!0;const t={page:1,limit:1e4,filters:[{field:"match_id",op:"eq",value:r.value,cr:"and",hidden:!1,type:"number"}]},m=(await B(t)).rows||[];if(m.length===0){_.warning("برای این مسابقه برندهای یافت نشد");return}const v=m.map((c,S)=>({ردیف:S+1,"نام مسابقه":c.match_title||"","شرح مسابقه":c.match_description||"","نام کاربر":c.user_name||"","شماره همراه":c.user_mobile||"","امتیاز کسب شده":c.score||0,تاریخ:T(c.created_at||"")})),p=await W(()=>import("./xlsx-6ed613d4.js"),[]),x=p.utils.json_to_sheet(v),o=p.utils.book_new();p.utils.book_append_sheet(o,x,"برندگان");const w=u.value.find(c=>c.value===r.value),D=`برندگان_${(w==null?void 0:w.label)||`مسابقه_${r.value}`}_${new Date().getTime()}.xlsx`;p.writeFile(o,D),_.success("فایل اکسل با موفقیت دانلود شد"),L()}catch(t){console.error("Error exporting to Excel:",t),_.error("خطا در تولید فایل اکسل")}finally{y.value=!1}}return A(()=>{k()}),(t,e)=>{const m=K,v=H,p=G,x=z;return X(),q("div",null,[l(p,null,{default:f(()=>[n("div",te,[oe,n("div",ae,[l(m,{onClick:U,style:{backgroundColor:"#FF6B35",borderColor:"#FF6B35",color:"#fff"},class:"lottery-btn"},{default:f(()=>[l(E,{icon:"vuesax-linear:gift",class:"mr-1"}),C(" قرعه کشی ")]),_:1}),l(m,{onClick:P,style:{backgroundColor:"#217346",borderColor:"#217346",color:"#fff"},class:"excel-export-btn"},{default:f(()=>[l(E,{icon:"vuesax-linear:document-download",class:"mr-1"}),C(" خروجی اکسل ")]),_:1})])]),l(v,J(N.value,{ref_key:"table",ref:$,onRegister:I(R)}),null,16,["onRegister"])]),_:1}),l(x,{visible:g.value,"onUpdate:visible":e[1]||(e[1]=o=>g.value=o),title:"خروجی اکسل برندگان مسابقه",onOk:V,onCancel:L,confirmLoading:y.value},{default:f(()=>[n("div",le,[n("div",null,[ne,l(I(d),{value:r.value,"onUpdate:value":e[0]||(e[0]=o=>r.value=o),options:u.value,placeholder:"لطفاً مسابقه را انتخاب کنید",loading:b.value,class:"w-full","allow-clear":""},null,8,["value","options","loading"])])])]),_:1},8,["visible","confirmLoading"]),l(x,{visible:h.value,"onUpdate:visible":e[3]||(e[3]=o=>h.value=o),title:"قرعه کشی برندگان مسابقه",onOk:O,onCancel:M,confirmLoading:F.value},{default:f(()=>[n("div",se,[n("div",null,[re,l(I(d),{value:i.value,"onUpdate:value":e[2]||(e[2]=o=>i.value=o),options:u.value,placeholder:"لطفاً مسابقه را انتخاب کنید",loading:b.value,class:"w-full","allow-clear":""},null,8,["value","options","loading"])])])]),_:1},8,["visible","confirmLoading"])])}}});export{Xe as default};
|