SearchBox.vue
3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<template>
<n-drawer display-directive="if" :show="modelShow" :width="502" :placement="placement">
<n-drawer-content title="设备筛选">
<n-space vertical>
<span>组织</span>
<n-tree-select
placement="top-start"
label-field="name"
v-model:value="searchParams.organizationId"
key-field="id"
children-field="children"
:options="originationOption"
/>
<span>产品</span>
<n-select v-model:value="searchParams.deviceProfileIds" :options="deviceProfileOption" />
<span>设备</span>
<n-input v-model:value="searchParams.name" type="text" placeholder="请输入设备名称" />
<span>设备状态</span>
<n-radio-group v-model:value="searchParams.deviceState" name="radiogroup">
<n-space>
<n-radio v-for="(item, index) in deviceStateGroup" :key="index" :value="item.value">
{{ item.label }}
</n-radio>
</n-space>
</n-radio-group>
<span>是否告警</span>
<n-radio-group v-model:value="searchParams.alarmStatus" name="radiogroup">
<n-space>
<n-radio v-for="(item, index) in alarmStatusGroup" :key="index" :value="item.value">
{{ item.label }}
</n-radio>
</n-space>
</n-radio-group>
<span>配置查询分页</span>
<n-space justify="space-between">
<n-input-number :min="1" v-model:value="searchPage.page" clearable />
<n-input-number :step="10" :min="10" v-model:value="searchPage.pageSize" clearable />
</n-space>
</n-space>
<template #footer>
<n-button @click="handleCancel" type="tertiary">取消</n-button>
<div style="visibility: hidden; width: 10px">占位</div>
<n-button @click="handleSubmit" type="success">确定</n-button>
</template>
</n-drawer-content>
</n-drawer>
</template>
<script lang="ts" setup>
import { ref, onMounted, reactive } from 'vue'
import { NTreeSelect } from 'naive-ui'
import { getOrganizationList, getProfileList } from '@/api/external/common/index'
interface searchParamsInterface {
organizationId: string | null
deviceProfileIds: null
name: string
deviceState: string | null
alarmStatus: number
}
defineProps({
modelShow: Boolean
})
const emit = defineEmits(['searchParams', 'closeDrawer'])
const placement = ref('right')
//设备状态
const deviceStateGroup = [
{
label: '全部',
value: null
},
{
label: '待激活',
value: 'INACTIVE'
},
{
label: '在线',
value: 'ONLINE'
},
{
label: '离线',
value: 'OFFLINE'
}
]
//告警状态
const alarmStatusGroup = [
{
label: '是',
value: 1
},
{
label: '否',
value: 0
}
]
const searchPage = reactive<{ page: number; pageSize: number }>({
page: 1,
pageSize: 10
})
const searchParams = reactive<searchParamsInterface>({
organizationId: null,
deviceProfileIds: null,
name: '',
deviceState: null,
alarmStatus: 0
})
const originationOption = ref([])
const deviceProfileOption = ref([])
const loadList = async () => {
const resOrganization = await getOrganizationList()
const resProfileList = await getProfileList()
Promise.all([resOrganization, resProfileList]).then(res => {
originationOption.value = res[0]
deviceProfileOption.value = res[1].map((item: { name: string; tbProfileId: string }) => ({
label: item.name,
value: item.tbProfileId
}))
})
}
const handleSubmit = () => {
searchParams.deviceProfileIds = [searchParams.deviceProfileIds] as any
emit('searchParams', searchPage, searchParams)
handleCancel()
}
const handleCancel = () => {
for (let i in searchParams) Reflect.set(searchParams, i, null)
searchParams.name = ''
searchParams.alarmStatus = 0
searchPage.page = 1
searchPage.pageSize = 10
emit('closeDrawer')
}
onMounted(() => {
loadList()
})
</script>
<style lang="scss" scoped></style>