2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{_ as me}from"./BasicMainCard-d7ded7d7.js";import{_ as le}from"./BasicModal.vue_vue_type_style_index_0_lang-d37c1f01.js";import{u as Y,_ as ie}from"./useBaseTable-5854ed19.js";import{_ as pe,B as _e}from"./button.vue_vue_type_style_index_0_lang-110418ce.js";import{a as fe}from"./member-676e20ad.js";import{N as F,d as ee,g as d,h as oe,E as ve,o as y,c as b,a,b as n,j as B,w as i,e as c,t as u,k as A,F as re,n as ge,G as Z,D as $,v as ye,ae as be}from"./index-b43045cf.js";import{t as V}from"./useDataTime-4b2700c1.js";import{M as he}from"./index-1e0b33f2.js";import{C as ae}from"./index-6e92857b.js";import{I as ne,a as xe}from"./index-b94f9b16.js";import{I as we}from"./Icon-53c563d2.js";import{S as ke}from"./index-6f54d687.js";import{D as Ie,_ as Re}from"./index-9a980046.js";import{k as Ce,S as $e}from"./fa_IR-2461e941.js";import{T as Te}from"./shallowequal-18e8473a.js";import{_ as Se,T as Pe}from"./index-0d9e50ef.js";import"./index-e4c6896e.js";import"./index-b2401969.js";import"./Col-8aeddcae.js";import"./styleChecker-0c8ed500.js";import"./vnode-96240c5a.js";import"./_plugin-vue_export-helper-d47eb12d.js";import"./isPlainObject-8c91e78f.js";import"./useState-ace49857.js";import"./FormItemContext-a080d4f0.js";import"./lodash-7fcfac04.js";import"./pickAttrs-5ae7ff2e.js";import"./toArray-8f75a9bb.js";import"./useRefs-3d56a112.js";const Be=async e=>(await F.post("/admin/sms/preview",e)).data,Le=async e=>(await F.post("/admin/sms/test",e)).data,De=async e=>(await F.post("/admin/sms/campaigns/start",e)).data,Me=async e=>{var f;const o=await F.get("/admin/sms/campaigns",{params:{page:e.page,limit:e.limit,search:e.search}}),g=e.page||1,x=e.limit||20,T=(g-1)*x;return{rows:(o.data||[]).map((v,w)=>({...v,index:T+w})),total:o.total??((f=o.data)==null?void 0:f.length)??0,query:{...e,total:o.total??0,page:g,limit:x}}},se=async(e,o)=>(await F.get(`/admin/sms/campaigns/${e}`,{params:o})).data,Ue=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,customRender:e=>e.index+1},{title:"نام",dataIndex:"first_name",key:"first_name",filterable:!0},{title:"نام خانوادگی",dataIndex:"last_name",key:"last_name",filterable:!0},{title:"شماره همراه",dataIndex:"phone",key:"phone",filterable:!0},{title:"زمان ثبتنام",dataIndex:"created_at",key:"created_at",type:"Date",filterable:!0,customRender:e=>e.record.created_at?V(e.record.created_at):"-"}],Ae={class:"grid grid-cols-1 xl:grid-cols-3 gap-4 mb-4"},Ne={class:"xl:col-span-2 space-y-4"},Ke=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),qe={class:"flex flex-wrap gap-4 items-center"},Fe={class:"flex flex-wrap gap-2"},Oe={class:"bg-gray-50 rounded-lg p-4 border border-gray-200 space-y-2 text-sm"},Ve=a("div",{class:"font-semibold text-gray-700 mb-2"},"خلاصه ارسال",-1),je={key:0},Ee={key:0,class:"text-amber-600 mt-1"},ze={key:1,class:"text-gray-500"},Ge={key:2,class:"pt-2 border-t border-gray-200"},He=a("div",{class:"font-medium mb-1"},"نمونه گیرندگان:",-1),Je={class:"space-y-1 text-xs text-gray-600"},Qe={key:3,class:"pt-2 border-t border-gray-200"},We=a("div",{class:"font-medium mb-1"},"آخرین کمپین:",-1),Xe={class:"text-blue-600 mt-1"},Ye={class:"border-t border-gray-200 pt-4"},Ze=a("div",{class:"mb-2 text-sm text-gray-600"}," کاربران را فیلتر کنید و گیرندگان مورد نظر را انتخاب کنید. فقط کاربرانی که شماره موبایل دارند نمایش داده میشوند. ",-1),et={class:"space-y-3"},tt=a("div",{class:"mb-1 text-sm text-gray-600"},"شماره موبایل",-1),at=a("div",{class:"text-xs text-gray-500"}," متن پیامک از باکس اصلی استفاده میشود. ",-1),nt=ee({__name:"SendPanel",emits:["campaign-started"],setup(e,{emit:o}){const{TextArea:g}=ne,[x,T]=Y(),f=d(""),v=d(!0),w=d(!0),l=d(null),k=d(!1),I=d(!1),h=d(null),S=d(!1),R=d(""),N=d(!1),P=d([]),L=d({}),j=oe(()=>({selectedRowKeys:P.value,onChange:m=>{P.value=m.map(String)},preserveSelectedRowKeys:!0})),E=d({columns:Ue,api:async m=>{const s={...m,filters:[...m.filters||[],{field:"phone",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}]};return v.value&&s.filters.push({field:"first_name",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0},{field:"last_name",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}),!s.sort&&!s.order&&(s.order="-created_at"),L.value=s,fe(s)},defaultPageLimit:20,height:"45vh"});ve(v,()=>{l.value=null,T()});function K(m){var s;return{message:f.value.trim(),appendAppName:w.value,registrationComplete:v.value,search:L.value.search||void 0,filters:(s=L.value.filters)==null?void 0:s.filter(_=>!_.hidden),sort:L.value.sort||void 0,order:L.value.order||void 0,mode:m,userIds:m==="selected"?P.value:void 0}}async function z(){var m,s;if(!f.value.trim()){$.warning("ابتدا متن پیامک را وارد کنید");return}k.value=!0;try{l.value=await Be(K("filtered"))}catch(_){$.error(((s=(m=_==null?void 0:_.response)==null?void 0:m.data)==null?void 0:s.error)||"خطا در پیشنمایش")}finally{k.value=!1}}async function G(){var m,s;if(!f.value.trim()){$.warning("متن پیامک الزامی است");return}if(!R.value.trim()){$.warning("شماره موبایل الزامی است");return}N.value=!0;try{await Le({...K("filtered"),phone:R.value.trim()}),$.success("پیامک تستی ارسال شد"),S.value=!1}catch(_){$.error(((s=(m=_==null?void 0:_.response)==null?void 0:m.data)==null?void 0:s.error)||"ارسال تستی ناموفق بود")}finally{N.value=!1}}async function O(m){if(!f.value.trim()){$.warning("متن پیامک الزامی است");return}if(m==="selected"&&!P.value.length){$.warning("حداقل یک کاربر انتخاب کنید");return}const s=m==="selected"?`آیا از ارسال پیامک به ${P.value.length} کاربر انتخابشده مطمئن هستید؟`:"آیا از ارسال پیامک به همه کاربران فیلترشده مطمئن هستید؟";return new Promise(_=>{he.confirm({title:"تأیید ارسال پیامک",content:s,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var M,U;I.value=!0,h.value=null;try{const t=await De(K(m));h.value=t,o("campaign-started",t.campaignId),$.success(`کمپین #${t.campaignId} با ${t.totalRecipients} گیرنده در پسزمینه ارسال میشود`)}catch(t){$.error(((U=(M=t==null?void 0:t.response)==null?void 0:M.data)==null?void 0:U.error)||"شروع کمپین ناموفق بود")}finally{I.value=!1,_()}},onCancel:()=>_()})})}function H(){return O("selected")}function J(){return O("filtered")}return(m,s)=>{var t,p;const _=pe,M=ie,U=le;return y(),b("div",null,[a("div",Ae,[a("div",Ne,[a("div",null,[Ke,n(B(g),{value:f.value,"onUpdate:value":s[0]||(s[0]=r=>f.value=r),placeholder:"متن پیامک را وارد کنید...",rows:6,maxlength:1e3,"show-count":""},null,8,["value"])]),a("div",qe,[n(B(ae),{checked:v.value,"onUpdate:checked":s[1]||(s[1]=r=>v.value=r)},{default:i(()=>[c(" فقط کاربران با ثبتنام کامل (نام و نام خانوادگی) ")]),_:1},8,["checked"]),n(B(ae),{checked:w.value,"onUpdate:checked":s[2]||(s[2]=r=>w.value=r)},{default:i(()=>[c(" افزودن نام اپلیکیشن به انتهای پیام ")]),_:1},8,["checked"])]),a("div",Fe,[n(_,{loading:k.value,onClick:z},{default:i(()=>[c(" پیشنمایش گیرندگان ")]),_:1},8,["loading"]),n(_,{onClick:s[3]||(s[3]=r=>S.value=!0)},{default:i(()=>[c(" ارسال تست ")]),_:1}),n(_,{type:"primary",loading:I.value,disabled:!f.value.trim(),onClick:H},{default:i(()=>[c(" ارسال به انتخابشدهها ("+u(P.value.length)+") ",1)]),_:1},8,["loading","disabled"]),n(_,{type:"primary",ghost:"",loading:I.value,disabled:!f.value.trim(),onClick:J},{default:i(()=>[c(" ارسال به همه فیلترشدهها ")]),_:1},8,["loading","disabled"])])]),a("div",Oe,[Ve,l.value?(y(),b("div",je,[a("div",null,[c("تعداد گیرنده: "),a("strong",null,u(l.value.totalRecipients),1)]),a("div",null,[c("شماره یکتا: "),a("strong",null,u(l.value.uniquePhones),1)]),a("div",null,[c("پارت پیامک (هر نفر): "),a("strong",null,u(l.value.smsPartsPerRecipient),1)]),a("div",null,[c("تخمین کل پارت: "),a("strong",null,u(l.value.estimatedTotalParts),1)]),l.value.cappedAt?(y(),b("div",Ee," حداکثر "+u(l.value.cappedAt)+" گیرنده در هر ارسال ",1)):A("",!0)])):(y(),b("div",ze," برای مشاهده تعداد گیرندگان، پیشنمایش بگیرید. ")),(p=(t=l.value)==null?void 0:t.samples)!=null&&p.length?(y(),b("div",Ge,[He,a("ul",Je,[(y(!0),b(re,null,ge(l.value.samples,r=>(y(),b("li",{key:r.id},u(r.first_name)+" "+u(r.last_name)+" — "+u(r.phone),1))),128))])])):A("",!0),h.value?(y(),b("div",Qe,[We,a("div",null,[c("کمپین: "),a("strong",null,"#"+u(h.value.campaignId),1)]),a("div",null,[c("گیرندگان: "),a("strong",null,u(h.value.totalRecipients),1)]),a("div",Xe,u(h.value.message),1)])):A("",!0)])]),a("div",Ye,[Ze,n(M,Z(E.value,{"row-selection":j.value,onRegister:B(x)}),null,16,["row-selection","onRegister"])]),n(U,{visible:S.value,"onUpdate:visible":s[5]||(s[5]=r=>S.value=r),title:"ارسال پیامک تست",onOk:G,onCancel:s[6]||(s[6]=r=>S.value=!1),"confirm-loading":N.value},{default:i(()=>[a("div",et,[a("div",null,[tt,n(B(ne),{value:R.value,"onUpdate:value":s[4]||(s[4]=r=>R.value=r),placeholder:"مثال: 09123456789"},null,8,["value"])]),at])]),_:1},8,["visible","confirm-loading"])])}}}),st={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق"},lt={selected:"انتخابشده",filtered:"فیلترشده"},it=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"شناسه",dataIndex:"id",key:"id",filterable:!1},{title:"متن پیام",dataIndex:"message",key:"message",filterable:!1,customRender:e=>{const o=e.record.message||"";return o.length>60?`${o.slice(0,60)}...`:o}},{title:"گیرندگان",dataIndex:"total_recipients",key:"total_recipients",filterable:!1},{title:"پیشرفت",dataIndex:"sent_count",key:"progress",filterable:!1,customRender:e=>{const o=e.record;if(!o.total_recipients)return"-";const g=(o.sent_count||0)+(o.failed_count||0),x=Math.round(g/o.total_recipients*100);return`${g}/${o.total_recipients} (${x}%)`}},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1},{title:"نوع ارسال",dataIndex:"send_mode",key:"send_mode",filterable:!1,customRender:e=>lt[e.record.send_mode]||e.record.send_mode},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>st[e.record.status]||e.record.status},{title:"تاریخ",dataIndex:"created_at",key:"created_at",filterable:!1,customRender:e=>e.record.created_at?V(e.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],ot={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق"},rt=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"نام",dataIndex:"first_name",key:"first_name",filterable:!1},{title:"نام خانوادگی",dataIndex:"last_name",key:"last_name",filterable:!1},{title:"شماره",dataIndex:"phone",key:"phone",filterable:!1},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>ot[e.record.status]||e.record.status},{title:"زمان ارسال",dataIndex:"sent_at",key:"sent_at",filterable:!1,customRender:e=>e.record.sent_at?V(e.record.sent_at):"-"},{title:"خطا",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],dt={key:0,class:"mb-3 text-sm text-blue-600 flex items-center gap-2"},ct=a("span",null,"یک یا چند کمپین در حال ارسال است — جدول هر ۵ ثانیه بهروز میشود.",-1),ut={class:"gap-2 flex justify-center"},mt=a("span",null,"جزئیات کمپین",-1),pt={class:"text-green-600"},_t={class:"text-red-600"},ft={key:0,class:"text-gray-500 mr-2"},vt={class:"whitespace-pre-wrap text-sm"},gt={class:"flex flex-wrap gap-2 items-center mb-3"},yt=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت گیرندگان:",-1),bt=ee({__name:"CampaignsPanel",setup(e,{expose:o}){const[g,x]=Y(),[T,f]=Y(),v=d(!1),w=d(!1),l=d(null),k=d(null),I=d(),h=d(""),S=d(!1);let R=null;const N={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق"},P={selected:"انتخابشده",filtered:"فیلترشده"},L=d({columns:it,api:te,defaultPageLimit:20,height:"55vh"}),j=oe(()=>{var p;if(!((p=l.value)!=null&&p.campaign))return 0;const t=l.value.campaign;return Math.max(t.total_recipients-t.sent_count-t.failed_count,0)});async function te(t){const p=await Me(t);return S.value=p.rows.some(r=>r.status==="sending"),p}const E=d({columns:rt,api:O,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});function K(t){return N[t]||t}function z(t){return P[t]||t}function G(t){return t?V(t):"-"}async function O(t){if(!k.value)return{rows:[],total:0,query:{...t,total:0}};const p=await se(k.value,{page:t.page,limit:t.limit,status:I.value,search:h.value||t.search||void 0});l.value=p;const r=t.page||1,q=t.limit||20,Q=(r-1)*q;return{rows:p.recipients.rows.map((C,W)=>({...C,index:Q+W})),total:p.recipients.total,query:{...t,total:p.recipients.total,page:r,limit:q}}}async function H(t){w.value=!0;try{k.value=t,l.value=await se(t,{page:1,limit:20,status:I.value,search:h.value||void 0}),await f()}finally{w.value=!1}}function J(t){I.value=void 0,h.value="",v.value=!0,H(t.id)}function m(){v.value=!1,l.value=null,k.value=null}function s(){f()}function _(){x()}function M(){R||(R=setInterval(()=>{var t;x(),v.value&&k.value&&((t=l.value)==null?void 0:t.campaign.status)==="sending"&&f()},5e3))}function U(){R&&(clearInterval(R),R=null)}return ye(()=>{M()}),be(()=>{U()}),o({reload:_}),(t,p)=>{const r=ke,q=ie,Q=_e,C=Ie,W=Re,X=Ce,de=$e,ce=xe,ue=le;return y(),b("div",null,[S.value?(y(),b("div",dt,[n(r,{size:"small"}),ct])):A("",!0),n(q,Z(L.value,{onRegister:B(g)}),{action:i(({record:D})=>[a("div",ut,[n(B(Te),{class:"cursor-pointer"},{title:i(()=>[mt]),default:i(()=>[n(we,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:xt=>J(D)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),n(ue,{visible:v.value,"onUpdate:visible":p[2]||(p[2]=D=>v.value=D),title:"جزئیات کمپین پیامکی","custom-footer":"",width:"90%",onClose:m},{footer:i(()=>[n(Q,{onClick:m},{default:i(()=>[c("بستن")]),_:1})]),default:i(()=>[n(r,{spinning:w.value},{default:i(()=>[l.value?(y(),b(re,{key:0},[n(W,{bordered:"",column:2,size:"small",class:"mb-4"},{default:i(()=>[n(C,{label:"شناسه کمپین"},{default:i(()=>[c("#"+u(l.value.campaign.id),1)]),_:1}),n(C,{label:"وضعیت"},{default:i(()=>[c(u(K(l.value.campaign.status)),1)]),_:1}),n(C,{label:"تعداد گیرندگان"},{default:i(()=>[c(u(l.value.campaign.total_recipients),1)]),_:1}),n(C,{label:"موفق / ناموفق"},{default:i(()=>[a("span",pt,u(l.value.campaign.sent_count),1),c(" / "),a("span",_t,u(l.value.campaign.failed_count),1),l.value.campaign.status==="sending"?(y(),b("span",ft," ("+u(j.value)+" در انتظار) ",1)):A("",!0)]),_:1}),n(C,{label:"نوع ارسال"},{default:i(()=>[c(u(z(l.value.campaign.send_mode)),1)]),_:1}),n(C,{label:"تاریخ ایجاد"},{default:i(()=>[c(u(G(l.value.campaign.created_at)),1)]),_:1}),n(C,{label:"ایجادکننده",span:2},{default:i(()=>[c(u(l.value.campaign.created_by_admin_name||"-"),1)]),_:1}),n(C,{label:"متن پیام",span:2},{default:i(()=>[a("div",vt,u(l.value.campaign.message),1)]),_:1})]),_:1}),a("div",gt,[yt,n(de,{value:I.value,"onUpdate:value":p[0]||(p[0]=D=>I.value=D),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:s},{default:i(()=>[n(X,{value:"sent"},{default:i(()=>[c("ارسال شده")]),_:1}),n(X,{value:"failed"},{default:i(()=>[c("ناموفق")]),_:1}),n(X,{value:"pending"},{default:i(()=>[c("در انتظار")]),_:1})]),_:1},8,["value"]),n(ce,{value:h.value,"onUpdate:value":p[1]||(p[1]=D=>h.value=D),placeholder:"جستجو نام یا شماره",style:{width:"220px"},onSearch:s},null,8,["value"])]),n(q,Z(E.value,{onRegister:B(T)}),null,16,["onRegister"])],64)):A("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),ht=a("div",{class:"flex justify-between items-center mb-4"},[a("h2",null,"پنل پیامکی")],-1),Xt=ee({__name:"index",setup(e){const o=d("send"),g=d(null);function x(){var T;o.value="campaigns",(T=g.value)==null||T.reload()}return(T,f)=>{const v=Se,w=Pe,l=me;return y(),b("div",null,[n(l,null,{default:i(()=>[ht,n(w,{activeKey:o.value,"onUpdate:activeKey":f[0]||(f[0]=k=>o.value=k)},{default:i(()=>[n(v,{key:"send",tab:"ارسال پیامک"},{default:i(()=>[n(nt,{onCampaignStarted:x})]),_:1}),n(v,{key:"campaigns",tab:"کمپینهای ارسالی"},{default:i(()=>[n(bt,{ref_key:"campaignsPanelRef",ref:g},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})])}}});export{Xt as default};
|