@@ -8,6 +8,7 @@ export default {
88 cities : [ ] ,
99 items : [ ] ,
1010 isLoading : true ,
11+ searchLoading : false ,
1112 time : null
1213 } ,
1314 mutations : {
@@ -17,6 +18,7 @@ export default {
1718 } ,
1819 SET_ITEM_CITY ( state , payload ) {
1920 state . items = payload ;
21+ state . searchLoading = false ;
2022 } ,
2123 UNSET_CITY ( state ) {
2224 state . cities = [ ] ;
@@ -68,11 +70,10 @@ export default {
6870 dispatch ( 'GET_WEATHER_CITY' , response . data )
6971 }
7072 } )
71- . catch ( error => console . error ( error ) )
73+ // eslint-disable-next-line
74+ . catch ( error => console . error ( error . message ) )
7275 } ) ;
7376 } else {
74- /* eslint-disable */
75- console . error ( "геолокация НЕдоступна" ) ;
7677 alert ( "Геолокация Не доступна" )
7778 }
7879 } else {
@@ -112,35 +113,41 @@ export default {
112113 time : time ,
113114 pressure : `${ res . Pressure . Metric . Value } мм рт. ст.`
114115 } ;
116+ commit ( 'SET_CITY' , city )
115117 } )
116- . catch ( error => console . error ( error ) )
117- commit ( 'SET_CITY' , city )
118+ // eslint-disable-next-line
119+ . catch ( error => console . error ( error . message ) )
118120 } ,
119- SEARCH_CITY ( { commit } , payload ) {
121+ SEARCH_CITY ( { commit, state } , payload ) {
122+ state . searchLoading = true ;
120123 let url = `https://dataservice.accuweather.com/locations/v1/cities/autocomplete?apikey=${
121124 key . weather
122125 } &q=${ payload . searchText } &language=ru-ru`;
123126 let items = [ ]
124127 let cities = { } ;
125- axios . get ( url ) . then ( response => {
126- if ( response . data . length > 0 ) {
127- response . data . forEach ( el => {
128+ axios . get ( url )
129+ . then ( response => {
130+ if ( response . data . length > 0 ) {
131+ response . data . forEach ( el => {
132+ cities = {
133+ country : el . Country . LocalizedName ,
134+ city : el . LocalizedName ,
135+ Key : el . Key
136+ } ;
137+ items . push ( cities ) ;
138+ } ) ;
139+ } else {
128140 cities = {
129- country : el . Country . LocalizedName ,
130- city : el . LocalizedName ,
131- Key : el . Key
141+ city : "Ничего не найдено" ,
132142 } ;
133- items . push ( cities ) ;
134- } ) ;
135- } else {
136- cities = {
137- city : "Ничего не найдено" ,
138- } ;
139- items . push ( cities )
140- }
141- } ) ;
142- commit ( 'SET_ITEM_CITY' , items )
143+ items . push ( cities )
144+ }
145+ commit ( 'SET_ITEM_CITY' , items )
146+ } )
147+ // eslint-disable-next-line
148+ . catch ( error => console . error ( error . message ) )
143149 } ,
150+ // eslint-disable-next-line
144151 GET_WEATHER_FORECAST ( { commit } , payload ) {
145152 moment . locale ( 'ru' ) ;
146153 let arr = [ ] ;
@@ -163,49 +170,8 @@ export default {
163170 arr . push ( obj )
164171 } )
165172 } )
166- . catch ( error => console . error ( error ) )
167- // let arr = [
168- // {
169- // date: "24 июня",
170- // dayIcon: 6, // Day.Icon
171- // dayIconText: "Преимущественно облачно", // Day.IconPhrase
172- // tempDay: "8° C",// Temperature.Maximum.Value.toFixed(),
173- // nightIcon: 35, // Night.Icon
174- // tempNight: "0° C" // Temperature.Minimum.Value.toFixed(),
175- // },
176- // {
177- // date: "24 июня",
178- // dayIcon: 6, // Day.Icon
179- // dayIconText: "Преимущественно облачно", // Day.IconPhrase
180- // tempDay: "8° C",// Temperature.Maximum.Value.toFixed(),
181- // nightIcon: 35, // Night.Icon
182- // tempNight: "0° C" // Temperature.Minimum.Value.toFixed(),
183- // },
184- // {
185- // date: "24 июня",
186- // dayIcon: 6, // Day.Icon
187- // dayIconText: "Преимущественно облачно", // Day.IconPhrase
188- // tempDay: "8° C",// Temperature.Maximum.Value.toFixed(),
189- // nightIcon: 35, // Night.Icon
190- // tempNight: "0° C" // Temperature.Minimum.Value.toFixed(),
191- // },
192- // {
193- // date: "24 июня",
194- // dayIcon: 6, // Day.Icon
195- // dayIconText: "Преимущественно облачно", // Day.IconPhrase
196- // tempDay: "8° C",// Temperature.Maximum.Value.toFixed(),
197- // nightIcon: 35, // Night.Icon
198- // tempNight: "0° C" // Temperature.Minimum.Value.toFixed(),
199- // },
200- // {
201- // date: "25 июня",
202- // dayIcon: 6, // Day.Icon
203- // dayIconText: "Преимущественно облачно", // Day.IconPhrase
204- // tempDay: "8° C",// Temperature.Maximum.Value.toFixed(),
205- // nightIcon: 35, // Night.Icon
206- // tempNight: "0° C" // Temperature.Minimum.Value.toFixed(),
207- // }
208- // ]
173+ // eslint-disable-next-line
174+ . catch ( error => console . error ( error . message ) )
209175 return arr
210176 }
211177 } ,
0 commit comments