<template>
	<view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				taskId: '',
				preDetailList: [],
				deptList: []
			}
		},
		methods: {
			fetchPreDetail (taskId) {
				let that = this
				that.$api.preCrashExam.fetchPreCrashDetail({
					taskId
				}).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						res.data.data.forEach(item => {
							if (item.fileUrl != null) {
								item.fileUrl = item.fileUrl.split(',')
							}
							item.checked = false
						})
						that.preDetailList = res.data.data
						console.log(that.preDetailList);
					}
				}).catch(err => {
					console.log(err);
				})
			},
			getDeptTree () {
				let that = this
				that.$api.preCrashList.fetchDeptTree().then(res => {
					that.deptList = that.veri(res.data.data)
					console.log(that.deptList);
				}).catch(err => {
					console.log(err);
				})
			},
			veri (data) {
				let that = this
				if (!data || data.length <= 0) {
					return null;
				}
				return data.map(x => {
					const model = {
						name: x.label,
						id: x.id
					}
				    
				    const children = that.veri(x.children);
						
				    if (children) { 
					    model.children = children;
				    }
					
					return model;
				});
			}
		},
		onLoad(params) {
			console.log(params);
			this.taskId = params.taskId
			this.fetchPreDetail(this.taskId)
			this.getDeptTree()
		}
	}
</script>

<style>

</style>
