<template>
	<view class="statistics" :style="{background:'url('+ bannerImage +')'}">
		<!-- <view><nav-bar title="none" icon="none" background="transparent" border-color="transparent"></nav-bar></view> -->
		<view style="height: 160rpx;"></view>
		<view class="content">
			<view class="news">
				<view class="info flex">
					<image :src="info.avatar || defaultAvatar" class="img"></image>
					<view class="info-text flex-column jcsa">
						<view class="info-top flex">
							<view class="name">{{info.name}}</view>
							<view class="level flex aic">
								<re-image imgSrc="/retail/main/ic_chuji.png" width="40" height="44"></re-image>
								<view class="level-text">{{info.lvName}}</view>
							</view>
						</view>
						<view class="phone">{{info.username}}</view>
					</view>
				</view>
				<view class="news-total flex jcsa">
					<view class="total-item">
						<view class="item-num">{{info.sumPayNum}}</view>
						<view class="item-text">总销订单</view>
					</view>
					<view class="total-item">
						<view class="item-num">{{info.sumGameCurrency}}</view>
						<view class="item-text">总销游戏币</view>
					</view>
					<view class="total-item">
						<view class="item-num orange">¥{{info.sumIncome}}</view>
						<view class="item-text">预估总收益</view>
					</view>
				</view>
			</view>
			<view class="performance">
				<view class="per-top flex jcsb">
					<view class="left flex">
						<re-image width="40" height="40" imgSrc="/retail/statistics/ic_yeji.png"></re-image><text style="margin-left: 16rpx">分销业绩</text>
					</view>
					<view class="right flex aic" @click="show = true">
						<text>{{date}}</text><re-icon name="icon-xiala" :customStyle="{ fontSize: '10rpx',marginLeft:'10rpx'}"></re-icon>
					</view>
				</view>
				<view class="per-con flex">
					<view class="con-item flex">
						<re-image imgSrc="/retail/statistics/ic_dell.png" width="56" height="56"></re-image>
						<view class="con-new">
							<view class="new-text">总销订单</view>
							<view class="new-num">{{orderNum || 0}}</view>
						</view>
					</view>
					<view class="con-item flex">
						<re-image imgSrc="/retail/statistics/ic_youxibi.png" width="56" height="56"></re-image>
						<view class="con-new">
							<view class="new-text">总销游戏币</view>
							<view class="new-num">{{sumGameCurrency || 0}}</view>
						</view>
					</view>
					<view class="con-item con-btom flex">
						<re-image imgSrc="/retail/statistics/ic_money.png" width="56" height="56"></re-image>
						<view class="con-new">
							<view class="new-text">总充值金额</view>
							<view class="new-num"><text style="font-size:24rpx">¥</text>{{sumPay || 0}}</view>
						</view>
					</view>
					<view class="con-item con-btom flex">
						<re-image imgSrc="/retail/statistics/ic_money.png" width="56" height="56"></re-image>
						<view class="con-new">
							<view class="new-text">预估总收益</view>
							<view class="new-num"><text style="font-size:24rpx">¥</text>{{income || 0}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="grade">
				<view class="per-top">
					<view class="left_dec flex aic">
						<re-image width="40" height="40" imgSrc="/retail/statistics/ic_yeji.png"></re-image><text style="margin-left: 16rpx">分销等级说明</text>
					</view>
					<u-parse :content="nodes"></u-parse>
				</view>
			</view>
		</view>
		<u-picker ref="uPicker" :show="show" :columns="columns" keyName="label" :closeOnClickOverlay="true" @confirm="confirm" @change="changeHandler" @close="show = false" @cancel="show = false"></u-picker>
	</view>
</template>

<script>
	import {
		toRpx
	} from '@/utils/calculate.js'
	import defaultConfig from '@/config/default.js'
	import { statistics,getConfig } from '@/apis/statistic'
	import { getUserInfo } from '@/apis/user'
	export default {
		components: {},
		computed: {
			statusBarHeight() {
				return this.$store.state.info.systemInfo?.statusBarHeight
			},
		},
		data() {
			return {
				show:false,
				date:'今日',
				columns:[
					[{
						label:'今日',
						id:1
					},{
						label:'昨日',
						id:2
					},{
						label:'近一周',
						id:3
					},{
						label:'近一月',
						id:4
					},{
						label:'近一年',
						id:5
					}]
				],
				bannerImage: defaultConfig.ossImgUrl + '/retail/main/img_bgtop.png',
				navBarHeight: uni.getStorageSync('navBarHeight'),
				nodes:'',
				income:'',
				orderNum:'',
				sumGameCurrency:'',
				sumPay:'',
				info: '',
				defaultAvatar:'../../static/image/img_touxiang.png',
				// sumPayNum: uni.getStorageSync('userInfo').sumPayNum,// 总销订单
				// sumGameCurrency: uni.getStorageSync('userInfo').sumGameCurrency,// 总销游戏币
				// sumIncome: uni.getStorageSync('userInfo').sumIncome,//预估总收益，
				// name:'',
				// username:'',
			}
		},
		onLoad() {

		},

		methods: {
			changeHandler(e) {
				console.log(e,'e');
                const {
                    columnIndex,
                    value,
                    values, // values为当前变化列的数组内容
                    index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
                    picker = this.$refs.uPicker
                } = e
                // 当第一列值发生变化时，变化第二列(后一列)对应的选项
                // if (columnIndex === 0) {
                //     // picker为选择器this实例，变化第二列对应的选项
                //     picker.setColumnValues(1, this.columnData[index])
                // }
				
				
            },
			// 回调参数为包含columnIndex、value、values
			confirm(e) {
                console.log('confirm', e)
                this.show = false
				const date = e.value[0].id
				this.date = e.value[0].label
				this.getData(date)
			},
			async getInfo(){
				const userInfo = await getUserInfo()
				if(userInfo){
					this.info = userInfo
				}
			},
			// 获取统计
			async getData(type=1){
				uni.showLoading()
				const res = await statistics({type:type})
				const { income,orderNum,sumGameCurrency,sumPay } = res
				this.income = income
				this.orderNum = orderNum
				this.sumGameCurrency = sumGameCurrency
				this.sumPay = sumPay
				uni.hideLoading()
			},
			// 获取规则
			async getRule(){
				const res = await getConfig()
				this.nodes = res.lvRule
			}
		},
		onShow() {
			this.getData()
			this.getRule()
			this.getInfo()
		},
	}
</script>

<style lang="scss" scoped>
	.statistics {
		background-repeat: no-repeat !important;
		background-size: contain !important;
		// background-position: top;
		width: 100%;
		position: absolute;
		top: -160rpx;
		bottom: 0;

		.logo {
			// margin-top: 16rpx;
			margin-left: 24rpx;
		}

		.content {
			padding: 32rpx 32rpx var(--window-bottom);

			.news {
				background: #FFFFFF;
				box-shadow: 0rpx 6rpx 16rpx 0rpx #E3E6F2;
				border-radius: 24rpx;
				// margin-top: 48rpx;
				padding: 40rpx;

				.info {
					.img{
						flex-shrink: 0;
						width: 104rpx;
						height: 104rpx;
						border-radius: 8rpx;
						margin-right: 20rpx;
					}
					.info-text {
						.info-top {
							.name {
								font-weight: 500;
								font-size: 32rpx;
								color: #363531;
							}

							.level {
								margin-left: 12rpx;

								.level-text {
									width: 80rpx;
									height: 36rpx;
									padding: 6rpx 12rpx 6rpx 20rpx;
									background: linear-gradient(130deg, #FFB873 0%, #FEC287 0%, #E69349 100%);
									border-radius: 0rpx 18rpx 18rpx 0rpx;
									font-weight: 500;
									font-size: 24rpx;
									color: #FFFFFF;
									line-height: 24rpx;
									margin-left: -12rpx;
									// text-align: left;
								}
							}
						}

					}

					.phone {
						font-weight: 400;
						font-size: 28rpx;
						color: #989897;
					}
				}

				.news-total {
					margin-top: 44rpx;

					.item-num {
						font-weight: bold;
						font-size: 40rpx;
						color: #363531;
					}

					.orange {
						color: #FF6400;
					}

					.item-text {
						font-weight: 400;
						font-size: 28rpx;
						color: #9598A6;
					}
				}

			}
			.performance{
				background: #fff;
				padding: 32rpx 32rpx 52rpx;
				box-shadow: 0rpx 4rpx 12rpx 0rpx #EBECF1;
				border-radius: 24rpx;
				margin-top: 22rpx;
				.per-top{
					
					.right{
						// width: 112rpx;
						// height: 48rpx;
						background: #FFD370;
						border-radius: 8rpx;
						font-weight: 500;
						font-size: 28rpx;
						color: #2A200A;
						line-height: 48rpx;
						padding: 0 16rpx;
						white-space: nowrap;
					}
				}
				.per-con{
					margin-top: 44rpx;
					flex-wrap: wrap;
					.con-item{
						
						width: 50%;
						.con-new{
							margin-left: 20rpx;
							.new-text{
								font-weight: 400;
								font-size: 28rpx;
								color: #9598A6;
							}
							.new-num{
								margin-top: 20rpx;
								font-weight: bold;
								font-size: 40rpx;
								color: #363531;
								line-height: 40rpx;
							}
						}
					}
					.con-btom{
						margin-top: 44rpx;
					}
				}
			}
			.grade{
				padding: 32rpx;
				background: linear-gradient( 135deg, #FFDFDF 0%, #FFE4A4 100%);
				border-radius: 24rpx;
				margin: 22rpx 0;
				.left_dec{
					margin-bottom: 28rpx;
				}
			}
		}

	}
</style>