<template>
	<view v-if="isShow">
		<view class="top-fixed">
			<view class="search-box ddflex">
				<view class="search-input ddflex fflex">
					<image src="/static/images/ssico.png"></image>
					<input @confirm="searchFn" confirm-type="search" @input="searchFn" v-model="searchVal" class="fflex"
						placeholder="请输入关键词" />
				</view>
			</view>
		</view>
		<view style="height: 140rpx;"></view>
		<view class="act-list" v-if="pageList && pageList.length > 0">
			<view class="li" v-for="(item, index) in pageList" :key="index"  @click="jumpUrl('/library/pageDetail/index?code=' + item.code)">
				<view class="imgbox"><image :src="item.pic" mode="aspectFill"></image></view>
				<view class="infos fflex">
					<view class="stas ddflex">
						<view class="fflex">
							<view class="act-tit tover">{{ item.title }}</view>
							<!-- <view class="tag-box tovers">{{ item.brief }}</view> -->
							<view class="area ddflex">
								<view>分享 775  |  带来流量 89</view>
							</view>
						</view>
						<button class="act-btn ddflex">
							<image style="width: 20rpx;height: 22rpx;margin-right: 10rpx;" src="../static/images/money.png"></image>
							立即分享
						</button>
					</view>
				</view>
			</view>
		</view>
		<view class="nodata" v-else>
			<image :src="picUrlss + 'empty_dd.png'"></image>
			<text>暂无记录~</text>
		</view>
	</view>
</template>

<script>
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
const app = getApp();
export default {
	components: { },
	data() {
		return {
			picUrlss: req.public.picUrls,
			isShow: false,
			pageList: [],
			isLoad: true,
			form: {
				page: 1,
				limit: 10
			},
			isLogin: false,
			userinfovip: {}
		};
	},
	onLoad() {},
	onShow() {
		this.isLogin = req.isAuth();
		this.getPageList(true);
		if (this.isLogin) {
			this.getuserVip();
		}
	},
	onReachBottom: function() {
		this.form.page++;
		this.getPageList(false);
	},
	onShareAppMessage() {
		
	},
	onShareTimeline() {
		
	},

	methods: {
		jumpUrl(url) {
			if (!req.isLogins(true)) {
				return;
			}
			uni.navigateTo({
				url: url
			});
		},
		getPageList(isShow) {
			if (!this.isLoad) return false;
			this.isLoad = false;
			let form = this.form;
			form.rootCode = 'brochure'
			uni.showLoading();
			req.getRequest(
				'/api/material/library',
				form,
				res => {
					this.isShow = true;
					res = res?res.list:[]
					if (res && res.length == 10) {
						this.isLoad = true;
					}
					if (this.form.page > 1) {
						res = this.pageList.concat(res);
					}
					this.pageList = res;
					uni.hideLoading();
				},
				isShow
			);
		},
		getuserVip() {
			req.getRequest('/api/user/levelDetails', {}, data => {
				let expireTime = Array;
				if (data.expireTime) {
					expireTime = data.expireTime.split(' ');
					data.expireTime = data.expireTime.replace(/-/g, '/');
				} // 解决苹果不兼容---日期
				let nowTime = new Date().getTime();
				let endTime = new Date(data.expireTime).getTime();
				let times = parseInt((endTime - nowTime) / 1000); // var expireTime= new Date(data.expireTime)
				// console.log(times, nowTime, endTime, data.expireTime);
				this.userinfovip = data;
				if (times <= 0) {
					this.userinfovip.end = true;
				} else {
					this.userinfovip.end = false;
				}
			});
		},
		toActivity(item) {
			uni.navigateTo({
				url: '/match/activityDetail/activityDetail?id=' + item.id
			});
		}
	}
};
</script>

<style>
@import './page.css';
</style>
