<template>
	<view class="wrap">
		<page-nav :desc="desc" :title="title"></page-nav>
		<view class="container">
			<uni-list>
				<uni-list-item @click="openPage(item)" :clickable="true" :showArrow="isNext" :title="getFieldTitle(item)"
					v-for="(item, index) in projectList" :key="index" :thumb="getIcon('cell')" thumb-size="sm">
					<!-- 				<template v-slot:body>
						<image slot="icon" class="u-cell-icon" :src="getIcon('cell')" mode="widthFix"></image>
						<view @click="openPage(item)">
							<text>{{getFieldTitle(item)}}</text>
						</view>
					</template>
					<template v-slot:footer>
						<uni-icons type="right" size="20" style="color: #969799;"></uni-icons>
					</template> -->
				</uni-list-item>
			</uni-list>
		</view>

		<!-- 		<view class="list-wrap">
			<u-cell-group title-bg-color="rgb(243, 244, 246)" :title="getGroupTitle(item)"
				v-for="(item, index) in projectList" :key="index">
				<u-cell-item :titleStyle="{fontWeight: 500}" @click="openPage(item1)" :title="getFieldTitle(item1)"
					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) {
			const current = 1;
			const size = 1000;
			// let projectList = {};
			// projectList['groupName'] = '项目列表';
			var list = [];
			http.request({
				url: '/blade-business/report/projectInfo/listByUserId',
				method: 'GET',
				params: {
					current,
					size
				}
			}).then(res => {
				console.log(res.data)
				if (res.data != null && res.data.length > 0) {
					for (let i in res.data) {
						var projectInfo = {
							id: res.data[i].id,
							title: '' + res.data[i].projectName
						};
						list.push(projectInfo);
					}
				}

			}).catch(err => {
				console.log(err)
			})
			//projectList['list'] = list;
			this.projectList = list;
			this.model = option.model;
			if (this.model == '0') {
				this.isNext = true;
			} else {
				this.isNext = false;
			}
			console.log(option.model)
		},
		data() {
			return {
				projectList: [],
				title: '选择项目',
				desc: '',
				model: '0',
				isNext: true,
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: "选择项目"
			});
		},
		created() {

		},
		methods: {
			openPage(item) {
				if (this.model == '0') {
					uni.navigateTo({
						url: '/pages/checkReport/addCheckReport' + '?id=' + item.id
					})
				} else {
					uni.$emit("handClickProjectSelect", {
						projectId: item.id,
						title: item.title
					});
					uni.navigateBack();
				}
			},
			getGroupTitle(item) {
				return item.groupName
			},
			getFieldTitle(item) {
				return item.title
			}
		}
	}
</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>
