<template>
	<view>
		<view v-if="list.length > 0">
			<view class="co-title"></view>
			<view class="co-list">
				<view :class="item.status == 1 ? 'co-status1 co-item':'co-status2 co-item'" v-for="(item,index) in list">
					<view class="co-left">
						<view class="co-title">{{item.title}}</view>
						<view class="co-over">过期时间: {{item.over}}</view>
					</view>
					<view class="co-right">
						<view class="co-price">{{item.price}}</view>
						<view class="co-status">{{item.status_title}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="nodata_box" v-if="list.length==0">
			<image src="/static/user/no_data_img.png" mode="" style="width: 220rpx; height: 302rpx;"></image>
			<text>暂无数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {},
				user_id: '',
			}
		},
		onLoad() {
			if (uni.getStorageSync('id')) {
				this.getInfo();
				this.show = true;
			} else {
				// #ifdef MP
				this.mpLogin()
				return
				uni.showToast({
					title: '请先登录'
				})
				// #endif
			}
		},
		methods: {
			getInfo() {
				let that = this;
				let user_id = uni.getStorageSync('id');
				this.$post({
					data: {
						do: 'CouponList',
						data: {
							user_id: user_id,
						}
					}
				}).then(res => {
					that.list = res.data
				})
			},
			// 小程序登录
			mpLogin() {
				let that = this;
				uni.login({
					provider: 'weixin',
					success: (res) => {
						console.log(res, 'rrrrrr')
						const code = res.code
						this.$post({
							data: {
								do: 'Login',
								data: {
									code
								}
							}
						}).then(res => {
							this.logininfo = res.data
							uni.showModal({
								title: '提示',
								content: '是否进行头像和昵称授权',
								success: (res) => {
									if (res.confirm) {
										this.getnickImage()
									}
								}
							})
						})
					}
				})
			},
			getnickImage() {
				console.log(this.logininfo.id)
				uni.getUserProfile({
					desc: '用于昵称和头像的展示',
					success: res => {
						console.log(res, '++++')
						console.log({
							user_id: this.logininfo.id,
							nickName: res.userInfo.nickName,
							avatarUrl: res.userInfo.avatarUrl
						})
						this.$post({
							data: {
								do: 'UpdateUser',
								data: {
									user_id: this.logininfo.id,
									nickName: res.userInfo.nickName,
									avatarUrl: res.userInfo.avatarUrl
								}
							}
						}).then(res => {
							console.log(res, 'rrrrrrrrrr')
							for (let i in this.logininfo) {
								uni.setStorageSync(i, this.logininfo[i])
							}
							this.type == 0;
							this.getuserinfo();
						})
						// this.nickName = res.userInfo.nickName
						// this.avatarUrl = res.userInfo.avatarUrl
						// this.country = res.userInfo.country
						// this.province = res.userInfo.province
						// this.city = res.userInfo.city
						// this.gender = res.userInfo.gender
						// uni.login({
						// 	provider: 'weixin',
						// 	success: (res) => {
						// 		this.loginCode = res.code
						// 		uni.hideLoading()
						// 		this.popShow = true
						// 	},
						// })
					},
					fail: (err) => {
						uni.hideLoading()
					}
				})
			},
		}
	}
</script>

<style>
	.nodata_box{
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin: 0 auto;
			margin-top: 250rpx;
		}
	.co-left {
		width: 85%;
	}

	.co-item {
		display: flex;
		margin: 20rpx;
		padding: 35rpx;
		border-radius: 30rpx;
		align-items: center;
	}

	.co-title {
		font-size: 50rpx;
		margin: 0 0 20rpx;
	}

	.co-price {
		font-size: 40rpx;
	}
	
	.co-status1{
		background-color: #ffdada;
	}
	.co-status2{
		background-color: #f1f1f1;
	}
</style>
