<template>
	<view class="flex-col page">
		<lf-header :spreadOut="true" :diy="true" :boderBottom="true" bgColor="#ffffff">
			<view class="header-nav">
				<image class="searchIcon" src="@/static/icon/search.png" @click="$url('/pages/ratingQuery/ratingQuery')"></image>
				<text class="title">评级中心</text>
			</view>
		</lf-header>
		<view class="flex-col items-center group_3">
			<image src="@/static/icon/line.png" class="image_6" />
			<view class="flex-col section_2">
				<view class="flex-col">
					<!-- 用户信息 -->
					<view class="flex-col section_3" @click="nextToSettings">
						<view class="bottom-group flex-col items-center view_3">
							<view class="flex-col items-end image-wrapper">
								<image class="avatar" :src="user.avatar" mode="aspectFill" v-if="user.avatar"></image>
								<image class="avatar" src="@/static/mrtx.png" mode="aspectFill" v-else></image>
								<image src="@/static/icon/level.png" class="image_7" />
								<view class="flex-col items-center badge" v-if="$isRight(dots.system)">
									<text>{{ dots.system > 99 ? '99+' : dots.system }}</text>
								</view>
							</view>
						</view>
						<view class="justify-center group_5">
							<view class="user-name">{{ user.nick_name || '您未登录,点击登录' }}</view>
							<image src="@/static/icon/rightArrow.png" class="image_8" />
						</view>
					</view>
					<!-- 我的订单 -->
					<view class="section_4 flex-col">
						<view class="justify-between">
							<text class="text_4">我的订单</text>
							<view class="right-group flex-row" @click="nextToOrder">
								<text>全部</text>
								<image src="@/static/icon/rightArrow.png" class="image_8" />
							</view>
						</view>
						<view class="justify-between equal-division" >
							<view class="equal-division-item flex-col" @click="nextToOrder(1)">
								<view class="top-group flex-col items-center">
									<image src="@/static/icon/order1.png" class="image_11" />
									<view class="flex-col items-center badge_1" v-if="$isRight(dots.unconfirmed)">
										<text>{{ dots.unconfirmed }}</text>
									</view>
								</view>
								<text class="text_7">待确认</text>
							</view>
							<view class="flex-col items-center equal-division-item_1" @click="nextToOrder(2)">
								<view class="top-group flex-col items-center">
									<image src="@/static/icon/order2.png" class="image_11" />
									<view class="flex-col items-center badge_2" v-if="$isRight(dots.rating)">
										<text>{{ dots.rating }}</text>
									</view>
								</view>
								<text class="text_7">评级中</text>
							</view>
							<view class="flex-col items-center equal-division-item_2" @click="nextToOrder(3)">
								<view class="top-group flex-col items-center">
									<image src="@/static/icon/order3.png" class="image_11" />
									<view class="flex-col items-center badge_2" v-if="$isRight(dots.paying)">
										<text>{{ dots.paying }}</text>
									</view>
								</view>
								<text class="text_11">待付款</text>
							</view>
							<view class="equal-division-item flex-col" @click="nextToOrder(4)">
								<view class="top-group flex-col items-center">
									<image src="@/static/icon/order4.png" class="image_11" />
									<view class="flex-col items-center badge_2" v-if="$isRight(dots.shipping)">
										<text>{{ dots.shipping }}</text>
									</view>
								</view>
								<text class="text_7">待收货</text>
							</view>
						</view>
					</view>
					<!-- 快速评级 -->
					<view class="section_4 flex-col">
						<view class="justify-between group_9">
							<view class="group_10">
								<text class="text_14">快速评级</text>
								<text class="text_15">（7day）</text>
							</view>
							<view class="right-group flex-row" @click="$url('/pages/fastRating/fastRating')">
								<text>查看详情</text>
								<image src="@/static/icon/rightArrow.png" class="image_8" />
							</view>
						</view>
						<view class="grid">
							<view class="flex-col items-center grid-item_1" @click="rateIndex = 0" :class="{'grid-item-active': rateIndex == 0}">
								<text class="qxk-iconfont qxk-icon-mulu lf-font-40"></text>
								<text class="text_17">全面评级</text>
							</view>
							<view class="flex-col items-center grid-item_1"  @click="rateIndex = 1" :class="{'grid-item-active': rateIndex == 1}">
								<text class="qxk-iconfont qxk-icon-xinwen-moren lf-font-40"></text>
								<text class="text_9">卡品评级</text>
							</view>
							<view class="grid-item_2 flex-col items-center" @click="rateIndex = 2" :class="{'grid-item-active': rateIndex == 2}">
								<text class="qxk-iconfont qxk-icon-tuwenguanli lf-font-40"></text>
								<text class="text_19">签名评级</text>
							</view>
							<view class="grid-item_2 flex-col items-center" @click="rateIndex = 3" :class="{'grid-item-active': rateIndex == 3}">
								<text class="qxk-iconfont qxk-icon-kefujiqirenbeifen lf-font-40"></text>
								<text class="text_19">套壳服务</text>
							</view>
						</view>
						<view class="flex-col group_11">
							<view class="justify-between group_12">
								<view class="flex-row">
									<checkbox-group @change="e => isConsentAgreement = !isConsentAgreement">
										<checkbox color="#e6a33c" :checked="isConsentAgreement"></checkbox>
									</checkbox-group>
									<view class="group_14">
										<text class="text_22">阅读并同意</text>
										<text class="text_23" @click="$url('/packages/article/article?type=grade_agreement')">《相关协议》</text>
									</view>
								</view>
								<text class="text_24">45元/张</text>
							</view>
							<view class="flex-col items-center button" @click="nextToGrading">
								<text>下一步</text>
							</view>
						</view>
					</view>
					<!-- 已评卡 -->
					<view class="flex-col section_8" v-if="$isRight(evaluated_order)">
						<view class="justify-between group_15" @click="nextToOrder">
							<text>已评卡</text>
							<image
								src="@/static/icon/rightArrow.png"
								class="image_8" />
						</view>
						<view class="flex-row equal-division_1">
							<view class="flex-col items-center equal-division-item_3" @click="toSubOrder(item.id)" v-for="(item, index) in evaluated_order" :key="index">
								<image :src="item.itemImage" class="image_23" mode="aspectFill" />
								<text class="text_27">{{ item.title }}</text>
							</view>
						</view>
					</view>
					<!-- 评级标准 -->
					<view class="justify-between section_9" @click="$url('/pages/ratingCriteria/ratingCriteria')">
						<text>评级标准/卡砖设计</text>
						<image
							src="@/static/icon/rightArrow.png"
							class="image_8" />
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import lfHeader from '@/components/lf-header.vue';
	import { my } from '@/service/index.js';
	import { ratingSearch } from '@/service/grading.js';
	
	
	export default {
		components: {
			lfHeader
		},
		data() {
			return {
				isConsentAgreement: false,
				rateIndex: 0,
				user: {},
				dots: {},
				evaluated_order: []
			};
		},
		async onLoad(query){
			if(query && query.q){
				const q = decodeURIComponent(query.q);
				console.log("query",q);
				let sid = q.split('s=')[1];
				console.log("sid",sid)
				if(sid){
					let res = await ratingSearch(sid);
					let datas = res.data.datas;
					
					if(this.$isRight(datas.sub_order)){ // 查询到订单，默认取第一条
						let base_data = encodeURIComponent(JSON.stringify(datas));
						this.$url('/packages/ratingQueryDetail/ratingQueryDetail?data='+ base_data);
					}else{
						uni.showModal({
							title: '提示',
							content: '该评级编号暂无订单，换个编号试试？',
							showCancel: false
						})
					}
				}
			}else{
				this.getUserCenterDetail();
			}
		},
		methods: {
			
			async toSubOrder(value){
				let res = await ratingSearch(value);
				let datas = res.data.datas;
				
				let base_data = encodeURIComponent(JSON.stringify(datas));
				this.$url('/packages/ratingQueryDetail/ratingQueryDetail?data='+ base_data);
			},
			
			async getUserCenterDetail(){
				let res = await my();
				uni.setStorageSync('userInfo', res.data.datas.user);
				this.user = res.data.datas.user;
				this.dots = res.data.datas.dots;
				let evaluated_order = res.data.datas.evaluated_order;
				evaluated_order.forEach(item => item.itemImage = String(item.images).split(',')[0]);
				this.evaluated_order = evaluated_order;
			},
			nextToGrading(){
				if(!this.isConsentAgreement) return this.$msg('请先阅读并同意协议');
				let rateIndex = this.rateIndex;
				if(this.$isRight(this.user)){
					this.$url('/pages/write/baseInfo?rate_index='+ rateIndex);
				}else{
					this.$url('/pages/login/login');
				}
			},
			nextToOrder(current){
				if(this.$isRight(this.user)){
					let url = '/pages/order/order';
					if(this.$valueType(current) === 'number'){
						url += '?current='+ current;
					}
					this.$url(url);
				}else{
					this.$url('/pages/login/login');
				}
			},
			nextToSettings(){
				if(this.$isRight(this.user)){
					this.$url('/pages/settings/settings');
				}else{
					// this.$url('/pages/login/login', {type: 'redirect'})
					this.$url('/pages/login/login');
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.header-nav{
		text-align: center;
		position: relative;
		width: 720rpx;
		display: flex;
		justify-content: center;
		.searchIcon{
			position: absolute;
			left: 0;
			top: 6rpx;
			width: 38rpx;
			height: 36rpx;
			z-index: 999999;
		}
	}
	
	
	.bottom-group {
		position: relative;
	}

	.section_4 {
		margin-top: 30rpx;
		padding: 40rpx 32rpx;
		background-color: rgb(255, 255, 255);
	}

	.image_8 {
		width: 44rpx;
		height: 44rpx;
	}

	.equal-division-item {
		width: 84rpx;
	}

	.grid-item_2 {
		color: rgb(51, 51, 51);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
		padding: 28rpx 0 24rpx;
		border-radius: 10rpx;
		border: solid 2rpx rgb(195, 195, 195);
	}

	.top-group {
		color: rgb(255, 255, 255);
		font-size: 24rpx;
		font-weight: 500;
		line-height: 26rpx;
		white-space: nowrap;
		padding-top: 2rpx;
		position: relative;
	}

	.image_11 {
		width: 60rpx;
		height: 60rpx;
	}

	.image_17 {
		width: 50rpx;
		height: 50rpx;
	}

	.image_23 {
		border-radius: 10rpx;
		width: 200rpx;
		height: 240rpx;
	}

	.right-group {
		color: rgb(153, 153, 153);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
	}

	.text_7 {
		margin-top: 12rpx;
		color: rgb(85, 85, 85);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
	}

	.text_9 {
		margin-top: 14rpx;
	}

	.text_19 {
		margin-top: 14rpx;
	}

	.page {
		background-color: #f6f6f6;
		width: 100%;
		overflow-y: auto;
		height: 100%;
	}

	.group_3 {
		padding-bottom: 2024rpx;
		flex: 1 1 auto;
		overflow-y: auto;
		position: relative;
	}

	.image_6 {
		width: 100vw;
		height: 1vw;
	}

	.section_2 {
		padding-bottom: 14rpx;
		background-color: rgb(246, 246, 246);
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		position: absolute;
	}


	.section_3 {
		padding: 40rpx 0 38rpx;
		background-color: rgb(255, 255, 255);
	}

	.section_8 {
		margin-top: 30rpx;
		padding: 40rpx 0;
		background-color: rgb(255, 255, 255);
	}

	.section_9 {
		margin-top: 30rpx;
		padding: 40rpx 32rpx 30rpx;
		color: rgb(51, 51, 51);
		font-size: 32rpx;
		font-weight: 700;
		line-height: 44rpx;
		white-space: nowrap;
		background-color: rgb(255, 255, 255);
	}

	.view_3 {
		color: rgb(255, 255, 255);
		font-size: 24rpx;
		font-weight: 500;
		line-height: 34rpx;
		white-space: nowrap;
	}

	.group_5 {
		margin-top: 20rpx;
		color: rgb(51, 51, 51);
		font-size: 34rpx;
		font-weight: 600;
		line-height: 48rpx;
		white-space: nowrap;
	}

	.equal-division {
		margin: 36rpx 28rpx 0;
	}

	.group_9 {
		padding-left: 2rpx;
	}

	.grid {
		margin-top: 40rpx;
		height: 340rpx;
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		grid-row-gap: 22rpx;
		grid-column-gap: 24rpx;
	}

	.group_11 {
		margin-top: 40rpx;
	}

	.group_15 {
		padding: 0 32rpx;
		color: rgb(51, 51, 51);
		font-size: 32rpx;
		font-weight: 700;
		line-height: 44rpx;
		white-space: nowrap;
	}

	.equal-division_1 {
		margin-top: 40rpx;
		padding: 0 32rpx;
		color: rgb(51, 51, 51);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
	}

	.image-wrapper {
		padding-top: 72rpx;
		width: 112rpx;
		position: relative;
		.avatar{
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			border-radius: 50%;
		}
	}

	.badge {
		background-color: rgb(234, 43, 43);
		border-radius: 17rpx;
		min-width: 34rpx;
		position: absolute;
		// right: 284rpx;
		left: 78rpx;
		top: 0;
	}

	.text_4 {
		color: rgb(51, 51, 51);
		font-size: 32rpx;
		font-weight: 700;
		line-height: 44rpx;
		white-space: nowrap;
	}

	.equal-division-item_1 {
		color: rgb(85, 85, 85);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
	}

	.equal-division-item_2 {
		padding-top: 2rpx;
		color: rgb(85, 85, 85);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
	}

	.group_10 {
		white-space: nowrap;
		height: 44rpx;
	}

	.grid-item {
		padding: 22rpx 0 30rpx;
		color: rgb(231, 162, 63);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
		border-radius: 10rpx;
		border: solid 2rpx rgb(231, 162, 63);
	}
	.grid-item-active{
		color: rgb(231, 162, 63) !important;
		border: solid 2rpx rgb(231, 162, 63) !important;
	}

	.grid-item_1 {
		padding: 22rpx 0 30rpx;
		color: rgb(51, 51, 51);
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		white-space: nowrap;
		border-radius: 10rpx;
		border: solid 2rpx rgb(195, 195, 195);
	}

	.group_12 {
		padding-bottom: 20rpx;
	}

	.button {
		padding: 26rpx 0;
		color: rgb(255, 255, 255);
		font-size: 32rpx;
		font-weight: 600;
		line-height: 44rpx;
		white-space: nowrap;
		background-color: rgb(231, 162, 63);
		border-radius: 10rpx;
	}

	.equal-division-item_3 {
		// flex: 1 1 244rpx;
		align-items: flex-start;
		margin-right: 42rpx;
		&:nth-child(3n){
			margin-right: 0rpx;
		}
	}

	.equal-division-item_4 {
		flex: 1 1 244rpx;
	}

	.equal-division-item_5 {
		flex: 1 1 244rpx;
	}

	.image_7 {
		margin-right: 12rpx;
		border-radius: 50%;
		width: 40rpx;
		height: 40rpx;
		position: relative;
		z-index: 99;
	}

	.text_11 {
		margin-top: 12rpx;
	}

	.text_14 {
		color: rgb(51, 51, 51);
		font-size: 32rpx;
		font-weight: 700;
		line-height: 44rpx;
	}

	.text_15 {
		color: rgb(119, 119, 119);
		font-size: 24rpx;
		font-weight: 500;
		line-height: 34rpx;
	}

	.text_17 {
		margin-top: 14rpx;
	}

	.text_24 {
		color: rgb(119, 119, 119);
		font-size: 28rpx;
		line-height: 40rpx;
		white-space: nowrap;
	}

	.text_27 {
		margin-top: 10rpx;
	}

	.text_28 {
		margin-top: 10rpx;
	}

	.text_29 {
		margin-top: 10rpx;
	}

	.badge_1 {
		background-color: rgb(234, 43, 43);
		border-radius: 13rpx;
		min-width: 26rpx;
		position: absolute;
		right: 6rpx;
		top: 0;
	}

	.badge_2 {
		background-color: rgb(234, 43, 43);
		border-radius: 13rpx;
		width: 26rpx;
		position: absolute;
		right: 0;
		top: 0;
	}

	.section_7 {
		border-radius: 50%;
		width: 40rpx;
		height: 40rpx;
		border: solid 2rpx rgb(195, 195, 195);
	}

	.group_14 {
		margin-left: 14rpx;
		white-space: nowrap;
		height: 40rpx;
	}

	.text_22 {
		color: rgb(119, 119, 119);
		font-size: 28rpx;
		line-height: 40rpx;
	}

	.text_23 {
		color: rgb(209, 161, 28);
		font-size: 28rpx;
		line-height: 40rpx;
	}
	
	.user-name{
		max-width: 360rpx;
		white-space:nowrap;
		overflow:hidden;
		text-overflow:ellipsis;
	}
	
	/deep/checkbox .wx-checkbox-input {
		border-radius: 50% !important;
	}
</style>
