<template>
	<view class="nationalregionalCountryInformaions">
		<!-- 头部 -->
		<u-navbar back-icon-color="#fff" :height="50" :is-back="true" :background="{background:'#1777FE'}"
			:back-text-style="{color:'#fff'}" :border-bottom="true" title-color="#fff" :custom-back="back">
			<view class="slot-wrap">
				<u-search :placeholder="placeholder" v-model="keyword" :show-action="false" bg-color="#fff"
					@change="getKeyWord" @search="searchData"></u-search>
				<image class="icon" src="../../../static/checkbig.png" mode="widthFix" @click="showDialog"></image>
			</view>
		</u-navbar>
		<!-- 字母选择 -->
		<view class="tabABC">
			<view class="abcitem" v-for="(abcitem,abcindex) in ABCList" :key="abcindex" @click="selectBy('abc',abcitem)"
				:class="{active:abcIndex==abcitem}">{{abcitem}}</view>
		</view>
		<view class="dataList">
			<view class="listitem" v-for="(listitem,listindex) in countryList" :key="listindex">
				<view class="listTitle">{{listitem.letter}}</view>
				<view class="listDataList">
					<view class="sonlistitem" v-for="(sonlistitem,sonslistindex) in listitem.data"
						@click="showDetail(sonlistitem)">
						<view class="sonlistitem">
							<view class="thumb">
								<image class="flag" :src="websiteUrl+sonlistitem.nationalFlag" mode="widthFix"></image>
							</view>
							<!-- <view class="thumb"><image :src="'/api/file/pub/' + sonlistitem.nationalFlag" mode="widthFix"></image></view> -->
							<view class="title">{{sonlistitem.committeeName}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="nodata" v-if="countryList.length==0" style="text-align: center;margin-top: 120upx;">
				<view class="imgBox" style="height:600upx;margin-bottom:60upx">
					<image src="../../../static/img/public/7.png" style="width: 80%;margin:0 10%" mode="widthFix">
					</image>
				</view>
				<text style="font-size: 30upx;color:#ccc">{{$t('common.Nodata')}}</text>
			</view>
			<u-toast ref="uToast" />
		</view>
		<!-- 区域选择 -->
		<u-popup v-model="showDia" mode="right" border-radius="20" height="50%" width="80%">
			<view class="contentDom">
				<view class="selecttitle">{{$t('common.Screening')}}</view>
				<view class="zone">{{$t('common.Region')}}</view>
				<view class="zoneList">
					<view class="zoneitem" v-for="(zoneitem,zoneindex) in zoneList" :key="zoneitem.id"
						:class="{active:zoneIndex==zoneitem.id}" @click="setZone(zoneitem,zoneindex)">{{zoneitem.label}}
					</view>
				</view>
				<view class="btn">
					<view class="reset" :class="{active:btnIndex==0}" @click="selectOpt(0)">{{$t('common.reset')}}
					</view>
					<view class="submi" :class="{active:btnIndex==1}" @click="selectOpt(1)">{{$t('common.submit')}}
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 返回顶部 -->
		<rf-back-top :scrollTop="scrollTop"></rf-back-top>
	</view>
</template>

<script>
	import rfSearchBar from '@/components/rf-search-bar/index';
	export default {
		data() {
			return {
				scrollTop: 0,
				showDia: false,
				keyword: '',
				abcIndex: null,
				zoneIndex: null,
				region: null,
				btnIndex: 1,
				pageNo: 1,
				pageSize: 40,
				countryList: [],
				zoneList: [],
				placeholder: '',
				ABCList: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
					"T", "U", "V", "W", "X", "Y", "Z", "#"
				]
			}
		},
		onShow() {
			this.placeholder = this.$i18n.locale.toUpperCase() == 'EN' ? 'Please input National Committee' : '输入国家委员会名称'
		},
		mounted() {
			this.getDataList();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		computed: {

		},

		onReachBottom() {

		},

		methods: {
			//路由后退一步
			back() {
				// #ifdef H5
				history.back()
				// #endif
				// #ifndef H5
				uni.navigateBack()
				// #endif
			},
			//调转至国家委员会详情
			showDetail(item) {
				uni.setStorageSync('committeeData', item)
				uni.navigateTo({
					url: '/pages/nationalregionalCommissions/nationalregionalInformaions/committeeLayout'
				})
			},
			//打开区域筛选框
			showDialog() {
				this.showDia = true;
				this.getZoneList();
			},
			//监听搜索关键字变化
			getKeyWord(keyword) {
				this.keyword = keyword;
			},
			// 关键字搜索
			searchData() {
				if (!this.keyword) {
					return;
				}
				this.getDataList()
				this.keyword = '';
			},
			// 提交数据
			selectBy(type, item) {
				this.abcIndex = item;
				this.getDataList();
			},

			//选择区域
			setZone(item, index) {
				this.zoneIndex = item.id;
				this.region = index + 1;
			},
			//表单操作
			selectOpt(index) {
				this.btnIndex = index;
				if (index == 0) {
					this.zoneIndex = -1;
				} else {
					this.getDataList();
					this.showDia = false;
					this.zoneIndex = -1;
					this.region = null;
				}
			},
			//获取弹窗-区域列表
			async getZoneList() {
				let res = await this.$myRequest({
					url: '/sys/sysDicts',
					data: {
						type: `COMMITTEE_REGIONAL_DICT,COMMITTEE_REGIONAL_DICT_EN`
					}
				})
				if (res.status == 200) {
					let data = res.data
					this.zoneList = this.$i18n.locale == 'zh' ? data[0] : data[1];
				} else {
					this.zoneList = []
				}
			},
			// 获取数据--根据字母/区域筛选
			async getDataList() {
				let temp = {
					name: this.keyword,
					region: this.region,
					order: this.abcIndex,
					language: this.$i18n.locale.toUpperCase(),
					pageNo: this.pageNo,
					pageSize: this.pageSize
				}
				let data = await this.formatObject(temp)
				let res = await this.$myRequest({
					url: '/project/committeeBasisInfos/getCommitteeCountryInfosForApp',
					data: data
				})
				if (res.status == 200) {
					let data = res.data;
					if (data.length > 0) {
						this.countryList = data
					} else this.countryList = []
				} else {
					this.countryList = []
				}
			},
			//对象配置处理
			formatObject(obj) {
				let object = {}
				for (let i in obj) {
					if (obj[i] && obj[i] != '#') object[i] = decodeURIComponent(obj[i])
				}
				return object;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nationalregionalCountryInformaions {
		// background-color:#E4E5E6;
	}

	page {
		// background-color:#E4E5E6;
	}

	/deep/ .uni-scroll-view-content {
		padding: 60upx 10upx 60upx 20upx;
	}

	/deep/ .anchor-text {
		padding: 0.5rem 0;
	}

	.text {
		width: 100%;
		text-align: left;
		margin: 0;
	}

	/deep/ .slot-wrap {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.icon {
			width: 36upx;
			height: 36upx;
			display: block;
			position: relative;
			overflow: hidden;
			margin: 0 26upx;
			display: block;
		}
	}

	.tabABC {
		position: fixed;
		right: 0;
		top: 16%;
		width: 80upx;
		height: 76%;
		bottom: 8%;
		// background:#fff;
		padding-top: 20upx;

		.abcitem {
			width: 36upx;
			height: 36upx;
			line-height: 36upx;
			text-align: center;
			cursor: pointer;
			border-radius: 50%;
			margin: 0 auto;
			font-size: 20upx;

			&.active {
				color: #fff;
				background: #1677FF;

			}
		}
	}

	.dataList {
		display: flex;
		flex-direction: column;

		.listTitle {
			height: 60upx;
			line-height: 60upx;
			width: 90%;
			padding: 0 1rem;
			border-bottom: 1px solid #eee;
		}

		.listDataList {
			display: flex;
			flex-direction: column;
			background: #fff;

			.sonlistitem {
				flex: 1;
				display: flex;
				width: 89%;
				padding: 16upx 0;
				border-bottom: 1px solid #eee;

				&:last-of-type {
					border: none
				}

				.thumb {
					width: 240upx;
					// height:160upx;
					background: transparent;
					position: relative;
					overflow: hidden;
					margin-right: 28upx;
					margin-left: 28upx;
					border: 1px solid #eee;

					.flag {
						display: block;
						width: 100%;
					}
				}

				.title {
					flex: 1;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}
	}

	.contentDom {
		position: fixed;
		height: 80%;

		.selecttitle {
			font-size: 30upx;
			font-weight: 700;
			margin-bottom: 30upx;
			padding: 0 10upx;
		}

		.zone {
			margin-bottom: 10upx;
			padding: 0 10upx;
		}

		.zoneList {
			display: flex;
			flex-wrap: wrap;

			.zoneitem {
				padding: 8upx 20upx;
				// width:180upx;
				background-color: #F6F6F6;
				color: #7A7A7A;
				margin: 20upx 20upx 0 0;
				text-align: center;
				cursor: pointer;

				&.active {
					color: #09a0f2;
					background-color: #def;
				}
			}
		}

		.btn {
			position: fixed;
			bottom: 0;
			left: 0;
			display: flex;
			justify-content: space-between;
			width: 100%;

			.reset,
			.submi {
				width: 50%;
				height: 80upx;
				line-height: 80upx;
				text-align: center;
				color: #7A7A7A;

				&.active {
					background: #1677FF;
					color: #fff;
				}
			}
		}
	}
</style>
