<template>
	<view class="main">
		<view class="one">
			<uni-collapse accordion v-model="activeName">
				<view class="list" v-for="(item, index) in tabs" :key="index">
					<uni-collapse-item :title="item.label">
						<view class="content">
							{{info[item.model]||'暂无'}}
						</view>
					</uni-collapse-item>
				</view>
			</uni-collapse>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				user: {},
				info: {},
				activeName: '0',
				tabs: [{
						label: '平台概述',
						model: 'summary',
					},
					{
						label: '平台建设重要意义',
						model: 'purport',
					},
					{
						label: '平台基础情况',
						model: 'base',
					},
					{
						label: '平台建设情况',
						model: 'build',
					},
					{
						label: '平台未来3年发展规划及实施计划',
						model: 'plan',
					},
				],
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e && e.id || '');
			that.searchToken();
			that.search();
		},
		onPullDownRefresh: async function() {
			const that = this;
			await that.search();
			uni.stopPullDownRefresh();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						const user = that.$jwt(res);
						that.$set(that, `user`, user);
					} else {
						uni.navigateTo({
							url: `/pages/login/index`
						})
					}
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			async search() {
				const that = this;
				if (that.id) {
					const res = await that.$api(`/build/${that.id}`, 'GET', {}, 'freeLabel')
					if (res.errcode == '0') {
						that.$set(that, `info`, res.data)
					} else {
						uni.showToast({
							title: res.errmsg,
						});
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding: 2vw;

		.one {
			.list {
				.content {
					font-size: var(--font14Size);
					color: var(--f85Color);
					line-height: 7vw;
				}
			}
		}
	}
</style>