<template>
	<view class="content">
		<view class="nav flex">
			<view class="nav-item" v-for="(item,index) in navList" @click="navClick(index)"
				:class="{'action': index == currentIndex}">
				{{item.title}}
			</view>
		</view>
		<image :src="top_bg" mode="" class="top-bg"></image>
		<view class="bd-wrap flex">
			
			<view class="bd" v-if="showList.length > 0">
				<image :src="tit_bg" mode="widthFix" class="bd-tit"></image>
				<view class="gzsm" @click="navTo('/pages/public/artDetail?id=4')">
					规<br>则<br>说<br>明
				</view>
				<view class="bd-top flex">
					<view class="top-item" @click="navTo('/pages/user/model/model?uid=' + showList[1].auth_info.uid + '&type=2&mtype=1')">
						<view class="top-logo yp">
							<image :src="showList[1].auth_info.avatar" mode=""></image>
						</view>
						<view class="top-name">
							{{showList[1].auth_info.name || ''}}
						</view>
						<view class="top-visit">
							{{showList[1].card_look_count || '0'}}
						</view>
					</view>
					<view class="top-item-center" @click="navTo('/pages/user/model/model?uid=' + showList[0].auth_info.uid + '&type=2&mtype=1')">
						<view class="top-logo  jp">
							<image :src="showList[0].auth_info.avatar" mode=""></image>
						</view>
						<view class="top-name">
							{{showList[0].auth_info.name || ''}}
						</view>
						<view class="top-visit">
							{{showList[0].card_look_count || '0'}}
						</view>
					</view>
					<view class="top-item" @click="navTo('/pages/user/model/model?uid=' + showList[2].auth_info.uid + '&type=2&mtype=1')">
						<view class="top-logo tp">
							<image :src="showList[2].auth_info.avatar" mode=""></image>
						</view>
						<view class="top-name">
							{{showList[2].auth_info.name || ''}}
						</view>
						<view class="top-visit">
							{{showList[2].card_look_count || '0'}}
						</view>
					</view>
				</view>
				<view class="bd-btm-item flex" v-for="(item,index) in showList" v-if="(index != 0 && index != 1 && index!= 2)" :key="index"  @click="navTo('/pages/user/model/model?uid=' + item.auth_info.uid + '&type=2&mtype=1')">
					<image :src="item.auth_info.avatar" mode="" class="item-img"></image>
					<view class="flex item-info">
						<view class="item-name">
							{{item.auth_info.name || ''}} <image :src="rz" mode="" v-if="item.is_type_audit == 1"></image>
						</view>
						<view class="item-zy">
							{{item.user_work_type_id || ''}}
						</view>
						<!-- <view class="item-where">
							48岁 
						</view> -->
						<view class="" style="flex-grow: 1;">
							
						</view>
						<view class="item-vist">
							浏览量:{{item.card_look_count || '0'}}
						</view>
					</view>
				</view>
			</view>
			<view class="bd bd-no" v-else>
				暂无榜单数据
			</view>
		</view>
		<view class="" style="height: 60rpx;">

		</view>
	</view>
</template>

<script>
	import { getInviteCountRank } from '@/api/user.js'
	import { getCardLookCountRank,getArtDetail } from '@/api/index.js'
	export default {
		data() {
			return {
				times: '',
				top_bg: this.$store.state.baseURL + '/resource/icon/base/phb-bg.png',
				tit_bg: this.$store.state.baseURL + '/resource/icon/llph.png',
				rz: this.$store.state.baseURL + '/resource/icon/rz.png',
				navList: [{
					title: '周排行',
					time: ((new Date().setHours(0, 0, 0) - (new Date().getDay() - 1) *24 * 60 * 60 *1000)/1000).toFixed(0),
					times: ((new Date().setHours(0, 0, 0) + (7 - new Date().getDay()) *24 * 60 * 60 *1000)/1000).toFixed(0),
					list: [],
					loaded: false
				}, {
					title: '月排行',
					time: (new Date(new Date(new Date().getFullYear(), new Date().getMonth(), 1).setHours(0, 0, 0)).getTime()/1000).toFixed(0),
					times: ((new Date(new Date().getFullYear(), new Date().getMonth()+ 1, 0).setHours(23, 59, 59, 59))/1000).toFixed(0),
					list: [],
					loaded: false
				}],
				currentIndex: 0,
			}
		},
		onLoad() {

		},
		onShow() {
			console.log(this.$store.state.baseURL)
			this.times = ((new Date().setHours(0, 0, 0) - (new Date().getDay() - 1) *24 * 60 * 60 *1000)/1000).toFixed(0)
			this.getCardLookCountRank()
			getArtDetail({
				id: 4
			}).then(res => {
				console.log(res);
			})
		},
		onReachBottom() {

		},
		onReady() {

		},
		computed: {
			showList() {
				return this.navList[this.currentIndex].list
			}
		},
		methods: {
			navClick(index) {
				this.currentIndex = index
				this.getCardLookCountRank()
			},
			getCardLookCountRank() {
				let that = this
				let navitem = that.navList[that.currentIndex]
				if(navitem.loaded) {
					return
				}
				getCardLookCountRank({
					time: navitem.time,
					times: navitem.times
				}).then(res => {
					navitem.list = res.data
					navitem.loaded = true
				}).catch(err => {
					navitem.loaded = false
				})
			},
			navTo(url) {
				console.log(url);
				if (url) {
					if (url.indexOf('http') > -1) {
						// #ifdef H5
						window.location.href = url
						// #endif
						// #ifdef APP
						plus.runtime.openURL(url)
						// #endif
					} else {
						uni.navigateTo({
							url: url
						})
					}
				}
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	page,
	.content {
		height: auto;
		min-height: 100%;
		background-color: #900408;
	}

	.nav {
		width: 750rpx;
		height: 88rpx;

		.nav-item {
			line-height: 88rpx;
			width: 50%;
			text-align: center;
			font-size: 30rpx;
			font-weight: 500;
			color: #333333;
			height: 100%;
		}

		.action {
			font-weight: bold;
			position: relative;

			&::after {
				content: '';
				width: 50rpx;
				height: 6rpx;
				background: #FE5B38;
				border-radius: 3rpx;
				position: absolute;
				left: 0;
				right: 0;
				bottom: 6rpx;
				margin: auto;
			}
		}

		background-color: #fff;
	}

	.top-bg {
		width: 750rpx;
		height: 742rpx;
	}

	.bd-wrap {
		width: 699rpx;
		background: #F6E7E4;
		border-radius: 14rpx;
		justify-content: center;
		margin: -150rpx auto 0;
		position: relative;
		padding: 16rpx;
		.bd {
			width: 666rpx;
			background: #FFFFFF;
			border: 2px solid #A30F0E;
			border-radius: 14rpx;
			position: relative;
			padding: 35rpx;
			.bd-tit {
				width: 443rpx;
				height: 69rpx;
				position: absolute;
				top: -35rpx;
				left: 0;
				right: 0;
				margin: auto;
			}
			.bd-top {
				height: 376rpx;
				width: 100%;
				
				padding-bottom: 47rpx;
				.jp,.yp,.tp {
					&::after {
						content: '';
						width: 58rpx;
						height: 66rpx;
						position: absolute;
						position: absolute;
						bottom: 10rpx;
						right: -10rpx;
						z-index: 999;
					}
				}
				.jp {
					&::after {
						
						background: url($base-url + '/resource/icon/jp.png') no-repeat;
						background-size: 100% 100%;
					}
				}
				.yp {
					&::after {
						right: -15rpx;
						background: url($base-url + '/resource/icon/yp.png') no-repeat;
						background-size: 100% 100%;
					}
				}
				.tp {
					&::after {
						right: -15rpx;
						background: url($base-url + '/resource/icon/tp.png') no-repeat;
						background-size: 100% 100%;
					}
				}
				.top-item, .top-item-center {
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
					align-items: center;
					.top-logo {
						border-radius: 50%;
						border: #900408 1px solid;
						position: relative;
						image {
							width: 100%;
							height: 100%;
							background-color: #eee;
							border-radius: 50%;
						}
					}
					.top-name {
						font-size: 26rpx;
						font-weight: bold;
						color: #A30F0E;
						margin: 15rpx 0;
					}
					.top-visit {
						font-size: 22rpx;
						font-weight: bold;
						color: #171717;
					}
				}
				.top-item {
					flex-grow: 3;
					.top-logo {
						width: 139rpx;
						height: 139rpx;
					}
				}
				.top-item-center {
					flex-grow: 4;
					.top-logo {
						width: 198rpx;
						height: 197rpx;
					}
				}
			}
			.bd-btm-item {
				height: 260rpx;
				border-top:  #f2f2f2 1px solid;
				justify-content: flex-start;
				.item-info {
					height: 100%;
					flex-grow: 1;
					flex-direction: column;
					justify-content: flex-start;
					align-items: flex-start;
					padding: 34rpx 0 21rpx;
					
					.item-name {
						font-size: 31rpx;
						font-weight: bold;
						color: #333333;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						image {
							width: 100rpx;
							height: 30rpx;
							margin-left: 10rpx;
						}
					}
					.item-zy {
						padding: 6rpx 20rpx;
						background: #fee7e4;
						border-radius: 5rpx;
						font-size: 22rpx;
						font-weight: 500;
						color: #F86859;
						margin: 16rpx 0 20rpx;
					}
					.item-vist,.item-where {
						font-weight: 500;
						color: #969696;
					}
					.item-vist {
						font-size: 22rpx;
						justify-items: flex-end;
					}
					.item-where {
						font-size: 24rpx;
					}
				}
				.item-img {
					flex-shrink: 0;
					width: 160rpx;
					height: 220rpx;
					margin-right: 22rpx;
					background-color: #eee;
				}
				
			}
		}
	}
	.bd-no {
		height: 500rpx;
		text-align: center;
		line-height: 500rpx;
	}
	.gzsm {
		width: 44rpx;
		// height: 127rpx;
		display: inline-block;
		background-color: #dd2525;
		position: absolute;
		right: 0;
		top: 53rpx;
		border-radius: 10rpx 0 0 10rpx;
		color: #ffc573;
		font-size: 24rpx;
		text-align: center;
		padding: 10rpx;
	}
</style>