This commit is contained in:
795
src/views/account-management/enterprise-cards/index.vue
Normal file
795
src/views/account-management/enterprise-cards/index.vue
Normal file
@@ -0,0 +1,795 @@
|
||||
<template>
|
||||
<ArtTableFullScreen>
|
||||
<div class="enterprise-cards-page" id="table-full-screen">
|
||||
<!-- 企业信息卡片 -->
|
||||
<ElCard shadow="never" style="margin-bottom: 16px">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>企业信息</span>
|
||||
<ElButton @click="goBack">返回</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
<ElDescriptions :column="3" border v-if="enterpriseInfo">
|
||||
<ElDescriptionsItem label="企业名称">{{ enterpriseInfo.enterprise_name }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="企业编号">{{ enterpriseInfo.enterprise_code }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="联系人">{{ enterpriseInfo.contact_name }}</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</ElCard>
|
||||
|
||||
<!-- 搜索栏 -->
|
||||
<ArtSearchBar
|
||||
v-model:filter="searchForm"
|
||||
:items="searchFormItems"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
></ArtSearchBar>
|
||||
|
||||
<ElCard shadow="never" class="art-table-card">
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader
|
||||
:columnList="columnOptions"
|
||||
v-model:columns="columnChecks"
|
||||
@refresh="handleRefresh"
|
||||
>
|
||||
<template #left>
|
||||
<ElButton type="primary" @click="showAllocateDialog">授权卡</ElButton>
|
||||
<ElButton
|
||||
type="warning"
|
||||
:disabled="selectedCards.length === 0"
|
||||
@click="showRecallDialog"
|
||||
>
|
||||
批量回收
|
||||
</ElButton>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
row-key="id"
|
||||
:loading="loading"
|
||||
:data="cardList"
|
||||
:currentPage="pagination.page"
|
||||
:pageSize="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:marginTop="10"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<template #default>
|
||||
<ElTableColumn type="selection" width="55" />
|
||||
<ElTableColumn v-for="col in columns" :key="col.prop || col.type" v-bind="col" />
|
||||
</template>
|
||||
</ArtTable>
|
||||
|
||||
<!-- 授权卡对话框 -->
|
||||
<ElDialog
|
||||
v-model="allocateDialogVisible"
|
||||
title="授权卡给企业"
|
||||
width="700px"
|
||||
@close="handleAllocateDialogClose"
|
||||
>
|
||||
<ElForm ref="allocateFormRef" :model="allocateForm" :rules="allocateRules" label-width="120px">
|
||||
<ElFormItem label="ICCID列表" prop="iccids">
|
||||
<ElInput
|
||||
v-model="iccidsText"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
placeholder="请输入ICCID,每行一个或用逗号分隔"
|
||||
@input="handleIccidsChange"
|
||||
/>
|
||||
<div style="color: var(--el-color-info); margin-top: 4px; font-size: 12px">
|
||||
已输入 {{ allocateForm.iccids?.length || 0 }} 个ICCID
|
||||
</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="确认设备绑定">
|
||||
<ElCheckbox v-model="allocateForm.confirm_device_bundles">
|
||||
我确认已了解设备绑定关系,同意一起授权
|
||||
</ElCheckbox>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<!-- 预检结果 -->
|
||||
<div v-if="previewData" style="margin-top: 20px">
|
||||
<ElDivider content-position="left">预检结果</ElDivider>
|
||||
<ElDescriptions :column="2" border>
|
||||
<ElDescriptionsItem label="待授权卡数">
|
||||
{{ previewData.summary.total_cards }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="可授权卡数">
|
||||
<ElTag type="success">{{ previewData.summary.valid_cards }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="独立卡数">
|
||||
{{ previewData.summary.standalone_cards }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="设备绑定数">
|
||||
<ElTag type="warning">{{ previewData.summary.device_bundles }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="失败数" :span="2">
|
||||
<ElTag type="danger">{{ previewData.summary.failed_cards }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
|
||||
<!-- 失败项详情 -->
|
||||
<div v-if="previewData.failed_items && previewData.failed_items.length > 0" style="margin-top: 16px">
|
||||
<ElAlert title="以下ICCID无法授权" type="error" :closable="false" style="margin-bottom: 8px" />
|
||||
<ElTable :data="previewData.failed_items" border max-height="200">
|
||||
<ElTableColumn prop="iccid" label="ICCID" width="180" />
|
||||
<ElTableColumn prop="reason" label="失败原因" />
|
||||
</ElTable>
|
||||
</div>
|
||||
|
||||
<!-- 设备绑定详情 -->
|
||||
<div v-if="previewData.device_bundles && previewData.device_bundles.length > 0" style="margin-top: 16px">
|
||||
<ElAlert
|
||||
title="以下ICCID与设备绑定,授权后设备也将一起授权给企业"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
style="margin-bottom: 8px"
|
||||
/>
|
||||
<ElTable :data="previewData.device_bundles" border max-height="200">
|
||||
<ElTableColumn prop="device_imei" label="设备IMEI" width="180" />
|
||||
<ElTableColumn label="绑定卡数">
|
||||
<template #default="{ row }">
|
||||
{{ row.iccids?.length || 0 }}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="ICCID列表">
|
||||
<template #default="{ row }">
|
||||
{{ row.iccids?.join(', ') }}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton @click="allocateDialogVisible = false">取消</ElButton>
|
||||
<ElButton @click="handlePreview" :loading="previewLoading">预检</ElButton>
|
||||
<ElButton
|
||||
type="primary"
|
||||
@click="handleAllocate"
|
||||
:loading="allocateLoading"
|
||||
:disabled="!previewData || previewData.summary.valid_cards === 0"
|
||||
>
|
||||
确认授权
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 批量回收对话框 -->
|
||||
<ElDialog
|
||||
v-model="recallDialogVisible"
|
||||
title="批量回收卡授权"
|
||||
width="600px"
|
||||
@close="handleRecallDialogClose"
|
||||
>
|
||||
<ElForm ref="recallFormRef" :model="recallForm" :rules="recallRules">
|
||||
<ElFormItem label="回收卡数">
|
||||
<div>已选择 {{ selectedCards.length }} 张卡</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="回收原因">
|
||||
<ElInput
|
||||
v-model="recallForm.reason"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入回收原因(可选)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton @click="recallDialogVisible = false">取消</ElButton>
|
||||
<ElButton type="primary" @click="handleRecall" :loading="recallLoading">
|
||||
确认回收
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 结果对话框 -->
|
||||
<ElDialog v-model="resultDialogVisible" :title="resultTitle" width="700px">
|
||||
<ElDescriptions :column="2" border>
|
||||
<ElDescriptionsItem label="成功数">
|
||||
<ElTag type="success">{{ operationResult.success_count }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="失败数">
|
||||
<ElTag type="danger">{{ operationResult.fail_count }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
|
||||
<div
|
||||
v-if="operationResult.failed_items && operationResult.failed_items.length > 0"
|
||||
style="margin-top: 20px"
|
||||
>
|
||||
<ElDivider content-position="left">失败项详情</ElDivider>
|
||||
<ElTable :data="operationResult.failed_items" border max-height="300">
|
||||
<ElTableColumn prop="iccid" label="ICCID" width="180" />
|
||||
<ElTableColumn prop="reason" label="失败原因" />
|
||||
</ElTable>
|
||||
</div>
|
||||
|
||||
<!-- 显示授权的设备 -->
|
||||
<div
|
||||
v-if="operationResult.allocated_devices && operationResult.allocated_devices.length > 0"
|
||||
style="margin-top: 20px"
|
||||
>
|
||||
<ElDivider content-position="left">已授权设备</ElDivider>
|
||||
<ElTable :data="operationResult.allocated_devices" border max-height="200">
|
||||
<ElTableColumn prop="device_imei" label="设备IMEI" width="180" />
|
||||
<ElTableColumn label="绑定卡数">
|
||||
<template #default="{ row }">
|
||||
{{ row.iccids?.length || 0 }}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton type="primary" @click="resultDialogVisible = false">确定</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</ElCard>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { h } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { EnterpriseService } from '@/api/modules'
|
||||
import { ElMessage, ElMessageBox, ElTag } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue'
|
||||
import type {
|
||||
EnterpriseCardItem,
|
||||
AllocateCardsPreviewResponse,
|
||||
AllocateCardsResponse,
|
||||
RecallCardsResponse,
|
||||
FailedItem
|
||||
} from '@/types/api/enterpriseCard'
|
||||
import type { EnterpriseItem } from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'EnterpriseCards' })
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const allocateDialogVisible = ref(false)
|
||||
const allocateLoading = ref(false)
|
||||
const previewLoading = ref(false)
|
||||
const recallDialogVisible = ref(false)
|
||||
const recallLoading = ref(false)
|
||||
const resultDialogVisible = ref(false)
|
||||
const resultTitle = ref('')
|
||||
const tableRef = ref()
|
||||
const allocateFormRef = ref<FormInstance>()
|
||||
const recallFormRef = ref<FormInstance>()
|
||||
const selectedCards = ref<EnterpriseCardItem[]>([])
|
||||
const enterpriseId = ref<number>(0)
|
||||
const enterpriseInfo = ref<EnterpriseItem | null>(null)
|
||||
const iccidsText = ref('')
|
||||
const previewData = ref<AllocateCardsPreviewResponse | null>(null)
|
||||
const operationResult = ref<AllocateCardsResponse | RecallCardsResponse>({
|
||||
success_count: 0,
|
||||
fail_count: 0,
|
||||
failed_items: null,
|
||||
allocated_devices: null
|
||||
})
|
||||
|
||||
// 搜索表单初始值
|
||||
const initialSearchState = {
|
||||
iccid: '',
|
||||
msisdn: '',
|
||||
status: undefined as number | undefined,
|
||||
authorization_status: undefined as number | undefined
|
||||
}
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({ ...initialSearchState })
|
||||
|
||||
// 授权表单
|
||||
const allocateForm = reactive({
|
||||
iccids: [] as string[],
|
||||
confirm_device_bundles: false
|
||||
})
|
||||
|
||||
// 授权表单验证规则
|
||||
const allocateRules = reactive<FormRules>({
|
||||
iccids: [
|
||||
{
|
||||
required: true,
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value || value.length === 0) {
|
||||
callback(new Error('请输入至少一个ICCID'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// 回收表单
|
||||
const recallForm = reactive({
|
||||
reason: ''
|
||||
})
|
||||
|
||||
// 回收表单验证规则
|
||||
const recallRules = reactive<FormRules>({})
|
||||
|
||||
// 分页
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
total: 0
|
||||
})
|
||||
|
||||
// 搜索表单配置
|
||||
const searchFormItems: SearchFormItem[] = [
|
||||
{
|
||||
label: 'ICCID',
|
||||
prop: 'iccid',
|
||||
type: 'input',
|
||||
config: {
|
||||
clearable: true,
|
||||
placeholder: '请输入ICCID'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '手机号',
|
||||
prop: 'msisdn',
|
||||
type: 'input',
|
||||
config: {
|
||||
clearable: true,
|
||||
placeholder: '请输入手机号'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '卡状态',
|
||||
prop: 'status',
|
||||
type: 'select',
|
||||
config: {
|
||||
clearable: true,
|
||||
placeholder: '全部'
|
||||
},
|
||||
options: () => [
|
||||
{ label: '激活', value: 1 },
|
||||
{ label: '停机', value: 2 }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '授权状态',
|
||||
prop: 'authorization_status',
|
||||
type: 'select',
|
||||
config: {
|
||||
clearable: true,
|
||||
placeholder: '全部'
|
||||
},
|
||||
options: () => [
|
||||
{ label: '有效', value: 1 },
|
||||
{ label: '已回收', value: 0 }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
// 列配置
|
||||
const columnOptions = [
|
||||
{ label: 'ICCID', prop: 'iccid' },
|
||||
{ label: '手机号', prop: 'msisdn' },
|
||||
{ label: '运营商', prop: 'carrier_name' },
|
||||
{ label: '卡状态', prop: 'status' },
|
||||
{ label: '授权状态', prop: 'authorization_status' },
|
||||
{ label: '授权时间', prop: 'authorized_at' },
|
||||
{ label: '授权人', prop: 'authorizer_name' },
|
||||
{ label: '操作', prop: 'operation' }
|
||||
]
|
||||
|
||||
const cardList = ref<EnterpriseCardItem[]>([])
|
||||
|
||||
// 获取卡状态标签类型
|
||||
const getCardStatusTag = (status: number) => {
|
||||
return status === 1 ? 'success' : 'danger'
|
||||
}
|
||||
|
||||
// 获取卡状态文本
|
||||
const getCardStatusText = (status: number) => {
|
||||
return status === 1 ? '激活' : '停机'
|
||||
}
|
||||
|
||||
// 获取授权状态标签类型
|
||||
const getAuthStatusTag = (status: number) => {
|
||||
return status === 1 ? 'success' : 'info'
|
||||
}
|
||||
|
||||
// 获取授权状态文本
|
||||
const getAuthStatusText = (status: number) => {
|
||||
return status === 1 ? '有效' : '已回收'
|
||||
}
|
||||
|
||||
// 动态列配置
|
||||
const { columnChecks, columns } = useCheckedColumns(() => [
|
||||
{
|
||||
prop: 'iccid',
|
||||
label: 'ICCID',
|
||||
minWidth: 180
|
||||
},
|
||||
{
|
||||
prop: 'msisdn',
|
||||
label: '手机号',
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
prop: 'carrier_name',
|
||||
label: '运营商',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
prop: 'status',
|
||||
label: '卡状态',
|
||||
width: 100,
|
||||
formatter: (row: EnterpriseCardItem) => {
|
||||
return h(ElTag, { type: getCardStatusTag(row.status) }, () => getCardStatusText(row.status))
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: 'authorization_status',
|
||||
label: '授权状态',
|
||||
width: 100,
|
||||
formatter: (row: EnterpriseCardItem) => {
|
||||
return h(
|
||||
ElTag,
|
||||
{ type: getAuthStatusTag(row.authorization_status) },
|
||||
() => getAuthStatusText(row.authorization_status)
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: 'authorized_at',
|
||||
label: '授权时间',
|
||||
width: 180,
|
||||
formatter: (row: EnterpriseCardItem) =>
|
||||
row.authorized_at ? formatDateTime(row.authorized_at) : '-'
|
||||
},
|
||||
{
|
||||
prop: 'authorizer_name',
|
||||
label: '授权人',
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
formatter: (row: EnterpriseCardItem) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
row.status === 2
|
||||
? h(ArtButtonTable, {
|
||||
text: '复机',
|
||||
onClick: () => handleResume(row)
|
||||
})
|
||||
: h(ArtButtonTable, {
|
||||
text: '停机',
|
||||
onClick: () => handleSuspend(row)
|
||||
})
|
||||
])
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
onMounted(() => {
|
||||
const id = route.query.id
|
||||
if (id) {
|
||||
enterpriseId.value = Number(id)
|
||||
getEnterpriseInfo()
|
||||
getTableData()
|
||||
} else {
|
||||
ElMessage.error('缺少企业ID')
|
||||
goBack()
|
||||
}
|
||||
})
|
||||
|
||||
// 获取企业信息
|
||||
const getEnterpriseInfo = async () => {
|
||||
try {
|
||||
const res = await EnterpriseService.getEnterprises({
|
||||
page: 1,
|
||||
page_size: 1,
|
||||
id: enterpriseId.value
|
||||
})
|
||||
if (res.code === 0 && res.data.items && res.data.items.length > 0) {
|
||||
enterpriseInfo.value = res.data.items[0]
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取企业信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取企业卡列表
|
||||
const getTableData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: any = {
|
||||
page: pagination.page,
|
||||
page_size: pagination.pageSize,
|
||||
iccid: searchForm.iccid || undefined,
|
||||
msisdn: searchForm.msisdn || undefined,
|
||||
status: searchForm.status,
|
||||
authorization_status: searchForm.authorization_status
|
||||
}
|
||||
|
||||
// 清理空值
|
||||
Object.keys(params).forEach((key) => {
|
||||
if (params[key] === '' || params[key] === undefined) {
|
||||
delete params[key]
|
||||
}
|
||||
})
|
||||
|
||||
const res = await EnterpriseService.getEnterpriseCards(enterpriseId.value, params)
|
||||
if (res.code === 0) {
|
||||
cardList.value = res.data.items || []
|
||||
pagination.total = res.data.total || 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('获取企业卡列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 重置搜索
|
||||
const handleReset = () => {
|
||||
Object.assign(searchForm, { ...initialSearchState })
|
||||
pagination.page = 1
|
||||
getTableData()
|
||||
}
|
||||
|
||||
// 搜索
|
||||
const handleSearch = () => {
|
||||
pagination.page = 1
|
||||
getTableData()
|
||||
}
|
||||
|
||||
// 刷新表格
|
||||
const handleRefresh = () => {
|
||||
getTableData()
|
||||
}
|
||||
|
||||
// 处理表格分页变化
|
||||
const handleSizeChange = (newPageSize: number) => {
|
||||
pagination.pageSize = newPageSize
|
||||
getTableData()
|
||||
}
|
||||
|
||||
const handleCurrentChange = (newCurrentPage: number) => {
|
||||
pagination.page = newCurrentPage
|
||||
getTableData()
|
||||
}
|
||||
|
||||
// 表格选择变化
|
||||
const handleSelectionChange = (selection: EnterpriseCardItem[]) => {
|
||||
selectedCards.value = selection
|
||||
}
|
||||
|
||||
// 返回
|
||||
const goBack = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 显示授权对话框
|
||||
const showAllocateDialog = () => {
|
||||
allocateDialogVisible.value = true
|
||||
iccidsText.value = ''
|
||||
allocateForm.iccids = []
|
||||
allocateForm.confirm_device_bundles = false
|
||||
previewData.value = null
|
||||
if (allocateFormRef.value) {
|
||||
allocateFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 处理ICCID输入变化
|
||||
const handleIccidsChange = () => {
|
||||
// 解析输入的ICCID,支持逗号、空格、换行分隔
|
||||
const iccids = iccidsText.value
|
||||
.split(/[,\s\n]+/)
|
||||
.map((iccid) => iccid.trim())
|
||||
.filter((iccid) => iccid.length > 0)
|
||||
allocateForm.iccids = iccids
|
||||
// 清除预检结果
|
||||
previewData.value = null
|
||||
}
|
||||
|
||||
// 预检
|
||||
const handlePreview = async () => {
|
||||
if (!allocateFormRef.value) return
|
||||
|
||||
await allocateFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
previewLoading.value = true
|
||||
try {
|
||||
const res = await EnterpriseService.previewAllocateCards(enterpriseId.value, {
|
||||
iccids: allocateForm.iccids
|
||||
})
|
||||
if (res.code === 0) {
|
||||
previewData.value = res.data
|
||||
ElMessage.success('预检完成')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('预检失败')
|
||||
} finally {
|
||||
previewLoading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 执行授权
|
||||
const handleAllocate = async () => {
|
||||
if (!allocateFormRef.value) return
|
||||
|
||||
if (!previewData.value) {
|
||||
ElMessage.warning('请先进行预检')
|
||||
return
|
||||
}
|
||||
|
||||
if (previewData.value.summary.valid_cards === 0) {
|
||||
ElMessage.warning('没有可授权的卡')
|
||||
return
|
||||
}
|
||||
|
||||
// 如果有设备绑定且未确认,提示用户
|
||||
if (
|
||||
previewData.value.device_bundles &&
|
||||
previewData.value.device_bundles.length > 0 &&
|
||||
!allocateForm.confirm_device_bundles
|
||||
) {
|
||||
ElMessage.warning('请确认设备绑定关系')
|
||||
return
|
||||
}
|
||||
|
||||
allocateLoading.value = true
|
||||
try {
|
||||
const res = await EnterpriseService.allocateCards(enterpriseId.value, {
|
||||
iccids: allocateForm.iccids,
|
||||
confirm_device_bundles: allocateForm.confirm_device_bundles || undefined
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
operationResult.value = res.data
|
||||
resultTitle.value = '授权结果'
|
||||
allocateDialogVisible.value = false
|
||||
resultDialogVisible.value = true
|
||||
getTableData()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('授权失败')
|
||||
} finally {
|
||||
allocateLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭授权对话框
|
||||
const handleAllocateDialogClose = () => {
|
||||
if (allocateFormRef.value) {
|
||||
allocateFormRef.value.resetFields()
|
||||
}
|
||||
previewData.value = null
|
||||
}
|
||||
|
||||
// 显示批量回收对话框
|
||||
const showRecallDialog = () => {
|
||||
if (selectedCards.value.length === 0) {
|
||||
ElMessage.warning('请先选择要回收的卡')
|
||||
return
|
||||
}
|
||||
recallDialogVisible.value = true
|
||||
recallForm.reason = ''
|
||||
if (recallFormRef.value) {
|
||||
recallFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 执行批量回收
|
||||
const handleRecall = async () => {
|
||||
if (!recallFormRef.value) return
|
||||
|
||||
await recallFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
recallLoading.value = true
|
||||
try {
|
||||
const res = await EnterpriseService.recallCards(enterpriseId.value, {
|
||||
card_ids: selectedCards.value.map((card) => card.id)
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
operationResult.value = res.data
|
||||
resultTitle.value = '回收结果'
|
||||
recallDialogVisible.value = false
|
||||
resultDialogVisible.value = true
|
||||
// 清空选择
|
||||
if (tableRef.value) {
|
||||
tableRef.value.clearSelection()
|
||||
}
|
||||
selectedCards.value = []
|
||||
getTableData()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('回收失败')
|
||||
} finally {
|
||||
recallLoading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 关闭批量回收对话框
|
||||
const handleRecallDialogClose = () => {
|
||||
if (recallFormRef.value) {
|
||||
recallFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 停机卡
|
||||
const handleSuspend = (row: EnterpriseCardItem) => {
|
||||
ElMessageBox.confirm('确定要停机该卡吗?', '停机卡', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(async () => {
|
||||
try {
|
||||
await EnterpriseService.suspendCard(enterpriseId.value, row.id)
|
||||
ElMessage.success('停机成功')
|
||||
getTableData()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('停机失败')
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
// 复机卡
|
||||
const handleResume = (row: EnterpriseCardItem) => {
|
||||
ElMessageBox.confirm('确定要复机该卡吗?', '复机卡', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'info'
|
||||
})
|
||||
.then(async () => {
|
||||
try {
|
||||
await EnterpriseService.resumeCard(enterpriseId.value, row.id)
|
||||
ElMessage.success('复机成功')
|
||||
getTableData()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('复机失败')
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.enterprise-cards-page {
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user