<template>
	<view class="content">
		<!--搜索 start-->
		<view class="Search-box" @click="">
			<view class="Search-box-size">
				<image class="box-img" src="../../static/img/img01.png"></image>
				<input type="text" class="box-word" placeholder="请输入关键字" v-model="keyword"  />
			</view>
			<view class="Search-box-sort" @click="getList('click')">搜索</view>
		</view>
		<!-- 搜索 end-->
		<!-- 补位 -->
		<view class="" style="height: 100rpx;"></view>
		<!-- 自媒体列表 start -->
		<view class="dy-wrap flex" v-for="item in list" @click="navTo('/pages/user/dydetail?id=' + item.id)">
			<view class="user-logo">
				<image :src="item.headimg" mode=""></image>
			</view>
			<view class="user-num">
				<view class="user-name">
					{{item.name}}
				</view>
				<view class="sub-num">
					发表文章：{{item.count}}
				</view>
				<view class="read-num">
					阅读量：{{item.visit}}
				</view>
			</view>
			<view class="flex_direction">
				<view class="dy-btn" :class="{'dying':item.is_sub == 1}" @click.stop="dingYue(item)">
					{{item.is_sub == 1?'已订阅':'订阅'}}
				</view>
				<view class="jr-btn" v-if="item.join" :class="{'dying':item.join == 1}"  @click.stop='toJoin(item)'>
					已加入
				</view>
				<view class="jr-btn" style="display: block;" v-if="!item.joins&&!item.join" :class="dying" @click.stop='toJoin(item)'>
					加入
				</view>
			</view>
		</view>
		<!-- 自媒体列表 end -->
		<!-- <empty v-if=" list.length === 0"></empty> -->
	</view>
</template>

<script>
	import { searchZmt,dingYue } from '@/api/art.js'
	import empty from '@/components/empty';
	export default {
		components: {
			// uniLoadMore,
			empty
		},
		data() {
			return {
				list: [],
				page: 1,
				limit: 20,
				loadingType: 'more',
				keyword: '',
			}
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			navTo(url) {
				uni.navigateTo({
					url
				})
			},
			getList(type) {
				let obj = this
				if(type == 'click') {
					obj.list = []
					obj.page = 1
					obj.loadingType = 'more'
				}
				searchZmt({
					page: obj.page,
					rows: obj.limit,
					name: obj.keyword
				}).then(res => {
					console.log(res)
					obj.list = obj.list.concat(res.data.list)
				})
			},
			//加入
			toJoin(item){
				if(!this.merId){
					this.navTo('/pages/user/joinMedia?id=' + item.id)
				}
				
			},
			// 订阅
			dingYue(item) {
				let obj = this
				// is_sub 为1 时为关注状态
				if(item.is_sub == 1) {
					uni.showModal({
						title:'提示',
						content: '是否取消关注？',
						complete(e) {
							if(e.confirm) {
								// 取消关注
								dingYue({
									id:item.id
								}).then(res => {
									console.log(res)
									let s = obj.list.indexOf(item);
									obj.list[s].is_sub = 0
									obj.$api.msg('已取消关注')
								})
								
							}
						}
					})
				}else {
					// 关注
					dingYue({
						id:item.id
					}).then(res => {
						let s = obj.list.indexOf(item);
						obj.list[s].is_sub = 1
						obj.$api.msg('已关注')
					})
					
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #fff;
	}
	.jr-btn {
		flex-shrink: 0;
		text-align: center;
		width: 136rpx;
		line-height: 66rpx;
		border-radius: 10rpx;
		font-size: 28rpx;
		font-weight: 500;
		margin-top: 20rpx;
		background: #E6645F;
		color: #fff;
	}
	.Search-box {
		position: absolute;
		top: 0;
		width: 750rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		height: 100rpx;
		background: #ffffff;
		display: flex;
		justify-content: space-around;
		align-items: center;
	
		.Search-box-sort {
			font-size: 30rpx;
			flex-shrink: 0;
			font-weight: 500;
			color: rgba(102, 102, 102, 1);
	
			.sort-text {
				width: 57rpx;
				height: 29rpx;
				font-size: 30rpx;
				font-weight: 500;
				color: rgba(51, 51, 51, 1);
				line-height: 58rpx;
				margin-right: 19rpx;
			}
			.sort-img {
				width: 21rpx;
				height: 11rpx;
				margin-bottom: 4rpx;
			}
		}
		.Search-box-size {
			width: 605rpx;
			height: 65rpx;
			border-radius: 32rpx;
			background-color: #f1f1f1;
			padding-left: 36rpx;
			display: flex;
			align-items: center;
	
			.box-img {
				height: 32rpx;
				width: 32rpx;
				margin-right: 16rpx;
			}
			.box-word {
				padding: 10rpx;
				width: 100%;
				font-size: 22rpx;
				font-weight: 500;
				color: rgba(205, 203, 203, 1);
				line-height: 55rpx;
				height: 60rpx;
				color: #000000;
			}
		}
	}
	.dy-wrap {
		width: 707rpx;
		background: #fff;
		margin: auto;
		border-bottom: #E9E9E9 solid 1px;
		padding: 20rpx 0;
		.user-logo {
			flex-shrink: 0;
			height: 100rpx;
			width: 100rpx;
			border-radius: 50%;
			image {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
		.user-num {
			flex-grow: 1;
			padding-left: 10rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: #999999;
			.user-name {
				font-size: 34rpx;
				font-weight: 600;
				color: #333333;
				padding-right: 20rpx;
				padding: 0 20rpx 20rpx 0;
			}
		}
		.dy-btn {
			flex-shrink: 0;
			text-align: center;
			width: 136rpx;
			line-height: 66rpx;
			
			border-radius: 10rpx;
			font-size: 28rpx;
			font-weight: 500;
			
			background: #E6645F;
			color: #fff;
		}
		.dying {
			
			color: #999999;
			background: #E9E9E9;
		}
	}
</style>
