<template>
	<view>
		<ms-tabs :type="type" v-model="active" lineAnimated="true" @input='switchTabs'></ms-tabs>
		<view class="content">
			<view v-show="active===0">
				<view class="dayGift-box" v-for="(day,index) in dayGiftList" :key='day.id'>
					<view>{{index + 1}}</view>
					<view style="margin-left: -35%">{{day.date}}</view>
					<view style="color: #1AAD19;">+{{day.times}}次</view>
				</view>
		        <view class="dayGift-box" style="justify-content: center;" v-if="!dayGiftList.length">暂无明细</view>
			</view>
			<view v-show="active===1">
				<view class="dayGift-box" v-for="(friend,index) in inviteFriendList" :key='friend.id'>
					<view>{{index + 1}}</view>
					<view style="margin-left: -28%" class="flex-column">
					    <view class="flex-row">
							<view>
								<image :src="friend.invited_headimg" mode="scaleToFill" style="width: 100%;height: 100%;"></image>
							</view>
							<text>{{friend.invited_username}}</text>
						</view>
						<view class="friend-time">{{friend.date}}</view>
					</view>
					<view style="color: #1AAD19;">+{{friend.times}}次</view>
				</view>
			    <view class="dayGift-box" style="justify-content: center;" v-if="!inviteFriendList.length">暂无明细</view>
			</view>
		</view>
	</view>
</template>

<script>
	var md5 = require("../../../common/md5.js");
	import msTabs from '@/components/ms-tabs/ms-tabs.vue'
	export default {
		components: {
			msTabs
		},
		data() {
			return {
				type: [{
					title: '每日赠送次数'
				}, {
					title: '邀好友奖励次数'
				}],
				active: 0,
				page:'',
				pageSize:'',
				dayGiftList:[
					{
						giftTime:'2019.12.03 00:00',
						giftCounts:'3'
					},
					{
						giftTime:'2019.12.04 00:00',
						giftCounts:'3'
					},
					{
						giftTime:'2019.12.05 00:00',
						giftCounts:'3'
					},
					],
				inviteFriendList:[
					{
						friendHead:'/static/userDefault.png',
						friendName:'小瓶子',
						giftCounts:'10',
						giftTime:'2019.12.05 00:00',
					},
					{
						friendHead:'/static/userDefault.png',
						friendName:'小瓶子',
						giftCounts:'10',
						giftTime:'2019.12.06 00:00',
					},
					{
						friendHead:'/static/userDefault.png',
						friendName:'小瓶子',
						giftCounts:'10',
						giftTime:'2019.12.07 00:00',
					},
				]
			}
		},
		onShow() {
			this.getGiftRequest(4);
			this.getGiftRequest(1);
		},
		methods: {
			switchTabs(){
				console.log(this.active)
			},
			getGiftRequest(types){
				let that = this;
				uni.request({
					url: getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'get_times_record_list',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						uid:  getApp().globalData.user_id,
						sign: md5('get_times_record_list' + getApp().globalData.globalTimestamp),
						page:'',
						page_size:'',
						type:types
					},
					success: res => {
						if(res.data.code === 200){
							if(types === 1){
								that.inviteFriendList = res.data.msg
							}else {
								that.dayGiftList = res.data.msg
							}
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		height:100%
	}
	.content {
		height:100%;
		background: #fff;
		margin-bottom: 20rpx;
		.title {
			margin-left: 20rpx;
			padding: 20rpx 0;
			color: #818586;
			border-bottom: 1px solid #f6f6f6;
		}
		.btn {
			background: $uni-color-primary;
			background: #007aff;
			color: #fff;
			padding: 20rpx;
			display: inline-block;
			border-radius: 10rpx;
		}
		.dayGift-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			padding: 20rpx;
			border-bottom: 1px solid #ccc;
		}
		.flex-column {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;
		}
		.flex-row {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			width: 300rpx;
		}
		.flex-row view {
			width: 80upx;
			height: 80upx;
			margin-right: 2%;
			border: 1px solid white;
			border-radius: 50%;
			overflow: hidden;
		}
		.friend-time {
			font-size: 26upx;
			color: #999;
			margin-left: -15%;
			width: 260rpx;
			margin-top: 3%;
		}
	}
	
	

</style>
