2 lines
5.9 KiB
JavaScript
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-65856697.js";import{_ as W}from"./BasicModal.vue_vue_type_style_index_0_lang-b202ccf4.js";import{_ as z}from"./BasicMainCard-3439e95d.js";import{_ as G,u as H}from"./useBaseTable-0a9ca5c6.js";import{_ as K}from"./button.vue_vue_type_style_index_0_lang-c248f06f.js";import{g as E,a as Q}from"./competition-fc4aa186.js";import{t as Y,a as Z}from"./useDataTime-b5b0c094.js";import{I as B}from"./Icon-08f00b08.js";import{_ as ee}from"./TextPreview.vue_vue_type_script_setup_true_lang-5d83cb39.js";import{S as te}from"./fa_IR-9a5561fa.js";import"./index-3eb1fc79.js";import"./shallowequal-e2999554.js";import"./vnode-9598f8b5.js";import"./_plugin-vue_export-helper-d18c65cd.js";import"./Col-9bf281e5.js";import"./index-2debd256.js";import"./pickAttrs-5f523685.js";import"./FormItemContext-75d7b3a2.js";import"./index-0560f4e9.js";import"./index-fa326b70.js";import"./useState-74c053ae.js";import"./useRefs-320e6bbe.js";import"./isPlainObject-77557052.js";import"./lodash-1b6d5368.js";import"./index-5b62301e.js";import"./index-c60120a9.js";import"./toArray-c0948cf7.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};
|