<template>
	<view class="wrap">
		<page-nav :desc="desc" :title="title"></page-nav>
		<view class="container">
			<uni-list>
				<uni-list-item v-for="(item, index) in dictList" :key="index">
					<template v-slot:body>
						<image slot="icon" class="u-cell-icon" :src="getIcon('cell')" mode="widthFix"></image>
						<view @click="selectItem(item)">
							<text>{{item.dictValue}}</text>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
		</view>

		<!-- 		<view class="list-wrap">
			<u-cell-group title-bg-color="rgb(243, 244, 246)" :title="item.groupName" v-for="(item, index) in dictList"
				:key="index">
				<u-cell-item :titleStyle="{fontWeight: 500}" @click="selectItem(item1)" :title="item1.dictValue"
					v-for="(item1, index1) in item.list" :key="index1">
					<image slot="icon" class="u-cell-icon" :src="getIcon('cell')" mode="widthFix"></image>
				</u-cell-item>
			</u-cell-group>
		</view> -->
		<u-gap height="70"></u-gap>
	</view>
</template>

<script>
	import pageNav from '@/components/page-nav/page-nav.vue';
	import http from '@/http/api.js'
	export default {
		components: {
			pageNav
		},
		onLoad(option) {
			let dictId = option.id;
			// let dictList = {};
			// dictList['groupName'] = '列表信息';
			var list = [];
			http.request({
				url: '/galaxy-system/dict-biz/list?parentId=' + dictId,
				method: 'GET'
			}).then(res => {
				console.log(res.data)
				if (res.data != null) {
					const dictLength = res.data['length'];
					for (var i = 0; i < dictLength; i++) {
						let dict = res.data['' + i];
						list.push(dict);
					}
				}

			}).catch(err => {
				console.log(err)
			})
			// dictList['list'] = list;
			this.dictList = list;
		},
		data() {
			return {
				dictList: [],
				title: '选择问题隐患标签',
				desc: ''
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: ""
			});
		},
		created() {

		},
		methods: {
			selectItem(dict) {
				const that = this;
				const parentId = dict['id'];
				uni.showLoading({
					title: '处理中'
				});
				http.request({
					url: '/galaxy-system/dict-biz/list',
					method: 'GET',
					params: {
						parentId
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data != null) {
						const dictLength = res.data['length'];
						if (dictLength > 0) {
							let basisDict = res.data[0];

							var subDict = {
								id: basisDict['id'],
								dictKey: basisDict['dictKey'],
								dictValue: basisDict['dictValue'],
							};

							uni.$emit("handClickStandardSelect", {
								id: dict['id'],
								dictKey: dict['dictKey'],
								dictValue: dict['dictValue'],
								subDict: subDict
							});
							uni.navigateBack();

						} else {
							var subDict = {
								id: '',
								dictKey: '',
								dictValue: '',
							};
							uni.$emit("handClickStandardSelect", {
								id: dict['id'],
								dictKey: dict['dictKey'],
								dictValue: dict['dictValue'],
								subDict: subDict
							});
							uni.navigateBack();

							// uni.showModal({
							// 	content: '此标准下没有依据！',
							// 	showCancel: false
							// });
						}

					} else {
						// uni.showModal({
						// 	content: '此标准下没有依据！',
						// 	showCancel: false
						// });
						var subDict = {
							id: '',
							dictKey: '',
							dictValue: '',
						};
						uni.$emit("handClickStandardSelect", {
							id: dict['id'],
							dictKey: dict['dictKey'],
							dictValue: dict['dictValue'],
							subDict: subDict
						});
						uni.navigateBack();
					}


				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})

			},
		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */
</style>

<style lang="scss" scoped>
	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}
		.slot-box {
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			flex-direction: row;
			align-items: center;
		}
	
		.slot-image {
			/* #ifndef APP-NVUE */
			display: block;
			/* #endif */
			margin-right: 10px;
			width: 30px;
			height: 30px;
		}
	
		.slot-text {
			flex: 1;
			font-size: 14px;
			color: #4cd964;
			margin-right: 10px;
		}
</style>
