<template>
	<view class="user">
		<view class="user-navbar" :style="{'height': (statusBarHeight+44)+'px'}">
			<u-navbar :bgColor="bgColor" :fixed="false" :autoBack="true" title="我的关注">
				<view class="u-nav-slot" slot="content">
					<view class="nav"></view>
				</view>
			</u-navbar>
		</view>
		<view class="blank" :style="{'height': (statusBarHeight+44)+'px'}"></view>
		<view class="user-list">
			<view class="users">
				<view class="a">
					<image class="avater" src="@/static/default.png"></image>
					<view class="name">幽默的先生</view>
				</view>
				<view class="c">
					<image src="@/static/icon-dui.png"></image>已关注
				</view>
			</view>
		</view>
		<view class="list">
			<view class="tab">
				 <u-tabs :list="list1" @click="click"
					lineWidth="0"
					:activeStyle="{
						 color: '#00C6A9',
						 border: '1px solid #00C6A9',
						 borderRadius: '5px',
						 width: '150rpx',
						 textAlign: 'center',
						padding: '10rpx 0',
						display: 'block',
					}"
					:inactiveStyle="{
						color: '#999999',
						border: '1px solid #999999',
						width: '150rpx',
						display: 'block',
						padding: '10rpx 0',
						textAlign: 'center',
						borderRadius: '5px'
					 }"
				 ></u-tabs>
			</view>
			<view class="item" v-for="i in 10" :key="i" @click="openPage(1)">
				<view class="name">王某某欠钱不还，已起诉</view>
				<view class="desc">欠钱不还/欺诈/拖欠工资</view>
				<view class="do">
					<view class="fl"><image class="img1" src="@/static/icon-view.png"></image>560</view>
					<view class="fl"><image class="img2" src="@/static/dianzan.png"></image>260</view>
				</view>
				<view class="tag">善</view>
			</view>
			<view class="item" @click="openPage(1)">
				<view class="name">王某某欠钱不还，已起诉</view>
				<view class="desc">欠钱不还/欺诈/拖欠工资</view>
				<view class="do">
					<view class="fl"><image class="img1" src="@/static/icon-view.png"></image>560</view>
					<view class="fl"><image class="img2" src="@/static/dianzan.png"></image>260</view>
				</view>
				<view class="tag tag-on">恶</view>
			</view>
		</view>
	</view>
</template>

<script>
	import fooBar from '@/components/fooBar/fooBar.vue'
	export default {
		components: {
			fooBar
		},
		data() {
			return {
				current: 0,
				list1: [{
                    name: '热点事件',
                }, {
                    name: '暖心善举',
                }, {
                    name: '恶行曝光'
                }],
				statusBarHeight: 0,
				bannerList: ['https://cdn.uviewui.com/uview/swiper/swiper1.png', 'https://cdn.uviewui.com/uview/swiper/swiper2.png', 'https://cdn.uviewui.com/uview/swiper/swiper3.png'],
				goodsList: [],
				bgColor: "transparent",
				index: 3,
				title: ''
			}
		},
		
		mounted() {
			uni.hideTabBar();
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			
		},
		onShow() {
			uni.removeStorageSync("goodsList")
			uni.removeStorageSync("scanInfo")
		},
		methods: {
			openPage(id){
				uni.navigateTo({
					url: "/pages/release/detail?id="+id
				})
			},
			queryLocation() {
				uni.getLocation({
					type: 'gcj02',
					success(res) {
						console.log(res)
						let latitude = res.latitude,longitude = res.longitude;
						let url = `https://restapi.amap.com/v3/geocode/regeo?output=json&location=${longitude},${latitude}&key=b23865c8693171aecf4adf8cf9f0da36&radius=1000`
						uni.request({
							url,
							success(res) {
								console.log("地址解析")
								console.log(res)
								if(res.data.regeocode.addressComponent){
									let city = res.data.regeocode.addressComponent.city.length==0?res.data.regeocode.addressComponent.province:res.data.regeocode.addressComponent.city
									uni.setStorageSync("city",city);
								}
								
							}
						})
					},
					fail(e) {
						console.log(e)
					}
				})
			},
			toPage(index) {
				uni.setStorageSync("articleInfo", this.articleList2[index]);
				uni.navigateTo({
					url: "/pages/view/outer?type=3"
				})
			},
			openPage(index,id){
				if(index == 1){
					uni.navigateTo({
						url: "/pages/goods/detail?id="+id
					})
				}else if(index == 2){
					this.$toScan();
					// uni.scanCode({
					// 	onlyFromCamera: true,
					// 	success: function (res) {
					// 		console.log(res)
					// 	}
					// })
				}else if(index == 3){
					uni.$emit("categoryIndex",id)
					uni.switchTab({
						url: "/pages/category/index"
					})
				}else if(index == 4){
					uni.switchTab({
						url: "/pages/category/index"
					})
				}else if(index == 5){
					if(!uni.getStorageSync("token")){
						uni.navigateTo({
							url: "/pages/login/login"
						})
						return ;
					}
					uni.navigateTo({
						url: "/pages/user/vip"
					})
				}else if(index == 6){
					uni.navigateTo({
						url: "/pages/user/people"
					})
				}
			},
			//系统公告
			async queryArticleList1() {
				const { code, data } = await this.$api.articleList({type: 2})
				if(code == 200){
					if(data && data.length > 0){
						this.articleList1 = data[0]
						this.showPopup = false
					}
				}
			},
			//官方公告
			async queryArticleList2() {
				const { code, data } = await this.$api.articleList({type: 3})
				if(code == 200){
					if(data && data.length > 0){
						data.map(a=>{
							this.list5.push(a.title)
						})
					}
					this.articleList2 = data
				}
			},
			//获取商品分类
			async queryGoodsCategoryList() {
				const { code, data } = await this.$api.goodsCategoryList({})
				if(code == 200){
					this.goodsCategoryList = data
				}
			},
			//获取商品列表
			async queryGoodsList() {
				const { code, data } = await this.$api.goodsList({
					name: this.name,
					page: 1
				})
				if(code == 200){
					let list = data.list;
					if(list && list.length > 0){
						list.map(a=>{
							a.sold = (100 - ((a.sold_count/a.stock)*100).toFixed(2))
						})
					}
					this.goodsList = list
				}
			},
			//获取轮播图
			async queryBannerList() {
				const { code, data } = await this.$api.bannerList({})
				let arr = []
				if(data && data.length > 0){
					data.map(a=>{
						arr.push(a.image)
					})
				}
				if(code == 200){
					this.bannerList = arr
				}
			},
			changeSwiper(e) {
				this.current = e.current;
			},
			open() {
			  // console.log('open');
			},
			close() {
			  this.showPopup = false
			  // console.log('close');
			},
			async toIndex(index) {
				let that = this
				that.index = index
				if (index == 0) {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}else if (index == 2) {
					uni.switchTab({
						url: '/pages/release/index'
					})
				} else if (index == 3) {
					uni.switchTab({
						url: '/pages/user/index'
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.user {
		min-height: 100vh;
		background: url(@/static/bg.png) center top no-repeat;
		background-size: 100% auto;
		overflow: hidden;
		box-sizing: border-box;
		.list{
			padding: 0 0 25rpx 0;
			background-color: #f3f7f8;
			overflow: hidden;
			border-radius: 20rpx 20rpx 0 0 ;
			margin-top: 50rpx;
			.tab{
				margin-top: 20rpx;
			}
			.item{
				width: 700rpx;
				height: 180rpx;
				background: #FFFFFF;
				box-shadow: 0px 3rpx 10rpx 0px rgba(9,44,39,0.05);
				border-radius: 20rpx;
				padding: 30rpx;
				box-sizing: border-box;
				position: relative;
				margin: 0 auto;
				margin-top: 20rpx;
				.tag{
					width: 80rpx;
					height: 56rpx;
					text-align: center;
					line-height: 56rpx;
					background: #00C6A9;
					border-radius: 0px 20rpx 0px 20rpx;
					font-size: 32rpx;
					color: #FFFFFF;
					position: absolute;
					right: 0;
					top: 0;
					z-index: 2;
					&-on{
						background: #333333;
					}
				}
				.name{
					font-weight: 500;
					font-size: 30rpx;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
					color: #333333;
				}
				.desc{
					font-weight: 500;
					font-size: 24rpx;
					color: #999999;
					margin-top: 10rpx;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}
				.do{
					display: flex;
					align-items: center;
					margin-top: 10rpx;
					.fl{
						width: 130rpx;
						display: flex;
						align-items: center;
						font-weight: 500;
						font-size: 24rpx;
						color: #999999;
						.img1{
							width: 30rpx;
							height: 20rpx;
							margin-right: 10rpx;
							margin-top: 5rpx;
						}
						.img2{
							width: 24rpx;
							height: 24rpx;
							margin-right: 10rpx;
						}
					}
				}
			}
		}
		&-navbar{
			position: fixed;
			left: 0;
			right: 0;
			top: 0;
			z-index: 12;
			width: 100%;
			background: url(@/static/bg.png) center top no-repeat;
			background-size: 100% auto;
		}
		&-list{
			overflow: hidden;
			margin-top: 45rpx;
			.info{
				display: flex;
				align-items: center;
				overflow: hidden;
				margin-top: 40rpx;
				.item{
					flex: 1;
					font-weight: 500;
					font-size: 24rpx;
					color: #333333;
					text-align: center;
					text{
						display: block;
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
						margin-bottom: 20rpx;
					}
				}
			}
			.users{
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 25rpx;
				.a{
					font-weight: 400;
					font-size: 34rpx;
					color: #333333;
					line-height: 36rpx;
					display: flex;
					align-items: center;
					.avater{
						width: 110rpx;
						height: 110rpx;
						border-radius: 50%;
						margin-right: 25rpx;
					}
					.edit{
						width: 45rpx;
						height: 45rpx;
						margin-left: 10rpx;
						margin-top: 10rpx;
					}
				}
				.c{
					width: 130rpx;
					height: 50rpx;
					line-height: 50rpx;
					background: #00C6A9;
					border-radius: 4rpx;
					font-weight: 500;
					font-size: 22rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #FFFFFF;
					image{
						width: 20rpx;
						height: 14rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
	}
</style>
