<template>
	<view class="">
		<view class="box">
			<view class="box_top">
				<image style="width: 100%; height: 100%" src="https://huli-app.wenlvti.net/app_static/minnanhun/image/ccbg.png"></image>
			</view>
			<view class="gy_box" @click="tougaoBtn">
				<view class="">投稿</view>
				<uni-icons type="compose" size="22" color="#ffffff"></uni-icons>
			</view>
			<view class="box_search" @click="searchBtn">
				<view class="">
					<uni-icons type="search" size="20"></uni-icons>
				</view>
				<view class="">请输入搜索内容</view>
			</view>
			<view class="box_tab">
				<u-tabs
					@click="tabsBtn"
					:duration="200"
					:list="listTab"
					:lineWidth="25"
					:lineHeight="12"
					lineColor="#4E7198"
					:lineColor="`url(${tabImg}) 100% 100%`"
					:activeStyle="{
						color: '#4E7198',
						fontSize: '34rpx'
					}"
				></u-tabs>
			</view>

			<uv-waterfall ref="waterfall" v-model="list" :add-time="10" left-gap="10" right-gap="10" :column-gap="columnGap" @changeList="changeList">
				<template v-slot:list1>
					<view>
						<view @click="detailsBtn(index)" v-for="(item, index) in list1" :key="item.id" class="waterfall-item">
							<view class="waterfall-item__image" :style="[imageStyle(item)]">
								<image :src="item.image" mode="widthFix" style="border-radius: 25rpx 60rpx 0rpx 30rpx" :style="{ width: item.width + 'px' }"></image>
							</view>
							<view class="waterfall-item__ft">
								<view class="waterfall-item__ft__title">
									<text class="value">{{ item.title }}</text>
								</view>
							</view>
						</view>
					</view>
				</template>

				<template v-slot:list2>
					<view>
						<view @click="detailsBtn2(index)" v-for="(item, index) in list2" :key="item.id" class="waterfall-item">
							<view class="waterfall-item__image" :style="[imageStyle(item)]">
								<image :src="item.image" mode="widthFix" style="border-radius: 25rpx 60rpx 0rpx 30rpx" :style="{ width: item.width + 'px' }"></image>
							</view>
							<view class="waterfall-item__ft">
								<view class="waterfall-item__ft__title">
									<text class="value">{{ item.title }}</text>
								</view>
							</view>
						</view>
					</view>
				</template>
			</uv-waterfall>
		</view>
		<mntabBar footerTab="2" :messageCount="0"></mntabBar>
	</view>
</template>

<script>
import { mapState } from 'vuex';
let that;

export default {
	components: {},
	data() {
		return {
			main_body_id: '',
			tabImg: 'https://huli-app.wenlvti.net/app_static/minnanhun/image/tab.png',
			model_id: '',
			list: [],
			list1: [], // 瀑布流第一列数据
			list2: [], // 瀑布流第二列数据
			columnGap: 10,
			listTab: [
				{
					name: '非遗',
					tabid: 2
				},
				{
					name: '建筑',
					tabid: 1
				}
				// {
				// 	name: '书法',
				// 	tabid: 1
				// },
				// {
				// 	name: '戏曲',
				// 	tabid: 2
				// },

				// {
				// 	name: '文化',
				// 	tabid: 4
				// },
				// {
				// 	name: '创作',
				// 	tabid: 5
				// }
			]
		};
	},
	onLoad(option) {
		that = this;
		this.main_body_id = this.$db.get('main_body_id');
		this.getContentList();
	},
	computed: {
		imageStyle(item) {
			return (item) => {
				const v = uni.upx2px(750) - this.leftGap - this.rightGap - this.columnGap;
				const w = v / 2;
				const rate = w / item.w;
				const h = rate * item.h;
				return {
					width: w + 'px',
					height: h + 'px'
				};
			};
		}
	},
	methods: {
		// 栏目内容列表
		getContentList(id) {
			this.$api.getContentList(
				{
					model_id: id ? id : 2,
					main_body_id: this.main_body_id,
					page: 1,
					pageSize: '10'
				},
				function (res) {
					that.list = res.data;
					that.model_id = res.data[0].model_id;
					// console.log(that.model_id, 'that.model_id');
				}
			);
		},
		detailsBtn(i) {
			uni.navigateTo({
				url: this.list1[i].page
			});
		},
		detailsBtn2(i) {
			uni.navigateTo({
				url: this.list2[i].page
			});
		},
		tabsBtn(i) {
			that.list = [];
			that.$refs.waterfall.clear();
			that.list1 = [];
			that.list2 = [];
			// this.id1 = index.id;
			this.getContentList(this.listTab[i.index].tabid);
		},
		changeList(e) {
			this[e.name].push(e.value);
		},
		searchBtn() {
			uni.navigateTo({
				url: '/chuanCheng_fenbao/search?id=' + this.model_id
			});
		},
		tougaoBtn() {
			uni.navigateTo({
				url: '/chuanCheng_fenbao/touGao'
			});
		}
	}
};
</script>

<style>
.body {
	/* background-image: url('https://huli-app.wenlvti.net/uploads/20230512/88f8347924d08296bbde9d55afd74c15.jpg');
	background-size: 100% 100%; */
	background-attachment: fixed;
}
/deep/.u-tabs__wrapper__nav__item.data-v-48634e29 {
	padding: 0 40rpx !important;
}
/deep/.u-tabs__wrapper__nav__line.data-v-48634e29 {
	bottom: 16rpx !important;
}
/deep/.u-tabs__wrapper__nav__item.data-v-48634e29 {
	align-items: end !important;
}
/deep/.column-value.data-v-ddfcbb1c {
	border-radius: 25rpx 60rpx 0rpx 30rpx !important;
}
.box {
	height: auto;
	width: 100%;
	background-color: #eff6ff;
	background-attachment: fixed;
	border-radius: 16px 16px 0 0;
	position: relative;
	display: flex;
	flex-direction: column;
}
.box_top {
	width: 100%;
	height: 410rpx;
}
.box_search {
	display: flex;
	align-items: center;
	padding-left: 20rpx;
	box-sizing: border-box;
	width: 685rpx;
	height: 80rpx;
	color: #999999;
	font-size: 28rpx;
	background-color: #ffffff;
	z-index: 2;
	border-radius: 40rpx;
	margin: -90rpx 32rpx 0 34rpx;
}
.box_tab {
	margin: 45rpx 32rpx 20rpx 32rpx;
}

.gy_box {
	width: 160rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	position: absolute;
	top: 240rpx;
	right: 0;
	padding-left: 10rpx;
	font-size: 28rpx;
	font-family: MiSans, MiSans;
	font-weight: 500;
	color: #ffffff;
	justify-content: space-evenly;
	line-height: 44rpx;
	z-index: 11;
	border-radius: 20rpx 0rpx 0rpx 20rpx;
	background-color: #ca5642;
}
.waterfall-item__ft__title {
	width: 100%;
	height: 65rpx;
	position: absolute;
	bottom: 0;
	left: 0;
	line-height: 65rpx;
	background-color: #ca5642;
	font-size: 30rpx;
	text-align: center;
	color: #ffffff;
	border-radius: 0 0 10rpx 10rpx;
}
.waterfall-item__ft {
	position: relative;
}
.waterfall-item {
	margin-bottom: 30rpx;
}
</style>
