2 lines
33 KiB
JavaScript
2 lines
33 KiB
JavaScript
import{_ as Ue}from"./BasicShowContext.vue_vue_type_script_setup_true_lang-dfb4e830.js";import{_ as ge}from"./BasicModal.vue_vue_type_style_index_0_lang-3186fd13.js";import{u as se,_ as he}from"./useBaseTable-e684a9eb.js";import{_ as Me}from"./button.vue_vue_type_style_index_0_lang-de1581fe.js";import{g as Oe}from"./member-45b26ab9.js";import{R as V,d as re,i as c,j as pe,z as ze,o as I,c as T,b as a,e as t,l as D,w as s,f as d,t as p,n as z,F as xe,q as qe,L as le,H as y,x as Ee,S as Fe,k as ye,h as Ne}from"./index-185c08ed.js";import{t as ie}from"./useDataTime-284d8334.js";import{_ as Ve,v as be,t as we}from"./AudienceSegmentPicker.vue_vue_type_script_setup_true_lang-18409336.js";import{M as _e,_ as Ke}from"./index-2573091c.js";import{C as ve}from"./index-33777d70.js";import{I as fe,_ as Ce}from"./index-a29d0cc7.js";import{I as ae}from"./Icon-623de3ea.js";import{S as Te}from"./index-5a721f2f.js";import{B as Le}from"./index-f463cb03.js";import{D as Pe,_ as Ae}from"./index-bae38421.js";import{S as Be,_ as De}from"./index-0ee37254.js";import{T as ne}from"./isSymbol-18d6b370.js";import{_ as je}from"./BasicInput.vue_vue_type_style_index_0_lang-8f3a56f0.js";import{_ as He,T as Je}from"./index-c3741845.js";import"./updateLocale-d0f4ef4d.js";import"./shallowequal-6622fb79.js";import"./_plugin-vue_export-helper-e26fbd9a.js";import"./vnode-8a371720.js";import"./useState-50bb8c1f.js";import"./useMemo-4f3c1eb4.js";import"./FormItemContext-2d3e7341.js";import"./omit-d93eaa18.js";import"./lodash-0633e973.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-e9f1c563.js";import"./index-9383b001.js";import"./Badge-51142f0a.js";import"./isNumeric-3f69e2aa.js";import"./index-9e9f857b.js";import"./index-a2809ce1.js";import"./index-77ae4c49.js";import"./index-978007e9.js";import"./isMobile-e2e89480.js";import"./dayjs-67625168.js";import"./index-836b96c1.js";import"./DialogWrap-9863a7c0.js";import"./pickAttrs-e062aa3e.js";import"./styleChecker-7bb1c6f5.js";import"./index-975de3f6.js";import"./index-1f485cc0.js";import"./css-aae66f86.js";import"./SearchOutlined-d9b8def2.js";import"./toArray-da31f78e.js";import"./isPlainObject-5638f45d.js";import"./usePrice-bc935b83.js";import"./useRefs-b56c6fdc.js";import"./_flatRest-947e7901.js";const ke=async e=>(await V.post("/admin/sms/preview",e)).data,Ge=async e=>(await V.post("/admin/sms/test",e)).data,$e=async e=>(await V.post("/admin/sms/campaigns/start",e)).data,Qe=async e=>(await V.post(`/admin/sms/campaigns/${e}/continue-batch`)).data,We=async e=>{var g;const o=await V.get("/admin/sms/campaigns",{params:{page:e.page,limit:e.limit,search:e.search}}),b=e.page||1,R=e.limit||20,q=(b-1)*R;return{rows:(o.data||[]).map(($,L)=>({...$,index:q+L})),total:o.total??((g=o.data)==null?void 0:g.length)??0,query:{...e,total:o.total??0,page:b,limit:R}}},Ie=async(e,o)=>(await V.get(`/admin/sms/campaigns/${e}`,{params:o})).data,Xe=async e=>{const o=await V.get("/admin/sms/automations"),b=e.page||1,R=e.limit||20,q=(b-1)*R,g=o.data||[];return{rows:g.map(($,L)=>({...$,index:q+L})),total:o.total??g.length,query:{...e,total:o.total??g.length,page:b,limit:R}}},Re=async(e,o)=>(await V.patch(`/admin/sms/automations/${e}`,o)).data,Se=async(e,o)=>(await V.get(`/admin/sms/automations/${e}/sends`,{params:o})).data,Ye=async(e,o)=>(await V.post(`/admin/sms/automations/${e}/test`,{phone:o})).data,Ze=[{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?ie(e.record.created_at):"-"}],et={class:"grid grid-cols-1 xl:grid-cols-3 gap-4 mb-4"},tt={class:"xl:col-span-2 space-y-4"},at=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),nt={class:"flex flex-wrap gap-4 items-center"},st={class:"flex flex-wrap gap-2"},lt={class:"bg-gray-50 rounded-lg p-4 border border-gray-200 space-y-2 text-sm"},it=a("div",{class:"font-semibold text-gray-700 mb-2"},"خلاصه ارسال",-1),ot={key:0},rt={key:0,class:"text-amber-600 mt-1"},ct={key:0},ut={key:1,class:"text-gray-500"},dt={key:2,class:"pt-2 border-t border-gray-200"},mt=a("div",{class:"font-medium mb-1"},"نمونه گیرندگان:",-1),pt={class:"space-y-1 text-xs text-gray-600"},_t={key:3,class:"pt-2 border-t border-gray-200"},vt=a("div",{class:"font-medium mb-1"},"آخرین کمپین:",-1),ft={class:"text-blue-600 mt-1"},gt={class:"border-t border-gray-200 pt-4"},ht=a("div",{class:"mb-2 text-sm text-gray-600"}," کاربران را فیلتر کنید و گیرندگان مورد نظر را انتخاب کنید. فقط کاربرانی که شماره موبایل دارند نمایش داده میشوند. ",-1),xt={class:"space-y-3"},yt=a("div",{class:"mb-1 text-sm text-gray-600"},"شماره موبایل",-1),bt=a("div",{class:"text-xs text-gray-500"}," متن پیامک از باکس اصلی استفاده میشود. ",-1),wt=re({__name:"SendPanel",emits:["campaign-started"],setup(e,{emit:o}){const{TextArea:b}=fe,[R,q]=se(),g=c(""),$=c(!0),L=c(!0),x=c(null),u=c(!1),k=c(!1),S=c(null),P=c(!1),O=c(""),U=c(!1),A=c([]),C=c({}),E=c({segments:[],inactiveDays:7,subscriberInactiveDays:3}),F=c(!1),M=c(""),Q=pe(()=>({selectedRowKeys:A.value,onChange:h=>{A.value=h.map(String)},preserveSelectedRowKeys:!0})),W=c({columns:Ze,api:async h=>{const r={...h,filters:[...h.filters||[],{field:"phone",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}]};return $.value&&r.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}),!r.sort&&!r.order&&(r.order="-created_at"),C.value=r,Oe(r)},defaultPageLimit:20,height:"45vh"});ze($,()=>{x.value=null,q()});function H(h){var r;return{message:g.value.trim(),appendAppName:L.value,registrationComplete:$.value,search:C.value.search||void 0,filters:(r=C.value.filters)==null?void 0:r.filter(i=>!i.hidden),sort:C.value.sort||void 0,order:C.value.order||void 0,mode:h,userIds:h==="selected"?A.value:void 0}}async function X(){var h,r;if(!g.value.trim()){y.warning("ابتدا متن پیامک را وارد کنید");return}u.value=!0;try{x.value=await ke(H("filtered"))}catch(i){y.error(((r=(h=i==null?void 0:i.response)==null?void 0:h.data)==null?void 0:r.error)||"خطا در پیشنمایش")}finally{u.value=!1}}async function Y(){var h,r;if(!g.value.trim()){y.warning("متن پیامک الزامی است");return}if(!O.value.trim()){y.warning("شماره موبایل الزامی است");return}U.value=!0;try{await Ge({...H("filtered"),phone:O.value.trim()}),y.success("پیامک تستی ارسال شد"),P.value=!1}catch(i){y.error(((r=(h=i==null?void 0:i.response)==null?void 0:h.data)==null?void 0:r.error)||"ارسال تستی ناموفق بود")}finally{U.value=!1}}async function K(h){if(!g.value.trim()){y.warning("متن پیامک الزامی است");return}if(h==="selected"&&!A.value.length){y.warning("حداقل یک کاربر انتخاب کنید");return}const r=h==="selected"?`آیا از ارسال پیامک به ${A.value.length} کاربر انتخابشده مطمئن هستید؟`:"آیا از ارسال پیامک به همه کاربران فیلترشده مطمئن هستید؟";return new Promise(i=>{_e.confirm({title:"تأیید ارسال پیامک",content:r,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var m,n;k.value=!0,S.value=null;try{const l=await $e(H(h));S.value=l,o("campaign-started",l.campaignId),y.success(l.hasMoreBatches?`کمپین #${l.campaignId}: دسته اول ${l.totalRecipients.toLocaleString("fa-IR")} نفر — پس از اتمام، ${(l.remainingRecipients||0).toLocaleString("fa-IR")} نفر باقیمانده با تأیید ارسال میشود`:`کمپین #${l.campaignId} با ${l.totalRecipients.toLocaleString("fa-IR")} گیرنده در پسزمینه ارسال میشود`)}catch(l){y.error(((n=(m=l==null?void 0:l.response)==null?void 0:m.data)==null?void 0:n.error)||"شروع کمپین ناموفق بود")}finally{k.value=!1,i()}},onCancel:()=>i()})})}function Z(){return K("selected")}function ee(){return K("filtered")}async function J(){var i,m;if(!g.value.trim()){y.warning("ابتدا متن پیامک را وارد کنید");return}const h={...E.value,includeUserIds:A.value},r=be(h);if(r){y.warning(r);return}F.value=!0,M.value="";try{const n=we(h),l=await ke({message:g.value.trim(),appendAppName:L.value,registrationComplete:$.value,mode:"segment",...n});x.value=l;const w=A.value.length>0?` (+ ${A.value.length.toLocaleString("fa-IR")} کاربر از جدول)`:"";M.value=l.cappedAt?`گیرندگان این دستهها: ${l.totalRecipients.toLocaleString("fa-IR")} شماره${w} — دسته اول ${(l.firstBatchSize||l.cappedAt).toLocaleString("fa-IR")} نفر؛ باقیمانده پس از تأیید`:`گیرندگان این دستهها: ${l.totalRecipients.toLocaleString("fa-IR")} شماره${w}`}catch(n){console.log(n),y.error(((m=(i=n==null?void 0:n.response)==null?void 0:i.data)==null?void 0:m.error)||"خطا در پیشنمایش")}finally{F.value=!1}}async function G(){if(!g.value.trim()){y.warning("متن پیامک الزامی است");return}const h={...E.value,includeUserIds:A.value},r=be(h);if(r){y.warning(r);return}const i=E.value.segments.length,m=A.value.length,n=m>0?`ارسال به ${i} دسته (OR) بهعلاوه ${m} کاربر انتخابشده؟`:`ارسال به ${i} دسته مخاطب (اتحاد / OR)؟`;return new Promise(l=>{_e.confirm({title:"تأیید ارسال پیامک",content:n,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var w,v;k.value=!0,S.value=null;try{const B=we(h),f=await $e({message:g.value.trim(),appendAppName:L.value,registrationComplete:$.value,mode:"segment",...B});S.value=f,o("campaign-started",f.campaignId),y.success(f.hasMoreBatches?`کمپین #${f.campaignId}: دسته اول ${f.totalRecipients.toLocaleString("fa-IR")} نفر — پس از اتمام، ${(f.remainingRecipients||0).toLocaleString("fa-IR")} نفر باقیمانده با تأیید ارسال میشود`:`کمپین #${f.campaignId} با ${f.totalRecipients.toLocaleString("fa-IR")} گیرنده در پسزمینه ارسال میشود`)}catch(B){y.error(((v=(w=B==null?void 0:B.response)==null?void 0:w.data)==null?void 0:v.error)||"شروع کمپین ناموفق بود")}finally{k.value=!1,l()}},onCancel:()=>l()})})}return(h,r)=>{var l,w;const i=Me,m=he,n=ge;return I(),T("div",null,[a("div",et,[a("div",tt,[a("div",null,[at,t(D(b),{value:g.value,"onUpdate:value":r[0]||(r[0]=v=>g.value=v),placeholder:"متن پیامک را وارد کنید...",rows:6,maxlength:1e3,"show-count":""},null,8,["value"])]),a("div",nt,[t(D(ve),{checked:$.value,"onUpdate:checked":r[1]||(r[1]=v=>$.value=v)},{default:s(()=>[d(" فقط کاربران با ثبتنام کامل (نام و نام خانوادگی) ")]),_:1},8,["checked"]),t(D(ve),{checked:L.value,"onUpdate:checked":r[2]||(r[2]=v=>L.value=v)},{default:s(()=>[d(" افزودن نام اپلیکیشن به انتهای پیام ")]),_:1},8,["checked"])]),a("div",st,[t(i,{loading:u.value,onClick:X},{default:s(()=>[d(" پیشنمایش گیرندگان ")]),_:1},8,["loading"]),t(i,{onClick:r[3]||(r[3]=v=>P.value=!0)},{default:s(()=>[d(" ارسال تست ")]),_:1}),t(i,{type:"primary",loading:k.value,disabled:!g.value.trim(),onClick:Z},{default:s(()=>[d(" ارسال به انتخابشدهها ("+p(A.value.length)+") ",1)]),_:1},8,["loading","disabled"]),t(i,{type:"primary",ghost:"",loading:k.value,disabled:!g.value.trim(),onClick:ee},{default:s(()=>[d(" ارسال به همه فیلترشدهها ")]),_:1},8,["loading","disabled"])]),t(Ve,{modelValue:E.value,"onUpdate:modelValue":r[4]||(r[4]=v=>E.value=v),"include-user-count":A.value.length,"preview-loading":F.value,sending:k.value,disabled:!g.value.trim(),"preview-text":M.value,onPreview:J,onSend:G},null,8,["modelValue","include-user-count","preview-loading","sending","disabled","preview-text"])]),a("div",lt,[it,x.value?(I(),T("div",ot,[a("div",null,[d("تعداد گیرنده: "),a("strong",null,p(x.value.totalRecipients),1)]),a("div",null,[d("شماره یکتا: "),a("strong",null,p(x.value.uniquePhones),1)]),a("div",null,[d("پارت پیامک (هر نفر): "),a("strong",null,p(x.value.smsPartsPerRecipient),1)]),a("div",null,[d("تخمین کل پارت: "),a("strong",null,p(x.value.estimatedTotalParts),1)]),x.value.cappedAt?(I(),T("div",rt,[d(" مخاطبان بیشتر از "+p(x.value.cappedAt.toLocaleString("fa-IR"))+" نفر هستند. ابتدا "+p((x.value.firstBatchSize||x.value.cappedAt).toLocaleString("fa-IR"))+" نفر ارسال میشود؛ سپس با تأیید شما دسته بعدی ",1),x.value.remainingAfterFirstBatch?(I(),T("span",ct," ("+p(x.value.remainingAfterFirstBatch.toLocaleString("fa-IR"))+" باقیمانده) ",1)):z("",!0),d(" ارسال میشود. ")])):z("",!0)])):(I(),T("div",ut," برای مشاهده تعداد گیرندگان، پیشنمایش بگیرید. ")),(w=(l=x.value)==null?void 0:l.samples)!=null&&w.length?(I(),T("div",dt,[mt,a("ul",pt,[(I(!0),T(xe,null,qe(x.value.samples,v=>(I(),T("li",{key:v.id},p(v.first_name)+" "+p(v.last_name)+" — "+p(v.phone),1))),128))])])):z("",!0),S.value?(I(),T("div",_t,[vt,a("div",null,[d("کمپین: "),a("strong",null,"#"+p(S.value.campaignId),1)]),a("div",null,[d("گیرندگان: "),a("strong",null,p(S.value.totalRecipients),1)]),a("div",ft,p(S.value.message),1)])):z("",!0)])]),a("div",gt,[ht,t(m,le(W.value,{"row-selection":Q.value,onRegister:D(R)}),null,16,["row-selection","onRegister"])]),t(n,{visible:P.value,"onUpdate:visible":r[6]||(r[6]=v=>P.value=v),title:"ارسال پیامک تست",onOk:Y,onCancel:r[7]||(r[7]=v=>P.value=!1),"confirm-loading":U.value},{default:s(()=>[a("div",xt,[a("div",null,[yt,t(D(fe),{value:O.value,"onUpdate:value":r[5]||(r[5]=v=>O.value=v),placeholder:"مثال: 09123456789"},null,8,["value"])]),bt])]),_:1},8,["visible","confirm-loading"])])}}}),kt={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق",awaiting_next_batch:"منتظر تأیید دسته بعدی"},$t={selected:"انتخابشده",filtered:"فیلترشده",segment:"دسته مخاطب"},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,customRender:e=>{const o=e.record,b=o.total_recipients||0,R=o.audience_total||b;return R>b?`${b.toLocaleString("fa-IR")} / ${R.toLocaleString("fa-IR")}`:b}},{title:"پیشرفت",dataIndex:"sent_count",key:"progress",filterable:!1,customRender:e=>{const o=e.record;if(!o.total_recipients)return"-";const b=(o.sent_count||0)+(o.failed_count||0),R=Math.round(b/o.total_recipients*100);return`${b}/${o.total_recipients} (${R}%)`}},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1},{title:"نوع ارسال",dataIndex:"send_mode",key:"send_mode",filterable:!1,customRender:e=>$t[e.record.send_mode]||e.record.send_mode},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>kt[e.record.status]||e.record.status},{title:"تاریخ",dataIndex:"created_at",key:"created_at",filterable:!1,customRender:e=>e.record.created_at?ie(e.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],Rt={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق"},St=[{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=>Rt[e.record.status]||e.record.status},{title:"زمان ارسال",dataIndex:"sent_at",key:"sent_at",filterable:!1,customRender:e=>e.record.sent_at?ie(e.record.sent_at):"-"},{title:"خطا",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],Ct={key:0,class:"mb-3 text-sm text-blue-600 flex items-center gap-2"},Tt=a("span",null,"یک یا چند کمپین در حال ارسال است — جدول هر ۵ ثانیه بهروز میشود.",-1),Lt={class:"gap-2 flex justify-center"},Pt=a("span",null,"جزئیات کمپین",-1),At=a("span",null,"ارسال دسته بعدی",-1),Bt={class:"flex justify-end gap-2 w-full flex-wrap"},Dt={key:0},Ut={key:0,class:"text-gray-500 mr-1"},Mt={class:"text-green-600"},Ot={class:"text-red-600"},zt={key:0,class:"text-gray-500 mr-2"},qt={class:"whitespace-pre-wrap text-sm"},Et={key:0,class:"mb-3 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-800"},Ft={key:1,class:"mb-3 rounded-md border border-blue-200 bg-blue-50 px-3 py-2 text-sm text-blue-800"},Nt={class:"flex flex-wrap gap-2 items-center mb-3"},Vt=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت گیرندگان:",-1),Kt=re({__name:"CampaignsPanel",setup(e,{expose:o}){const[b,R]=se(),[q,g]=se(),$=c(!1),L=c(!1),x=c(!1),u=c(null),k=c(null),S=c(),P=c(""),O=c(!1);let U=null;const A={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق",awaiting_next_batch:"منتظر تأیید دسته بعدی"},C={selected:"انتخابشده",filtered:"فیلترشده",segment:"دسته مخاطب"},E=c({columns:It,api:Q,defaultPageLimit:20,height:"55vh"}),F=pe(()=>{var l;if(!((l=u.value)!=null&&l.campaign))return 0;const n=u.value.campaign;return Math.max(n.total_recipients-n.sent_count-n.failed_count,0)}),M=pe(()=>{var l;const n=(l=u.value)==null?void 0:l.campaign;return n?!!n.can_continue_batch&&(n.remaining_recipients||0)>0:!1});async function Q(n){const l=await We(n);return O.value=l.rows.some(w=>w.status==="sending"||w.status==="awaiting_next_batch"),l}const oe=c({columns:St,api:Y,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});function W(n){return A[n]||n}function H(n){return C[n]||n}function X(n){return n?ie(n):"-"}async function Y(n){if(!k.value)return{rows:[],total:0,query:{...n,total:0}};const l=await Ie(k.value,{page:n.page,limit:n.limit,status:S.value,search:P.value||n.search||void 0});u.value=l;const w=n.page||1,v=n.limit||20,B=(w-1)*v;return{rows:l.recipients.rows.map((f,te)=>({...f,index:B+te})),total:l.recipients.total,query:{...n,total:l.recipients.total,page:w,limit:v}}}async function K(n){L.value=!0;try{k.value=n,u.value=await Ie(n,{page:1,limit:20,status:S.value,search:P.value||void 0}),await g()}finally{L.value=!1}}function Z(n){S.value=void 0,P.value="",$.value=!0,K(n.id)}async function ee(n){S.value=void 0,P.value="",$.value=!0,await K(n.id),M.value&&r()}function J(){$.value=!1,u.value=null,k.value=null}function G(){g()}function h(){R()}function r(){var w;const n=(w=u.value)==null?void 0:w.campaign;if(!(n!=null&&n.id)||!M.value)return;const l=n.next_batch_size||Math.min(1e4,n.remaining_recipients||0);_e.confirm({title:"تأیید ارسال دسته بعدی",content:`آیا از ارسال دسته بعدی (${l.toLocaleString("fa-IR")} نفر از ${(n.remaining_recipients||0).toLocaleString("fa-IR")} باقیمانده) مطمئن هستید؟`,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var v,B;x.value=!0;try{const f=await Qe(n.id);y.success(f.message),await K(n.id),R()}catch(f){throw y.error(((B=(v=f==null?void 0:f.response)==null?void 0:v.data)==null?void 0:B.error)||"ارسال دسته بعدی ناموفق بود"),f}finally{x.value=!1}}})}function i(){U||(U=setInterval(()=>{var n,l;R(),$.value&&k.value&&(((n=u.value)==null?void 0:n.campaign.status)==="sending"||((l=u.value)==null?void 0:l.campaign.status)==="awaiting_next_batch")&&g()},5e3))}function m(){U&&(clearInterval(U),U=null)}return Ee(()=>{i()}),Fe(()=>{m()}),o({reload:h}),(n,l)=>{const w=Te,v=he,B=Le,f=Pe,te=Ae,j=Be,ce=De,ue=Ce,de=ge;return I(),T("div",null,[O.value?(I(),T("div",Ct,[t(w,{size:"small"}),Tt])):z("",!0),t(v,le(E.value,{onRegister:D(b)}),{action:s(({record:_})=>[a("div",Lt,[t(D(ne),{class:"cursor-pointer"},{title:s(()=>[Pt]),default:s(()=>[t(ae,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:N=>Z(_)},null,8,["onClick"])]),_:2},1024),_.can_continue_batch?(I(),ye(D(ne),{key:0,class:"cursor-pointer"},{title:s(()=>[At]),default:s(()=>[t(ae,{icon:"vuesax-linear:send-2",color:"#D97706",onClick:N=>ee(_)},null,8,["onClick"])]),_:2},1024)):z("",!0)])]),_:1},16,["onRegister"]),t(de,{visible:$.value,"onUpdate:visible":l[2]||(l[2]=_=>$.value=_),title:"جزئیات کمپین پیامکی","custom-footer":"",width:"90%",onClose:J},{footer:s(()=>[a("div",Bt,[M.value?(I(),ye(B,{key:0,type:"primary",loading:x.value,onClick:r},{default:s(()=>{var _;return[d(" ارسال دسته بعدی "),(_=u.value)!=null&&_.campaign.next_batch_size?(I(),T("span",Dt," ("+p(u.value.campaign.next_batch_size.toLocaleString("fa-IR"))+" نفر) ",1)):z("",!0)]}),_:1},8,["loading"])):z("",!0),t(B,{onClick:J},{default:s(()=>[d("بستن")]),_:1})])]),default:s(()=>[t(w,{spinning:L.value},{default:s(()=>[u.value?(I(),T(xe,{key:0},[t(te,{bordered:"",column:2,size:"small",class:"mb-4"},{default:s(()=>[t(f,{label:"شناسه کمپین"},{default:s(()=>[d("#"+p(u.value.campaign.id),1)]),_:1}),t(f,{label:"وضعیت"},{default:s(()=>[d(p(W(u.value.campaign.status)),1)]),_:1}),t(f,{label:"تعداد گیرندگان"},{default:s(()=>[a("span",null,p(u.value.campaign.total_recipients.toLocaleString("fa-IR")),1),(u.value.campaign.audience_total||0)>u.value.campaign.total_recipients?(I(),T("span",Ut," از "+p(u.value.campaign.audience_total.toLocaleString("fa-IR"))+" مخاطب ",1)):z("",!0)]),_:1}),t(f,{label:"موفق / ناموفق"},{default:s(()=>[a("span",Mt,p(u.value.campaign.sent_count),1),d(" / "),a("span",Ot,p(u.value.campaign.failed_count),1),u.value.campaign.status==="sending"?(I(),T("span",zt," ("+p(F.value)+" در انتظار) ",1)):z("",!0)]),_:1}),t(f,{label:"نوع ارسال"},{default:s(()=>[d(p(H(u.value.campaign.send_mode)),1)]),_:1}),t(f,{label:"تاریخ ایجاد"},{default:s(()=>[d(p(X(u.value.campaign.created_at)),1)]),_:1}),t(f,{label:"ایجادکننده",span:2},{default:s(()=>[d(p(u.value.campaign.created_by_admin_name||"-"),1)]),_:1}),t(f,{label:"متن پیام",span:2},{default:s(()=>[a("div",qt,p(u.value.campaign.message),1)]),_:1})]),_:1}),M.value?(I(),T("div",Et,[d(" مخاطب این کمپین دوباره محاسبه شد و شمارههای ارسالشده کم شدند. "),a("strong",null,p((u.value.campaign.remaining_recipients||0).toLocaleString("fa-IR")),1),d(" گیرنده باقی ماندهاند. با تأیید شما حداکثر "+p((u.value.campaign.batch_limit||1e4).toLocaleString("fa-IR"))+" نفر بعدی ارسال میشود. ",1)])):u.value.campaign.needs_remaining_probe?(I(),T("div",Ft," این کمپین احتمالاً به سقف ۱۰٬۰۰۰ رسیده بود. در حال بررسی باقیمانده مخاطب… ")):z("",!0),a("div",Nt,[Vt,t(ce,{value:S.value,"onUpdate:value":l[0]||(l[0]=_=>S.value=_),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:G},{default:s(()=>[t(j,{value:"sent"},{default:s(()=>[d("ارسال شده")]),_:1}),t(j,{value:"failed"},{default:s(()=>[d("ناموفق")]),_:1}),t(j,{value:"pending"},{default:s(()=>[d("در انتظار")]),_:1})]),_:1},8,["value"]),t(ue,{value:P.value,"onUpdate:value":l[1]||(l[1]=_=>P.value=_),placeholder:"جستجو نام یا شماره",style:{width:"220px"},onSearch:G},null,8,["value"])]),t(v,le(oe.value,{onRegister:D(q)}),null,16,["onRegister"])],64)):z("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),jt=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"نام",dataIndex:"name",key:"name",filterable:!1},{title:"کد",dataIndex:"code",key:"code",filterable:!1},{title:"متن پیام",dataIndex:"message",key:"message",filterable:!1,customRender:e=>{const o=e.record.message||"";return o.length>50?`${o.slice(0,50)}...`:o}},{title:"فعال",dataIndex:"is_active",key:"is_active",slot:"is_active",filterable:!1,align:"center"},{title:"ارسالشده",dataIndex:"sent_count",key:"sent_count",filterable:!1},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1},{title:"لغو/رد",dataIndex:"cancelled_count",key:"cancelled_count",filterable:!1},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],Ht={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق",cancelled:"لغو شده",skipped:"رد شده"},Jt=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"شماره",dataIndex:"phone",key:"phone",filterable:!1},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>Ht[e.record.status]||e.record.status},{title:"تاریخ برنامهریزی",dataIndex:"scheduled_for",key:"scheduled_for",filterable:!1},{title:"زمان ارسال",dataIndex:"sent_at",key:"sent_at",filterable:!1,customRender:e=>e.record.sent_at?ie(e.record.sent_at):"-"},{title:"توضیح",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],Gt=a("p",{class:"text-sm text-gray-500 mb-4"}," اتوماسیونهای پیامکی کدوبلو. متن و فعال بودن را میتوانید تغییر دهید؛ شرط ارسال در سیستم ثابت است. ",-1),Qt={class:"gap-2 flex justify-center"},Wt=a("span",null,"ویرایش",-1),Xt=a("span",null,"آمار ارسال",-1),Yt=a("span",null,"ارسال تست",-1),Zt={class:"space-y-4"},ea=a("div",{class:"mb-1 text-sm text-gray-600"},"نام",-1),ta={class:"font-medium"},aa=a("div",{class:"mb-1 text-sm text-gray-600"},"شرط ارسال",-1),na={class:"text-sm text-gray-700 whitespace-pre-wrap"},sa=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),la={class:"space-y-3"},ia={class:"text-sm text-gray-600"},oa={class:"text-green-600"},ra={class:"text-red-600"},ca={class:"text-gray-500"},ua=a("span",{class:"text-xs text-gray-400 mr-2"},"(موفق / ناموفق / لغو)",-1),da={class:"whitespace-pre-wrap text-sm"},ma={class:"flex flex-wrap gap-2 items-center mb-3"},pa=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت:",-1),_a=re({__name:"AutomationsPanel",setup(e,{expose:o}){const{TextArea:b}=fe,[R,q]=se(),[g,$]=se(),L=c({columns:jt,api:Xe,defaultPageLimit:20,height:"55vh",showOptionHeader:!1}),x=c(!1),u=c(null),k=Ne({message:"",is_active:!0}),S=c(!1),P=c(null),O=c(""),U=c(!1),A=c(!1),C=c(null),E=c(null),F=c(),M=c(""),Q=c({columns:Jt,api:ee,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});async function oe(i,m){if(i.is_active===m)return;const n=i.is_active;i.is_active=m;try{await Re(i.id,{is_active:m}),y.success(m?"اتوماسیون فعال شد":"اتوماسیون غیرفعال شد")}catch{i.is_active=n,y.error("تغییر وضعیت ناموفق بود")}}function W(i){u.value=i,k.message=i.message||"",k.is_active=i.is_active!==!1,x.value=!0}function H(){x.value=!1,u.value=null}async function X(){if(u.value){if(!k.message.trim()){y.error("متن پیامک الزامی است");return}try{await Re(u.value.id,{message:k.message.trim(),is_active:k.is_active}),y.success("اتوماسیون ذخیره شد"),H(),await q()}catch{y.error("ذخیره ناموفق بود")}}}function Y(i){P.value=i,O.value="",S.value=!0}function K(){S.value=!1,P.value=null,O.value=""}async function Z(){if(!P.value)return;const i=O.value.trim();if(!i){y.error("شماره موبایل الزامی است");return}try{await Ye(P.value.id,i),y.success("پیامک تست ارسال شد"),K()}catch{y.error("ارسال تست ناموفق بود")}}async function ee(i){if(!E.value)return{rows:[],total:0,query:{...i,total:0}};const m=await Se(E.value,{page:i.page,limit:i.limit,status:F.value,search:M.value||i.search||void 0});C.value=m;const n=i.page||1,l=i.limit||20,w=(n-1)*l;return{rows:m.sends.rows.map((v,B)=>({...v,index:w+B})),total:m.sends.total,query:{...i,total:m.sends.total,page:n,limit:l}}}async function J(i){A.value=!0;try{E.value=i,C.value=await Se(i,{page:1,limit:20,status:F.value,search:M.value||void 0}),await $()}finally{A.value=!1}}function G(i){F.value=void 0,M.value="",U.value=!0,J(i.id)}function h(){U.value=!1,C.value=null,E.value=null}function r(){$()}return o({reload:q}),(i,m)=>{const n=Ke,l=he,w=ge,v=je,B=Le,f=Pe,te=Ae,j=Be,ce=De,ue=Ce,de=Te;return I(),T("div",null,[Gt,t(l,le(L.value,{onRegister:D(R)}),{is_active:s(({record:_})=>[t(n,{checked:_.is_active,onChange:N=>oe(_,N)},null,8,["checked","onChange"])]),action:s(({record:_})=>[a("div",Qt,[t(D(ne),{class:"cursor-pointer"},{title:s(()=>[Wt]),default:s(()=>[t(ae,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:N=>W(_)},null,8,["onClick"])]),_:2},1024),t(D(ne),{class:"cursor-pointer"},{title:s(()=>[Xt]),default:s(()=>[t(ae,{icon:"vuesax-linear:eye",color:"#059669",onClick:N=>G(_)},null,8,["onClick"])]),_:2},1024),t(D(ne),{class:"cursor-pointer"},{title:s(()=>[Yt]),default:s(()=>[t(ae,{icon:"vuesax-linear:sms",color:"#7C3AED",onClick:N=>Y(_)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),t(w,{visible:x.value,"onUpdate:visible":m[2]||(m[2]=_=>x.value=_),title:"ویرایش اتوماسیون",width:"640px",onOk:X,onCancel:H},{default:s(()=>{var _,N;return[a("div",Zt,[a("div",null,[ea,a("div",ta,p((_=u.value)==null?void 0:_.name),1)]),a("div",null,[aa,a("div",na,p((N=u.value)==null?void 0:N.trigger_summary),1)]),a("div",null,[sa,t(D(b),{value:k.message,"onUpdate:value":m[0]||(m[0]=me=>k.message=me),rows:5,placeholder:"متن پیامک"},null,8,["value"])]),a("div",null,[t(D(ve),{checked:k.is_active,"onUpdate:checked":m[1]||(m[1]=me=>k.is_active=me)},{default:s(()=>[d("فعال")]),_:1},8,["checked"])])])]}),_:1},8,["visible"]),t(w,{visible:S.value,"onUpdate:visible":m[4]||(m[4]=_=>S.value=_),title:"ارسال تست اتوماسیون",width:"480px",onOk:Z,onCancel:K},{default:s(()=>{var _;return[a("div",la,[a("div",ia," متن فعلی «"+p((_=P.value)==null?void 0:_.name)+"» به شماره زیر ارسال میشود. ",1),t(v,{value:O.value,"onUpdate:value":m[3]||(m[3]=N=>O.value=N),placeholder:"09xxxxxxxxx"},null,8,["value"])])]}),_:1},8,["visible"]),t(w,{visible:U.value,"onUpdate:visible":m[7]||(m[7]=_=>U.value=_),title:"آمار ارسال اتوماسیون","custom-footer":"",width:"90%",onClose:h},{footer:s(()=>[t(B,{onClick:h},{default:s(()=>[d("بستن")]),_:1})]),default:s(()=>[t(de,{spinning:A.value},{default:s(()=>[C.value?(I(),T(xe,{key:0},[t(te,{bordered:"",column:2,size:"small",class:"mb-4"},{default:s(()=>[t(f,{label:"نام"},{default:s(()=>[d(p(C.value.automation.name),1)]),_:1}),t(f,{label:"کد"},{default:s(()=>[d(p(C.value.automation.code),1)]),_:1}),t(f,{label:"وضعیت"},{default:s(()=>[d(p(C.value.automation.is_active?"فعال":"غیرفعال"),1)]),_:1}),t(f,{label:"آمار کلی"},{default:s(()=>[a("span",oa,p(C.value.automation.sent_count),1),d(" / "),a("span",ra,p(C.value.automation.failed_count),1),d(" / "),a("span",ca,p(C.value.automation.cancelled_count),1),ua]),_:1}),t(f,{label:"شرط",span:2},{default:s(()=>[d(p(C.value.automation.trigger_summary),1)]),_:1}),t(f,{label:"متن پیام",span:2},{default:s(()=>[a("div",da,p(C.value.automation.message),1)]),_:1})]),_:1}),a("div",ma,[pa,t(ce,{value:F.value,"onUpdate:value":m[5]||(m[5]=_=>F.value=_),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:r},{default:s(()=>[t(j,{value:"sent"},{default:s(()=>[d("ارسال شده")]),_:1}),t(j,{value:"failed"},{default:s(()=>[d("ناموفق")]),_:1}),t(j,{value:"pending"},{default:s(()=>[d("در انتظار")]),_:1}),t(j,{value:"skipped"},{default:s(()=>[d("رد شده")]),_:1}),t(j,{value:"cancelled"},{default:s(()=>[d("لغو شده")]),_:1})]),_:1},8,["value"]),t(ue,{value:M.value,"onUpdate:value":m[6]||(m[6]=_=>M.value=_),placeholder:"جستجو شماره",style:{width:"220px"},onSearch:r},null,8,["value"])]),t(l,le(Q.value,{onRegister:D(g)}),null,16,["onRegister"])],64)):z("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),va=a("div",{class:"flex justify-between items-center mb-4"},[a("h2",null,"پنل پیامکی")],-1),_n=re({__name:"index",setup(e){const o=c("send"),b=c(null),R=c(null);function q(){var g;o.value="campaigns",(g=b.value)==null||g.reload()}return(g,$)=>{const L=He,x=Je,u=Ue;return I(),T("div",null,[t(u,null,{default:s(()=>[va,t(x,{activeKey:o.value,"onUpdate:activeKey":$[0]||($[0]=k=>o.value=k)},{default:s(()=>[t(L,{key:"send",tab:"ارسال پیامک"},{default:s(()=>[t(wt,{onCampaignStarted:q})]),_:1}),t(L,{key:"campaigns",tab:"کمپینهای ارسالی"},{default:s(()=>[t(Kt,{ref_key:"campaignsPanelRef",ref:b},null,512)]),_:1}),t(L,{key:"automations",tab:"اتوماسیونها"},{default:s(()=>[t(_a,{ref_key:"automationsPanelRef",ref:R},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})])}}});export{_n as default};
|