2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{_ as me}from"./BasicShowContext.vue_vue_type_script_setup_true_lang-3f976bcf.js";import{_ as le}from"./BasicModal.vue_vue_type_style_index_0_lang-1bdfd956.js";import{u as Y,_ as ie}from"./useBaseTable-dfc7081d.js";import{_ as pe,B as _e}from"./button.vue_vue_type_style_index_0_lang-1caad4e7.js";import{g as fe}from"./member-43089009.js";import{J as F,d as ee,g as d,h as oe,E as ve,o as b,c as y,a,b as s,j as B,w as i,e as c,t as u,k as A,F as re,n as ge,H as Z,D as T,v as be,K as ye}from"./index-a08997de.js";import{t as V}from"./useDataTime-e1a8db4a.js";import{M as he}from"./index-676f4182.js";import{C as ae}from"./index-3f53f7ff.js";import{I as se,_ as xe}from"./index-8b4fbdda.js";import{I as we}from"./Icon-c87fac13.js";import{S as ke}from"./index-23f9a644.js";import{S as Ie,a as Re}from"./fa_IR-22f438b3.js";import{D as Ce,_ as Te}from"./index-e6eb1bed.js";import{T as $e}from"./isSymbol-6a02f777.js";import{T as Se,a as Pe}from"./index-a6b85004.js";import"./_plugin-vue_export-helper-20260c74.js";import"./vnode-ddd966cb.js";import"./useState-4330fc6d.js";import"./FormItemContext-5c31efc9.js";import"./lodash-aac8995a.js";import"./css-0fc50739.js";import"./DialogWrap-4549d95e.js";import"./pickAttrs-a3c5523a.js";import"./styleChecker-0d78d27e.js";import"./toArray-efae666c.js";import"./isPlainObject-a1ebcbd7.js";import"./useRefs-e28c9a2f.js";import"./_flatRest-e8546dba.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,Ue=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,$=(g-1)*x;return{rows:(o.data||[]).map((v,w)=>({...v,index:$+w})),total:o.total??((f=o.data)==null?void 0:f.length)??0,query:{...e,total:o.total??0,page:g,limit:x}}},ne=async(e,o)=>(await F.get(`/admin/sms/campaigns/${e}`,{params:o})).data,Me=[{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"},Ke={class:"xl:col-span-2 space-y-4"},Ne=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"},He={key:2,class:"pt-2 border-t border-gray-200"},Je=a("div",{class:"font-medium mb-1"},"نمونه گیرندگان:",-1),Ge={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),st=ee({__name:"SendPanel",emits:["campaign-started"],setup(e,{emit:o}){const{TextArea:g}=se,[x,$]=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(""),K=d(!1),P=d([]),L=d({}),j=oe(()=>({selectedRowKeys:P.value,onChange:m=>{P.value=m.map(String)},preserveSelectedRowKeys:!0})),E=d({columns:Me,api:async m=>{const n={...m,filters:[...m.filters||[],{field:"phone",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}]};return v.value&&n.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}),!n.sort&&!n.order&&(n.order="-created_at"),L.value=n,fe(n)},defaultPageLimit:20,height:"45vh"});ve(v,()=>{l.value=null,$()});function N(m){var n;return{message:f.value.trim(),appendAppName:w.value,registrationComplete:v.value,search:L.value.search||void 0,filters:(n=L.value.filters)==null?void 0:n.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,n;if(!f.value.trim()){T.warning("ابتدا متن پیامک را وارد کنید");return}k.value=!0;try{l.value=await Be(N("filtered"))}catch(_){T.error(((n=(m=_==null?void 0:_.response)==null?void 0:m.data)==null?void 0:n.error)||"خطا در پیشنمایش")}finally{k.value=!1}}async function H(){var m,n;if(!f.value.trim()){T.warning("متن پیامک الزامی است");return}if(!R.value.trim()){T.warning("شماره موبایل الزامی است");return}K.value=!0;try{await Le({...N("filtered"),phone:R.value.trim()}),T.success("پیامک تستی ارسال شد"),S.value=!1}catch(_){T.error(((n=(m=_==null?void 0:_.response)==null?void 0:m.data)==null?void 0:n.error)||"ارسال تستی ناموفق بود")}finally{K.value=!1}}async function O(m){if(!f.value.trim()){T.warning("متن پیامک الزامی است");return}if(m==="selected"&&!P.value.length){T.warning("حداقل یک کاربر انتخاب کنید");return}const n=m==="selected"?`آیا از ارسال پیامک به ${P.value.length} کاربر انتخابشده مطمئن هستید؟`:"آیا از ارسال پیامک به همه کاربران فیلترشده مطمئن هستید؟";return new Promise(_=>{he.confirm({title:"تأیید ارسال پیامک",content:n,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var U,M;I.value=!0,h.value=null;try{const t=await De(N(m));h.value=t,o("campaign-started",t.campaignId),T.success(`کمپین #${t.campaignId} با ${t.totalRecipients} گیرنده در پسزمینه ارسال میشود`)}catch(t){T.error(((M=(U=t==null?void 0:t.response)==null?void 0:U.data)==null?void 0:M.error)||"شروع کمپین ناموفق بود")}finally{I.value=!1,_()}},onCancel:()=>_()})})}function J(){return O("selected")}function G(){return O("filtered")}return(m,n)=>{var t,p;const _=pe,U=ie,M=le;return b(),y("div",null,[a("div",Ae,[a("div",Ke,[a("div",null,[Ne,s(B(g),{value:f.value,"onUpdate:value":n[0]||(n[0]=r=>f.value=r),placeholder:"متن پیامک را وارد کنید...",rows:6,maxlength:1e3,"show-count":""},null,8,["value"])]),a("div",qe,[s(B(ae),{checked:v.value,"onUpdate:checked":n[1]||(n[1]=r=>v.value=r)},{default:i(()=>[c(" فقط کاربران با ثبتنام کامل (نام و نام خانوادگی) ")]),_:1},8,["checked"]),s(B(ae),{checked:w.value,"onUpdate:checked":n[2]||(n[2]=r=>w.value=r)},{default:i(()=>[c(" افزودن نام اپلیکیشن به انتهای پیام ")]),_:1},8,["checked"])]),a("div",Fe,[s(_,{loading:k.value,onClick:z},{default:i(()=>[c(" پیشنمایش گیرندگان ")]),_:1},8,["loading"]),s(_,{onClick:n[3]||(n[3]=r=>S.value=!0)},{default:i(()=>[c(" ارسال تست ")]),_:1}),s(_,{type:"primary",loading:I.value,disabled:!f.value.trim(),onClick:J},{default:i(()=>[c(" ارسال به انتخابشدهها ("+u(P.value.length)+") ",1)]),_:1},8,["loading","disabled"]),s(_,{type:"primary",ghost:"",loading:I.value,disabled:!f.value.trim(),onClick:G},{default:i(()=>[c(" ارسال به همه فیلترشدهها ")]),_:1},8,["loading","disabled"])])]),a("div",Oe,[Ve,l.value?(b(),y("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?(b(),y("div",Ee," حداکثر "+u(l.value.cappedAt)+" گیرنده در هر ارسال ",1)):A("",!0)])):(b(),y("div",ze," برای مشاهده تعداد گیرندگان، پیشنمایش بگیرید. ")),(p=(t=l.value)==null?void 0:t.samples)!=null&&p.length?(b(),y("div",He,[Je,a("ul",Ge,[(b(!0),y(re,null,ge(l.value.samples,r=>(b(),y("li",{key:r.id},u(r.first_name)+" "+u(r.last_name)+" — "+u(r.phone),1))),128))])])):A("",!0),h.value?(b(),y("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,s(U,Z(E.value,{"row-selection":j.value,onRegister:B(x)}),null,16,["row-selection","onRegister"])]),s(M,{visible:S.value,"onUpdate:visible":n[5]||(n[5]=r=>S.value=r),title:"ارسال پیامک تست",onOk:H,onCancel:n[6]||(n[6]=r=>S.value=!1),"confirm-loading":K.value},{default:i(()=>[a("div",et,[a("div",null,[tt,s(B(se),{value:R.value,"onUpdate:value":n[4]||(n[4]=r=>R.value=r),placeholder:"مثال: 09123456789"},null,8,["value"])]),at])]),_:1},8,["visible","confirm-loading"])])}}}),nt={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=>nt[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"},bt=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت گیرندگان:",-1),yt=ee({__name:"CampaignsPanel",setup(e,{expose:o}){const[g,x]=Y(),[$,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 K={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 Ue(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 N(t){return K[t]||t}function z(t){return P[t]||t}function H(t){return t?V(t):"-"}async function O(t){if(!k.value)return{rows:[],total:0,query:{...t,total:0}};const p=await ne(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 J(t){w.value=!0;try{k.value=t,l.value=await ne(t,{page:1,limit:20,status:I.value,search:h.value||void 0}),await f()}finally{w.value=!1}}function G(t){I.value=void 0,h.value="",v.value=!0,J(t.id)}function m(){v.value=!1,l.value=null,k.value=null}function n(){f()}function _(){x()}function U(){R||(R=setInterval(()=>{var t;x(),v.value&&k.value&&((t=l.value)==null?void 0:t.campaign.status)==="sending"&&f()},5e3))}function M(){R&&(clearInterval(R),R=null)}return be(()=>{U()}),ye(()=>{M()}),o({reload:_}),(t,p)=>{const r=ke,q=ie,Q=_e,C=Ce,W=Te,X=Ie,de=Re,ce=xe,ue=le;return b(),y("div",null,[S.value?(b(),y("div",dt,[s(r,{size:"small"}),ct])):A("",!0),s(q,Z(L.value,{onRegister:B(g)}),{action:i(({record:D})=>[a("div",ut,[s(B($e),{class:"cursor-pointer"},{title:i(()=>[mt]),default:i(()=>[s(we,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:xt=>G(D)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),s(ue,{visible:v.value,"onUpdate:visible":p[2]||(p[2]=D=>v.value=D),title:"جزئیات کمپین پیامکی","custom-footer":"",width:"90%",onClose:m},{footer:i(()=>[s(Q,{onClick:m},{default:i(()=>[c("بستن")]),_:1})]),default:i(()=>[s(r,{spinning:w.value},{default:i(()=>[l.value?(b(),y(re,{key:0},[s(W,{bordered:"",column:2,size:"small",class:"mb-4"},{default:i(()=>[s(C,{label:"شناسه کمپین"},{default:i(()=>[c("#"+u(l.value.campaign.id),1)]),_:1}),s(C,{label:"وضعیت"},{default:i(()=>[c(u(N(l.value.campaign.status)),1)]),_:1}),s(C,{label:"تعداد گیرندگان"},{default:i(()=>[c(u(l.value.campaign.total_recipients),1)]),_:1}),s(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"?(b(),y("span",ft," ("+u(j.value)+" در انتظار) ",1)):A("",!0)]),_:1}),s(C,{label:"نوع ارسال"},{default:i(()=>[c(u(z(l.value.campaign.send_mode)),1)]),_:1}),s(C,{label:"تاریخ ایجاد"},{default:i(()=>[c(u(H(l.value.campaign.created_at)),1)]),_:1}),s(C,{label:"ایجادکننده",span:2},{default:i(()=>[c(u(l.value.campaign.created_by_admin_name||"-"),1)]),_:1}),s(C,{label:"متن پیام",span:2},{default:i(()=>[a("div",vt,u(l.value.campaign.message),1)]),_:1})]),_:1}),a("div",gt,[bt,s(de,{value:I.value,"onUpdate:value":p[0]||(p[0]=D=>I.value=D),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:n},{default:i(()=>[s(X,{value:"sent"},{default:i(()=>[c("ارسال شده")]),_:1}),s(X,{value:"failed"},{default:i(()=>[c("ناموفق")]),_:1}),s(X,{value:"pending"},{default:i(()=>[c("در انتظار")]),_:1})]),_:1},8,["value"]),s(ce,{value:h.value,"onUpdate:value":p[1]||(p[1]=D=>h.value=D),placeholder:"جستجو نام یا شماره",style:{width:"220px"},onSearch:n},null,8,["value"])]),s(q,Z(E.value,{onRegister:B($)}),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 $;o.value="campaigns",($=g.value)==null||$.reload()}return($,f)=>{const v=Se,w=Pe,l=me;return b(),y("div",null,[s(l,null,{default:i(()=>[ht,s(w,{activeKey:o.value,"onUpdate:activeKey":f[0]||(f[0]=k=>o.value=k)},{default:i(()=>[s(v,{key:"send",tab:"ارسال پیامک"},{default:i(()=>[s(st,{onCampaignStarted:x})]),_:1}),s(v,{key:"campaigns",tab:"کمپینهای ارسالی"},{default:i(()=>[s(yt,{ref_key:"campaignsPanelRef",ref:g},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})])}}});export{Xt as default};
|