<template>
	<view class='content'>
		<view>
			<u-empty v-if="dataList.length==0" marginTop="250"></u-empty>
			<view class="relic_list" v-else='dataList.length>0'>
				<view class='relic_item' v-for='item in dataList' @click='todetail(item.id)'>
					<img :src="item.head_upload.url" alt="">
					<view>
						<view>{{item.name}}</view>
						<view class='contain'>{{item.contain}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentPage: 1,
				isLoading: false,
				dataList: []
			}
		},
		onLoad() {
			this.loadrelic(1)
		},

		onPullDownRefresh() {
			if (!this.isLoading) {
				this.loadrelic(this.currentPage + 1);
			}
		},
		onReachBottom() {
			if (!this.isLoading) {
				this.loadrelic(this.currentPage + 1);
			}
		},
		methods: {
			relicChange(e) {
				this.current = e.index;
				this.loadrelic(1);
			},
			cancelTime(str) {
				return str ? str.substring(0, 10) : ''
			},
			todetail(id) {
				uni.navigateTo({
					url: "/pages/relic/detail?id=" + id
				});
			},
			loadrelic(page) {
				uni.hideKeyboard()
				var that = this;
				that.isLoading = true;
				this.util.request({
					api: '/api/mobile/cultural-relic/index',
					customLoading: false,
					data: {
						page: page,
						page_size: 6
					},
					utilSuccess: function(r) {
						var res = r.data;
						that.isLoading = false;
						var hasNoMore = r.total < 6 && page > 1;
						console.log("hasNoMore", hasNoMore)
						if (hasNoMore || res.length == 0 && page > 1) {
							uni.stopPullDownRefresh(); // 服务器总条数 < 每页条数, 会将第一页的条数重新返回
							// 已加载到最后一页
							uni.showToast({
								title: '已加载到最后一页',
								icon: 'none'
							});
							return;
						}
						var dataList = that.dataList;

						// 		for (var m of res) {
						// 			if (m.created_at.indexOf('T') > 0)
						// 				m.created_at = m.created_at.split("T")[0] + " " + m.created_at.split("T")[
						// 					1].split(".")[0];


						// 			m.poster = (weixin.isNull(m.poster) ? "../../static/rishang.png" : m
						// 				.poster_url)
						// 		}

						if (page == 1) {
							dataList = res;
						} else {
							dataList.push(...res);
						}

						that.currentPage = page;
						that.dataList = dataList;
					},
					utilFail: function(res) {

						if (page == 1) {

							that.currentPage = page;
						}

						that.util.alert(res);
					}
				});
			}
		}
	}
</script>

<style>
	.tabsnav {
		background-color: #fbf3ea;
	}

	.relic_list {
		padding: 0 30rpx;
	}

	.relic_item {
		width: 100%;
		padding: 30rpx 0;
		padding-top: 20rpx;
		border-bottom: 1px solid #fafaf9;
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
	}

	.relic_item img {
		width: 310rpx;
		height: 183rpx;
		border-radius: 10rpx;
	}

	.relic_item>view {
		width: 370rpx;
	}

	.relic_item>view view {
		margin-top: 10rpx;
	}

	.relic_item>view view:first-child {
		width: 100%;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		/* 这里是超出几行省略 */
		overflow: hidden;
		font-size: 30rpx;
		margin-top:0
	}

	.relic_item>view view:last-child {
		width: 100%;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		/* 这里是超出几行省略 */
		overflow: hidden;
		font-size: 26rpx;
		margin-top: 10rpx;
	}
</style>