<template>
	<!-- 选择城市 -->
	<view class="page-main">
		<liu-indexed-list :dataList="dataList"  @click="click"></liu-indexed-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				searchlist:[],//搜索历史
			};
		},
		onShow() {
			this.getCountryList()
			if(uni.getStorageSync('searchlist')){
				this.searchlist = uni.getStorageSync('searchlist')
			}
		},
		methods: {
			//根据国家获取城市
			getCountryList() {  
				uni.$u.http.get(`/api/area?is_domestic=0&pid=`).then((res) => {
					this.dataList = res;
				});
			},
			// getCountryList() {
			// 	uni.$u.http.get(`/api/container/country`).then((res) => {
			// 		this.dataList = res;
			// 	});
			// },
			//点击列表回调事件
			click(e) {
				var that = this
				console.log(e);
				const eventchannel = that.getOpenerEventChannel();
				
				console.log(eventchannel);
				
				eventchannel.emit('getadd', e)
				if(that.searchlist.includes(e)){
					
				}else{
					that.searchlist.unshift(e)
					uni.setStorageSync('searchlist',that.searchlist.slice(0,6))
				}
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">

</style>