2 lines
29 KiB
JavaScript
2 lines
29 KiB
JavaScript
import{_ as Ue,v as fe,t as ge,a as Me}from"./AudienceSegmentPicker.vue_vue_type_script_setup_true_lang-3f018cd5.js";import{_ as me}from"./BasicModal.vue_vue_type_style_index_0_lang-dce46cd2.js";import{u as te,_ as pe}from"./useBaseTable-a305524f.js";import{_ as Be}from"./button.vue_vue_type_style_index_0_lang-ae7cb173.js";import{g as Ee}from"./member-cc12ec16.js";import{L as K,d as oe,g as u,h as $e,E as Oe,o as P,c as A,a,b as t,j as L,w as l,e as m,t as p,k as z,F as ve,n as Ne,H as ae,D as g,v as qe,M as Ve,r as Fe}from"./index-64bb19a3.js";import{t as ne}from"./useDataTime-0e280561.js";import{M as ye,_ as Ke}from"./index-557a2985.js";import{C as ce}from"./index-a5e6bc16.js";import{I as de,_ as Ie}from"./index-6f7ee4ee.js";import{I as le}from"./Icon-2a751d73.js";import{S as Re}from"./index-d19de556.js";import{B as Ce}from"./index-7a73a23b.js";import{D as Se,_ as Te}from"./index-f0cd9e38.js";import{S as Pe,a as Ae}from"./index-ff7b0bbe.js";import{T as ie}from"./isSymbol-77db9868.js";import{_ as je}from"./BasicInput.vue_vue_type_style_index_0_lang-3cdf1cab.js";import{_ as He,T as ze}from"./index-fe1cc383.js";import"./dayjs-28193619.js";import"./updateLocale-34973999.js";import"./shallowequal-a3fa20ee.js";import"./_plugin-vue_export-helper-47756888.js";import"./vnode-a1a3bc0f.js";import"./useState-45a66864.js";import"./useMemo-fddb4a7a.js";import"./FormItemContext-78515ae9.js";import"./omit-41b1cee4.js";import"./index-bc659f42.js";import"./lodash-17ce3880.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-6148f843.js";import"./index-304c1b28.js";import"./Badge-6baddd17.js";import"./isNumeric-3f69e2aa.js";import"./index-2a5be533.js";import"./index-b5f90115.js";import"./index-d5b53aee.js";import"./DialogWrap-c12b3672.js";import"./pickAttrs-ff8c51c6.js";import"./styleChecker-44a60ba7.js";import"./index-4ee722bc.js";import"./index-95a0af99.js";import"./css-aae66f86.js";import"./SearchOutlined-5a638563.js";import"./toArray-156bc105.js";import"./isPlainObject-908a4d4b.js";import"./isMobile-e2e89480.js";import"./usePrice-bc935b83.js";import"./useRefs-10844536.js";import"./_flatRest-6bd9fe69.js";const xe=async e=>(await K.post("/admin/sms/preview",e)).data,Je=async e=>(await K.post("/admin/sms/test",e)).data,he=async e=>(await K.post("/admin/sms/campaigns/start",e)).data,Xe=async e=>{var _;const o=await K.get("/admin/sms/campaigns",{params:{page:e.page,limit:e.limit,search:e.search}}),b=e.page||1,C=e.limit||20,B=(b-1)*C;return{rows:(o.data||[]).map((y,k)=>({...y,index:B+k})),total:o.total??((_=o.data)==null?void 0:_.length)??0,query:{...e,total:o.total??0,page:b,limit:C}}},be=async(e,o)=>(await K.get(`/admin/sms/campaigns/${e}`,{params:o})).data,Ge=async e=>{const o=await K.get("/admin/sms/automations"),b=e.page||1,C=e.limit||20,B=(b-1)*C,_=o.data||[];return{rows:_.map((y,k)=>({...y,index:B+k})),total:o.total??_.length,query:{...e,total:o.total??_.length,page:b,limit:C}}},we=async(e,o)=>(await K.patch(`/admin/sms/automations/${e}`,o)).data,ke=async(e,o)=>(await K.get(`/admin/sms/automations/${e}/sends`,{params:o})).data,Qe=async(e,o)=>(await K.post(`/admin/sms/automations/${e}/test`,{phone:o})).data,We=[{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?ne(e.record.created_at):"-"}],Ye={class:"grid grid-cols-1 xl:grid-cols-3 gap-4 mb-4"},Ze={class:"xl:col-span-2 space-y-4"},et=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),tt={class:"flex flex-wrap gap-4 items-center"},at={class:"flex flex-wrap gap-2"},nt={class:"bg-gray-50 rounded-lg p-4 border border-gray-200 space-y-2 text-sm"},st=a("div",{class:"font-semibold text-gray-700 mb-2"},"خلاصه ارسال",-1),lt={key:0},it={key:0,class:"text-amber-600 mt-1"},ot={key:1,class:"text-gray-500"},rt={key:2,class:"pt-2 border-t border-gray-200"},ut=a("div",{class:"font-medium mb-1"},"نمونه گیرندگان:",-1),ct={class:"space-y-1 text-xs text-gray-600"},dt={key:3,class:"pt-2 border-t border-gray-200"},mt=a("div",{class:"font-medium mb-1"},"آخرین کمپین:",-1),pt={class:"text-blue-600 mt-1"},vt={class:"border-t border-gray-200 pt-4"},_t=a("div",{class:"mb-2 text-sm text-gray-600"}," کاربران را فیلتر کنید و گیرندگان مورد نظر را انتخاب کنید. فقط کاربرانی که شماره موبایل دارند نمایش داده میشوند. ",-1),ft={class:"space-y-3"},gt=a("div",{class:"mb-1 text-sm text-gray-600"},"شماره موبایل",-1),yt=a("div",{class:"text-xs text-gray-500"}," متن پیامک از باکس اصلی استفاده میشود. ",-1),xt=oe({__name:"SendPanel",emits:["campaign-started"],setup(e,{emit:o}){const{TextArea:b}=de,[C,B]=te(),_=u(""),y=u(!0),k=u(!0),c=u(null),I=u(!1),f=u(!1),$=u(null),D=u(!1),S=u(""),V=u(!1),R=u([]),w=u({}),E=u({segments:[],inactiveDays:7,subscriberInactiveDays:3}),O=u(!1),N=u(""),X=$e(()=>({selectedRowKeys:R.value,onChange:i=>{R.value=i.map(String)},preserveSelectedRowKeys:!0})),G=u({columns:We,api:async i=>{const n={...i,filters:[...i.filters||[],{field:"phone",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}]};return y.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"),w.value=n,Ee(n)},defaultPageLimit:20,height:"45vh"});Oe(y,()=>{c.value=null,B()});function j(i){var n;return{message:_.value.trim(),appendAppName:k.value,registrationComplete:y.value,search:w.value.search||void 0,filters:(n=w.value.filters)==null?void 0:n.filter(s=>!s.hidden),sort:w.value.sort||void 0,order:w.value.order||void 0,mode:i,userIds:i==="selected"?R.value:void 0}}async function Q(){var i,n;if(!_.value.trim()){g.warning("ابتدا متن پیامک را وارد کنید");return}I.value=!0;try{c.value=await xe(j("filtered"))}catch(s){g.error(((n=(i=s==null?void 0:s.response)==null?void 0:i.data)==null?void 0:n.error)||"خطا در پیشنمایش")}finally{I.value=!1}}async function W(){var i,n;if(!_.value.trim()){g.warning("متن پیامک الزامی است");return}if(!S.value.trim()){g.warning("شماره موبایل الزامی است");return}V.value=!0;try{await Je({...j("filtered"),phone:S.value.trim()}),g.success("پیامک تستی ارسال شد"),D.value=!1}catch(s){g.error(((n=(i=s==null?void 0:s.response)==null?void 0:i.data)==null?void 0:n.error)||"ارسال تستی ناموفق بود")}finally{V.value=!1}}async function H(i){if(!_.value.trim()){g.warning("متن پیامک الزامی است");return}if(i==="selected"&&!R.value.length){g.warning("حداقل یک کاربر انتخاب کنید");return}const n=i==="selected"?`آیا از ارسال پیامک به ${R.value.length} کاربر انتخابشده مطمئن هستید؟`:"آیا از ارسال پیامک به همه کاربران فیلترشده مطمئن هستید؟";return new Promise(s=>{ye.confirm({title:"تأیید ارسال پیامک",content:n,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var r,x;f.value=!0,$.value=null;try{const d=await he(j(i));$.value=d,o("campaign-started",d.campaignId),g.success(`کمپین #${d.campaignId} با ${d.totalRecipients} گیرنده در پسزمینه ارسال میشود`)}catch(d){g.error(((x=(r=d==null?void 0:d.response)==null?void 0:r.data)==null?void 0:x.error)||"شروع کمپین ناموفق بود")}finally{f.value=!1,s()}},onCancel:()=>s()})})}function J(){return H("selected")}function Y(){return H("filtered")}async function Z(){var s,r;if(!_.value.trim()){g.warning("ابتدا متن پیامک را وارد کنید");return}const i={...E.value,includeUserIds:R.value},n=fe(i);if(n){g.warning(n);return}O.value=!0,N.value="";try{const x=ge(i),d=await xe({message:_.value.trim(),appendAppName:k.value,registrationComplete:y.value,mode:"segment",...x}),T=recipients.length>MAX_SMS_RECIPIENTS;c.value=d;const v=R.value.length>0?` (+ ${R.value.length.toLocaleString("fa-IR")} کاربر از جدول)`:"";N.value=d.cappedAt?`گیرندگان این دستهها: ${d.totalRecipients.toLocaleString("fa-IR")} شماره${v} — در ارسال حداکثر ${d.cappedAt.toLocaleString("fa-IR")} نفر`:`گیرندگان این دستهها: ${d.totalRecipients.toLocaleString("fa-IR")} شماره${v}`}catch(x){g.error(((r=(s=x==null?void 0:x.response)==null?void 0:s.data)==null?void 0:r.error)||"خطا در پیشنمایش")}finally{O.value=!1}}async function ee(){if(!_.value.trim()){g.warning("متن پیامک الزامی است");return}const i={...E.value,includeUserIds:R.value},n=fe(i);if(n){g.warning(n);return}const s=E.value.segments.length,r=R.value.length,x=r>0?`ارسال به ${s} دسته (OR) بهعلاوه ${r} کاربر انتخابشده؟`:`ارسال به ${s} دسته مخاطب (اتحاد / OR)؟`;return new Promise(d=>{ye.confirm({title:"تأیید ارسال پیامک",content:x,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var T,v;f.value=!0,$.value=null;try{const q=ge(i),U=await he({message:_.value.trim(),appendAppName:k.value,registrationComplete:y.value,mode:"segment",...q});$.value=U,o("campaign-started",U.campaignId),g.success(`کمپین #${U.campaignId} با ${U.totalRecipients} گیرنده در پسزمینه ارسال میشود`)}catch(q){g.error(((v=(T=q==null?void 0:q.response)==null?void 0:T.data)==null?void 0:v.error)||"شروع کمپین ناموفق بود")}finally{f.value=!1,d()}},onCancel:()=>d()})})}return(i,n)=>{var d,T;const s=Be,r=pe,x=me;return P(),A("div",null,[a("div",Ye,[a("div",Ze,[a("div",null,[et,t(L(b),{value:_.value,"onUpdate:value":n[0]||(n[0]=v=>_.value=v),placeholder:"متن پیامک را وارد کنید...",rows:6,maxlength:1e3,"show-count":""},null,8,["value"])]),a("div",tt,[t(L(ce),{checked:y.value,"onUpdate:checked":n[1]||(n[1]=v=>y.value=v)},{default:l(()=>[m(" فقط کاربران با ثبتنام کامل (نام و نام خانوادگی) ")]),_:1},8,["checked"]),t(L(ce),{checked:k.value,"onUpdate:checked":n[2]||(n[2]=v=>k.value=v)},{default:l(()=>[m(" افزودن نام اپلیکیشن به انتهای پیام ")]),_:1},8,["checked"])]),a("div",at,[t(s,{loading:I.value,onClick:Q},{default:l(()=>[m(" پیشنمایش گیرندگان ")]),_:1},8,["loading"]),t(s,{onClick:n[3]||(n[3]=v=>D.value=!0)},{default:l(()=>[m(" ارسال تست ")]),_:1}),t(s,{type:"primary",loading:f.value,disabled:!_.value.trim(),onClick:J},{default:l(()=>[m(" ارسال به انتخابشدهها ("+p(R.value.length)+") ",1)]),_:1},8,["loading","disabled"]),t(s,{type:"primary",ghost:"",loading:f.value,disabled:!_.value.trim(),onClick:Y},{default:l(()=>[m(" ارسال به همه فیلترشدهها ")]),_:1},8,["loading","disabled"])]),t(Ue,{modelValue:E.value,"onUpdate:modelValue":n[4]||(n[4]=v=>E.value=v),"include-user-count":R.value.length,"preview-loading":O.value,sending:f.value,disabled:!_.value.trim(),"preview-text":N.value,onPreview:Z,onSend:ee},null,8,["modelValue","include-user-count","preview-loading","sending","disabled","preview-text"])]),a("div",nt,[st,c.value?(P(),A("div",lt,[a("div",null,[m("تعداد گیرنده: "),a("strong",null,p(c.value.totalRecipients),1)]),a("div",null,[m("شماره یکتا: "),a("strong",null,p(c.value.uniquePhones),1)]),a("div",null,[m("پارت پیامک (هر نفر): "),a("strong",null,p(c.value.smsPartsPerRecipient),1)]),a("div",null,[m("تخمین کل پارت: "),a("strong",null,p(c.value.estimatedTotalParts),1)]),c.value.cappedAt?(P(),A("div",it," حداکثر "+p(c.value.cappedAt)+" گیرنده در هر ارسال ",1)):z("",!0)])):(P(),A("div",ot," برای مشاهده تعداد گیرندگان، پیشنمایش بگیرید. ")),(T=(d=c.value)==null?void 0:d.samples)!=null&&T.length?(P(),A("div",rt,[ut,a("ul",ct,[(P(!0),A(ve,null,Ne(c.value.samples,v=>(P(),A("li",{key:v.id},p(v.first_name)+" "+p(v.last_name)+" — "+p(v.phone),1))),128))])])):z("",!0),$.value?(P(),A("div",dt,[mt,a("div",null,[m("کمپین: "),a("strong",null,"#"+p($.value.campaignId),1)]),a("div",null,[m("گیرندگان: "),a("strong",null,p($.value.totalRecipients),1)]),a("div",pt,p($.value.message),1)])):z("",!0)])]),a("div",vt,[_t,t(r,ae(G.value,{"row-selection":X.value,onRegister:L(C)}),null,16,["row-selection","onRegister"])]),t(x,{visible:D.value,"onUpdate:visible":n[6]||(n[6]=v=>D.value=v),title:"ارسال پیامک تست",onOk:W,onCancel:n[7]||(n[7]=v=>D.value=!1),"confirm-loading":V.value},{default:l(()=>[a("div",ft,[a("div",null,[gt,t(L(de),{value:S.value,"onUpdate:value":n[5]||(n[5]=v=>S.value=v),placeholder:"مثال: 09123456789"},null,8,["value"])]),yt])]),_:1},8,["visible","confirm-loading"])])}}}),ht={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق"},bt={selected:"انتخابشده",filtered:"فیلترشده",segment:"دسته مخاطب"},wt=[{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 b=(o.sent_count||0)+(o.failed_count||0),C=Math.round(b/o.total_recipients*100);return`${b}/${o.total_recipients} (${C}%)`}},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1},{title:"نوع ارسال",dataIndex:"send_mode",key:"send_mode",filterable:!1,customRender:e=>bt[e.record.send_mode]||e.record.send_mode},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>ht[e.record.status]||e.record.status},{title:"تاریخ",dataIndex:"created_at",key:"created_at",filterable:!1,customRender:e=>e.record.created_at?ne(e.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],kt={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق"},$t=[{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=>kt[e.record.status]||e.record.status},{title:"زمان ارسال",dataIndex:"sent_at",key:"sent_at",filterable:!1,customRender:e=>e.record.sent_at?ne(e.record.sent_at):"-"},{title:"خطا",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],It={key:0,class:"mb-3 text-sm text-blue-600 flex items-center gap-2"},Rt=a("span",null,"یک یا چند کمپین در حال ارسال است — جدول هر ۵ ثانیه بهروز میشود.",-1),Ct={class:"gap-2 flex justify-center"},St=a("span",null,"جزئیات کمپین",-1),Tt={class:"text-green-600"},Pt={class:"text-red-600"},At={key:0,class:"text-gray-500 mr-2"},Lt={class:"whitespace-pre-wrap text-sm"},Dt={class:"flex flex-wrap gap-2 items-center mb-3"},Ut=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت گیرندگان:",-1),Mt=oe({__name:"CampaignsPanel",setup(e,{expose:o}){const[b,C]=te(),[B,_]=te(),y=u(!1),k=u(!1),c=u(null),I=u(null),f=u(),$=u(""),D=u(!1);let S=null;const V={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق"},R={selected:"انتخابشده",filtered:"فیلترشده",segment:"دسته مخاطب"},w=u({columns:wt,api:O,defaultPageLimit:20,height:"55vh"}),E=$e(()=>{var n;if(!((n=c.value)!=null&&n.campaign))return 0;const i=c.value.campaign;return Math.max(i.total_recipients-i.sent_count-i.failed_count,0)});async function O(i){const n=await Xe(i);return D.value=n.rows.some(s=>s.status==="sending"),n}const N=u({columns:$t,api:j,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});function X(i){return V[i]||i}function se(i){return R[i]||i}function G(i){return i?ne(i):"-"}async function j(i){if(!I.value)return{rows:[],total:0,query:{...i,total:0}};const n=await be(I.value,{page:i.page,limit:i.limit,status:f.value,search:$.value||i.search||void 0});c.value=n;const s=i.page||1,r=i.limit||20,x=(s-1)*r;return{rows:n.recipients.rows.map((d,T)=>({...d,index:x+T})),total:n.recipients.total,query:{...i,total:n.recipients.total,page:s,limit:r}}}async function Q(i){k.value=!0;try{I.value=i,c.value=await be(i,{page:1,limit:20,status:f.value,search:$.value||void 0}),await _()}finally{k.value=!1}}function W(i){f.value=void 0,$.value="",y.value=!0,Q(i.id)}function H(){y.value=!1,c.value=null,I.value=null}function J(){_()}function Y(){C()}function Z(){S||(S=setInterval(()=>{var i;C(),y.value&&I.value&&((i=c.value)==null?void 0:i.campaign.status)==="sending"&&_()},5e3))}function ee(){S&&(clearInterval(S),S=null)}return qe(()=>{Z()}),Ve(()=>{ee()}),o({reload:Y}),(i,n)=>{const s=Re,r=pe,x=Ce,d=Se,T=Te,v=Pe,q=Ae,U=Ie,re=me;return P(),A("div",null,[D.value?(P(),A("div",It,[t(s,{size:"small"}),Rt])):z("",!0),t(r,ae(w.value,{onRegister:L(b)}),{action:l(({record:M})=>[a("div",Ct,[t(L(ie),{class:"cursor-pointer"},{title:l(()=>[St]),default:l(()=>[t(le,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:_e=>W(M)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),t(re,{visible:y.value,"onUpdate:visible":n[2]||(n[2]=M=>y.value=M),title:"جزئیات کمپین پیامکی","custom-footer":"",width:"90%",onClose:H},{footer:l(()=>[t(x,{onClick:H},{default:l(()=>[m("بستن")]),_:1})]),default:l(()=>[t(s,{spinning:k.value},{default:l(()=>[c.value?(P(),A(ve,{key:0},[t(T,{bordered:"",column:2,size:"small",class:"mb-4"},{default:l(()=>[t(d,{label:"شناسه کمپین"},{default:l(()=>[m("#"+p(c.value.campaign.id),1)]),_:1}),t(d,{label:"وضعیت"},{default:l(()=>[m(p(X(c.value.campaign.status)),1)]),_:1}),t(d,{label:"تعداد گیرندگان"},{default:l(()=>[m(p(c.value.campaign.total_recipients),1)]),_:1}),t(d,{label:"موفق / ناموفق"},{default:l(()=>[a("span",Tt,p(c.value.campaign.sent_count),1),m(" / "),a("span",Pt,p(c.value.campaign.failed_count),1),c.value.campaign.status==="sending"?(P(),A("span",At," ("+p(E.value)+" در انتظار) ",1)):z("",!0)]),_:1}),t(d,{label:"نوع ارسال"},{default:l(()=>[m(p(se(c.value.campaign.send_mode)),1)]),_:1}),t(d,{label:"تاریخ ایجاد"},{default:l(()=>[m(p(G(c.value.campaign.created_at)),1)]),_:1}),t(d,{label:"ایجادکننده",span:2},{default:l(()=>[m(p(c.value.campaign.created_by_admin_name||"-"),1)]),_:1}),t(d,{label:"متن پیام",span:2},{default:l(()=>[a("div",Lt,p(c.value.campaign.message),1)]),_:1})]),_:1}),a("div",Dt,[Ut,t(q,{value:f.value,"onUpdate:value":n[0]||(n[0]=M=>f.value=M),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:J},{default:l(()=>[t(v,{value:"sent"},{default:l(()=>[m("ارسال شده")]),_:1}),t(v,{value:"failed"},{default:l(()=>[m("ناموفق")]),_:1}),t(v,{value:"pending"},{default:l(()=>[m("در انتظار")]),_:1})]),_:1},8,["value"]),t(U,{value:$.value,"onUpdate:value":n[1]||(n[1]=M=>$.value=M),placeholder:"جستجو نام یا شماره",style:{width:"220px"},onSearch:J},null,8,["value"])]),t(r,ae(N.value,{onRegister:L(B)}),null,16,["onRegister"])],64)):z("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),Bt=[{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"}],Et={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق",cancelled:"لغو شده",skipped:"رد شده"},Ot=[{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=>Et[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?ne(e.record.sent_at):"-"},{title:"توضیح",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],Nt=a("p",{class:"text-sm text-gray-500 mb-4"}," اتوماسیونهای پیامکی کدوبلو. متن و فعال بودن را میتوانید تغییر دهید؛ شرط ارسال در سیستم ثابت است. ",-1),qt={class:"gap-2 flex justify-center"},Vt=a("span",null,"ویرایش",-1),Ft=a("span",null,"آمار ارسال",-1),Kt=a("span",null,"ارسال تست",-1),jt={class:"space-y-4"},Ht=a("div",{class:"mb-1 text-sm text-gray-600"},"نام",-1),zt={class:"font-medium"},Jt=a("div",{class:"mb-1 text-sm text-gray-600"},"شرط ارسال",-1),Xt={class:"text-sm text-gray-700 whitespace-pre-wrap"},Gt=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),Qt={class:"space-y-3"},Wt={class:"text-sm text-gray-600"},Yt={class:"text-green-600"},Zt={class:"text-red-600"},ea={class:"text-gray-500"},ta=a("span",{class:"text-xs text-gray-400 mr-2"},"(موفق / ناموفق / لغو)",-1),aa={class:"whitespace-pre-wrap text-sm"},na={class:"flex flex-wrap gap-2 items-center mb-3"},sa=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت:",-1),la=oe({__name:"AutomationsPanel",setup(e,{expose:o}){const{TextArea:b}=de,[C,B]=te(),[_,y]=te(),k=u({columns:Bt,api:Ge,defaultPageLimit:20,height:"55vh",showOptionHeader:!1}),c=u(!1),I=u(null),f=Fe({message:"",is_active:!0}),$=u(!1),D=u(null),S=u(""),V=u(!1),R=u(!1),w=u(null),E=u(null),O=u(),N=u(""),X=u({columns:Ot,api:Y,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});async function se(s,r){if(s.is_active===r)return;const x=s.is_active;s.is_active=r;try{await we(s.id,{is_active:r}),g.success(r?"اتوماسیون فعال شد":"اتوماسیون غیرفعال شد")}catch{s.is_active=x,g.error("تغییر وضعیت ناموفق بود")}}function G(s){I.value=s,f.message=s.message||"",f.is_active=s.is_active!==!1,c.value=!0}function j(){c.value=!1,I.value=null}async function Q(){if(I.value){if(!f.message.trim()){g.error("متن پیامک الزامی است");return}try{await we(I.value.id,{message:f.message.trim(),is_active:f.is_active}),g.success("اتوماسیون ذخیره شد"),j(),await B()}catch{g.error("ذخیره ناموفق بود")}}}function W(s){D.value=s,S.value="",$.value=!0}function H(){$.value=!1,D.value=null,S.value=""}async function J(){if(!D.value)return;const s=S.value.trim();if(!s){g.error("شماره موبایل الزامی است");return}try{await Qe(D.value.id,s),g.success("پیامک تست ارسال شد"),H()}catch{g.error("ارسال تست ناموفق بود")}}async function Y(s){if(!E.value)return{rows:[],total:0,query:{...s,total:0}};const r=await ke(E.value,{page:s.page,limit:s.limit,status:O.value,search:N.value||s.search||void 0});w.value=r;const x=s.page||1,d=s.limit||20,T=(x-1)*d;return{rows:r.sends.rows.map((v,q)=>({...v,index:T+q})),total:r.sends.total,query:{...s,total:r.sends.total,page:x,limit:d}}}async function Z(s){R.value=!0;try{E.value=s,w.value=await ke(s,{page:1,limit:20,status:O.value,search:N.value||void 0}),await y()}finally{R.value=!1}}function ee(s){O.value=void 0,N.value="",V.value=!0,Z(s.id)}function i(){V.value=!1,w.value=null,E.value=null}function n(){y()}return o({reload:B}),(s,r)=>{const x=Ke,d=pe,T=me,v=je,q=Ce,U=Se,re=Te,M=Pe,_e=Ae,Le=Ie,De=Re;return P(),A("div",null,[Nt,t(d,ae(k.value,{onRegister:L(C)}),{is_active:l(({record:h})=>[t(x,{checked:h.is_active,onChange:F=>se(h,F)},null,8,["checked","onChange"])]),action:l(({record:h})=>[a("div",qt,[t(L(ie),{class:"cursor-pointer"},{title:l(()=>[Vt]),default:l(()=>[t(le,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:F=>G(h)},null,8,["onClick"])]),_:2},1024),t(L(ie),{class:"cursor-pointer"},{title:l(()=>[Ft]),default:l(()=>[t(le,{icon:"vuesax-linear:eye",color:"#059669",onClick:F=>ee(h)},null,8,["onClick"])]),_:2},1024),t(L(ie),{class:"cursor-pointer"},{title:l(()=>[Kt]),default:l(()=>[t(le,{icon:"vuesax-linear:sms",color:"#7C3AED",onClick:F=>W(h)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),t(T,{visible:c.value,"onUpdate:visible":r[2]||(r[2]=h=>c.value=h),title:"ویرایش اتوماسیون",width:"640px",onOk:Q,onCancel:j},{default:l(()=>{var h,F;return[a("div",jt,[a("div",null,[Ht,a("div",zt,p((h=I.value)==null?void 0:h.name),1)]),a("div",null,[Jt,a("div",Xt,p((F=I.value)==null?void 0:F.trigger_summary),1)]),a("div",null,[Gt,t(L(b),{value:f.message,"onUpdate:value":r[0]||(r[0]=ue=>f.message=ue),rows:5,placeholder:"متن پیامک"},null,8,["value"])]),a("div",null,[t(L(ce),{checked:f.is_active,"onUpdate:checked":r[1]||(r[1]=ue=>f.is_active=ue)},{default:l(()=>[m("فعال")]),_:1},8,["checked"])])])]}),_:1},8,["visible"]),t(T,{visible:$.value,"onUpdate:visible":r[4]||(r[4]=h=>$.value=h),title:"ارسال تست اتوماسیون",width:"480px",onOk:J,onCancel:H},{default:l(()=>{var h;return[a("div",Qt,[a("div",Wt," متن فعلی «"+p((h=D.value)==null?void 0:h.name)+"» به شماره زیر ارسال میشود. ",1),t(v,{value:S.value,"onUpdate:value":r[3]||(r[3]=F=>S.value=F),placeholder:"09xxxxxxxxx"},null,8,["value"])])]}),_:1},8,["visible"]),t(T,{visible:V.value,"onUpdate:visible":r[7]||(r[7]=h=>V.value=h),title:"آمار ارسال اتوماسیون","custom-footer":"",width:"90%",onClose:i},{footer:l(()=>[t(q,{onClick:i},{default:l(()=>[m("بستن")]),_:1})]),default:l(()=>[t(De,{spinning:R.value},{default:l(()=>[w.value?(P(),A(ve,{key:0},[t(re,{bordered:"",column:2,size:"small",class:"mb-4"},{default:l(()=>[t(U,{label:"نام"},{default:l(()=>[m(p(w.value.automation.name),1)]),_:1}),t(U,{label:"کد"},{default:l(()=>[m(p(w.value.automation.code),1)]),_:1}),t(U,{label:"وضعیت"},{default:l(()=>[m(p(w.value.automation.is_active?"فعال":"غیرفعال"),1)]),_:1}),t(U,{label:"آمار کلی"},{default:l(()=>[a("span",Yt,p(w.value.automation.sent_count),1),m(" / "),a("span",Zt,p(w.value.automation.failed_count),1),m(" / "),a("span",ea,p(w.value.automation.cancelled_count),1),ta]),_:1}),t(U,{label:"شرط",span:2},{default:l(()=>[m(p(w.value.automation.trigger_summary),1)]),_:1}),t(U,{label:"متن پیام",span:2},{default:l(()=>[a("div",aa,p(w.value.automation.message),1)]),_:1})]),_:1}),a("div",na,[sa,t(_e,{value:O.value,"onUpdate:value":r[5]||(r[5]=h=>O.value=h),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:n},{default:l(()=>[t(M,{value:"sent"},{default:l(()=>[m("ارسال شده")]),_:1}),t(M,{value:"failed"},{default:l(()=>[m("ناموفق")]),_:1}),t(M,{value:"pending"},{default:l(()=>[m("در انتظار")]),_:1}),t(M,{value:"skipped"},{default:l(()=>[m("رد شده")]),_:1}),t(M,{value:"cancelled"},{default:l(()=>[m("لغو شده")]),_:1})]),_:1},8,["value"]),t(Le,{value:N.value,"onUpdate:value":r[6]||(r[6]=h=>N.value=h),placeholder:"جستجو شماره",style:{width:"220px"},onSearch:n},null,8,["value"])]),t(d,ae(X.value,{onRegister:L(_)}),null,16,["onRegister"])],64)):z("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),ia=a("div",{class:"flex justify-between items-center mb-4"},[a("h2",null,"پنل پیامکی")],-1),an=oe({__name:"index",setup(e){const o=u("send"),b=u(null),C=u(null);function B(){var _;o.value="campaigns",(_=b.value)==null||_.reload()}return(_,y)=>{const k=He,c=ze,I=Me;return P(),A("div",null,[t(I,null,{default:l(()=>[ia,t(c,{activeKey:o.value,"onUpdate:activeKey":y[0]||(y[0]=f=>o.value=f)},{default:l(()=>[t(k,{key:"send",tab:"ارسال پیامک"},{default:l(()=>[t(xt,{onCampaignStarted:B})]),_:1}),t(k,{key:"campaigns",tab:"کمپینهای ارسالی"},{default:l(()=>[t(Mt,{ref_key:"campaignsPanelRef",ref:b},null,512)]),_:1}),t(k,{key:"automations",tab:"اتوماسیونها"},{default:l(()=>[t(la,{ref_key:"automationsPanelRef",ref:C},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})])}}});export{an as default};
|