<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>分享 {{item.shareCount?item.shareCount:0}}  |  浏览 {{item.browseCount?item.browseCount:0}}</view>
							</view>
						</view>
						<button @click.stop="" class="act-btn ddflex" :data-id="item.id" :data-code="item.code" :data-title="item.title" :data-pic="item.pic" open-type="share">
							<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,
			searchVal:'',
			form: {
				page: 1,
				limit: 10
			},
			isLogin: false,
			userInfo:{}
		};
	},
	onLoad() {
		this.userInfo = req.getStorage('userInfo')
		uni.hideShareMenu()
	},
	onShow() {
		this.isLogin = req.isAuth();
		this.getPageList(true);
	},
	onReachBottom: function() {
		this.form.page++;
		this.getPageList(false);
	},
	onShareAppMessage(res) {
		if (res.from === 'button') {
			this.userBehavior(6,res.target.dataset.id)
			return {
				title: res.target.dataset.title,
				imageUrl: res.target.dataset.pic,
				path: '/library/pageDetail/index?code=' + res.target.dataset.code +'&isShare=' + true+(this.userInfo.userType==1?('&shareId='+this.userInfo.saleNo):'')
			};
		}
	},

	methods: {
		// 用户行为
		userBehavior(type,id) {
			var dataP = {};
			dataP.type =
				7 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
			dataP.behavior = type; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
			dataP.bindId = id;
			req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
			});
		},
		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'
			form.search = this.searchVal?this.searchVal:null
			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
			);
		},
		
		toActivity(item) {
			uni.navigateTo({
				url: '/match/activityDetail/activityDetail?id=' + item.id
			});
		},
		// 搜索
		searchFn(){
			this.isLoad = true
			this.form.page = 1
			this.getPageList()
		}
	}
};
</script>

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