<template>
	<view>
		<view :class="'top-fixed'+(config.greyTheme==1?' grayTheme':'')">
			<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 class="image-nav ddflex" v-if="recommendList&&recommendList.length>0">
				<scroll-view scroll-x="true" class="map-acs ddflex" style="height: 141rpx;">
					<image v-for="item,index in recommendList" :key="index" :src="item.icon" @click="jumpUrl('/topic/contentList/contentList?code='+item.code+'&title='+item.name)"></image>
					<!-- <image src="/static/images/tbal.png" @click="jumpUrl('/topic/contentList/contentList?code='+tbalCode+'&title=投保案例')"></image>
					<image src="/static/images/lpal.png" @click="jumpUrl('/topic/contentList/contentList?code='+lpalCode+'&title=理赔案例')"></image> -->
				</scroll-view>
			</view>
			<view class="map-ac">
				<scroll-view scroll-x="true" class="map-acs ddflex" style="height: 70rpx;">
					<view :class="'fx-nav '+(fxIndex==index?'fx-nav-active':'')" v-for="item,index in fxList" @click="changeFxTab(index)">{{item.name}}</view>
				</scroll-view>
			</view>
		</view>
		<view :style="'height: '+(recommendList&&recommendList.length>0?400:240)+'rpx;'"></view>
		<view :class="'list'+(config.greyTheme==1?' grayTheme':'')">
			<view class="video-box" v-if="fxContentList&&fxContentList.length > 0">
				<view class="video-card" v-for="(item, index) in fxContentList" :key="index" @click="jumpUrl('/topic/content/content?id='+item.id)">
					<view class="video-cover">
						<view class="video">
							<image mode="aspectFill" style="max-width: 100%;max-height: 100%;" :src="item.pic"></image>
						</view>
						<image v-if="item.contentType==2" class="video-play" src="/static/images/video_play.png"></image>
					</view>
					<view class="video-info">
						<view class="video-name tovers3">{{item.title}}</view>
						<view class="video-info-desc">
							<view class="ddflex" style="overflow: hidden;">
								{{formatTime(item.createDate)}}
							</view>
							<view class="ddflex">
								<image style="width: 27rpx;height: 20rpx;margin-right: 10rpx" src="/static/images/eyes.png"></image>
								<view>{{unitFormat(item.browse)}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="nodata" v-if="!fxContentList||fxContentList.length==0">
				<image :src="picUrlss+'empty_zb.png'"></image>
				<text>暂无资讯</text>
			</view>
		</view>

		<foot channel="found" :isUpdate="isUpdate"></foot>
	</view>
</template>

<script>
	// pages/live/live.js
	const app = getApp();
	const req = require("../../utils/request.js");
	const util = require("../../utils/util.js");
	import foot from "../../components/nav-bar/index";

	export default {
		data() {
			return {
				picUrlss: req.public.picUrls,
				bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
				page: 1,
				pageList: [],
				searchVal:'',
				isLoad: true,
				isUpdate: false, // 是否更新消息
				hasmore: false,
				ishow: false,
				videoList:[],
				videoCurrent:null,//当前正在播放的视频下标
				config:{},
				isFullScreen:false,//是否正在全屏播放
				
				swiperPlayIndex:0,
				
				fxList:[],
				fxContentList:[],
				fxIndex:0,
				
				xbrmCode:req.public.xbrmCode,
				tbalCode:req.public.tbalCode,
				lpalCode:req.public.lpalCode,
				
				recommendList:[]
			};
		},

		components: {
			foot
		},
		props: {},

		async onLoad() { // this.getList()
			await this.getConfig()
			this.getFx()
			this.getRecommendList()
			req.saveBehaviorNew('',14,4)
		},

		onShow() {
			this.setData({
				isUpdate: !this.isUpdate
			});
		},

		onReachBottom() {
			this.page++;
			this.getFxContenteList();
		},

		methods: {
			// 获取文章栏目推荐列表
			getRecommendList(){
				return new Promise((r,j)=>{
					req.getRequest('/api/content/category/list',{isRecommend:1},res=>{
						this.recommendList = res?res:[]
						// this.recommendList = this.fxList
						r(res?res:[])
					})
				})
			},
			getConfig() {
				return new Promise((resolve, reject) => {
					req.getRequest('/api/other/config', {}, (res)=> {
						this.config = res;
						resolve(res)
					});
				});
			},
			jumpUrl(url) {
				// if (!req.isLogins(true)) {
				// 	return;
				// }
				uni.navigateTo({
					url: url
				});
			},
			// 获取发现
			async getFx(){
				this.fxList = await this.getContentList(req.public.fxCode)
				this.getFxContenteList()
			},
			// 获取文章栏目列表
			getContentList(code){
				return new Promise((r,j)=>{
					req.getRequest('/api/content/category/list',{parentCode:code},res=>{
						r(res?res:[])
					})
				})
			},
			// 发现tab切换
			changeFxTab(index){
				if(this.fxIndex==index) return false;
				this.fxIndex = index
				this.isLoad = true
				this.page = 1
				this.getFxContenteList(this.fxList[this.fxIndex].code)
			},
			// 获取发现文章列表
			getFxContenteList() {
				let that = this;
				let isShowLoading = false;
				// console.log(that.isLoad);
				if (!that.isLoad) return false;
				that.isLoad = false;
				let form = {
					page: that.page,
					limit: 10,
					code:that.fxList[that.fxIndex].code
				};
				if(this.searchVal){
					form.title=this.searchVal
				}else{
					delete form.title
				}
				if (form.page == 1 && !isShowLoading) {
					req.loadIng('加载中');
					isShowLoading = true;
				}
				if(req.getStorage("shareId")){
					form.shareSaleNo = req.getStorage("shareId")
				}
				req.getRequest('/api/content/list', form, data => {
					if (data && data.length == 10) that.isLoad = true;
					if (that.page > 1) data = that.pageList.concat(data);

					if (!data || data.length < 10) {
						that.setData({
							hasmore: true
						});
					}

					if (data) {
						data.map(item => {
							if (item.start_time) {
								item.time = util.transTime(item.start_time);
							}

							return item;
						});
					}

					// console.log(data);
					that.setData({
						fxContentList: data
					});

					if (!this.pageList) {
						that.setData({
							ishow: true
						});
					} else {
						that.setData({
							ishow: false
						});
					}
					if (isShowLoading) {
						uni.hideLoading();
						isShowLoading = false;
					}
				});
			},
			searchFn(){
				this.isLoad = true
				this.page = 1
				this.getFxContenteList(this.fxList[this.fxIndex].code)
			},
			captureTime(time) {
				return util.formatTime(new Date(time.replace(/\-/g, '/'))).t2;
			},
			// 视频浏览数
			getBrowse(libraryId) {
				let params = {
					bindId: libraryId,
					type: 7,//素材
					behavior:4//浏览
				}
				req.postRequest('/api/v3/behavior/save', params, data => {});
			},
			// 秒转换分秒
			getMinuteTime(data) {
				let minute = parseInt(data / 60);
				let second = parseInt(data % 60);
				if (minute.toString().length == 1) minute = `0${minute}`;
				if (second.toString().length == 1) second = `0${second}`;
				return `${minute}:${second}`;
			},
			unitFormat(data){
				return req.unitConverter(data).text
			},
			formatTime(date){
				date = new Date(date.replace(/-/g, '/'))
				return util.formatTime(date).t3
			}

		}
	};
</script>
<style>
	@import "./found.css";
</style>
