Files
one-pipe-system/src/views/asset-management/expiring-assets/index.vue
luo d9d07422a9
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m44s
fix: update some files
2026-08-18 17:36:41 +08:00

412 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<ArtTableFullScreen>
<div class="expiring-assets-page" id="table-full-screen">
<ArtSearchBar
v-model:filter="searchForm"
:items="searchFormItems"
:show-expand="true"
label-width="100px"
@reset="handleReset"
@search="handleSearch"
/>
<ElCard shadow="never" class="art-table-card">
<ArtTableHeader
:columnList="columnOptions"
v-model:columns="columnChecks"
@refresh="handleRefresh"
>
<template #left>
<div class="page-intro">
临期资产 {{ summary.total_count }} 条(卡 {{ summary.card_count }},设备
{{ summary.device_count }}),0-3 天资产优先显示。
</div>
</template>
</ArtTableHeader>
<ArtTable
ref="tableRef"
row-key="asset_id"
:loading="loading"
:data="items"
:currentPage="pagination.currentPage"
:pageSize="pagination.pageSize"
:total="pagination.total"
:marginTop="10"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
>
<template #default>
<ElTableColumn v-for="col in columns" :key="col.prop || col.type" v-bind="col" />
</template>
</ArtTable>
</ElCard>
</div>
</ArtTableFullScreen>
</template>
<script setup lang="ts">
import { h, onMounted, reactive, ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElButton, ElMessage, ElTag } from 'element-plus'
import { AssetService, PackageManageService, ShopService } from '@/api/modules'
import type {
ExpiringAssetItem,
ExpiringAssetSummary,
ExpiringAssetType,
ExpiringAssetQueryParams,
PackageResponse,
ShopResponse
} from '@/types/api'
import type { SearchFormItem } from '@/types'
import { RoutesAlias } from '@/router/routesAlias'
import { useCheckedColumns } from '@/composables/useCheckedColumns'
import { formatDateTime } from '@/utils/business/format'
defineOptions({ name: 'ExpiringAssets' })
const router = useRouter()
const route = useRoute()
const tableRef = ref()
const loading = ref(false)
const shopLoading = ref(false)
const packageLoading = ref(false)
const shopOptions = ref<ShopResponse[]>([])
const packageOptions = ref<PackageResponse[]>([])
const items = ref<ExpiringAssetItem[]>([])
const summary = reactive<ExpiringAssetSummary>({
card_count: 0,
device_count: 0,
total_count: 0,
window_days: 15
})
const searchForm = reactive<ExpiringAssetQueryParams & { expires_range: string[] }>({
asset_type: undefined,
keyword: '',
shop_id: undefined,
package_id: undefined,
days_min: undefined,
days_max: undefined,
expires_from: undefined,
expires_to: undefined,
expires_range: []
})
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const searchFormItems = computed<SearchFormItem[]>(() => [
{
label: '资产类型',
prop: 'asset_type',
type: 'select',
config: { clearable: true, placeholder: '全部' },
options: [
{ label: '物联网卡', value: 'iot_card' },
{ label: '设备', value: 'device' }
]
},
{
label: '关键词',
prop: 'keyword',
type: 'input',
config: { clearable: true, placeholder: '请输入资产标识' }
},
{
label: '店铺',
prop: 'shop_id',
type: 'select',
config: {
clearable: true,
filterable: true,
remote: true,
loading: shopLoading.value,
remoteMethod: (query: string) => searchShops(query),
placeholder: '请选择或搜索店铺'
},
options: () => shopOptions.value.map((shop) => ({ label: shop.shop_name, value: shop.id }))
},
{
label: '套餐',
prop: 'package_id',
type: 'select',
config: {
clearable: true,
filterable: true,
remote: true,
loading: packageLoading.value,
remoteMethod: (query: string) => searchPackages(query),
placeholder: '请选择或搜索套餐'
},
options: () =>
packageOptions.value.map((pkg) => ({
label: `${pkg.package_name} (${pkg.package_code})`,
value: pkg.id
}))
},
{
label: '最小剩余天数',
prop: 'days_min',
type: 'input',
config: {
clearable: true,
type: 'number',
min: 0,
max: 15,
placeholder: '最小天数'
}
},
{
label: '最大剩余天数',
prop: 'days_max',
type: 'input',
config: {
clearable: true,
type: 'number',
min: 0,
max: 15,
placeholder: '最大天数'
}
},
{
label: '预计到期起止',
prop: 'expires_range',
type: 'datetimerange',
config: {
type: 'datetimerange',
rangeSeparator: '至',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间',
valueFormat: 'YYYY-MM-DDTHH:mm:ssZ',
clearable: true
}
}
])
const columnOptions = [
{ label: '资产类型', prop: 'asset_type' },
{ label: '资产标识', prop: 'identifier' },
{ label: '店铺', prop: 'shop_name' },
{ label: '当前套餐', prop: 'package_name' },
{ label: '预计最终到期', prop: 'estimated_final_expires_at' },
{ label: '剩余天数', prop: 'days_until_final_expiry' }
]
const getExpiryClass = (level?: string | null) => {
if (level === 'red') return 'expiry-critical'
if (level === 'purple') return 'expiry-warning'
if (level === 'pink') return 'expiry-notice'
return ''
}
const getExpiryTagType = (level?: string | null) => {
if (level === 'red') return 'danger'
if (level === 'purple') return 'warning'
return 'info'
}
const searchShops = async (query = '') => {
shopLoading.value = true
try {
const response = await ShopService.getShops({
page: 1,
page_size: 20,
shop_name: query || undefined
})
if (response.code === 0) shopOptions.value = response.data.items || []
} finally {
shopLoading.value = false
}
}
const searchPackages = async (query = '') => {
packageLoading.value = true
try {
const response = await PackageManageService.getPackages({
page: 1,
page_size: 20,
package_name: query || undefined
})
if (response.code === 0) packageOptions.value = response.data.items || []
} finally {
packageLoading.value = false
}
}
const { columnChecks, columns } = useCheckedColumns(() => [
{
prop: 'asset_type',
label: '资产类型',
width: 100,
formatter: (row: ExpiringAssetItem) => (row.asset_type === 'iot_card' ? '物联网卡' : '设备')
},
{
prop: 'identifier',
label: '资产标识',
minWidth: 180,
showOverflowTooltip: true,
formatter: (row: ExpiringAssetItem) =>
h(
ElButton,
{
type: 'primary',
link: true,
onClick: () => goToAsset(row)
},
() => row.identifier || '-'
)
},
{
prop: 'shop_name',
label: '店铺',
minWidth: 140,
showOverflowTooltip: true,
formatter: (row: ExpiringAssetItem) => row.shop_name || '-'
},
{
prop: 'package_name',
label: '当前套餐',
minWidth: 160,
showOverflowTooltip: true,
formatter: (row: ExpiringAssetItem) => row.package_name || '-'
},
{
prop: 'estimated_final_expires_at',
label: '预计最终到期',
width: 180,
formatter: (row: ExpiringAssetItem) =>
h(
'span',
{ class: getExpiryClass(row.expiry_level) },
formatDateTime(row.estimated_final_expires_at) || '-'
)
},
{
prop: 'days_until_final_expiry',
label: '剩余天数',
width: 100,
formatter: (row: ExpiringAssetItem) =>
h(ElTag, { type: getExpiryTagType(row.expiry_level), size: 'small' }, () =>
row.days_until_final_expiry == null ? '-' : `${row.days_until_final_expiry}天`
)
}
])
const loadAssets = async () => {
loading.value = true
try {
const toInteger = (value: unknown) => {
if (value === undefined || value === null || value === '') return undefined
const numberValue = Number(value)
return Number.isInteger(numberValue) ? numberValue : undefined
}
const params: ExpiringAssetQueryParams = {
page: pagination.currentPage,
page_size: pagination.pageSize
}
if (searchForm.asset_type) params.asset_type = searchForm.asset_type
const keyword = searchForm.keyword?.trim()
if (keyword) params.keyword = keyword
if (searchForm.shop_id !== undefined && searchForm.shop_id !== null) {
params.shop_id = searchForm.shop_id
}
if (searchForm.package_id !== undefined && searchForm.package_id !== null) {
params.package_id = searchForm.package_id
}
const daysMin = toInteger(searchForm.days_min)
const daysMax = toInteger(searchForm.days_max)
if (daysMin !== undefined) params.days_min = daysMin
if (daysMax !== undefined) params.days_max = daysMax
const [expiresFrom, expiresTo] = searchForm.expires_range || []
if (expiresFrom) params.expires_from = expiresFrom
if (expiresTo) params.expires_to = expiresTo
const response = await AssetService.getExpiringAssets(params)
if (response.code === 0 && response.data) {
items.value = response.data.items || []
pagination.total = response.data.total || 0
Object.assign(summary, response.data.summary)
} else {
ElMessage.error(response.msg || '获取临期资产失败')
}
} catch (error) {
console.error('获取临期资产失败:', error)
ElMessage.error('获取临期资产失败')
} finally {
loading.value = false
}
}
const handleSearch = () => {
pagination.currentPage = 1
void loadAssets()
}
const handleReset = () => {
Object.assign(searchForm, {
asset_type: undefined,
keyword: '',
shop_id: undefined,
package_id: undefined,
days_min: undefined,
days_max: undefined,
expires_from: undefined,
expires_to: undefined,
expires_range: []
})
pagination.currentPage = 1
void loadAssets()
}
const handleRefresh = () => void loadAssets()
const handleSizeChange = (value: number) => {
pagination.pageSize = value
void loadAssets()
}
const handleCurrentChange = (value: number) => {
pagination.currentPage = value
void loadAssets()
}
const goToAsset = (row: ExpiringAssetItem) => {
router.push({
path: RoutesAlias.AssetInformation,
query:
row.asset_type === 'iot_card' ? { iccid: row.identifier } : { virtual_no: row.identifier }
})
}
onMounted(() => {
const assetType = route.query.asset_type
if (assetType === 'card' || assetType === 'iot_card' || assetType === 'device') {
searchForm.asset_type = assetType === 'card' ? 'iot_card' : (assetType as ExpiringAssetType)
}
void Promise.all([loadAssets(), searchShops(), searchPackages()])
})
</script>
<style scoped lang="scss">
.expiring-assets-page {
.page-intro {
color: var(--el-text-color-secondary);
}
.expiry-critical,
.expiry-warning,
.expiry-notice {
font-weight: 600;
}
.expiry-critical {
color: #f56c6c;
}
.expiry-warning {
color: #8e44ad;
}
.expiry-notice {
color: #e83e8c;
}
}
</style>