|
21 | 21 | :placeholder="$t('label.search')" |
22 | 22 | v-model="searchQuery" |
23 | 23 | style="margin-bottom: 10px;" |
24 | | - @search="handleSearch" /> |
| 24 | + @search="fetchData" /> |
25 | 25 | <a-table |
26 | 26 | size="small" |
27 | 27 | style="overflow-y: auto" |
28 | 28 | :loading="loading" |
29 | 29 | :columns="columns" |
30 | | - :dataSource="items" |
| 30 | + :dataSource="hosts" |
31 | 31 | :pagination="false" |
32 | 32 | :rowKey="record => record.id"> |
33 | 33 | <div slot="suitability" slot-scope="record"> |
@@ -95,7 +95,6 @@ export default { |
95 | 95 | return { |
96 | 96 | loading: true, |
97 | 97 | hosts: [], |
98 | | - items: [], |
99 | 98 | selectedHost: {}, |
100 | 99 | searchQuery: '', |
101 | 100 | totalCount: 0, |
@@ -130,34 +129,23 @@ export default { |
130 | 129 | }, |
131 | 130 | methods: { |
132 | 131 | fetchData () { |
133 | | - var page = 1 |
134 | | - const hosts = [] |
135 | | - const getNextPage = () => { |
136 | | - this.loading = true |
137 | | - api('findHostsForMigration', { |
138 | | - virtualmachineid: this.resource.id, |
139 | | - listAll: true, |
140 | | - details: 'min', |
141 | | - page: page, |
142 | | - pageSize: 500 |
143 | | - }).then(response => { |
144 | | - if (response && response.findhostsformigrationresponse && response.findhostsformigrationresponse.host) { |
145 | | - hosts.push(...response.findhostsformigrationresponse.host) |
146 | | - } |
147 | | - if (response.findhostsformigrationresponse.host) { |
148 | | - page++ |
149 | | - getNextPage() |
150 | | - } |
151 | | - }).catch(error => { |
152 | | - this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`) |
153 | | - }).finally(() => { |
154 | | - this.hosts = hosts |
155 | | - this.totalCount = this.hosts.length |
156 | | - this.items = this.hosts.slice(0, Math.min(this.totalCount, this.pageSize)) |
157 | | - this.loading = false |
| 132 | + this.loading = true |
| 133 | + api('findHostsForMigration', { |
| 134 | + virtualmachineid: this.resource.id, |
| 135 | + keyword: this.searchQuery, |
| 136 | + page: this.page, |
| 137 | + pagesize: this.pageSize |
| 138 | + }).then(response => { |
| 139 | + this.hosts = response.findhostsformigrationresponse.host || [] |
| 140 | + this.hosts.sort((a, b) => { |
| 141 | + return b.suitableformigration - a.suitableformigration |
158 | 142 | }) |
159 | | - } |
160 | | - getNextPage() |
| 143 | + this.totalCount = response.findhostsformigrationresponse.count |
| 144 | + }).catch(error => { |
| 145 | + this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`) |
| 146 | + }).finally(() => { |
| 147 | + this.loading = false |
| 148 | + }) |
161 | 149 | }, |
162 | 150 | submitForm () { |
163 | 151 | this.loading = true |
@@ -193,27 +181,15 @@ export default { |
193 | 181 | this.$message.error(`${this.$t('message.migrating.vm.to.host.failed')} ${this.selectedHost.name}`) |
194 | 182 | }) |
195 | 183 | }, |
196 | | - handleSearch () { |
197 | | - this.loading = true |
198 | | - this.page = 1 |
199 | | - this.items = this.hosts.filter(x => x.name.toLowerCase().includes(this.searchQuery)) |
200 | | - this.totalCount = this.items.length |
201 | | - this.items = this.items.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize)) |
202 | | - this.loading = false |
203 | | - }, |
204 | 184 | handleChangePage (page, pageSize) { |
205 | | - this.loading = true |
206 | 185 | this.page = page |
207 | 186 | this.pageSize = pageSize |
208 | | - this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize)) |
209 | | - this.loading = false |
| 187 | + this.fetchData() |
210 | 188 | }, |
211 | 189 | handleChangePageSize (currentPage, pageSize) { |
212 | | - this.loading = true |
213 | 190 | this.page = currentPage |
214 | 191 | this.pageSize = pageSize |
215 | | - this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize)) |
216 | | - this.loading = false |
| 192 | + this.fetchData() |
217 | 193 | } |
218 | 194 | }, |
219 | 195 | filters: { |
|
0 commit comments