<template>
	<view class="centent">
		<view class="centent-name">
			<view class="name-name">非遗推荐</view>
			<view class="name-title">非遗精选</view>
		</view>
		<view class="fkiml">
			<view :class="['xwwfbox',istop?'toplm':'follm']" id="lmid">
				<view :class="['xwwfinds',xwwfind==index?'act':'']" v-for="(item,index) in djlist"
					@click="ckxwwfind(index)">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="main">
			<view class="mainlist">
				<view class="libox" v-for="(el, ind) in djlist[xwwfind].list" @click="$getpage('/other/foodCard?id='+el.id)">
					<view class="name">{{ el.title}}</view>
					<!-- <view class="liboxtop"
						:style="{background:el.typeImg == '' || el.typeImg == null? 'url(https://cs.tour-ma.com/r/cms/www/m/changshu/noimg.png) center no-repeat' : 'url(' + $geturl(el.typeImg) + ') center no-repeat'}"> -->
						<!-- <view class="xing" :style="{ width: el.level * 29.6 + 'rpx' }">
							<image class="img" :src="getImg('ra-liebiao-icon-xing.png')" mode=""></image>
						</view> -->
					<!-- </view> -->
					<image class="liboxtop" :src="el.typeImg == '' || el.typeImg == null? 'https://cs.tour-ma.com/r/cms/www/m/changshu/noimg.png':$geturl480(el.typeImg)" mode=""></image>
					<view class="liboxbot">
						<view class="title1 text_overflow_2" v-html="el.txt"></view>
						<view class="lbrli">
							<view class="lbrliind">{{el.cateType}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	var web = require('@/components/utils/request.js');
	import back from '@/components/html/back.vue';
	export default {
		components: {
			back
		},
		data() {
			return {
				id: 76, //非遗
				info: {
					color: true
				},
				istop: false,
				nowdata: {},
				zslist: [{
					list: []
				}],
				first: 0,
				count: 50,
				xwwfind: 0,
				djlist: [{
						name: '全部',
						ind: 0,
						list: []
					},
					{
						name: '国家级',
						ind: 1,
						list: []
					},
					{
						name: '江苏省级',
						ind: 2,
						list: []
					},
					{
						name: '苏州市级',
						ind: 3,
						list: []
					},
					{
						name: '常熟市级',
						ind: 4,
						list: []
					}
				],
			}
		},
		onReachBottom() {
			this.first += 50;
			this.getDatalist();
		},
		onPageScroll(e) {
			if (e.scrollTop > this.lmtop) {
				this.istop = true;
			}
			if (e.scrollTop < this.lmtop) {
				this.istop = false;
			}
		},
		onReady() {
			var that = this;
			const query = uni.createSelectorQuery().in(this);
			query.select('#lmid').boundingClientRect(data => {
				that.lmtop = data.top;
				console.log(data)
			}).exec();
		},
		mounted() {
			this.getData();
			this.getDatalist();
		},
		methods: {
			ckxwwfind(ind) {
				this.xwwfind = ind;
				 this.getDatalist();
			},
			navto(id) {
				uni.navigateTo({
					url: url
				})
			},
			getData() {
				var url = '/json/channel_get.jspx?id=' + this.id;
				var para = {};
				var that = this;
				web.httpGejqr(that, url, para, function(res) {
					if (res.statusCode == 200) {
						that.nowdata = res.data;
					} else {
						uni.showToast({
							title: '查询失败'
						});
					}
				})
			},
			getDatalist() {
				uni.showToast({
					title: '加载中...',
					icon: "loading",
					duration: 100000
				});
				var url = '/json/content_list.jspx?channelIds=' + this.id + '&first=' + this.first + '&count=' + this
					.count;
				var para = {};
				var that = this;
				web.httpGejqr(that, url, para, function(res) {
					uni.hideToast();
					if (res.statusCode == 200) {
						if (res.data.length == 0) {
							return
						}
						var json = [];
						 json=res.data;
						var tmp = that.djlist;
						if (that.xwwfind == 0) {
							for (var i = 0; i < json.length; i++) {
								tmp[0].list.push(json[i]);
							}
							that.djlist = tmp;
						}
						if (that.xwwfind != 0) {
							for (var i = 0; i < json.length; i++) {
								for(var j=0;j<tmp.length;j++){
									if(json[i].cateLevel == tmp[j].name){
										tmp[j].list.push(json[i]);
									}
								}
							}
							that.djlist = tmp;
						}
					} else {
						uni.showToast({
							title: '查询失败'
						});
					}
				})
			},
			toOther() {
				uni.navigateToMiniProgram({
					appId: 'wx8ece732cc3a87e0f',
					path: 'pages/index/index',
					envVersion: 'release',
					extraData: {},
					success(res) {
						console.log("chenggong");
					},
					fail(e) {
						console.log(e);
					}
				})
			}

		}
	}
</script>

<style lang="scss">
	.centent {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 750upx;
		overflow-y: scroll;
		position: relative;
		// background: #274B6D;

		.centent-name {
			width: 93%;
			margin: 30rpx auto 30rpx;
			display: flex;
			align-items: center;

			.name-name {
				font-size: 48rpx;
				font-family: Source Han Sans CN;
				font-weight: 500;
				color: #5a5a5a;
				line-height: 58rpx;
			}

			.name-title {
				font-size: 32rpx;
				font-family: Source Han Sans CN;
				font-weight: 500;
				color: #8b8b8b;
				line-height: 28rpx;
				margin-left: 20rpx;
			}
		}

		.follm {
			position: absolute;
			left: 0rpx;
			top: 14rpx;
		}

		.toplm {
			position: fixed;
			top: 0;
			left: 0;
			background: #F2F2F2;
			height: 80rpx;
			z-index: 9;
		}

		.fkiml {
			width: 93%;
			position: relative;
			height: 80rpx;
			margin: 0 auto;
		}

		.xwwfbox {
			width: 100%;
			display: flex;
			flex-direction: row;
			white-space: nowrap;
			align-items: center;
			overflow-x: scroll;
			overflow-y: hidden;
			justify-content: center;
			// margin-bottom: 16upx;
			// padding-bottom: 20upx;

			.xwwfinds {
				background: #E6E7E8;
				border-radius: 30upx;
				font-size: 28upx;
				font-weight: 400;
				color: #666666;
				padding: 10upx 24upx;
				margin-right: 20upx;

				&:first-child {
					margin-left: 120upx;
				}
			}
			
			.act {
				background: linear-gradient(0deg, #3269F7 0%, #4A9AF9 100%);
				color: #FFFFFF;
			}
		}

		.main {
			padding: 7% 4%;
		}


		.mainlist .libox {
			margin-bottom: 7%;
			border-radius: 20upx;
			overflow: hidden;
			box-shadow: 0upx 0upx 15upx 10upx #eee;
			background: #fff;
		}

		.libox .name {
			color: #333333;
			font-weight: 500;
			font-size: 38upx;
			display: flex;
			align-items: center;
			padding: 28rpx;

			&::after {
				content: '';
				display: inline-block;
				width: 60rpx;
				height: 40rpx;
				background: url(https://cs.tour-ma.com/r/cms/www/m/changshu/youjt.png) no-repeat;
				background-size: 100% 100%;
				position: absolute;
				right: 49rpx;
			}
		}


		.libox .liboxtop {
			width: 93%;
			height: 370upx;
			position: relative;
			background-size: 100% 100%;
			object-fit: cover;
			margin: 0 auto;
			border-radius: 14rpx;
		}

		.liboxtop .xing {
			position: absolute;
			top: 15upx;
			left: 35upx;
			overflow: hidden;
		}

		.liboxtop .xing .img {
			width: 148upx;
			height: 26upx;
		}


		.liboxbot .title1 {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			opacity: 0.8;
			margin: 28rpx;
			width: 92%;
		}

		.lbrli {
			display: flex;
			white-space: nowrap;
			overflow-x: scroll;
			overflow-y: hidden;
			padding: 0 28rpx 40rpx;

			.lbrliind {
				font-size: 24upx;
				font-weight: 500;
				color: #33AC59;
				border: 2upx solid #B3DBBE;
				border-radius: 6upx;
				padding: 5upx 10upx;
				margin-right: 16upx;
				background: #E9FBF7;
			}
		}


	}
</style>
