修复bug
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 11m14s

This commit is contained in:
sexygoat
2026-04-08 10:19:25 +08:00
parent ff087abd44
commit b510b4539f
55 changed files with 2274 additions and 2612 deletions

View File

@@ -75,16 +75,73 @@
v-model="createForm.old_asset_type"
placeholder="请选择旧资产类型"
style="width: 100%"
@change="handleOldAssetTypeChange"
>
<ElOption label="IoT卡" value="iot_card" />
<ElOption label="设备" value="device" />
</ElSelect>
</ElFormItem>
<ElFormItem label="旧资产标识符" prop="old_identifier">
<ElInput
<ElFormItem
v-if="createForm.old_asset_type === 'iot_card'"
label="旧资产标识符"
prop="old_identifier"
>
<ElSelect
v-model="createForm.old_identifier"
placeholder="请输入ICCID/虚拟号/IMEI/SN"
/>
filterable
remote
reserve-keyword
placeholder="请输入ICCID搜索"
:remote-method="searchOldIotCards"
:loading="oldCardSearchLoading"
style="width: 100%"
clearable
>
<ElOption
v-for="card in oldIotCardOptions"
:key="card.id"
:label="`${card.iccid} (${card.msisdn || '无接入号'})`"
:value="card.iccid"
>
<div style="display: flex; justify-content: space-between">
<span>{{ card.iccid }}</span>
<span style="font-size: 12px; color: var(--el-text-color-secondary)">
{{ card.msisdn || '无接入号' }}
</span>
</div>
</ElOption>
</ElSelect>
</ElFormItem>
<ElFormItem
v-if="createForm.old_asset_type === 'device'"
label="旧资产标识符"
prop="old_identifier"
>
<ElSelect
v-model="createForm.old_identifier"
filterable
remote
reserve-keyword
placeholder="请输入虚拟号或IMEI搜索"
:remote-method="searchOldDevices"
:loading="oldDeviceSearchLoading"
style="width: 100%"
clearable
>
<ElOption
v-for="device in oldDeviceOptions"
:key="device.id"
:label="`${device.virtual_no} (${device.device_name || device.imei})`"
:value="device.virtual_no"
>
<div style="display: flex; justify-content: space-between">
<span>{{ device.virtual_no }}</span>
<span style="font-size: 12px; color: var(--el-text-color-secondary)">
{{ device.device_name || device.imei }}
</span>
</div>
</ElOption>
</ElSelect>
</ElFormItem>
<ElFormItem label="备注">
<ElInput
@@ -129,7 +186,7 @@
</ElFormItem>
<ElFormItem label="是否迁移数据">
<ElSwitch v-model="shipForm.migrate_data" />
<div style=" margin-top: 4px;font-size: 12px; color: #909399">
<div style="margin-top: 4px; font-size: 12px; color: #909399">
开启后将迁移钱包余额、套餐记录到新资产
</div>
</ElFormItem>
@@ -152,8 +209,9 @@
<script setup lang="ts">
import { h } from 'vue'
import { useRouter } from 'vue-router'
import { ExchangeService } from '@/api/modules'
import { ExchangeService, CardService, DeviceService } from '@/api/modules'
import type { ExchangeResponse } from '@/api/modules/exchange'
import type { StandaloneIotCard, Device } from '@/types/api'
import { ElMessage, ElTag, ElButton, ElMessageBox, ElSwitch } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import type { SearchFormItem } from '@/types'
@@ -208,9 +266,15 @@
const createRules = reactive<FormRules>({
exchange_reason: [{ required: true, message: '请输入换货原因', trigger: 'blur' }],
old_asset_type: [{ required: true, message: '请选择旧资产类型', trigger: 'change' }],
old_identifier: [{ required: true, message: '请输入旧资产标识符', trigger: 'blur' }]
old_identifier: [{ required: true, message: '请选择旧资产标识符', trigger: 'change' }]
})
// 旧资产搜索相关
const oldIotCardOptions = ref<StandaloneIotCard[]>([])
const oldCardSearchLoading = ref(false)
const oldDeviceOptions = ref<Device[]>([])
const oldDeviceSearchLoading = ref(false)
// 发货表单
const shipForm = reactive({
new_identifier: '',
@@ -311,7 +375,7 @@
prop: 'new_asset_identifier',
label: '新资产标识符',
width: 180,
formatter: (row: any) => row.new_asset_identifier || '--'
formatter: (row: any) => row.new_asset_identifier
},
{
prop: 'status',
@@ -327,8 +391,8 @@
}
])
const getStatusType = (status: number) => {
const types: Record<number, string> = {
const getStatusType = (status: number): 'success' | 'info' | 'warning' | 'danger' | 'primary' => {
const types: Record<number, 'success' | 'info' | 'warning' | 'danger' | 'primary'> = {
1: 'warning',
2: 'info',
3: 'primary',
@@ -363,7 +427,7 @@
const res = await ExchangeService.getExchanges(params)
if (res.code === 0 && res.data) {
exchangeList.value = res.data.list || []
exchangeList.value = res.data.items || []
pagination.total = res.data.total || 0
}
} catch (error) {
@@ -406,6 +470,123 @@
createDialogVisible.value = true
}
// 旧资产类型变更
const handleOldAssetTypeChange = async () => {
// 清空旧资产标识符
createForm.old_identifier = ''
oldIotCardOptions.value = []
oldDeviceOptions.value = []
// 根据类型加载默认数据
if (createForm.old_asset_type === 'iot_card') {
await loadDefaultIotCards()
} else if (createForm.old_asset_type === 'device') {
await loadDefaultDevices()
}
}
// 加载默认IoT卡列表
const loadDefaultIotCards = async () => {
oldCardSearchLoading.value = true
try {
const res = await CardService.getStandaloneIotCards({
page: 1,
page_size: 10
})
if (res.code === 0 && res.data) {
oldIotCardOptions.value = res.data.items || []
if (oldIotCardOptions.value.length === 0) {
ElMessage.info('暂无可用的IoT卡')
}
}
} catch (error) {
console.error('加载IoT卡列表失败:', error)
oldIotCardOptions.value = []
} finally {
oldCardSearchLoading.value = false
}
}
// 加载默认设备列表
const loadDefaultDevices = async () => {
oldDeviceSearchLoading.value = true
try {
const res = await DeviceService.getDevices({
page: 1,
page_size: 10
})
if (res.code === 0 && res.data) {
oldDeviceOptions.value = res.data.items || []
if (oldDeviceOptions.value.length === 0) {
ElMessage.info('暂无可用的设备')
}
}
} catch (error) {
console.error('加载设备列表失败:', error)
oldDeviceOptions.value = []
} finally {
oldDeviceSearchLoading.value = false
}
}
// 搜索旧IoT卡
const searchOldIotCards = async (query: string) => {
if (!query) {
// 如果清空搜索,加载默认列表
await loadDefaultIotCards()
return
}
oldCardSearchLoading.value = true
try {
const res = await CardService.getStandaloneIotCards({
iccid: query,
page: 1,
page_size: 20
})
if (res.code === 0 && res.data) {
oldIotCardOptions.value = res.data.items || []
if (oldIotCardOptions.value.length === 0) {
ElMessage.info('未找到匹配的IoT卡')
}
}
} catch (error) {
console.error('搜索IoT卡失败:', error)
oldIotCardOptions.value = []
} finally {
oldCardSearchLoading.value = false
}
}
// 搜索旧设备
const searchOldDevices = async (query: string) => {
if (!query) {
// 如果清空搜索,加载默认列表
await loadDefaultDevices()
return
}
oldDeviceSearchLoading.value = true
try {
const res = await DeviceService.getDevices({
keyword: query,
page: 1,
page_size: 20
})
if (res.code === 0 && res.data) {
oldDeviceOptions.value = res.data.items || []
if (oldDeviceOptions.value.length === 0) {
ElMessage.info('未找到匹配的设备')
}
}
} catch (error) {
console.error('搜索设备失败:', error)
oldDeviceOptions.value = []
} finally {
oldDeviceSearchLoading.value = false
}
}
// 确认创建
const handleConfirmCreate = () => {
createFormRef.value?.validate(async (valid) => {
@@ -417,7 +598,7 @@
if (res.code === 0) {
ElMessage.success('换货单创建成功')
createDialogVisible.value = false
loadExchangeList()
await loadExchangeList()
}
} catch (error) {
console.error('创建换货单失败:', error)
@@ -430,6 +611,9 @@
// 关闭创建对话框
const handleCloseCreateDialog = () => {
createFormRef.value?.resetFields()
// 清空搜索选项
oldIotCardOptions.value = []
oldDeviceOptions.value = []
}
// 查看详情
@@ -492,7 +676,7 @@
})
// 处理右键菜单
const handleRowContextMenu = (row: ExchangeResponse, column: any, event: MouseEvent) => {
const handleRowContextMenu = (row: ExchangeResponse, _column: any, event: MouseEvent) => {
event.preventDefault()
event.stopPropagation()
currentExchangeRow.value = row
@@ -531,7 +715,7 @@
const res = await ExchangeService.cancelExchange(row.id, { remark: value })
if (res.code === 0) {
ElMessage.success('取消成功')
loadExchangeList()
await loadExchangeList()
}
} catch (error) {
console.error('取消换货失败:', error)
@@ -562,7 +746,7 @@
if (res.code === 0) {
ElMessage.success('发货成功')
shipDialogVisible.value = false
loadExchangeList()
await loadExchangeList()
}
} catch (error) {
console.error('发货失败:', error)
@@ -589,7 +773,7 @@
const res = await ExchangeService.completeExchange(row.id)
if (res.code === 0) {
ElMessage.success('操作成功')
loadExchangeList()
await loadExchangeList()
}
} catch (error) {
console.error('确认完成失败:', error)
@@ -610,7 +794,7 @@
const res = await ExchangeService.renewExchange(row.id)
if (res.code === 0) {
ElMessage.success('操作成功')
loadExchangeList()
await loadExchangeList()
}
} catch (error) {
console.error('旧资产转新失败:', error)