<template>
	<view style="background-color: #fff;padding-bottom: 110rpx;" v-if="loading == true">
		<u-radio-group v-model="value" iconPlacement="right" placement="colum" @change="change">
			<u-collapse accordion >
				<view v-for="v in gdDept" :key="v.archiveTypeId">
					<u-collapse-item :title="v.name" :name="v.archiveTypeId" v-if="v.children != undefined">
						<view class="checkitem" v-for=" i in v.children" :key="i.archiveTypeId">
							<u-radio :label="i.name" :name="i.archiveTypeId+','+i.name"></u-radio>
						</view>
					</u-collapse-item>
					<view class="checkitem" style="padding: 20rpx;" v-else>
						<u-radio :label="v.name" :name="v.archiveTypeId+','+v.name"></u-radio>
					</view>
				</view>
			</u-collapse>
		</u-radio-group>
		<view style="position: fixed;bottom: 0;left: 0;width: 100%;height: 100rpx;background-color: #fff;box-sizing: border-box;padding: 20rpx;">
			<u-button type="primary" text="确认" @click="submit"></u-button>
		</view>
	</view>
</template>

<script>
	import {handleTree} from "@/utils/wjw.js"
	export default {
		data() {
			return {
				//归档部门
				gdDept:null,
				value:null,
				loading:false
			}
		},
		onLoad(){
			uni.showLoading({
				title:"加载中...",
			})
			this.getGdList()
		},
		onNavigationBarButtonTap(e) {
			if(this.value == null){
				uni.showToast({
					title:"请选择归档分类",
					icon:"none"
				})
			}else{
				getApp().globalData.gdId = this.value
				uni.$emit('query' , {a : 2})
				uni.navigateBack()
			}
		},
		methods: {
			//查询归档部门
			getGdList(){
				uni.$u.http.get("/archive/type/list").then(res=>{
					uni.hideLoading()
					this.$nextTick(()=>{
						this.gdDept = handleTree(res.data,"archiveTypeId","parentId")
						// console.log(this.gdDept)
					})
					setTimeout(()=>{
						this.$forceUpdate()
						this.loading = true
					},500)
				})
			},
			//选中
			change(e){
				
			},
			submit(){
				if(this.value == null){
					uni.showToast({
						title:"请选择归档分类",
						icon:"none"
					})
				}else{
					getApp().globalData.gdId = this.value
					uni.$emit('query' , {a : 2})
					uni.navigateBack()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.checkitem{
		font-size: 32rpx;
		padding: 20rpx 0;
		border-bottom: 1px solid #eaeaea;
	}
</style>
