diff --git a/src/api/enterprise.ts b/src/api/enterprise.ts index d3bbe2f..4c5f324 100644 --- a/src/api/enterprise.ts +++ b/src/api/enterprise.ts @@ -26,6 +26,7 @@ export interface EnterpriseCardsParams { carrier_id?: number // 运营商ID iccid?: string // ICCID (模糊查询) virtual_no?: string // 虚拟号 (模糊查询) + msisdn?: string // 接入号 (模糊查询) } /** @@ -34,7 +35,10 @@ export interface EnterpriseCardsParams { export interface EnterpriseDevicesParams { page?: number page_size?: number + status?: number + device_name?: string // 设备号 / 设备名称 (模糊搜索) virtual_no?: string // 虚拟号 (模糊搜索) + imei?: string // IMEI (模糊搜索) } /** diff --git a/src/components/SimplePicker.vue b/src/components/SimplePicker.vue index f4d9072..5f58e3b 100644 --- a/src/components/SimplePicker.vue +++ b/src/components/SimplePicker.vue @@ -10,6 +10,8 @@ interface Props { show: boolean options: PickerOption[] title?: string + autoConfirm?: boolean + selectedValue?: any } interface Emits { @@ -19,13 +21,42 @@ interface Emits { } const props = withDefaults(defineProps(), { - title: '请选择' + title: '请选择', + autoConfirm: false, }) const emit = defineEmits() const selectedIndex = ref(0) +function syncSelectedIndex() { + if (!props.options.length) { + selectedIndex.value = 0 + return + } + + const matchedIndex = props.options.findIndex(option => option.value === props.selectedValue) + selectedIndex.value = matchedIndex >= 0 ? matchedIndex : 0 +} + +watch(() => props.show, (show) => { + if (show) { + syncSelectedIndex() + } +}, { immediate: true }) + +watch(() => props.selectedValue, () => { + if (props.show) { + syncSelectedIndex() + } +}) + +watch(() => props.options, () => { + if (props.show) { + syncSelectedIndex() + } +}, { deep: true }) + // 关闭弹窗 function close() { emit('update:show', false) @@ -48,6 +79,11 @@ function handleConfirm() { // 选择选项 function selectOption(index: number) { selectedIndex.value = index + + if (props.autoConfirm && props.options[index]) { + emit('confirm', props.options[index]) + close() + } } @@ -69,9 +105,17 @@ function selectOption(index: number) { {{ title }} - + 确定 + diff --git a/src/pages/agent-system/asset-detail/index.vue b/src/pages/agent-system/asset-detail/index.vue index 9554d21..8c204c7 100644 --- a/src/pages/agent-system/asset-detail/index.vue +++ b/src/pages/agent-system/asset-detail/index.vue @@ -454,7 +454,7 @@ - 最后同步 diff --git a/src/pages/agent-system/assets/index.vue b/src/pages/agent-system/assets/index.vue index c292076..b9c5623 100644 --- a/src/pages/agent-system/assets/index.vue +++ b/src/pages/agent-system/assets/index.vue @@ -80,13 +80,54 @@ deviceStart: 'asset:device_start_h5', } as const + type CardSearchType = 'iccid' | 'virtual_no' | 'msisdn' + type DeviceSearchType = 'device_name' | 'virtual_no' | 'imei' + + interface SearchTypeOption { + label : string + value : string + } + + interface StandaloneCardsParams { + page : number + page_size : number + carrier_id ?: number + status ?: number + iccid ?: string + virtual_no ?: string + msisdn ?: string + shop_id ?: number + } + + interface DevicesParams { + page : number + page_size : number + status ?: number + device_name ?: string + virtual_no ?: string + imei ?: string + shop_id ?: number + } + + const cardSearchTypeOptions : SearchTypeOption[] = [ + { label: 'ICCID', value: 'iccid' }, + { label: '虚拟号', value: 'virtual_no' }, + { label: '接入号', value: 'msisdn' }, + ] + + const deviceSearchTypeOptions : SearchTypeOption[] = [ + { label: '设备号', value: 'device_name' }, + { label: '虚拟号', value: 'virtual_no' }, + { label: 'IMEI', value: 'imei' }, + ] + // 获取单卡列表(代理端) - function getStandaloneCards(params : any) { + function getStandaloneCards(params : StandaloneCardsParams) { return get<{ items : CardInfo[], page : number, size : number, total : number }>('/api/admin/iot-cards/standalone', { params }) } // 获取设备列表(代理端) - function getDevices(params : any) { + function getDevices(params : DevicesParams) { return get<{ items : DeviceInfo[], page : number, size : number, total : number }>('/api/admin/devices', { params }) } @@ -131,13 +172,35 @@ const carrierFilter = ref(undefined) const statusFilter = ref(undefined) const selectedShopFilter = ref(null) + const cardSearchType = ref('iccid') + const deviceSearchType = ref('device_name') const showCarrierPicker = ref(false) + const showSearchTypePicker = ref(false) const showStatusPicker = ref(false) const showShopPicker = ref(false) // 运营商列表 const carrierList = ref([]) const isAgent = computed(() => userInfo.value?.user_type === 3) - const searchPlaceholder = computed(() => activeTab.value === 'card' ? '搜索ICCID' : '搜索设备号') + const currentSearchType = computed(() => activeTab.value === 'card' ? cardSearchType.value : deviceSearchType.value) + const searchTypeOptions = computed(() => activeTab.value === 'card' ? cardSearchTypeOptions : deviceSearchTypeOptions) + const selectedSearchTypeLabel = computed(() => { + return searchTypeOptions.value.find(option => option.value === currentSearchType.value)?.label + || (activeTab.value === 'card' ? 'ICCID' : '设备号') + }) + const isDefaultSearchType = computed(() => { + return activeTab.value === 'card' ? cardSearchType.value === 'iccid' : deviceSearchType.value === 'device_name' + }) + const searchPlaceholder = computed(() => { + if (activeTab.value === 'card') { + if (cardSearchType.value === 'virtual_no') return '搜索虚拟号' + if (cardSearchType.value === 'msisdn') return '搜索接入号' + return '搜索ICCID' + } + + if (deviceSearchType.value === 'imei') return '搜索IMEI' + if (deviceSearchType.value === 'virtual_no') return '搜索虚拟号' + return '搜索设备号' + }) const canShowDeviceStopButton = computed(() => hasActionButtonPermission(ASSET_ACTION_BUTTON_CODES.deviceStop)) const canShowDeviceStartButton = computed(() => hasActionButtonPermission(ASSET_ACTION_BUTTON_CODES.deviceStart)) @@ -192,6 +255,34 @@ : 'bg-[#fff7e6] text-[#d46b08]' } + function applyCardSearchKeyword(params : StandaloneCardsParams, keyword : string) { + if (cardSearchType.value === 'virtual_no') { + params.virtual_no = keyword + return + } + + if (cardSearchType.value === 'msisdn') { + params.msisdn = keyword + return + } + + params.iccid = keyword + } + + function applyDeviceSearchKeyword(params : DevicesParams, keyword : string) { + if (deviceSearchType.value === 'imei') { + params.imei = keyword + return + } + + if (deviceSearchType.value === 'device_name') { + params.device_name = keyword + return + } + + params.virtual_no = keyword + } + // 合并后的资产列表 const assetList = computed(() => { const cards : AssetItem[] = cardList.value.map(card => ({ @@ -259,7 +350,7 @@ cardHasMore.value = true } - const params : any = { + const params : StandaloneCardsParams = { page: cardPage.value, page_size: pageSize, } @@ -272,7 +363,7 @@ params.status = statusFilter.value } if (searchKeyword.value.trim()) { - params.iccid = searchKeyword.value.trim() + applyCardSearchKeyword(params, searchKeyword.value.trim()) } if (userInfo.value?.user_type === 3 && selectedShopFilter.value) { params.shop_id = selectedShopFilter.value.id @@ -326,13 +417,13 @@ deviceHasMore.value = true } - const params : any = { + const params : DevicesParams = { page: devicePage.value, page_size: pageSize, } if (searchKeyword.value.trim()) { - params.virtual_no = searchKeyword.value.trim() + applyDeviceSearchKeyword(params, searchKeyword.value.trim()) } if (statusFilter.value !== undefined) { params.status = statusFilter.value @@ -416,6 +507,16 @@ refreshList() } + function onSearchTypeConfirm(option : SearchTypeOption) { + if (activeTab.value === 'card') { + cardSearchType.value = option.value as CardSearchType + } else { + deviceSearchType.value = option.value as DeviceSearchType + } + + refreshList() + } + // 获取当前选中的运营商名称 const selectedCarrierName = computed(() => { if (carrierFilter.value === undefined) return '运营商' @@ -661,6 +762,14 @@ + + + {{ selectedSearchTypeLabel }} + + + + - + + + - +