fetch(add): 订单管理-企业设备
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 3m30s
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 3m30s
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
<ElButton type="warning" :disabled="selectedCards.length === 0" @click="showRecallDialog">
|
||||
批量回收
|
||||
</ElButton>
|
||||
<ElButton type="info" :disabled="selectedCards.length === 0" @click="showSeriesBindingDialog">
|
||||
批量设置套餐系列
|
||||
</ElButton>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
@@ -259,6 +262,75 @@
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 批量设置套餐系列绑定对话框 -->
|
||||
<ElDialog
|
||||
v-model="seriesBindingDialogVisible"
|
||||
title="批量设置套餐系列绑定"
|
||||
width="600px"
|
||||
@close="handleSeriesBindingDialogClose"
|
||||
>
|
||||
<ElForm ref="seriesBindingFormRef" :model="seriesBindingForm" :rules="seriesBindingRules" label-width="120px">
|
||||
<ElFormItem label="已选择卡数">
|
||||
<div>已选择 {{ selectedCards.length }} 张卡</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="套餐系列分配" prop="series_allocation_id">
|
||||
<ElSelect
|
||||
v-model="seriesBindingForm.series_allocation_id"
|
||||
placeholder="请选择套餐系列分配(选择清除关联将解除绑定)"
|
||||
style="width: 100%"
|
||||
:loading="seriesLoading"
|
||||
>
|
||||
<ElOption label="清除关联" :value="0" />
|
||||
<ElOption
|
||||
v-for="series in seriesAllocationList"
|
||||
:key="series.id"
|
||||
:label="`${series.series_name} (${series.shop_name})`"
|
||||
:value="series.id"
|
||||
:disabled="series.status !== 1"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton @click="seriesBindingDialogVisible = false">取消</ElButton>
|
||||
<ElButton type="primary" @click="handleSeriesBinding" :loading="seriesBindingLoading">
|
||||
确认设置
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 套餐系列绑定结果对话框 -->
|
||||
<ElDialog
|
||||
v-model="seriesBindingResultDialogVisible"
|
||||
title="设置结果"
|
||||
width="700px"
|
||||
>
|
||||
<ElDescriptions :column="2" border>
|
||||
<ElDescriptionsItem label="成功数">
|
||||
<ElTag type="success">{{ seriesBindingResult.success_count }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="失败数">
|
||||
<ElTag type="danger">{{ seriesBindingResult.fail_count }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
|
||||
<div v-if="seriesBindingResult.failed_items && seriesBindingResult.failed_items.length > 0" style="margin-top: 20px">
|
||||
<ElDivider content-position="left">失败项详情</ElDivider>
|
||||
<ElTable :data="seriesBindingResult.failed_items" border max-height="300">
|
||||
<ElTableColumn prop="iccid" label="ICCID" width="180" />
|
||||
<ElTableColumn prop="reason" label="失败原因" />
|
||||
</ElTable>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton type="primary" @click="seriesBindingResultDialogVisible = false">确定</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
</ElCard>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
@@ -267,6 +339,7 @@
|
||||
<script setup lang="ts">
|
||||
import { h } from 'vue'
|
||||
import { CardService, StorageService } from '@/api/modules'
|
||||
import { ShopSeriesAllocationService } from '@/api/modules/shopSeriesAllocation'
|
||||
import { ElMessage, ElTag, ElUpload } from 'element-plus'
|
||||
import type { FormInstance, FormRules, UploadProps, UploadUserFile } from 'element-plus'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
@@ -277,8 +350,10 @@
|
||||
StandaloneCardStatus,
|
||||
AllocateStandaloneCardsRequest,
|
||||
RecallStandaloneCardsRequest,
|
||||
AllocateStandaloneCardsResponse
|
||||
AllocateStandaloneCardsResponse,
|
||||
BatchSetCardSeriesBindingResponse
|
||||
} from '@/types/api/card'
|
||||
import type { ShopSeriesAllocationResponse } from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'StandaloneCardList' })
|
||||
|
||||
@@ -306,6 +381,25 @@
|
||||
failed_items: null
|
||||
})
|
||||
|
||||
// 套餐系列绑定相关
|
||||
const seriesBindingDialogVisible = ref(false)
|
||||
const seriesBindingLoading = ref(false)
|
||||
const seriesBindingResultDialogVisible = ref(false)
|
||||
const seriesBindingFormRef = ref<FormInstance>()
|
||||
const seriesLoading = ref(false)
|
||||
const seriesAllocationList = ref<ShopSeriesAllocationResponse[]>([])
|
||||
const seriesBindingForm = reactive({
|
||||
series_allocation_id: undefined as number | undefined
|
||||
})
|
||||
const seriesBindingRules = reactive<FormRules>({
|
||||
series_allocation_id: [{ required: true, message: '请选择套餐系列分配', trigger: 'change' }]
|
||||
})
|
||||
const seriesBindingResult = ref<BatchSetCardSeriesBindingResponse>({
|
||||
success_count: 0,
|
||||
fail_count: 0,
|
||||
failed_items: null
|
||||
})
|
||||
|
||||
// 搜索表单初始值
|
||||
const initialSearchState = {
|
||||
status: undefined,
|
||||
@@ -937,6 +1031,102 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 显示套餐系列绑定对话框
|
||||
const showSeriesBindingDialog = async () => {
|
||||
if (selectedCards.value.length === 0) {
|
||||
ElMessage.warning('请先选择要设置的卡')
|
||||
return
|
||||
}
|
||||
|
||||
// 加载套餐系列分配列表
|
||||
await loadSeriesAllocationList()
|
||||
|
||||
seriesBindingDialogVisible.value = true
|
||||
seriesBindingForm.series_allocation_id = undefined
|
||||
if (seriesBindingFormRef.value) {
|
||||
seriesBindingFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 加载套餐系列分配列表
|
||||
const loadSeriesAllocationList = async () => {
|
||||
seriesLoading.value = true
|
||||
try {
|
||||
const res = await ShopSeriesAllocationService.getShopSeriesAllocations({
|
||||
page: 1,
|
||||
page_size: 1000 // 获取所有可用的套餐系列分配
|
||||
})
|
||||
if (res.code === 0 && res.data.list) {
|
||||
seriesAllocationList.value = res.data.list
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('获取套餐系列分配列表失败')
|
||||
} finally {
|
||||
seriesLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭套餐系列绑定对话框
|
||||
const handleSeriesBindingDialogClose = () => {
|
||||
if (seriesBindingFormRef.value) {
|
||||
seriesBindingFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 执行套餐系列绑定
|
||||
const handleSeriesBinding = async () => {
|
||||
if (!seriesBindingFormRef.value) return
|
||||
|
||||
await seriesBindingFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
const iccids = selectedCards.value.map((card) => card.iccid)
|
||||
|
||||
if (iccids.length === 0) {
|
||||
ElMessage.warning('请先选择要设置的卡')
|
||||
return
|
||||
}
|
||||
|
||||
seriesBindingLoading.value = true
|
||||
try {
|
||||
const res = await CardService.batchSetCardSeriesBinding({
|
||||
iccids,
|
||||
series_allocation_id: seriesBindingForm.series_allocation_id!
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
seriesBindingResult.value = res.data
|
||||
seriesBindingDialogVisible.value = false
|
||||
seriesBindingResultDialogVisible.value = true
|
||||
|
||||
// 清空选择
|
||||
if (tableRef.value) {
|
||||
tableRef.value.clearSelection()
|
||||
}
|
||||
selectedCards.value = []
|
||||
|
||||
// 刷新列表
|
||||
getTableData()
|
||||
|
||||
// 显示消息提示
|
||||
if (res.data.fail_count === 0) {
|
||||
ElMessage.success('套餐系列绑定设置成功')
|
||||
} else if (res.data.success_count === 0) {
|
||||
ElMessage.error('套餐系列绑定设置失败')
|
||||
} else {
|
||||
ElMessage.warning(`部分设置成功:成功 ${res.data.success_count} 项,失败 ${res.data.fail_count} 项`)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('套餐系列绑定设置失败,请重试')
|
||||
} finally {
|
||||
seriesBindingLoading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<ElButton @click="handleBatchRecall" :disabled="!selectedDevices.length">
|
||||
批量回收
|
||||
</ElButton>
|
||||
<ElButton type="info" @click="handleBatchSetSeries" :disabled="!selectedDevices.length">
|
||||
批量设置套餐系列
|
||||
</ElButton>
|
||||
<ElButton @click="handleImportDevice">导入设备</ElButton>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
@@ -177,6 +180,71 @@
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 批量设置套餐系列绑定对话框 -->
|
||||
<ElDialog v-model="seriesBindingDialogVisible" title="批量设置设备套餐系列绑定" width="600px">
|
||||
<ElForm ref="seriesBindingFormRef" :model="seriesBindingForm" :rules="seriesBindingRules" label-width="120px">
|
||||
<ElFormItem label="已选设备数">
|
||||
<span style="color: #409eff; font-weight: bold">{{ selectedDevices.length }}</span> 台
|
||||
</ElFormItem>
|
||||
<ElFormItem label="套餐系列分配" prop="series_allocation_id">
|
||||
<ElSelect
|
||||
v-model="seriesBindingForm.series_allocation_id"
|
||||
placeholder="请选择套餐系列分配(选择清除关联将解除绑定)"
|
||||
style="width: 100%"
|
||||
:loading="seriesLoading"
|
||||
>
|
||||
<ElOption label="清除关联" :value="0" />
|
||||
<ElOption
|
||||
v-for="series in seriesAllocationList"
|
||||
:key="series.id"
|
||||
:label="`${series.series_name} (${series.shop_name})`"
|
||||
:value="series.id"
|
||||
:disabled="series.status !== 1"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<!-- 设置结果 -->
|
||||
<div v-if="seriesBindingResult" style="margin-top: 20px">
|
||||
<ElAlert
|
||||
:type="seriesBindingResult.fail_count === 0 ? 'success' : 'warning'"
|
||||
:closable="false"
|
||||
style="margin-bottom: 10px"
|
||||
>
|
||||
<template #title>
|
||||
成功设置 {{ seriesBindingResult.success_count }} 台,失败 {{ seriesBindingResult.fail_count }} 台
|
||||
</template>
|
||||
</ElAlert>
|
||||
<div v-if="seriesBindingResult.failed_items && seriesBindingResult.failed_items.length > 0">
|
||||
<div style="margin-bottom: 10px; font-weight: bold">失败详情:</div>
|
||||
<div
|
||||
v-for="item in seriesBindingResult.failed_items"
|
||||
:key="item.device_id"
|
||||
style="margin-bottom: 8px; color: #f56c6c; font-size: 12px"
|
||||
>
|
||||
设备号: {{ item.device_no }} - {{ item.reason }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton @click="handleCloseSeriesBindingDialog">
|
||||
{{ seriesBindingResult ? '关闭' : '取消' }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="!seriesBindingResult"
|
||||
type="primary"
|
||||
@click="handleConfirmSeriesBinding"
|
||||
:loading="seriesBindingLoading"
|
||||
>
|
||||
确认设置
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</ElCard>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
@@ -186,19 +254,22 @@
|
||||
import { h } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { DeviceService, ShopService } from '@/api/modules'
|
||||
import { ShopSeriesAllocationService } from '@/api/modules/shopSeriesAllocation'
|
||||
import { ElMessage, ElMessageBox, ElTag, ElSwitch } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import type {
|
||||
Device,
|
||||
DeviceStatus,
|
||||
AllocateDevicesResponse,
|
||||
RecallDevicesResponse
|
||||
RecallDevicesResponse,
|
||||
BatchSetDeviceSeriesBindingResponse
|
||||
} from '@/types/api'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import { CommonStatus, getStatusText } from '@/config/constants'
|
||||
import type { ShopSeriesAllocationResponse } from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'DeviceList' })
|
||||
|
||||
@@ -216,6 +287,20 @@
|
||||
const allocateResult = ref<AllocateDevicesResponse | null>(null)
|
||||
const recallResult = ref<RecallDevicesResponse | null>(null)
|
||||
|
||||
// 套餐系列绑定相关
|
||||
const seriesBindingDialogVisible = ref(false)
|
||||
const seriesBindingLoading = ref(false)
|
||||
const seriesBindingFormRef = ref<FormInstance>()
|
||||
const seriesLoading = ref(false)
|
||||
const seriesAllocationList = ref<ShopSeriesAllocationResponse[]>([])
|
||||
const seriesBindingForm = reactive({
|
||||
series_allocation_id: undefined as number | undefined
|
||||
})
|
||||
const seriesBindingRules = reactive<FormRules>({
|
||||
series_allocation_id: [{ required: true, message: '请选择套餐系列分配', trigger: 'change' }]
|
||||
})
|
||||
const seriesBindingResult = ref<BatchSetDeviceSeriesBindingResponse | null>(null)
|
||||
|
||||
// 搜索表单初始值
|
||||
const initialSearchState = {
|
||||
device_no: '',
|
||||
@@ -665,6 +750,81 @@
|
||||
const handleImportDevice = () => {
|
||||
router.push('/batch/device-import')
|
||||
}
|
||||
|
||||
// 批量设置套餐系列
|
||||
const handleBatchSetSeries = async () => {
|
||||
if (selectedDevices.value.length === 0) {
|
||||
ElMessage.warning('请先选择要设置的设备')
|
||||
return
|
||||
}
|
||||
seriesBindingForm.series_allocation_id = undefined
|
||||
seriesBindingResult.value = null
|
||||
await loadSeriesAllocationList()
|
||||
seriesBindingDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 加载套餐系列分配列表
|
||||
const loadSeriesAllocationList = async () => {
|
||||
seriesLoading.value = true
|
||||
try {
|
||||
const res = await ShopSeriesAllocationService.getShopSeriesAllocations({
|
||||
page: 1,
|
||||
page_size: 1000
|
||||
})
|
||||
if (res.code === 0 && res.data.list) {
|
||||
seriesAllocationList.value = res.data.list
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取套餐系列分配列表失败:', error)
|
||||
ElMessage.error('获取套餐系列分配列表失败')
|
||||
} finally {
|
||||
seriesLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 确认设置套餐系列绑定
|
||||
const handleConfirmSeriesBinding = async () => {
|
||||
if (!seriesBindingFormRef.value) return
|
||||
|
||||
await seriesBindingFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
seriesBindingLoading.value = true
|
||||
try {
|
||||
const data = {
|
||||
device_ids: selectedDevices.value.map((d) => d.id),
|
||||
series_allocation_id: seriesBindingForm.series_allocation_id!
|
||||
}
|
||||
const res = await DeviceService.batchSetDeviceSeriesBinding(data)
|
||||
if (res.code === 0) {
|
||||
seriesBindingResult.value = res.data
|
||||
if (res.data.fail_count === 0) {
|
||||
ElMessage.success('全部设置成功')
|
||||
setTimeout(() => {
|
||||
handleCloseSeriesBindingDialog()
|
||||
getTableData()
|
||||
}, 1500)
|
||||
} else {
|
||||
ElMessage.warning(`部分设置失败,请查看失败详情`)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error('设置套餐系列绑定失败')
|
||||
} finally {
|
||||
seriesBindingLoading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 关闭套餐系列绑定对话框
|
||||
const handleCloseSeriesBindingDialog = () => {
|
||||
seriesBindingDialogVisible.value = false
|
||||
seriesBindingResult.value = null
|
||||
if (seriesBindingFormRef.value) {
|
||||
seriesBindingFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
642
src/views/asset-management/enterprise-devices/index.vue
Normal file
642
src/views/asset-management/enterprise-devices/index.vue
Normal file
@@ -0,0 +1,642 @@
|
||||
<template>
|
||||
<ArtTableFullScreen>
|
||||
<div class="enterprise-devices-page" id="table-full-screen">
|
||||
<!-- 企业信息卡片 -->
|
||||
<ElCard shadow="never" style="margin-bottom: 16px">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>{{ $t('enterpriseDevices.title') }}</span>
|
||||
<ElButton @click="goBack">{{ $t('common.cancel') }}</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">{{
|
||||
$t('enterpriseDevices.buttons.allocateDevices')
|
||||
}}</ElButton>
|
||||
<ElButton
|
||||
type="warning"
|
||||
:disabled="selectedDevices.length === 0"
|
||||
@click="showRecallDialog"
|
||||
>
|
||||
{{ $t('enterpriseDevices.buttons.recallDevices') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
row-key="device_id"
|
||||
:loading="loading"
|
||||
:data="deviceList"
|
||||
: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="$t('enterpriseDevices.dialog.allocateTitle')"
|
||||
width="700px"
|
||||
@close="handleAllocateDialogClose"
|
||||
>
|
||||
<ElForm
|
||||
ref="allocateFormRef"
|
||||
:model="allocateForm"
|
||||
:rules="allocateRules"
|
||||
label-width="120px"
|
||||
>
|
||||
<ElFormItem :label="$t('enterpriseDevices.form.deviceNos')" prop="device_nos">
|
||||
<ElInput
|
||||
v-model="deviceNosText"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
:placeholder="$t('enterpriseDevices.form.deviceNosPlaceholder')"
|
||||
@input="handleDeviceNosChange"
|
||||
/>
|
||||
<div style="color: var(--el-color-info); margin-top: 4px; font-size: 12px">
|
||||
{{
|
||||
$t('enterpriseDevices.form.selectedCount', {
|
||||
count: allocateForm.device_nos?.length || 0
|
||||
})
|
||||
}}
|
||||
</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="$t('enterpriseDevices.form.remark')">
|
||||
<ElInput
|
||||
v-model="allocateForm.remark"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
:placeholder="$t('enterpriseDevices.form.remarkPlaceholder')"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton @click="allocateDialogVisible = false">{{
|
||||
$t('common.cancel')
|
||||
}}</ElButton>
|
||||
<ElButton type="primary" @click="handleAllocate" :loading="allocateLoading">
|
||||
{{ $t('common.confirm') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 撤销授权对话框 -->
|
||||
<ElDialog
|
||||
v-model="recallDialogVisible"
|
||||
:title="$t('enterpriseDevices.dialog.recallTitle')"
|
||||
width="600px"
|
||||
@close="handleRecallDialogClose"
|
||||
>
|
||||
<ElForm ref="recallFormRef" :model="recallForm" :rules="recallRules">
|
||||
<ElFormItem :label="$t('enterpriseDevices.form.selectedDevices')">
|
||||
<div>
|
||||
{{
|
||||
$t('enterpriseDevices.form.selectedCount', {
|
||||
count: selectedDevices.length
|
||||
})
|
||||
}}
|
||||
</div>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton @click="recallDialogVisible = false">{{ $t('common.cancel') }}</ElButton>
|
||||
<ElButton type="primary" @click="handleRecall" :loading="recallLoading">
|
||||
{{ $t('common.confirm') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 结果对话框 -->
|
||||
<ElDialog
|
||||
v-model="resultDialogVisible"
|
||||
:title="$t('enterpriseDevices.dialog.resultTitle')"
|
||||
width="700px"
|
||||
>
|
||||
<ElDescriptions :column="2" border>
|
||||
<ElDescriptionsItem :label="$t('enterpriseDevices.result.successCount')">
|
||||
<ElTag type="success">{{ operationResult.success_count }}</ElTag>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem :label="$t('enterpriseDevices.result.failCount')">
|
||||
<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">{{
|
||||
$t('enterpriseDevices.result.failedItems')
|
||||
}}</ElDivider>
|
||||
<ElTable :data="operationResult.failed_items" border max-height="300">
|
||||
<ElTableColumn
|
||||
prop="device_no"
|
||||
:label="$t('enterpriseDevices.result.deviceNo')"
|
||||
width="180"
|
||||
/>
|
||||
<ElTableColumn prop="reason" :label="$t('enterpriseDevices.result.reason')" />
|
||||
</ElTable>
|
||||
</div>
|
||||
|
||||
<!-- 显示已授权设备 -->
|
||||
<div
|
||||
v-if="
|
||||
operationResult.authorized_devices && operationResult.authorized_devices.length > 0
|
||||
"
|
||||
style="margin-top: 20px"
|
||||
>
|
||||
<ElDivider content-position="left">{{
|
||||
$t('enterpriseDevices.result.authorizedDevices')
|
||||
}}</ElDivider>
|
||||
<ElTable :data="operationResult.authorized_devices" border max-height="200">
|
||||
<ElTableColumn
|
||||
prop="device_no"
|
||||
:label="$t('enterpriseDevices.result.deviceNo')"
|
||||
width="180"
|
||||
/>
|
||||
<ElTableColumn
|
||||
prop="device_id"
|
||||
:label="$t('enterpriseDevices.result.deviceId')"
|
||||
width="100"
|
||||
/>
|
||||
<ElTableColumn :label="$t('enterpriseDevices.result.cardCount')">
|
||||
<template #default="{ row }">
|
||||
{{ row.card_count || 0 }}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton type="primary" @click="resultDialogVisible = false">{{
|
||||
$t('common.confirm')
|
||||
}}</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</ElCard>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { h } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
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 type {
|
||||
EnterpriseDeviceItem,
|
||||
AllocateDevicesResponse,
|
||||
RecallDevicesResponse,
|
||||
AuthorizedDeviceItem,
|
||||
FailedDeviceItem
|
||||
} from '@/types/api/enterpriseDevice'
|
||||
import type { EnterpriseItem } from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'EnterpriseDevices' })
|
||||
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const allocateDialogVisible = ref(false)
|
||||
const allocateLoading = ref(false)
|
||||
const recallDialogVisible = ref(false)
|
||||
const recallLoading = ref(false)
|
||||
const resultDialogVisible = ref(false)
|
||||
const tableRef = ref()
|
||||
const allocateFormRef = ref<FormInstance>()
|
||||
const recallFormRef = ref<FormInstance>()
|
||||
const selectedDevices = ref<EnterpriseDeviceItem[]>([])
|
||||
const enterpriseId = ref<number>(0)
|
||||
const enterpriseInfo = ref<EnterpriseItem | null>(null)
|
||||
const deviceNosText = ref('')
|
||||
const operationResult = ref<AllocateDevicesResponse | RecallDevicesResponse>({
|
||||
success_count: 0,
|
||||
fail_count: 0,
|
||||
failed_items: null,
|
||||
authorized_devices: null
|
||||
})
|
||||
|
||||
// 搜索表单初始值
|
||||
const initialSearchState = {
|
||||
device_no: ''
|
||||
}
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({ ...initialSearchState })
|
||||
|
||||
// 授权表单
|
||||
const allocateForm = reactive({
|
||||
device_nos: [] as string[],
|
||||
remark: ''
|
||||
})
|
||||
|
||||
// 授权表单验证规则
|
||||
const allocateRules = reactive<FormRules>({
|
||||
device_nos: [
|
||||
{
|
||||
required: true,
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value || value.length === 0) {
|
||||
callback(new Error(t('enterpriseDevices.validation.deviceNosRequired')))
|
||||
} else if (value.length > 100) {
|
||||
callback(new Error(t('enterpriseDevices.validation.deviceNosMaxLength')))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// 撤销表单
|
||||
const recallForm = reactive({})
|
||||
|
||||
// 撤销表单验证规则
|
||||
const recallRules = reactive<FormRules>({})
|
||||
|
||||
// 分页
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
total: 0
|
||||
})
|
||||
|
||||
// 搜索表单配置
|
||||
const searchFormItems: SearchFormItem[] = [
|
||||
{
|
||||
label: t('enterpriseDevices.searchForm.deviceNo'),
|
||||
prop: 'device_no',
|
||||
type: 'input',
|
||||
config: {
|
||||
clearable: true,
|
||||
placeholder: t('enterpriseDevices.searchForm.deviceNoPlaceholder')
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
// 列配置
|
||||
const columnOptions = [
|
||||
{ label: t('enterpriseDevices.table.deviceId'), prop: 'device_id' },
|
||||
{ label: t('enterpriseDevices.table.deviceNo'), prop: 'device_no' },
|
||||
{ label: t('enterpriseDevices.table.deviceName'), prop: 'device_name' },
|
||||
{ label: t('enterpriseDevices.table.deviceModel'), prop: 'device_model' },
|
||||
{ label: t('enterpriseDevices.table.cardCount'), prop: 'card_count' },
|
||||
{ label: t('enterpriseDevices.table.authorizedAt'), prop: 'authorized_at' }
|
||||
]
|
||||
|
||||
const deviceList = ref<EnterpriseDeviceItem[]>([])
|
||||
|
||||
// 动态列配置
|
||||
const { columnChecks, columns } = useCheckedColumns(() => [
|
||||
{
|
||||
prop: 'device_id',
|
||||
label: t('enterpriseDevices.table.deviceId'),
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
prop: 'device_no',
|
||||
label: t('enterpriseDevices.table.deviceNo'),
|
||||
minWidth: 150
|
||||
},
|
||||
{
|
||||
prop: 'device_name',
|
||||
label: t('enterpriseDevices.table.deviceName'),
|
||||
minWidth: 150
|
||||
},
|
||||
{
|
||||
prop: 'device_model',
|
||||
label: t('enterpriseDevices.table.deviceModel'),
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
prop: 'card_count',
|
||||
label: t('enterpriseDevices.table.cardCount'),
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
prop: 'authorized_at',
|
||||
label: t('enterpriseDevices.table.authorizedAt'),
|
||||
width: 180,
|
||||
formatter: (row: EnterpriseDeviceItem) =>
|
||||
row.authorized_at ? formatDateTime(row.authorized_at) : '-'
|
||||
}
|
||||
])
|
||||
|
||||
onMounted(() => {
|
||||
const id = route.query.id
|
||||
if (id) {
|
||||
enterpriseId.value = Number(id)
|
||||
getEnterpriseInfo()
|
||||
getTableData()
|
||||
} else {
|
||||
ElMessage.error(t('enterpriseDevices.messages.loadFailed'))
|
||||
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,
|
||||
device_no: searchForm.device_no || undefined
|
||||
}
|
||||
|
||||
// 清理空值
|
||||
Object.keys(params).forEach((key) => {
|
||||
if (params[key] === '' || params[key] === undefined) {
|
||||
delete params[key]
|
||||
}
|
||||
})
|
||||
|
||||
const res = await EnterpriseService.getEnterpriseDevices(enterpriseId.value, params)
|
||||
if (res.code === 0) {
|
||||
deviceList.value = res.data.list || []
|
||||
pagination.total = res.data.total || 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error(t('enterpriseDevices.messages.loadFailed'))
|
||||
} 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: EnterpriseDeviceItem[]) => {
|
||||
selectedDevices.value = selection
|
||||
}
|
||||
|
||||
// 返回
|
||||
const goBack = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 显示授权对话框
|
||||
const showAllocateDialog = () => {
|
||||
allocateDialogVisible.value = true
|
||||
deviceNosText.value = ''
|
||||
allocateForm.device_nos = []
|
||||
allocateForm.remark = ''
|
||||
if (allocateFormRef.value) {
|
||||
allocateFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 处理设备号输入变化
|
||||
const handleDeviceNosChange = () => {
|
||||
// 解析输入的设备号,支持逗号、空格、换行分隔
|
||||
const deviceNos = deviceNosText.value
|
||||
.split(/[,\s\n]+/)
|
||||
.map((no) => no.trim())
|
||||
.filter((no) => no.length > 0)
|
||||
allocateForm.device_nos = deviceNos
|
||||
}
|
||||
|
||||
// 执行授权
|
||||
const handleAllocate = async () => {
|
||||
if (!allocateFormRef.value) return
|
||||
|
||||
await allocateFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
if (allocateForm.device_nos.length === 0) {
|
||||
ElMessage.warning(t('enterpriseDevices.messages.deviceNosEmpty'))
|
||||
return
|
||||
}
|
||||
|
||||
if (allocateForm.device_nos.length > 100) {
|
||||
ElMessage.warning(t('enterpriseDevices.messages.deviceNosMaxLimit'))
|
||||
return
|
||||
}
|
||||
|
||||
allocateLoading.value = true
|
||||
try {
|
||||
const res = await EnterpriseService.allocateDevices(enterpriseId.value, {
|
||||
device_nos: allocateForm.device_nos,
|
||||
remark: allocateForm.remark || undefined
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
operationResult.value = res.data
|
||||
allocateDialogVisible.value = false
|
||||
resultDialogVisible.value = true
|
||||
|
||||
// 显示成功消息
|
||||
if (res.data.success_count > 0 && res.data.fail_count === 0) {
|
||||
ElMessage.success(t('enterpriseDevices.messages.allocateSuccess'))
|
||||
} else if (res.data.success_count > 0 && res.data.fail_count > 0) {
|
||||
ElMessage.warning(
|
||||
t('enterpriseDevices.messages.allocatePartialSuccess', {
|
||||
success: res.data.success_count,
|
||||
fail: res.data.fail_count
|
||||
})
|
||||
)
|
||||
} else {
|
||||
ElMessage.error(t('enterpriseDevices.messages.allocateFailed'))
|
||||
}
|
||||
|
||||
getTableData()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error(t('enterpriseDevices.messages.allocateFailed'))
|
||||
} finally {
|
||||
allocateLoading.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 关闭授权对话框
|
||||
const handleAllocateDialogClose = () => {
|
||||
if (allocateFormRef.value) {
|
||||
allocateFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 显示撤销授权对话框
|
||||
const showRecallDialog = () => {
|
||||
if (selectedDevices.value.length === 0) {
|
||||
ElMessage.warning(t('enterpriseDevices.messages.noSelection'))
|
||||
return
|
||||
}
|
||||
recallDialogVisible.value = true
|
||||
if (recallFormRef.value) {
|
||||
recallFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 执行撤销授权
|
||||
const handleRecall = async () => {
|
||||
if (!recallFormRef.value) return
|
||||
|
||||
ElMessageBox.confirm(
|
||||
t('enterpriseDevices.messages.recallConfirmText', {
|
||||
count: selectedDevices.value.length
|
||||
}),
|
||||
t('enterpriseDevices.messages.recallConfirm'),
|
||||
{
|
||||
confirmButtonText: t('common.confirm'),
|
||||
cancelButtonText: t('common.cancel'),
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
.then(async () => {
|
||||
recallLoading.value = true
|
||||
try {
|
||||
const res = await EnterpriseService.recallDevices(enterpriseId.value, {
|
||||
device_nos: selectedDevices.value.map((device) => device.device_no)
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
operationResult.value = res.data
|
||||
recallDialogVisible.value = false
|
||||
resultDialogVisible.value = true
|
||||
|
||||
// 显示成功消息
|
||||
if (res.data.success_count > 0 && res.data.fail_count === 0) {
|
||||
ElMessage.success(t('enterpriseDevices.messages.recallSuccess'))
|
||||
} else if (res.data.success_count > 0 && res.data.fail_count > 0) {
|
||||
ElMessage.warning(
|
||||
t('enterpriseDevices.messages.recallPartialSuccess', {
|
||||
success: res.data.success_count,
|
||||
fail: res.data.fail_count
|
||||
})
|
||||
)
|
||||
} else {
|
||||
ElMessage.error(t('enterpriseDevices.messages.recallFailed'))
|
||||
}
|
||||
|
||||
// 清空选择
|
||||
if (tableRef.value) {
|
||||
tableRef.value.clearSelection()
|
||||
}
|
||||
selectedDevices.value = []
|
||||
getTableData()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ElMessage.error(t('enterpriseDevices.messages.recallFailed'))
|
||||
} finally {
|
||||
recallLoading.value = false
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
// 关闭撤销授权对话框
|
||||
const handleRecallDialogClose = () => {
|
||||
if (recallFormRef.value) {
|
||||
recallFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.enterprise-devices-page {
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user