<template>
	<view class="msilde">
		<view class="left">
			<u-collapse accordion :value="list[0].deptId">
				<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="list" v-if="doctor_list.length > 0">
				<view v-for="(item, index) in doctor_list" :key="index" class="item" @click="go('/pages/doctor/detail?id=' + item.id)">
					<image :src="item.avatar ? ip + item.avatar : '../../static/head.png'" mode="scaleToFill" class="avatar"></image>
					<view class="con">
						<view class="name">{{ item.name }}</view>
						<view class="brief ellip">{{ item.brief }}</view>
					</view>
				</view>
			</view>
			<u-empty v-else></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			doctor_list: {},
			list: [{ deptId: 0 }]
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/department/list',
				success: (res) => {
					this.list = res.data.data;
					this.selected(this.list[0].children[0], 0);
				}
			});
		},
		open() {
			this.current = -1;
		},
		selected(item, index) {
			this.list.flatMap((i) => i.children).forEach((j) => (j.current = -1));
			item.current = index;
			this.http.request({
				url: '/app/doctor/list',
				data: { deptId: item.deptId },
				success: (res) => {
					this.doctor_list = res.data.data;
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		}
	}
};
</script>

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