<template>
	<ComponentLoading class="outer" :loading="loading">
		<view class="top-img">
			<view class="tree-body">
				<HomeSearch @search="search"></HomeSearch>
				<TreeNomal :treeList="treeList" @detail="detail" v-if="dataList.length == 0"></TreeNomal>
				<view class="data_item" v-for="(item) in dataList" :key="item.id" v-else>
					<view>{{ item.dictValue }}</view>
					<view class="btn-group">
						<view class="btn_orange btns" @click="detail(item)">详情</view>
					</view>
				</view>
			</view>
		</view>
	</ComponentLoading>
</template>
<script>
	import {
		getrequest,
		login,
		bsznList,
		selectListByMc
	} from '@/api/wjxxy.js'
	import ComponentLoading from '@/components/component-loading/index'
	import HomeSearch from './components/HomeSearch.vue'
	import TreeNomal from '@/components/tree-nomal/tree-nomal.vue'
	import md5 from '@/utils/md5.js'

	export default {
		components: {
			ComponentLoading,
			HomeSearch,
			TreeNomal
		},
		data() {
			return {
				loading: false,
				bj_blue: require('./img/bj_blue.svg'),
				treeList: [],
				dataList: [],
				tenantId: '000000',
				// username: 'admin',
				username: 'sqmj1',
				// password: 'admin',
				password: '123456',
			}
		},
		onLoad(option) {
			// console.log(uni.getStorageSync('isSzApp'))
			this.login()
		},
		methods: {
			search(val) {

				if (val) {
					this.loading = true
					selectListByMc(val).then(res => {
						let data = JSON.parse(res.data.dataList[0].fieldValues[0].value)
						this.dataList = data.data
					}).finally(() => {
						this.loading = false
					})
				} else {
					this.dataList = []
				}

			},
			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)
					bsznList().then(res => {
						console.log('bsznList bsznList bsznList', res)
						let list = JSON.parse(res.data.dataList[0].fieldValues[0].value)
						this.treeList = list.data
					}).finally(() => {
						this.loading = false
					})
				})

				// login(this.tenantId, this.username, md5(this.password)).then(user => {
				// 	this.$u.func.login(user)
				// 	bsznList().then(res => {
				// 		this.treeList = res.data
				// 	}).finally(() => {
				// 		this.loading = false
				// 	})
				// })

			},
			detail(val) {
				console.log('detail', val)
				uni.navigateTo({
					url: `/pages/home/detail?param=${JSON.stringify(val)}`
				})
				// switch (val) {
				// 	case '户口簿损毁换领':
				// 		uni.navigateTo({
				// 			url: '/pages/jmhkb/hkbShhl'
				// 		})
				// 		break;
				// 	default:
				// 		break;
				// }
			},

		}
	}
</script>

<style lang="scss" scoped>
	.outer {
		background-color: rgba(248, 248, 248, 1);
		height: calc(100vh - 88rpx);
		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 16rpx;
		// background-color: rgba(248, 248, 248, 1);
	}

	.data_item {
		display: flex;
		justify-content: space-between;
		// min-height: 68rpx;
		margin: 16rpx 0 16rpx 40rpx;
		line-height: 48rpx;
	}

	.btn-group {
		width: 100rpx;
		display: flex;

		.btns {
			height: 48rpx;
			width: 96rpx;
			text-align: center;
			line-height: 46rpx;
			border-radius: 8rpx;
			margin-left: 24rpx;
		}

		.btn_orange {
			color: rgba(237, 123, 47, 1);
			border: 1rpx solid rgba(237, 123, 47, 1);
		}

		.btn_green {
			color: rgba(0, 168, 112, 1);
			border: 1rpx solid rgba(0, 168, 112, 1);
		}

		.btn_blue {
			color: rgba(16, 109, 255, 1);
			border: 1rpx solid rgba(16, 109, 255, 1);
		}
	}
</style>