<template>
	<view class="msilde">
		<view class="left">
			<u-collapse accordion >
				<u-collapse-item :title="d.deptName" :name="d.deptId" v-for="(d, index) in list" :key="d.deptName">
					<view :class="{ active: index == i.current }" v-for="(i, index) in d.children" :key="i.deptName" class="item" @click="selected(i, index)">{{ i.deptName }}</view>
				</u-collapse-item>
			</u-collapse>
		</view>
		<view class="right">
			<view class="contents">
				<u-divider :text="item.deptName + '介绍'" v-if="item.deptName"></u-divider>
				<u-parse :content="item.brief"></u-parse>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {},
			list: []
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/department/list',
				success: (res) => {
					this.list = res.data.data;
				}
			});
		},
		selected(item, index) {
			this.list.flatMap((i) => i.children).forEach((j) => (j.current = -1));
			item.current = index;
			this.http.request({
				url: '/app/department/detail/' + item.deptId,
				success: (res) => {
					this.item = res.data.data;
					this.item.brief = res.data.data.brief.replace(new RegExp('/profile/upload/', 'g'), this.http.ip + '/profile/upload/');
				}
			});
		}
	}
};
</script>

<style lang="scss"></style>
