<template>
	<view class="container">
		<uni-card>
			<uni-section v-for="(item, index) in dataList" :title="item.typeName" :key="index" type="line">
				<uni-list border class="list">
					<uni-list-item v-for="(i, idx) in item.children" :key="idx" :ellipsis="1" :title="i.typeName" link clickable  @click="listItemBtn(i)" ></uni-list-item>
				</uni-list>
			</uni-section>
			<!-- <uni-load-more :status="more" /> -->
		</uni-card>
	</view>
</template>

<script>
	import request from '../../api/cms.js';
	export default {
		onLoad: function (option) {
		},
		data() {
			return {
				dataList: [],
				// more: 'more',
				page: 0,
				size: 20,
				type: ''
			}
		},
		async mounted() {
			await this.getList();
		},
		methods: {
			listItemBtn(e) {
				console.log(e)
				uni.navigateTo({ url: `/pages/illness/testingRoomList?alias=${e.alias}` });
			},
			// 查询列表函数
			async getList() {
				this.page += 1;
				this.more = 'loading';
				const res = await request.getTypeList({ alias: 'hsjc' });
				const data = res.data.map(e => {
					const list = e.ancestors.split(',')
					if (list.length <= 2) e.parent = true;
					return e;
				})
				const list = data.filter(j => j.parent).map(e => this.children(e, data))
				this.dataList = list;
				// 根据总数 算页数  如果当前页 = 总页数就是没有数据  否则就是上拉加载
				// this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
			},
			children(item, list) {
				const childrenList = list.filter(j => j.parentId == item.typeId).map(e => this.children(e, list));
				// 如果当前子菜单项存在 就添加children属性
				if (childrenList.length > 0) {
				  return { ...item, children: childrenList };
				}
				// 不存在就不添加
				return { ...item };
			}
		},
		// 页面生命周期中onReachBottom（页面滚动到底部的事件）
		// onReachBottom() {
		// 	if(this.more != 'noMore') {
		// 		this.more = 'more';
		// 		this.getList();
		// 	}
		// }
	}
</script>

<style>
</style>
