Files
boursecu_admin/src/pages/menuPages/sms/index.vue
T

148 lines
3.8 KiB
Vue
Raw Normal View History

2026-01-24 17:45:54 +03:30
<template>
<div>
<BasicMainCard>
<div class="flex w-full h-full">
<tbl ref="table" class="w-full h-full" @add="add" />
</div>
</BasicMainCard>
2026-05-31 11:51:52 +03:30
<BasicActionSheet
v-model:visible="addSMSVisible"
title="ارسال پیامک"
modal-width="80vw"
drawer-height="90vh"
:loading="loading"
:showButton="true"
:showCancel="true"
:showOk="true"
2026-08-16 20:01:54 +03:30
ok-text="شروع ارسال"
2026-05-31 11:51:52 +03:30
cancel-text="انصراف"
2026-01-24 17:45:54 +03:30
@ok="ok"
2026-05-31 11:51:52 +03:30
@close="closeSmsSheet"
@cancel="closeSmsSheet"
2026-01-24 17:45:54 +03:30
>
2026-05-31 11:51:52 +03:30
<div v-if="isMobile" class="mb-3 text-base font-700">ارسال پیامک</div>
2026-08-16 20:01:54 +03:30
<a-alert
class="mb-3"
type="warning"
show-icon
message="ارسال ۱۰تایی انجام می‌شود. تا پایان کار پنل را نبندید و صفحه را رفرش نکنید."
/>
2026-08-16 20:27:13 +03:30
<SmsEditorFormBody ref="smsEditorRef" :form="form" :group-items="groupItems" :loading="loading" />
2026-05-31 11:51:52 +03:30
</BasicActionSheet>
2026-01-24 17:45:54 +03:30
</div>
</template>
<script setup lang="ts">
2026-08-16 20:01:54 +03:30
import { ref, watch } from 'vue'
2026-01-24 17:45:54 +03:30
import tbl from './components/table.vue'
import type { FormInstance } from 'ant-design-vue'
2026-05-31 11:51:52 +03:30
import BasicActionSheet from '@/components/BasicActionSheet.vue'
import SmsEditorFormBody from './components/SmsEditorFormBody.vue'
2026-01-24 17:45:54 +03:30
import { message } from 'ant-design-vue/es'
import type { FunctionItem } from '@/model/Item'
2026-08-16 20:01:54 +03:30
import { getGroupsList } from '@/api/sms'
2026-01-24 17:45:54 +03:30
import type { Sms } from '@/model/sms'
2026-05-31 11:51:52 +03:30
import { isMobile } from '@core/utils/is'
2026-08-16 20:01:54 +03:30
import { groupSmsEnabledSetting, initWalletSettingsFromApi } from '@/utils/config'
import { useGroupSmsSendStore } from '@/store/groupSmsSendStore'
2026-01-24 17:45:54 +03:30
const loading = ref<boolean>(false)
const groupItems = ref<FunctionItem[]>()
2026-05-31 11:51:52 +03:30
const table = ref<null | { fetch: () => void }>(null)
const smsEditorRef = ref<{
validateFields?: () => ReturnType<NonNullable<FormInstance['validateFields']>>
resetAll?: () => void
}>()
2026-08-16 20:01:54 +03:30
const sendStore = useGroupSmsSendStore()
2026-05-31 11:51:52 +03:30
const form = ref<Sms>({
message: '',
2026-08-16 20:27:13 +03:30
numbers: []
2026-05-31 11:51:52 +03:30
})
const addSMSVisible = ref<boolean>(false)
2026-01-24 17:45:54 +03:30
2026-08-16 20:01:54 +03:30
onMounted(() => {
void initWalletSettingsFromApi()
getGroups()
})
watch(
() => sendStore.finished,
(finished) => {
if (finished) refreshTable()
}
)
2026-01-24 17:45:54 +03:30
async function getGroups() {
try {
loading.value = true
groupItems.value = await getGroupsList()
} catch (e) {
2026-05-31 11:51:52 +03:30
console.error(e)
2026-01-24 17:45:54 +03:30
} finally {
loading.value = false
}
}
2026-05-31 11:51:52 +03:30
function refreshTable() {
table.value?.fetch()
2026-01-24 17:45:54 +03:30
}
2026-05-31 11:51:52 +03:30
function closeSmsSheet() {
2026-08-16 20:01:54 +03:30
if (loading.value) return
2026-05-31 11:51:52 +03:30
addSMSVisible.value = false
2026-01-24 17:45:54 +03:30
}
async function add() {
2026-08-16 20:01:54 +03:30
if (!groupSmsEnabledSetting.value) {
message.warning('ارسال پیامک گروهی غیرفعال است')
return
}
if (sendStore.active) {
message.info('یک ارسال گروهی در حال انجام است')
sendStore.expand()
return
}
2026-01-24 17:45:54 +03:30
addSMSVisible.value = true
resetData()
}
2026-05-31 11:51:52 +03:30
function resetData() {
2026-01-24 17:45:54 +03:30
form.value = {
message: '',
2026-08-16 20:27:13 +03:30
numbers: []
2026-01-24 17:45:54 +03:30
}
2026-05-31 11:51:52 +03:30
smsEditorRef.value?.resetAll?.()
2026-01-24 17:45:54 +03:30
}
2026-08-16 20:01:54 +03:30
function uniqueNumbers(list: string[]): string[] {
return Array.from(new Set(list.map((n) => String(n).trim()).filter(Boolean)))
}
2026-01-24 17:45:54 +03:30
function ok() {
2026-08-16 20:01:54 +03:30
if (sendStore.active) {
message.warning('ارسال قبلی هنوز تمام نشده است')
return
}
2026-05-31 11:51:52 +03:30
smsEditorRef.value?.validateFields?.().then(async () => {
2026-08-16 20:27:13 +03:30
const numbers = uniqueNumbers([...(form.value.numbers ?? [])])
2026-08-16 20:01:54 +03:30
if (!numbers.length) {
2026-08-16 20:27:13 +03:30
message.warning('حداقل یک مشتری از لیست انتخاب کنید')
2026-08-16 20:01:54 +03:30
return
2026-01-24 17:45:54 +03:30
}
2026-08-16 20:01:54 +03:30
if (!form.value.message?.trim()) {
message.warning('متن پیامک خالی است')
return
}
const text = form.value.message
addSMSVisible.value = false
resetData()
await sendStore.start(numbers, text)
2026-01-24 17:45:54 +03:30
})
}
</script>