Files
machartaa_admin_dist/dist/assets/index-03922f62.js
T

2 lines
5.9 KiB
JavaScript

import{d as j,g as l,v as D,o as A,c as J,b as a,w as _,a as s,e as M,E as X,j as w,C as p,_ as q}from"./index-5870e6d3.js";import{_ as W}from"./BasicModal.vue_vue_type_style_index_0_lang-cd9077ad.js";import{_ as z}from"./BasicMainCard-40d6570b.js";import{_ as G,u as H}from"./useBaseTable-084adda9.js";import{_ as K}from"./button.vue_vue_type_style_index_0_lang-379723a2.js";import{g as E,a as Q}from"./competition-f2feae90.js";import{t as Y,a as Z}from"./useDataTime-b0920a9a.js";import{I as B}from"./Icon-61906fca.js";import{_ as ee}from"./TextPreview.vue_vue_type_script_setup_true_lang-cdd90622.js";import{S as te}from"./fa_IR-09853d0d.js";import"./index-ccb2a61b.js";import"./shallowequal-2bdf6cc7.js";import"./vnode-22dd7580.js";import"./_plugin-vue_export-helper-5e3c08f4.js";import"./Col-619d881f.js";import"./index-12089cb1.js";import"./pickAttrs-38dcf0c9.js";import"./FormItemContext-817438bc.js";import"./index-6338714e.js";import"./index-3e5e4620.js";import"./useState-9f642396.js";import"./useRefs-f4db4963.js";import"./isPlainObject-9db900ef.js";import"./lodash-c64d74c3.js";import"./index-f48a08af.js";import"./index-46729aba.js";import"./toArray-f3da0fcb.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=s("h2",null,"امتیازات و برندگان مسابقات",-1),se={class:"flex gap-2"},ne={class:"space-y-4"},ie=s("div",{class:"mb-1 text-sm text-gray-600"},"انتخاب مسابقه",-1),re={class:"space-y-4"},ce=s("div",{class:"mb-1 text-sm text-gray-600"},"انتخاب مسابقه",-1),Ve=j({__name:"index",setup(u){const I=te,$=l(null),[T,de]=H(),f=l(!1),g=l(!1),n=l(void 0),i=l(void 0),c=l([]),h=l(!1),b=l(!1),R=l(!1),F=l({columns:oe,api:E,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(){n.value=void 0,f.value=!0,c.value.length===0&&y()}function C(){f.value=!1,n.value=void 0}function P(){i.value=void 0,g.value=!0,c.value.length===0&&y()}function L(){g.value=!1,i.value=void 0}function S(){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"),L()}async function U(){if(!n.value){p.warning("لطفاً مسابقه را انتخاب کنید");return}try{b.value=!0;const t={page:1,limit:1e4,filters:[{field:"match_id",op:"eq",value:n.value,cr:"and",hidden:!1,type:"number"}]},d=(await E(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===n.value),O=`برندگان_${(k==null?void 0:k.label)||`مسابقه_${n.value}`}_${new Date().getTime()}.xlsx`;m.writeFile(o,O),p.success("فایل اکسل با موفقیت دانلود شد"),C()}catch(t){console.error("Error exporting to Excel:",t),p.error("خطا در تولید فایل اکسل")}finally{b.value=!1}}return D(()=>{y()}),(t,e)=>{const d=K,v=G,m=z,x=W;return A(),J("div",null,[a(m,null,{default:_(()=>[s("div",ae,[le,s("div",se,[a(d,{onClick:P,style:{backgroundColor:"#FF6B35",borderColor:"#FF6B35",color:"#fff"},class:"lottery-btn"},{default:_(()=>[a(B,{icon:"vuesax-linear:gift",class:"mr-1"}),M(" قرعه کشی ")]),_:1}),a(d,{onClick:N,style:{backgroundColor:"#217346",borderColor:"#217346",color:"#fff"},class:"excel-export-btn"},{default:_(()=>[a(B,{icon:"vuesax-linear:document-download",class:"mr-1"}),M(" خروجی اکسل ")]),_: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:U,onCancel:C,confirmLoading:b.value},{default:_(()=>[s("div",ne,[s("div",null,[ie,a(w(I),{value:n.value,"onUpdate:value":e[0]||(e[0]=o=>n.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:S,onCancel:L,confirmLoading:R.value},{default:_(()=>[s("div",re,[s("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{Ve as default};