<template>
	<view class="page">
		<view class="topBody">
			<view class="header">
				<view class="infoBg">
					<view class="top_row">
						<view class="left" @click="goPage('/pages/my/editInfo')">
							<image class="img" mode="aspectFill" :src="myinfo.avator"></image>
						</view>
						<view class="right" @click="goPage('/pages/my/editInfo')">
							<view class="nickname">
								<text>{{myinfo.nickname}}</text>
								<image src="../../static/icon/man.png" mode="widthFix" v-if="myinfo.sex_id == 1" />
								<image src="../../static/icon/woman.png" mode="widthFix"
									v-else-if="myinfo.sex_id == 2" />
								<view class="level">Lv{{myinfo.my_level}}</view>
							</view>
							<view class="tags_list">
								<block v-for="(item,index) in aihao_tags">
									<uni-tag class="tag" type="primary" :inverted="false" :text="item" size="mini" />
								</block>
							</view>
						</view>
					</view>

					<view class="bottom_row">
						<view class="intro_row">
							<text class="intro_text">{{myinfo.content}}</text>
						</view>
						<view class="follow_info">
							<text class="num">{{myinfo.num_attention}}</text>
							<text class="label">关注</text>
							<text class="separator"></text>
							<text class="num">{{myinfo.num_fans}}</text>
							<text class="label">粉丝</text>
							<text class="separator"></text>
							<text class="num">{{myinfo.num_like}}</text>
							<text class="label">获赞</text>
						</view>
					</view>
				</view>

			</view>
		</view>
		<view class="myinfo" @touchstart="handleTouchStart">
			<view class="line"></view>
			<view class="tips">3作品</view>
			<view class="numlist2" style="margin-top: 60rpx;">
				<view class="item" v-for="(item,index) in worksList" :key="index">
					<view class="num">
						<image class="icon" :src="item.images" mode="widthFix" />
						<view class="name">
							<text class="title-text">{{item.title || '作品'+index}}</text>
							<view class="like-count">
								<image class="heart-icon" src="../../static/icon/icon-7.png" mode="widthFix"></image>
								<text>{{item.like_count || 0}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 加载更多提示 -->
			<view class="loading-more" v-if="isLoading">加载中...</view>

		</view>

		<!-- <view class="btn_submit" @click="chatTA()">
			<image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
			私聊
		</view> -->
		<view class="thread2"></view>
		<view class="thread2"></view>

	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				title: '',
				userID: 0,
				selImg: 0,
				home_image: '',
				myinfo: {},
				tag_list: [],
				image_list: [],
				imgs: [],
				descs: [],
				aihao_tags: [],
				worksList: [],
				activeTab: 0,
				offset: 0,
				hasMore: true,
				isLoading: false,

				myInfo: {
					user_id: 1,
					user_name: "cc",
					user_avatar: "https://img0.baidu.com/it/u=2836960144,3650263035&fm=253&fmt=auto&app=138&f=JPEG?w=474&h=474",
				},
			}
		},
		onLoad(parms) {
			let self = this;
			this.userID = parms.uid || 1;
		},
		onShow() {
			uni.$emit('check_update');
			// this.loadData();
			this.loadData();
			this.loadWorksList();
		},
		methods: {
			handleTouchStart(event) {
				event.preventDefault(); // 防止页面滚动
				console.log('触摸开始');
			},
			onLinqu(item) {
				uni.navigateTo({
					url: '/pages/my/wishHelp?id=' + item.myid,
				})
			},
			selPhoto(item, sel) {
				this.selImg = sel;
				this.home_image = this.image_list[sel];
			},
			loadInfo() {
				console.log({
					uuid: getApp().globalData.uuid,
					skey: getApp().globalData.skey
				});
				uni.request({
					url: this.$apiHost + '/User/getinfo',
					data: {
						uuid: getApp().globalData.uuid,
						skey: getApp().globalData.skey
					},
					header: {
						"content-type": "application/json",
						'sign': getApp().globalData.headerSign
					},
					success: (res) => {
						console.log("----:", res.data);
						if (res.data.need_login == "yes") {
							// getApp().globalData.skey = "";
							// getApp().globalData.uuid = "";
							// uni.removeStorageSync("wapptoken");
							// uni.redirectTo({
							// 	url: '/pages/login/login'
							// });
							// return;
						}
						if (res.data.aihao) {
							this.aihao_tags = res.data.aihao.split(",");
						}
						this.myinfo = res.data;
					},
					complete: (com) => {
						// uni.hideLoading();
					},
					fail: (e) => {
						console.log("----e:", e);
					}
				});
			},
			toArr(imgs) {
				let arr = imgs.split("|");
				return arr;
			},
			previewOpen(imgs1, index) {
				this.imgs = imgs1.split("|");
				setTimeout(() => this.$refs.previewImage.open(index), 0)
				// 传入当前选中的图片地址或序号
				return; //如需测试和uni原生预览差别可注释这两行
			},
			loadData() {
				// console.log({
				// 	uuid: getApp().globalData.uuid,
				// 	skey: getApp().globalData.skey
				// });
				uni.request({
					url: this.$apiHost + '/Member/getHomeInfo',
					data: {
						uuid: getApp().globalData.uuid,
						userID: this.userID
					},
					header: {
						"content-type": "application/json",
						'sign': getApp().globalData.headerSign
					},
					success: (res) => {
						console.log("----:", res.data);
						this.myinfo = res.data;
						if (res.data.aihao) {
							this.aihao_tags = res.data.aihao.split(",");
						}
						this.myinfo = res.data;
					},
					complete: (com) => {
						// uni.hideLoading();
					},
					fail: (e) => {
						console.log("----e:", e);
					}
				});
			},

			loadWorksList() {
				if (this.isLoading) return;
				this.isLoading = true;

				uni.request({
					url: this.$apiHost + '/Work/getlist',
					data: {
						uuid: getApp().globalData.uuid,
						skey: getApp().globalData.skey,
						ismy: 1, // 固定为1，表示获取自己的作品
						offset: this.offset,
						status: 1
					},
					header: {
						"content-type": "application/json",
						'sign': getApp().globalData.headerSign
					},
					success: (res) => {
						console.log("作品列表数据:", res.data);
						if (res.data.success == 'yes' && res.data.list) {
							if (res.data.list.length > 0) {
								this.worksList = [...this.worksList, ...res.data.list];
								this.offset += res.data.list.length;
							}

							if (res.data.list.length < 20) {
								this.hasMore = false;
							}
						} else {
							this.hasMore = false;
						}

					},
					complete: () => {
						this.isLoading = false;
					},
					fail: (e) => {
						console.log("请求作品列表失败:", e);
						this.isLoading = false;
					}
				});
			},


		}
	}
</script>

<style scoped lang="scss">
	@import 'peopleHome.scss';
</style>