2 lines
5.9 KiB
JavaScript
2 lines
5.9 KiB
JavaScript
import{d as D,g as l,v as O,o as V,c as j,b as o,w as _,a as s,e as L,G as A,j as k,D as p,_ as J}from"./index-14c3003c.js";import{_ as W}from"./BasicModal.vue_vue_type_style_index_0_lang-4effc2b1.js";import{_ as X}from"./BasicMainCard-eb9343e9.js";import{_ as G,u as q}from"./useBaseTable-c909e392.js";import{_ as z}from"./button.vue_vue_type_style_index_0_lang-a7c15404.js";import{g as H,a as K,b as Q}from"./competition-47b1b41b.js";import{t as Y,a as Z}from"./useDataTime-e4f5bf79.js";import{I as C}from"./Icon-f0620776.js";import{_ as ee}from"./TextPreview.vue_vue_type_script_setup_true_lang-25f62147.js";import{S as te}from"./fa_IR-245a648a.js";import"./index-43497ac0.js";import"./shallowequal-a5ad9c9b.js";import"./vnode-0d5a6b01.js";import"./_plugin-vue_export-helper-9d873422.js";import"./styleChecker-569634cf.js";import"./index-77af8dcc.js";import"./DialogWrap-0c54c10f.js";import"./pickAttrs-c4f5e9cb.js";import"./FormItemContext-8fd31893.js";import"./index-8e611dfd.js";import"./index-031faeaf.js";import"./useState-f0d82672.js";import"./useRefs-47c5d0d5.js";import"./_flatRest-3e64feef.js";import"./index-785693d7.js";import"./Col-006339a7.js";import"./isPlainObject-c274713e.js";import"./lodash-3dfbaf74.js";import"./index-866e6f6b.js";import"./css-e89e37f1.js";import"./index-96a49d7d.js";import"./toArray-f191f093.js";import"./textUtils-c37780ad.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),ne={class:"flex gap-2"},se={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),We=D({__name:"index",setup(u){const w=te,B=l(null),[E,de]=q(),f=l(!1),g=l(!1),i=l(void 0),r=l(void 0),d=l([]),h=l(!1),b=l(!1),$=l(!1),T=l({columns:oe,api:H,defaultPageLimit:20});async function y(){try{h.value=!0;const t=await K();d.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 R(){i.value=void 0,f.value=!0,d.value.length===0&&y()}function I(){f.value=!1,i.value=void 0}function F(){r.value=void 0,g.value=!0,d.value.length===0&&y()}function M(){g.value=!1,r.value=void 0}function N(){if(!r.value){p.warning("لطفاً مسابقه را انتخاب کنید");return}const t=d.value.find(v=>v.value===r.value),e=encodeURIComponent((t==null?void 0:t.label)||`مسابقه_${r.value}`),n=`/lottery?matchId=${r.value}&title=${e}`;window.open(n,"_blank","width=1200,height=800"),M()}async function P(){if(!i.value){p.warning("لطفاً مسابقه را انتخاب کنید");return}try{b.value=!0;const t=await Q(i.value);if(t.length===0){p.warning("برای این مسابقه برندهای یافت نشد");return}const e=t.map((c,U)=>({ردیف:U+1,"نام مسابقه":c.match_title||"","شرح مسابقه":c.match_description||"","نام کاربر":c.user_name||"","شماره همراه":c.user_mobile||"","امتیاز کسب شده":c.score||0,تاریخ:Z(c.created_at||"")})),n=await J(()=>import("./xlsx-6ed613d4.js"),[]),v=n.utils.json_to_sheet(e),x=n.utils.book_new();n.utils.book_append_sheet(x,v,"برندگان");const m=d.value.find(c=>c.value===i.value),S=`برندگان_${(m==null?void 0:m.label)||`مسابقه_${i.value}`}_${new Date().getTime()}.xlsx`;n.writeFile(x,S),p.success("فایل اکسل با موفقیت دانلود شد"),I()}catch(t){console.error("Error exporting to Excel:",t),p.error("خطا در تولید فایل اکسل")}finally{b.value=!1}}return O(()=>{y()}),(t,e)=>{const n=z,v=G,x=X,m=W;return V(),j("div",null,[o(x,null,{default:_(()=>[s("div",ae,[le,s("div",ne,[o(n,{onClick:F,style:{backgroundColor:"#FF6B35",borderColor:"#FF6B35",color:"#fff"},class:"lottery-btn"},{default:_(()=>[o(C,{icon:"vuesax-linear:gift",class:"mr-1"}),L(" قرعه کشی ")]),_:1}),o(n,{onClick:R,style:{backgroundColor:"#217346",borderColor:"#217346",color:"#fff"},class:"excel-export-btn"},{default:_(()=>[o(C,{icon:"vuesax-linear:document-download",class:"mr-1"}),L(" خروجی اکسل ")]),_:1})])]),o(v,A(T.value,{ref_key:"table",ref:B,onRegister:k(E)}),{match_description:_(({record:a})=>[o(ee,{text:a.match_description},null,8,["text"])]),_:1},16,["onRegister"])]),_:1}),o(m,{visible:f.value,"onUpdate:visible":e[1]||(e[1]=a=>f.value=a),title:"خروجی اکسل برندگان مسابقه",onOk:P,onCancel:I,confirmLoading:b.value},{default:_(()=>[s("div",se,[s("div",null,[ie,o(k(w),{value:i.value,"onUpdate:value":e[0]||(e[0]=a=>i.value=a),options:d.value,placeholder:"لطفاً مسابقه را انتخاب کنید",loading:h.value,class:"w-full","allow-clear":""},null,8,["value","options","loading"])])])]),_:1},8,["visible","confirmLoading"]),o(m,{visible:g.value,"onUpdate:visible":e[3]||(e[3]=a=>g.value=a),title:"قرعه کشی برندگان مسابقه",onOk:N,onCancel:M,confirmLoading:$.value},{default:_(()=>[s("div",re,[s("div",null,[ce,o(k(w),{value:r.value,"onUpdate:value":e[2]||(e[2]=a=>r.value=a),options:d.value,placeholder:"لطفاً مسابقه را انتخاب کنید",loading:h.value,class:"w-full","allow-clear":""},null,8,["value","options","loading"])])])]),_:1},8,["visible","confirmLoading"])])}}});export{We as default};
|