<template>
	<view>
		<view class="content1">
			<u-search placeholder="搜索用户名称" v-model="keyword" :show-action='false' bg-color="#F5F6FA"></u-search>
		</view>

		<mescroll-body ref="mescrollRef" @init="mescrollInit" top="0" @down="downCallback" :up="upOption"
			@up="upCallback" @emptyclick="emptyClick">
			<!-- 数据列表 -->
			<view class="list" v-if="goods.length!=0">
				<view class="list-item" v-for="(item,index) in goods">
					<view class="left">
						<image :src="item.commonUser.avatarUrl?item.commonUser.avatarUrl:'../../static/img/face/27.png'"
							mode="aspectFill" class="head-img"></image>
						<view class="name">
							{{item.commonUser.wechatNo}}
						</view>
					</view>
					<!-- <view class="right">
						<u-icon name="plus" color="#333333" size="17" bold></u-icon><text class="case">关注</text>
					</view> -->
					<view class="right" @click="follow(item)">
						<text class="case" style="color:#878C9C;">已关注</text>
					</view>
				</view>
			</view>
		</mescroll-body>
		<u-modal v-model="show" :content="content" :show-title='false' :show-cancel-button='true'
			:content-style="contentStyle" showCancelButton='true' @confirm="cancelFollow" @cancel="show=false">
		</u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	import {
		apiGoods
	} from "@/api/mock.js"
	export default {
		components: {

		},
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				selectItem: {},
				contentStyle: {
					"font-weight": 700
				},
				show: false,
				content: '确定不在关注？',
				keyword: '',
				inputStyle: {
					// "padding-left": '30rpx'
				},
				upOption: {
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						icon: '/static/empty.png',
						tip: '暂无内容', // 提示
						// btnText: '去看看'
					}
				},
				goods: [], //列表数据
			}
		},


		onShow() {
			uni.showTabBar()
			uni.hideKeyboard()
			var userInfo = uni.getStorageSync("userInfo")
			var that = this
			console.log("userInfo", userInfo)

		},
		onLoad(options) {},


		methods: {
			cancelFollow() {
				let _obj = {
					id: this.selectItem.id
				}
				console.log()
				this.$api.doRequest('post', '/followInformation/api/deleteInfo', _obj).then(res => {
					console.log(res.data)
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '取关成功',
							type: 'success',
						})
						this.mescroll.resetUpScroll()
					}
					uni.hideLoading()
				})
			},
			follow(val) {
				this.selectItem = val
				this.show = true
			},
			edit() {},
			del() {},
			selectAddress(val) {
				console.log(val)
			},
			release() {
				uni.navigateTo({
					url: 'release'
				})
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				uni.showLoading({
					title: '数据加载中',
					mask: true
				})
				console.log("this.selectPlace", this.selectPlace)
				console.log("this.selectType", this.selectType)
				let _obj = {

				}
				if (this.selectType == '关注') {
					_obj = {
						pageSize: page.size,
						currentPage: page.num,
						placeDelivery: this.selectPlace,
						tranType: this.selectType,
						userIdFollow: this.userInfo.id,
						nowUserId: this.userInfo.id
					}
				} else {
					_obj = {
						pageSize: page.size,
						currentPage: page.num,
						userId: this.userInfo.id,
					}
				}
				this.$api.doRequest('get', '/followInformation/getInfo', _obj).then(res => {
					console.log(res.data.data.records)
					if (res.data.code == 200) {
						let curPageData = res.data.data.records;
						let curPageLen = curPageData.length;
						let totalPage = res.data.data.total;
						if (page.num == 1) this.goods = [];
						this.goods = this.goods.concat(curPageData);
						console.log(curPageLen, totalPage)
						this.mescroll.endByPage(curPageLen, totalPage);
					}
					uni.hideLoading()
				})
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			},

			// 切换菜单
			tabChange() {
				this.goods = [] // 先置空列表,显示加载进度
				this.mescroll.resetUpScroll() // 再刷新列表数据
			}

		}
	}
</script>

<style lang='scss'>
	.head-img {
		width: 76rpx;
		height: 76rpx;
		border-radius: 50%;
	}

	page {
		background: #fff !important;
	}

	.content1 {
		padding: 20rpx;
	}

	.list {
		padding: 0 22rpx;

		.left {
			display: flex;
			align-items: center;

			.name {
				font-size: 32rpx;
				font-weight: 400;
				color: #262626;
				margin-left: 26rpx;
			}
		}

		.right {
			width: 124rpx;
			height: 58rpx;
			background: #FFFFFF;
			border-radius: 29rpx;
			border: 1px solid #CDCDCD;
			line-height: 58rpx;
			text-align: center;

			.case {
				font-weight: 700;
			}
		}

		.list-item {

			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 31rpx;
			border-bottom: 1px solid #E6E6E6;
		}
	}
</style>
