<template>
	<view class="statistics" :style="{background:'url('+ bannerImage +')'}">
		<view><nav-bar title="none" icon="none" background="transparent" border-color="transparent"
				></nav-bar></view>
		<view class="logo"><re-image imgSrc="/retail/main/img_logo.png" width="300" height="56"></re-image></view>
		<view class="content">
			<view class="news">
				<view class="info flex">
					<re-image imgSrc="/" width="104" height="104"></re-image>
					<view class="info-text flex-column jcsa">
						<view class="info-top flex">
							<view class="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">初级</view>
							</view>
						</view>
						<view class="phone">13630639549</view>
					</view>
				</view>
				<view class="news-total flex jcsa">
					<view class="total-item">
						<view class="item-num">156</view>
						<view class="item-text">总销订单</view>
					</view>
					<view class="total-item">
						<view class="item-num">156</view>
						<view class="item-text">总销游戏币</view>
					</view>
					<view class="total-item">
						<view class="item-num orange">¥156</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 flex jcsb">
					<view class="left flex aic">
						<re-image width="40" height="40" imgSrc="/retail/statistics/ic_yeji.png"></re-image><text style="margin-left: 16rpx">分销等级说明</text>
					</view>
					<rich-text :nodes="nodes"></rich-text>
				</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'
	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:''
			}
		},
		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
				this.date = e.value[0].label
			},
			async getData(){
				uni.showLoading()
				const res = await statistics()
				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()
		},
	}
</script>

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

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

		.content {
			padding: 0 32rpx;

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

				.info {
					.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-top: 22rpx;
			}
		}

	}
</style>