<template>
	<view>
		<movable-area class="movable-area">
		    <movable-view :x="touchX" :y="touchY" direction="all" style="z-index: 10;">
				<image @click="handleEditClick" class="edit-btn" :src="imgfixUrls + 'dating/bd_dynamics_edit.svg'" mode=""></image>
			</movable-view>
			
			<loadlogo v-if="!loadlogo" />
			
			<navbar :navbarList="navbar" :isfix="true" :topHeight="0" :leftWidth="0" :isbgf="true" @navbarChange="handleNavbarItemClcik"></navbar>
			<scroll-view scroll-y="true" class="content" @scrolltolower="scrolltolower">
				<view>
					<view class="item" v-for="item in dynamicList" :key="item.id">
						<personnal-item :dynamicInfo="item" @toDetail="toDynamicDetail"></personnal-item>
						<view class="interval"></view>
					</view>
				</view>
			</scroll-view>
		</movable-area>
	</view>
</template>

<script>
	import App from '@/common/js/app.js';
	import navbar from '../template/navbar.vue';
	import Loadlogo from '@/components/template/loadlogo.vue';
	import personnalItem from '../template/personalItem.vue';
	export default {
		data() {
			return {
				loadlogo: false,
				navbar: ['最新','热门','附近','VIP专区'],
				dynamicList: [],  //动态列表
				currentPage: 1,
				totalPage: 1,
				navbarIndex: 0,
				lng: '',
				lat: '',
				touchX: 300,
				touchY: 400,
				type: 1
			}
		},
		onLoad() {
			let _this = this
			// 经纬度赋值
			uni.getLocation({
			    type: 'wgs84',
			    success(res) {
					_this.lng = res.longitude
					_this.lat = res.latitude
			    }
			})
			_this.getDynamicList()
		},
		components: {
			navbar,
			personnalItem,
			Loadlogo
		},
		methods: {
			// 获取动态列表
			getDynamicList() {
				let _this = this,
					params = {
						page: _this.currentPage,
						sort: Number(_this.navbarIndex) + 1,
						lng: _this.lng,
						lat: _this.lat,
						is_vip: _this.type
					}
				App._post_form(
					`&p=dating&do=dynamicList`,
					params,
					res => {
						_this.dynamicList = [..._this.dynamicList,...res.data.list]
						_this.totalPage = res.data.total
						_this.currentPage ++
						_this.loadlogo = true
					},
					false,
					() => {
					}
				);
			},
			
			// 去动态详情
			toDynamicDetail(id,type) {
				if(!type) {
					console.log(type,'触发type')
					App.navigationTo({
						url: `pages/subPages2/blindDate/dynamics/detail?id=${id}`
					})
				}
			},
			
			// 导航栏点击
			handleNavbarItemClcik(index) {
				this.navbarIndex = index
				//  是否获取vip信息
				this.type = index == 3 ? 2 : 1
				this.currentPage = 1
				this.dynamicList = []
				this.getDynamicList()
			},
			
			// 去编辑动态
			handleEditClick() {
				App.navigationTo({
					url: `pages/subPages2/blindDate/dynamics/edit?id=0`
				})
			},
			
			// 触底加载更多
			scrolltolower() {
				if(this.currentPage <= this.totalPage) {
					this.getDynamicList()
				}
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.movable-area {
		min-height: 100vh;
		width: 100vw;
	}
	
	.content {
		padding-top: 90rpx;
		height: calc(100vh - 90rpx);
		background-color: #f8f8f8;
	}
	
	.edit-btn {
		width: 136rpx;
		height: 136rpx;
		// position: fixed;
		// bottom: 200rpx;
		// right: 10rpx;
		z-index: 10;
	}
	
	.interval {
		width: 690rpx;
		height: 8rpx;
		margin: auto;
		background-color: #eee;
	}
</style>
