<template>
	<view class="page">
		<!-- 导航栏 -->
		<navbar title="礼包列表" leftClick @leftClick="$utils.navigateBack" bgColor="#E3441A" color="#fff" />

		<!-- 订单筛选 -->
		<view class="tabs">
			<uv-tabs :list="tabs" 
			:activeStyle="{color : 'rgb(235, 51, 0)', fontWeight : 600}" 
			lineColor="rgb(235, 51, 0)"
			:inactiveStyle="{color: 'rgba(235, 51, 0, .8)'}" 
			lineHeight="8rpx" 
			lineWidth="50rpx" 
			:current="current"
			:scrollable="false"
			@click="clickTabs"></uv-tabs>
		</view>

		<view class="list">
			<view class="item" v-for="(item, index) in list" @click="toGiftDetail(item.id)" :key="index">
				<view class="content">
					<view class="top">
						<view class="service">
							{{ item.title }}
						</view>
						<view class="status">
							<text>{{ item.state === 0 ? '待领取' : '已领取' }}</text>
						</view>
					</view>

					<view class="main">
						<view class="left">
							<image mode="aspectFill" :src="item.image && item.image.split(',')[0]"></image>
						</view>

						<view class="right">
							<view class="text-hidden-1">
								赠送人：{{item.senderName}}
							</view>
							<view class="text-hidden-1">
								赠送时间：{{item.createTime}}
							</view>
							<view class="text-hidden-2">
								祝福语：{{item.message}}
							</view>
						</view>
					</view>
				</view>

				<view class="bottom">
					<view class="price">
						<text class="total-title">礼包价值：</text>
						<text class="unit">￥</text>
						<text class="num">{{item.price}}</text>
						<text class="c-unit">元</text>
					</view>

					<view @click.stop="receiveGift(item)" class="btn" v-if="item.state === 0">
						立即领取
					</view>
				</view>
			</view>
			
			<view style="margin-top: 20rpx; min-width: 700rpx;">
				<uv-empty mode="list" v-if="list.length === 0"></uv-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import mixinsList from '@/mixins/list.js'
	
	export default {
		mixins: [mixinsList],
		data() {
			return {
				mixinsListApi: 'getGiftList',
				tabs: [
					{
						name: '我赠送的'
					},
					{
						name: '我收到的'
					}
				],
				current : 0,
			}
		},
		methods: {
			clickTabs({index}){
				
			},
			// 跳转礼包详情
			toGiftDetail(id) {
				uni.navigateTo({
					url: '/pages_order/order/giftDetail?id=' + id
				})
			},
			// 领取礼包
			receiveGift(item) {
				uni.showModal({
					title: '提示',
					content: '确认领取该礼包吗？',
					success: async (res) => {
						if (res.confirm) {
							await this.$http.post('/gift/receive', {
								id: item.id
							})
							uni.showToast({
								title: '领取成功',
								icon: 'success'
							})
							this.getData()
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.list {
		.item {
			width: calc(100% - 40rpx);
			background-color: #fff;
			margin: 20rpx;
			box-sizing: border-box;
			border-radius: 16rpx;
			padding: 30rpx;

			.content {
				.top {
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 34rpx;

					.status {
						font-weight: 600;
						color: #FFAC2F;
						flex-shrink: 0;
						margin-left: 20rpx;
					}
				}

				.main {
					display: flex;
					margin: 20rpx 0rpx;

					.left {
						display: flex;
						align-items: center;
						justify-content: center;
						width: 180rpx;
						height: 180rpx;

						image {
							width: 95%;
							height: 95%;
							border-radius: 10rpx;
						}
					}

					.right {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: calc(100% - 200rpx);
						color: #777;
						font-size: 26rpx;
						padding: 30rpx 20rpx;
						box-sizing: border-box;
						margin-left: 20rpx;
						border-radius: 10rpx;
						background-color: #F8F8F8;
					}
				}
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				font-size: 25rpx;

				.price {
					.num {
						font-size: 36rpx;
					}

					.num,
					.unit,
					.c-unit {
						color: $uni-color;
					}
				}

				.btn {
					border: 1px solid #C7C7C7;
					padding: 10rpx 20rpx;
					border-radius: 40rpx;
					color: #575757;
				}
			}
		}
	}
</style>