<template>
	<view class="rf-category">
		<u-navbar :back-text="i18n('Back')" :back-text-style="backStyle" back-icon-color="#fff" title-color="#fff"
			:title="i18n('CountryInformation')" :background="background">
		</u-navbar>
		<view>
			<image src="../../../static/country.jpg" style="width: 100%;height: 480upx;"></image>
		</view>

		<view>
			<!-- 大洲选项卡 -->
			<view v-for="(item,index) in countryList" :key="index" @click="countryClick(index)" class="country_item"
				style="margin-left: 3%;display: inline-block;
				height: 80upx;width: 45%;margin-top: 20upx;border-radius: 20upx;">
				<view class="" style="margin-top: 15upx;" :style="$i18n.locale=='zh'?
					'margin-left: 100upx;':'margin-left: 80upx;'">
					<image :src="getIcon(item.labelEn,index)" alt="" style="width: 60upx;height: 60upx;
					vertical-align: middle;margin-right: 10upx;">

						{{$i18n.locale=='zh'?item.label:item.labelEn}}
				</view>

			</view>
		</view>
		<!-- 国家列表 -->
		<view class="clist" style="margin-top: 10px;" v-if="listShow">
			<view style="font-size: 40upx;text-align: center;font-weight: bold;">{{areName}}</view>
			<view style="margin:20upx 50upx;">
				<view @click="toView(item.baseEntityId)" v-for="(item,index) in countryInfos" :key="index"
					class="country">
					{{item.zhName}}
				</view>

			</view>

		</view>

		<view style="margin-top: 10px;">
			<mSearch class="mSearch-input-box" :mode="2" button="inside"
				:placeholder="i18n('PleaseEnter') +  i18n('Nameofcountry')" @search="search" @confirm="doSearchf"
				v-model="keyword"></mSearch>
		</view>
		<u-popup v-model="show">

			<view style="margin:20upx 50upx ;padding-top: 60upx;">

				<view @click="toView(item.baseEntityId)" v-for="(item,index) in showCountryList" :key="index"
					class="country2">
					{{$i18n.locale=='zh'?item.zhName:item.enName}}
				</view>


			</view>
		</u-popup>

		<view style="margin-top: 10px;">
			<scroll-view scroll-x class="index-cate">
				<view style="display: inline-block;width: 100%;">
					<view class="index-cate-item" style="color: #000;"
						:class="tabCurrentIndex === 0 ? `text-${themeColor.name} active` : ''" @tap.stop="tabClick(0)">
						{{ $t('common.LatestDevelopment') }}
					</view>

					<view class="index-cate-item" style="color: #000;"
						:class="tabCurrentIndex === 1 ? `text-${themeColor.name} active` : ''" @tap.stop="tabClick(1)">
						{{ $t('common.ProjectTrends') }}
					</view>
					<view class="index-cate-item" style="color: #000;"
						:class="tabCurrentIndex === 2 ? `text-${themeColor.name} active` : ''" @tap.stop="tabClick(2)">
						{{ $t('common.EnterpriseInquiry') }}
					</view>
				</view>

			</scroll-view>

			<view v-if="tabCurrentIndex == 2">
				<view @click="toUnitView(item.baseEntityId)"
					style="margin: 20upx 20upx;height: 200upx;border-radius: 30upx;overflow: hidden;background-color: #fff;"
					v-for="(item,index) in infos">
					<img :src="websiteUrl+ item.photo" alt="" v-if="item.photo" style="width: 200upx;height: 200upx;">
					<img :src="websiteUrl+'/def/projectdefault.png'" alt="" v-else style="width: 200upx;height: 200upx;">
					<view class="recommend-bottom">
						<text class="recommend-bottom-name">
							{{item.unitName}}
						</text>
						<text class="tabs" v-if="item.recommendFlag=='y'">
							{{i18n('recommend2')}}
						</text>
						<view>
							<text>
								{{$i18n.locale === 'zh'?item.unitCountry:item.unitCountryDict.charAt(0).toUpperCase() + item.unitCountryDict.slice(1)}}
							</text>
							<!-- <text v-show="item.unitRegion"> - </text>
							<text>{{item.unitRegion}}</text> -->
						</view>
						<text v-for="(item,index) in item.labelList">
							<u-tag :text="item" mode="light" style="margin:10px 15upx 15upx 0upx;" v-if="index<3" />
						</text>
						<!-- <view>{{item.labelList}}</view> -->
						<!-- <view>发布日期：{{handlePublishTimeDesc(toDate,item.createDate,$i18n.locale)}} {{$t('common.release')}}</view> -->
					</view>
					<u-toast ref="uToast" />
				</view>
				<u-loadmore :status="status" />
			</view>


			<view v-if="tabCurrentIndex == 1">
				<view style="margin: 20upx 20upx;height: 200upx;border-radius: 30upx;
				overflow: hidden;background-color: #fff;" v-for="(item,index) in projectInfos"
					@click="navToList('/pages/country/projectPresentation/projectPresentationDetails',item.projectId)">
					<img :src="websiteUrl+ item.bannerList[0]" alt="" v-if="item.bannerList"
						style="width: 200upx;height: 200upx;">
					<img :src="websiteUrl+'/def/projectdefault.png'" alt="" v-else
						style="width: 200upx;height: 200upx;">
					<view class="recommend-bottom">
						<view class="recommend-bottom-name">{{item.projectName}}</view>
						<view>{{formatDate(item.createDate)}} </view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>

			<view v-if="tabCurrentIndex == 0">
				<view v-for="(item,index) in newsInfos"
					@click="navToList('/pages/country/countryList/countryInformationDetails',item.baseEntityId)">
					<view class="media-item view">
						<view class="infoList">
							<view class="leftImg" v-if="item.pictureUrl">
								<image class="img" :src="websiteUrl+item.pictureUrl" mode=""></image>
							</view>
							<view class="rightCont" :style="{ width: item.pictureUrl?'460upx':'100%' }">
								<view class="title">{{ item.title }}</view>
								<view class="info-cont">
									{{ item.content }}
								</view>
								<view class="title-base">
									<text>{{ item.auther }}</text>
									<text class="time">{{ formatDate(item.publishDate) }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>

			</view>

		</view>
		<u-toast ref="uToast" />
		<rf-back-top :scrollTop="scrollTop"></rf-back-top>
	</view>
</template>

<script>
	import mSearch from '@/components/rf-search/rf-search';
	import newsItem from '@/pages/information/news-item'

	export default {
		data() {
			return {
				categoryList: [{
						"label": "最新动态",
						"value": "1"
					},
					{
						"label": "项目进展",
						"value": "2"
					},

				],
				background: {
					backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
				},
				backStyle: {
					color: '#fff'
				},
				status: 'loadmore',
				showCountryList: [],
				tabCurrentIndex: 0,
				keyword: '',
				listShow: false,
				screen1sIndex: null,
				show: false,
				scrollTop: 0,
				countryList: [{
						label: '亚洲',
						labelEn: 'Asia'
					},
					{
						label: '非洲',
						labelEn: 'Africa'
					},
					{
						label: '欧洲',
						labelEn: 'Europe'
					},
					{
						label: '北美洲',
						labelEn: 'Northamerica'
					},
					{
						label: '南美洲',
						labelEn: 'Southamerica'
					},
					{
						label: '大洋洲',
						labelEn: 'Oceania'
					},


				],
				page: 1,
				total2: 0,
				areName: '',
				areNameEn: '',
				countryMap: Object,
				countryInfos: [],
				projectInfos: [],
				newsInfos: [],
				toDate: Date.parse(new Date()),
				infos: [],
				
			}
		},
		components: {
			mSearch,
			newsItem
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onShow() {
			this.countryClick(0)
			this.tabClick(0)
		},
		onReady() {
			let page = {

			}
			this.getCountryMap(page);
			this.getProjectInfo(1);
			this.getNewsInfo(page);
			this.getUnitList(page);
		},
		onReachBottom() {

			if (this.page * 10 >= this.total2) return;
			this.status = 'loading';
			this.page = this.page + 1;
			console.log(this.page, 'pagepagepagepage');

			if ((this.page - 1) * 10 >= this.total2) {
				this.status = 'nomore';
			} else {
				this.status = 'loading';
				this.getProjectInfo(this.page);
			}


		},
		methods: {
			i18n(data) {
				return this.$t('common.' + data);
			},
			toView(baseEntityId) {
				console.log('id', baseEntityId)
				this.$mRouter.push({
					route: `/pages/country/countryList/countryDetail?baseEntityId=${baseEntityId}`
				});
			},
			doSearch(flag) {
				console.log(flag)
				this.show = true;
			},
			async search(data) {
				
				console.log('zhName',data)
				const res = await this.$myRequest({
					url: '/project/baseCountryViews/',
					data: {
						zhName: data,
						// enName:this.$i18n.locale=="en"?data:'',
					}
				});
				this.showCountryList = res.data.baseCountryViews;

				const that = this;
				if (this.showCountryList) {
					that.show = true;
				} else {
					that.$refs.uToast.show({
						title: this.$i18n.locale == 'zh' ? '暂无当前国家信息' : 'No current country information',
						type: 'error',

					})
				}
			},
			getIcon(value, index) {
				if (index == this.screen1sIndex) {
					return require("../../../static/img/country/" + value + '.png');
				} else {
					return require("../../../static/img/country/" + value + '1.png');
				}
			},
			tabClick(index) {
				this.tabCurrentIndex = index;
			},
			async getCountryMap(page) {
				const res = await this.$myRequest({
					url: '/project/baseCountryViews/',
					data: {
						language: this.$i18n.locale.toUpperCase()
					}
				});

				if (res.data) {
					this.countryMap = res.data.areMap
				}
			},
			countryClick(index) {

				this.listShow = true;
				this.screen1sIndex = index;
				this.areNameEn = this.countryList[index]['labelEn']
				this.areName = this.$i18n.locale == 'zh' ? this.countryList[index]['label'] : this.countryList[index][
					'labelEn'
				]
				
				this.getCountryByAre(this.countryList[index].labelEn) // 获取洲际索引
				this.getUnitList();
			},
			async getCountryByAre(are) {
				are = are.toLowerCase();
				await this.getCountryMap();
				this.countryInfos = this.countryMap[are];

			},
			async getProjectInfo(page) {

				const res = await this.$myRequest({
					url: '/project/baseProjectViews/',
					data: {
						pageNo: page,
						pageSize: 10,
						language: this.$i18n.locale.toUpperCase(),
						descStatus: 0,
						status: 1
					}
				});

				if (res.data) {
					if (this.page == 1) {
						this.projectInfos = res.data.baseProjectViews;
					} else {
						this.projectInfos = this.projectInfos.concat(res.data.baseProjectViews)
					}
					this.total2 = res.data.page.totalCount;
					if (this.projectInfos.length >= this.total2 - 0) {
						this.status = 'nomore';
					}
				}
			},
			async getNewsInfo(page) {
				const res = await this.$myRequest({
					url: '/cms/cmsInformationViews/getCountryDynamicInfos',
					data: {
						pageNo: 1,
						pageSize: 10,
						language: this.$i18n.locale.toUpperCase(),
					}
				});
				if (res.data) {
					this.newsInfos = res.data;
				}
			},
			navToList(src, data) {

				this.$mRouter.push({
					route: src + '?id=' + data
				});
			},
			//获取企业展示
			async getUnitList(data) {
				console.log(this.areNameEn)
				const res = await this.$myRequest({
					url: '/project/baseUnitViews/',
					data: {
						pageSize: 10,
						pageNo: 1,
						areDict: this.areNameEn,
						language: this.$i18n.locale.toUpperCase(),
					}
				});
			
				if (res.data) {
					console.log(res.data);
					this.infos = res.data.baseUnitViews;
				}
			},
			//企业跳转详情
			toUnitView(baseEntityId) {
				this.$mRouter.push({
					route: `/pages/country/enterprise/enterpriseDetail?baseEntityId=${baseEntityId}`
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.rf-category {
		background-color: $color-white;
		/*  #ifdef  APP-PLUS  */
		// margin-top: calc(20upx + var(--status-bar-height));
		/*  #endif  */


	}

	.recommend-bottom {
		float: right;
		height: 200upx;
		width: 488upx;
	}

	.index-cate .index-cate-item {
		// margin: 0 4upx 10upx;
		width: 50%;
		display: inline-block;
	}

	.infoList {
		padding-top: 20upx;
		display: flex;
		flex-direction: initial;
		justify-content: space-between;
	}

	.leftImg {
		width: 185upx;
		height: 140upx;
	}

	.img {
		width: 100%;
		height: 100%;
	}

	.country_item:nth-of-type(1),
	.country_item:nth-of-type(4) {
		background: #fef7f1;
		color: #fe6e27;
	}

	.country_item:nth-of-type(2),
	.country_item:nth-of-type(5) {
		background: #eefaf8;
		color: #6ee0bc;
	}

	.country_item:nth-of-type(3),
	.country_item:nth-of-type(6) {
		background: #eff6ff;
		color: #7ca4d5;
	}

	.rightCont {
		width: 460upx;
		padding-bottom: 20upx;
		border-bottom: 1px solid #F1F1F1;
	}

	.title {
		color: #333333;
		font-size: 32upx;
		font-weight: 700;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.title-base {
		font-size: 24upx;
		color: #999999;
		margin-top: 10upx;
		display: flex;
		flex-direction: initial;


	}

	.time {
		margin-left: 30upx;
	}

	.info-cont {
		margin-top: 10upx;
		font-size: 28upx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.view {
		flex-direction: column;
	}

	.flex-row {
		flex-direction: row;
	}

	.flex-col {
		flex-direction: column;
	}

	.list-cell {
		padding: 0 15px;
	}

	.uni-list-cell-hover {
		background-color: #eeeeee;
	}

	.media-item {
		position: relative;
		flex: 1;
		flex-direction: column;
		padding: 0 30upx;
	}

	.media-item-line {
		position: absolute;
		left: 15px;
		right: 15px;
		bottom: 0;
		height: 1px;
		background-color: #ebebeb;
	}

	.media-image-right {
		flex-direction: row;
	}

	.country {
		border: 1px solid #f1f1f1;
		-webkit-box-shadow: 10upx 10upx 10upx #f1f1f1;
		box-shadow: 10upx 10upx 10upx #f1f1f1;
		display: inline-block;
		margin-top: 10px;
		color: #2c558a;
		border-radius: 10upx;
		width: 45%;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
		margin-left: 20upx;
	}

	.country2 {
		border: 1px solid #f1f1f1;
		-webkit-box-shadow: 10upx 10upx 10upx #f1f1f1;
		box-shadow: 10upx 10upx 10upx #f1f1f1;
		margin-top: 10px;
		color: #2c558a;
		border-radius: 10upx;
		width: 400upx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
		margin-left: 20upx;
	}

	.media-image-left {
		flex-direction: row-reverse;
	}

	.media-title {
		flex: 1;
	}

	.media-title {
		lines: 3;
		text-overflow: ellipsis;
		font-size: 15px;
		color: #555555;
	}

	.media-title2 {
		flex: 1;
		margin-top: 3px;
		line-height: 20px;
	}

	.image-section {
		margin-top: 10px;
		flex-direction: row;
		justify-content: space-between;
	}

	.image-section-right {
		margin-top: 0;
		margin-left: 5px;
		width: 112px;
		height: 73px;
	}

	.image-section-left {
		margin-top: 0;
		margin-right: 5px;
		width: 112px;
		height: 73px;
	}

	.image-list1 {
		height: 240px;
	}

	.image-list2 {
		width: 112px;
		height: 73px;
	}

	.image-list3 {
		width: 112px;
		height: 73px;
	}

	.media-info {
		flex-direction: row;
		align-items: center;
	}

	.info-text {
		margin-right: 10px;
		color: #999999;
		font-size: 12px;
	}

	.media-foot {
		margin-top: 12px;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.close-view {
		position: relative;
		align-items: center;
		flex-direction: row;
		width: 20px;
		height: 15px;
		line-height: 15px;
		border-width: 1upx;
		border-style: solid;
		border-color: #aaaaaa;
		border-radius: 4px;
		justify-content: center;
		text-align: center;
	}

	.close-l {
		position: absolute;
		width: 9px;
		height: 1px;
		background-color: #aaaaaa;
	}

	.close-h {
		transform: rotate(45deg);
	}

	.close-v {
		transform: rotate(-45deg);
	}

	.recommend-bottom-name {
		font-size: 35upx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #0B0B11;
		line-height: 65upx;
		margin-top: 30upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.wrap {
		padding: 24upx;
	}

	.item {
		padding: 24upx 0;
		color: $u-content-color;
		font-size: 28upx;
	}

	/deep/.serach .content .content-box .input.center {
		width: 400upx;
	}
</style>
