<template>
	<view class="zixun-list">
		<view class="zixun-header">
			<view class="zixun-search">
				<view class="search-box u-flex">
					<u-icon name="search"></u-icon>
					<input type="text" placeholder="搜索你感兴趣的内容" v-model="keyword1" confirm-type="search" @confirm="tosearch(1)">
				</view>
			</view>
			<view class="zixun-tabs u-flex u-row-between">
				<view class="tabs-item u-flex-col u-col-center u-flex-1" :class="{'tabs-item1':current == 0}" @click="changetabs(0)">
					<text>全部</text>
					<text></text>
				</view>
				<view class="tabs-item u-flex-col u-col-center u-flex-1" :class="{'tabs-item1':current == 1}" @click="changetabs(1)">
					<text>精选</text>
					<text></text>
				</view>
			</view>
		</view>
		<view v-if="current == 0">
			<view class="zixun-item u-flex u-row-between" v-for="(item,index) in list" :key="index" @click="toinfo(item)">
				<view class="u-flex-col u-flex-1">
					<text class="text1">{{item.title}}</text>
					<!-- <text class="text2">{{item.source}}·{{$u.timeFrom(new Date(item.audit_time.replace(/-/g, "/")).getTime())}}</text> -->
				</view>
				<image :src="item.image" class="zixun-img" mode=""></image>
			</view>
			
		</view>
		<view v-if="current == 1">
			<view class="guanggao2" v-if="list[0]" @click="openad(list[0])">
				<view class="guanggao2-text">
					{{list[0].title}}
				</view>
				<view class="guanggao2-img">
					<text>广告</text>
					<image :src="list[0].image" mode="aspectFill"></image>
				</view>
			</view>
			<view class="guanggao1 u-flex u-row-between" v-for="(item,index) in list" :key="index" v-if="index > 0" @click="openad(item)">
				<view class="u-flex-col u-flex-1 guanggai1-left u-row-between">
					<text>{{item.title}}</text>
					<text>广告</text>
				</view>
				<image :src="item.image" class="zixun-img" mode="aspectFill"></image>
			</view>
		</view>
		<view style="height: 70vh;display: flex;justify-content: center;align-items: center;" v-if="list.length == 0">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	import {article_get_detail,get_ad_list } from "@/units/inquire.js"
	export default {
		data() {
			return {
				page: 1,
				list: [
					
				],
				total: 0,
				current: 0,
				keyword: '',
				keyword1: '',
			}
		},
		onLoad() {
			this.getlist()
		},
		onReachBottom() {
			if (this.total != this.list.length && this.current == 0) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			openad(item){
				if(item.link_type == 1){
					uni.navigateTo({
						url: "/pagesD/zixun-info?id=" + item.link
					})
				}else{
					uni.setClipboardData({
						data:item.link,
						success: () => {
							this.$u.toast("链接已复制")
						}
					})
				}
			},
			changetabs(index) {
				this.current = index
				this.tosearch()
			},
			tosearch(type) {
				if (type == 1) {
					this.keyword = this.keyword1
					this.current = 0
				}
				this.page = 1
				this.list = []
				this.getlist()
			},
			getlist() {
				if (this.current == 0) {
					article_get_detail({
						page: this.page,
						search: this.keyword
					}).then(res => {
						this.list = this.list.concat(res.data.data)
						this.total = res.data.total
						console.log(res);
					})
					
				} else {
					get_ad_list().then(res => {
						this.list = res.data
					})
				}
			},
			toinfo(item) {
				uni.navigateTo({
					url: "/pagesD/zixun-info?id=" + item.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.zixun-list {
		.zixun-header {
			position: sticky;
			top: 0;
			left: 0;
			width: 750rpx;
			background-color: #fff;
			z-index: 99;

			.zixun-tabs {
				height: 76rpx;

				.tabs-item {
					text:first-child {
						font-size: 32rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #141414;
						position: relative;
						z-index: 1;
					}

					text:last-child {
						width: 56rpx;
						height: 12rpx;
						border-radius: 6rpx;
						margin-top: -16rpx;
						margin-left: 20rpx;
					}
				}

				.tabs-item1 {
					text:first-child {
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #141414;
					}

					text:last-child {
						background: linear-gradient(270deg, #0C66C2 0%, #FFFFFF 100%);
					}
				}
			}
		}

		.guanggao2 {
			padding: 24rpx 0;
			margin: 0 32rpx;
			border-bottom: 2rpx solid #F0F0F0;

			.guanggao2-text {
				font-size: 34rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #222222;
				margin-bottom: 10rpx;
			}

			.guanggao2-img {
				height: 324rpx;
				border-radius: 12rpx;
				width: 100%;
				overflow: hidden;
				position: relative;

				text {
					position: absolute;
					top: 30rpx;
					right: 26rpx;
					width: 54rpx;
					line-height: 32rpx;
					background: rgba(19, 20, 21, 0.5);
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #FFFFFF;
				}

				image {
					height: 324rpx;
					border-radius: 12rpx;
					width: 100%;
				}
			}
		}

		.guanggao1 {
			padding: 24rpx 0;
			margin: 0 32rpx;
			border-bottom: 2rpx solid #F0F0F0;
			align-items: stretch;

			.guanggai1-left {
				text:first-child {
					font-size: 34rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
				}

				text:last-child {
					width: 54rpx;
					line-height: 32rpx;
					border-radius: 4rpx;
					border: 1rpx solid #979797;
					text-align: center;
					font-size: 20rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}
			}

			.zixun-img {
				width: 240rpx;
				height: 144rpx;
				border-radius: 8rpx;
				margin-left: 32rpx;
			}
		}

		.zixun-item {
			padding: 24rpx 0;
			margin: 0 32rpx;
			border-bottom: 2rpx solid #F0F0F0;

			.text1 {
				font-size: 34rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #222222;
				margin-bottom: 16rpx;
			}

			.text2 {
				font-size: 20rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
			}

			.zixun-img {
				width: 240rpx;
				height: 144rpx;
				border-radius: 8rpx;
				margin-left: 32rpx;
			}
		}

		.zixun-search {
			padding: 20rpx 32rpx;

			.search-box {
				height: 68rpx;
				background: #F3F3F3;
				border-radius: 20rpx;
				padding: 0 24rpx;

				input {
					flex: 1;
					margin-left: 12rpx;
					font-size: 26rpx;
				}
			}
		}
	}
</style>