<template>
	<ComponentLoading class="outer" :loading="loading">
		<view class="top-img">
			<view class="tree-body">
				<!-- <view class="header">物建员</view> -->
				<TreeAddress :treeList="treeList" @node-click="treeClick"></TreeAddress>
			</view>
		</view>
	</ComponentLoading>
</template>

<script>
	import {
		getrequest,
		getLdListPt,
		login
	} from '@/api/wjxxy.js'
	import md5 from '@/utils/md5.js'
	import TreeAddress from '@/components/tree-address/index'
	import ComponentLoading from '@/components/component-loading/index'

	export default {
		components: {
			TreeAddress,
			ComponentLoading
		},
		data() {
			return {
				tenantId: '000000',
				username: 'sqmj1',
				password: '123456',
				treeList: [],
				loading: false,
				bj_blue: require('./img/bj_blue.svg'),
			}
		},
		onLoad(option) {
			this.login()
		},
		methods: {
			// 监听按钮点击事件
			onNavigationBarButtonTap(e) {
				plus.runtime.quit()
			},
			//下拉后触发的事件
			onPullDownRefresh() {},
			login() {
				this.loading = true
				getrequest('bladeTokenEndPoint', 'token3').then(res => {
					let userInfo = JSON.parse(res.data.dataList[0].fieldValues[0].value)
					this.$u.func.login(userInfo)
					this.getLdListPt()
				})

				// login(this.tenantId, this.username, md5(this.password)).then(res => {
				// 	this.$u.func.login(res)
				// 	this.getLdListPt()
				// })
			},
			getLdListPt() {
				getrequest('xxyController', 'getLdListPt').then(res => {
					let result = JSON.parse(res.data.dataList[0].fieldValues[0].value)
					let list = result.data.map(r1 => { // 五兴村
						let l1 = {}
						if (r1.data) { // 前兴屯
							l1.data = r1.data.map(r2 => {
								let l2 = r2

								l2.isClick = false
								return l2
							})
						}
						l1.ldph = r1.ldph
						l1.isClick = false
						return l1
					})

					this.treeList = list
				}).finally(() => {
					this.loading = false
				})

				// getLdListPt().then(res => {
				// 	let list = res.data.map(r1 => { // 五兴村
				// 		let l1 = {}
				// 		if (r1.data) { // 前兴屯
				// 			l1.data = r1.data.map(r2 => {
				// 				let l2 = r2

				// 				l2.isClick = false
				// 				return l2
				// 			})
				// 		}
				// 		l1.ldph = r1.ldph
				// 		l1.isClick = false
				// 		return l1
				// 	})

				// 	this.treeList = list
				// }).finally(() => {
				// 	this.loading = false
				// })
			},
			treeClick(item, parent, index) {
				const param = JSON.stringify(item)
				uni.navigateTo({
					url: `/pages/home/wjy?param=${param}`
				})

			},

		}
	}
</script>

<style lang="scss" scoped>
	.outer {
		background-color: rgba(248, 248, 248, 1);
		height: 100vh;
		overflow-y: scroll;
		font-family: PingFangSC, PingFang SC;

		.top-img {
			width: 100%;
			background-image: url(./img/bj_blue.svg);
			background-repeat: repeat-x;
		}
	}

	.tree-body {
		width: 100%;
		padding: 24rpx;
	}

	.header {
		color: rgba(17, 17, 17, 1);
		font-size: 36rpx;
		font-weight: 600;
		text-align: center;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
	}
</style>