<template>
	<view class="msilde">
		<view class="left">
			<u-collapse accordion @open="current = -1">
				<u-collapse-item :title="d.deptName" name="Docs guide" v-for="(d, index) in list" :key="d.deptName">
					<view :class="{ active: index == 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">
				<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="aspectFit" class="avatar"></image>
					<view class="name">{{ item.name }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			doctor_list: {},
			current: -1,
			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.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>
