1818<template >
1919 <div class =" form" >
2020 <div class =" form__item" :class =" {'error': domainError}" >
21- <a-spin :spinning =" domainsLoading" >
22- <p class =" form__label" >{{ $t('label.domain') }}<span class =" required" >*</span ></p >
23- <p class =" required required-label" >{{ $t('label.required') }}</p >
24- <a-select
25- style =" width : 100% "
26- showSearch
27- optionFilterProp =" label"
28- :filterOption =" (input, option) => {
29- return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
30- }"
31- @change =" handleChangeDomain"
32- v-focus =" true"
33- v-model:value =" domainId" >
34- <a-select-option
35- v-for =" (domain, index) in domainsList"
36- :value =" domain.id"
37- :key =" index"
38- :label =" domain.path || domain.name || domain.description" >
39- {{ domain.path || domain.name || domain.description }}
40- </a-select-option >
41- </a-select >
42- </a-spin >
21+ <p class =" form__label" >{{ $t('label.domain') }}<span class =" required" >*</span ></p >
22+ <p class =" required required-label" >{{ $t('label.required') }}</p >
23+ <infinite-scroll-select
24+ style =" width : 100% "
25+ v-model:value =" domainId"
26+ api =" listDomains"
27+ :apiParams =" domainsApiParams"
28+ resourceType =" domain"
29+ optionValueKey =" id"
30+ optionLabelKey =" path"
31+ defaultIcon =" block-outlined"
32+ v-focus =" true"
33+ @change-option-value =" handleChangeDomain" />
4334 </div >
44- <div class =" form__item" v-if = " accountsList " >
35+ <div class =" form__item" >
4536 <p class =" form__label" >{{ $t('label.account') }}</p >
46- <a -select
37+ <infinite-scroll -select
4738 style =" width : 100% "
48- @change =" handleChangeAccount"
49- showSearch
50- optionFilterProp =" value"
51- :filterOption =" (input, option) => {
52- return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
53- }" >
54- <a-select-option v-for =" (account, index) in accountsList" :value =" account.name" :key =" index" >
55- {{ account.name }}
56- </a-select-option >
57- </a-select >
39+ v-model:value =" selectedAccount"
40+ api =" listAccounts"
41+ :apiParams =" accountsApiParams"
42+ resourceType =" account"
43+ optionValueKey =" name"
44+ optionLabelKey =" name"
45+ defaultIcon =" team-outlined"
46+ @change-option-value =" handleChangeAccount" />
5847 </div >
5948 </div >
6049</template >
6150
6251<script >
63- import { api } from ' @/api '
52+ import InfiniteScrollSelect from ' @/components/widgets/InfiniteScrollSelect.vue '
6453
6554export default {
6655 name: ' DedicateDomain' ,
56+ components: {
57+ InfiniteScrollSelect
58+ },
6759 props: {
6860 error: {
6961 type: Boolean ,
@@ -72,59 +64,49 @@ export default {
7264 },
7365 data () {
7466 return {
75- domainsLoading: false ,
7667 domainId: null ,
77- accountsList: null ,
78- domainsList: null ,
68+ selectedAccount: null ,
7969 domainError: false
8070 }
8171 },
72+ computed: {
73+ domainsApiParams () {
74+ return {
75+ listall: true ,
76+ details: ' min'
77+ }
78+ },
79+ accountsApiParams () {
80+ if (! this .domainId ) {
81+ return {
82+ listall: true ,
83+ showicon: true
84+ }
85+ }
86+ return {
87+ showicon: true ,
88+ domainid: this .domainId
89+ }
90+ }
91+ },
8292 watch: {
8393 error () {
8494 this .domainError = this .error
8595 }
8696 },
8797 created () {
88- this .fetchData ()
8998 },
9099 methods: {
91- fetchData () {
92- this .domainsLoading = true
93- api (' listDomains' , {
94- listAll: true ,
95- details: ' min'
96- }).then (response => {
97- this .domainsList = response .listdomainsresponse .domain
98-
99- if (this .domainsList [0 ]) {
100- this .domainId = this .domainsList [0 ].id
101- this .handleChangeDomain (this .domainId )
102- }
103- }).catch (error => {
104- this .$notifyError (error)
105- }).finally (() => {
106- this .domainsLoading = false
107- })
108- },
109- fetchAccounts () {
110- api (' listAccounts' , {
111- domainid: this .domainId
112- }).then (response => {
113- this .accountsList = response .listaccountsresponse .account || []
114- if (this .accountsList && this .accountsList .length === 0 ) {
115- this .handleChangeAccount (null )
116- }
117- }).catch (error => {
118- this .$notifyError (error)
119- })
120- },
121- handleChangeDomain (e ) {
122- this .$emit (' domainChange' , e)
100+ handleChangeDomain (domainId ) {
101+ this .domainId = domainId
102+ this .selectedAccount = null
103+ this .$emit (' domainChange' , domainId)
123104 this .domainError = false
124- this . fetchAccounts ()
105+ // InfiniteScrollSelect will auto-reload accounts when apiParams changes
125106 },
126- handleChangeAccount (e ) {
127- this .$emit (' accountChange' , e)
107+ handleChangeAccount (accountName ) {
108+ this .selectedAccount = accountName
109+ this .$emit (' accountChange' , accountName)
128110 }
129111 }
130112}
0 commit comments