<template>
	<view class="addIssue">
		<view class="fixedheader">
			<headers :showBack="true" :themeType="true">
				<view class="headerName">
					项目日志列表
				</view>
				<!-- <view @click="show = !show" :class="{'search-icon_acitve': show}" class="search-icon" slot="right">
				</view> -->
			</headers>
		</view>
		<view class="search-box" :style="{paddingTop: mobileTopHeight + 44 + 'px'}">
			<view class="uni-form-item">
				<input class="uni-input" name="searchName" v-model="searchName" placeholder="请搜索名称" />
				<view class="search-btn" @click="loadData">
					搜索
				</view>
			</view>
		</view>
		<view class="content" :style="{paddingTop: mobileTopHeight + 104 + 'px'}">
			<view @click="navigateToDetail(item)" class="content-box" v-for="item in personalDiaryList" :key="item.id">
				<view class="main2_box" v-if="personalDiaryList.length > 0">
					<view class="main2_box-main" v-for="item in personalDiaryList" :key="item.id">
						<view class="box-header">
							<view>{{$dayjs(item.date).format("YYYY年MM月DD日")}}</view>
							<view @click="onNavigateToDetail(item)">查看详情</view>
						</view>
						<view class="box-item1">
							<view>
								风力:{{item.weatherJson ? item.weatherJson.win_speed : '--'}}
							</view>
							<view>
								气温:{{item.weatherJson ? item.weatherJson.tem_day : '--'}}
							</view>
							<view>
								天气: {{item.weatherJson ? item.weatherJson.wea: '--'}}
							</view>
						</view>
						<view class="box-item">
							<view>上传人</view>
							<view>{{item.uploaderName}}</view>
						</view>
						<view class="box-item">
							<view>施工区域</view>
							<view>{{item.constructionAreaNames}}</view>
						</view>
						<view class="box-item">
							<view>施工单位</view>
							<view>{{item.constructionUnitNames}}</view>
						</view>
						<view class="box-item">
							<view>施工人员</view>
							<view>{{item.constructionWorkerNames}}</view>
						</view>
					</view>
				</view>
				<view class="new-nodata" v-else>
					<view></view>
					<text>暂无数据...</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		isJSON
	} from "@/utils/tool.js"
	export default {
		data() {
			return {
				checkedIds: [''],
				mobileTopHeight: 0,
				searchName: "",

				projectDetail: {},
				pageNo: 1,
				pageSize: 10,
				personalDiaryList: [],
				isLoadMore: false,
				loadStatus: 'more',
				optsDetail: {},
				formInline: {
					date: "",
					type: "",
				},
			}
		},
		onLoad(opts) {
			console.log(112233, opts)
			this.formInline.date = opts.date;
			this.formInline.type = opts.type;
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))
			this.loadData();
		},
		mounted() {
			var that = this
			uni.getSystemInfo({
				success(res) {
					that.mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
					uni.setStorageSync('systemInfo', res)
					console.log(res)
				}
			})
		},
		onReachBottom() {
			console.log(1)
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.pageNo += 1
				this.getSelectWorkerInfoList()
			}
		},
		onPullDownRefresh() {
			console.log(2)
			this.pageNo = 1
			this.personalDiaryList = []
			this.getSelectWorkerInfoList()
		},
		methods: {
			// 打开详情
			onNavigateToDetail(row) {
				uni.navigateTo({
					url: `./buildersDiaryDetail?id=${row.id}&type=${this.formInline.type}`
				})
			},
			loadData() {
				this.pageNo = 1
				this.personalDiaryList = []
				this.getSelectWorkerInfoList()
			},
			getSelectWorkerInfoList() {
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					projectSn: this.projectDetail.projectSn,
					uploaderName: this.searchName,
					type: this.formInline.type,
					date: this.formInline.date,
				}

				this.sendRequest({
					url: 'xmgl/ocrBuildLog/page',
					method: 'GET',
					data: data,
					success: res => {
						uni.hideLoading()
						if (res.code == 200) {
							const resultList = res.result.records.map(item => {
								return {
									...item,
									weatherJson: isJSON(item.weatherJson) ?
										JSON.parse(item.weatherJson) : {},
								}
							});
							this.personalDiaryList = this.personalDiaryList.concat(resultList)
							if (res.result.records.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
								this.isLoadMore = true
								this.loadStatus = 'nomore'
							} else {
								this.isLoadMore = false
								// that.loadStatus='more'
							}
							uni.stopPullDownRefresh()
						}
					}
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.new-nodata {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		>view {
			width: 300rpx;
			height: 300rpx;
			background-image: url('@/static/staffAttendance/nodata.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}

		>text {
			font-size: 22rpx;
			color: #808080;
			margin-top: 60rpx;
		}
	}

	.addIssue {
		min-height: 100vh;
		background-color: #F2F3F7;
	}

	.search-box {
		background-color: white;
		width: 100%;
		position: fixed;
		z-index: 99;

		.uni-form-item {
			padding: 26rpx 26rpx;
			position: relative;

			.uni-input {
				background: #F2F3F8;
				border-radius: 68rpx;
				padding: 12rpx 48rpx;
				font-size: 30rpx;
				color: #444444;
			}

			.search-btn {
				width: 130rpx;
				height: calc(100% - 26rpx - 26rpx);
				background: #2F8FF3;
				border-radius: 68rpx;
				font-size: 30rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
				position: absolute;
				right: 26rpx;
				top: 50%;
				transform: translateY(-50%);
			}
		}
	}

	.content {
		padding: 26rpx;

		.main2_box {
			.main2_box-btn {
				margin-top: 26rpx;
				background-color: white;
				padding: 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: 500;
				font-size: 30rpx;
				color: #5382F6;

				>.u-icon {
					margin-left: 10rpx;
				}
			}

			.main2_box-main {
				padding: 20rpx 26rpx;
				margin-top: 26rpx;
				position: relative;
				background-color: white;

				.box-item1 {
					margin-top: 20rpx;
					background-color: white;
					font-size: 28rpx;
					color: #808080;
					display: flex;
					justify-content: space-between;
				}

				.box-item {
					display: flex;
					align-items: center;
					margin-top: 26rpx;
					font-size: 28rpx;

					>view:first-child {
						width: 168rpx;
						margin-right: 26rpx;
						color: #808080;
					}

					>view:last-child {
						flex: 1;
						color: #4D4D4D;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						/* 限制为两行 */
						overflow: hidden;
					}
				}

				.box-header {
					display: flex;
					align-items: center;
					justify-content: space-between;

					>view:first-child {
						font-weight: 500;
						font-size: 30rpx;
						color: #1A1A1A;
					}

					>view:last-child {
						font-weight: 500;
						font-size: 24rpx;
						color: #4D8EEC;
					}
				}
			}
		}


	}

	.fixedheader {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 999;

		/deep/ .headerBox {
			border-bottom: none;
		}

		.headerName {
			z-index: 1;
		}
	}

	.search-icon {
		position: absolute;
		top: 50%;
		right: 10px;
		transform: translateY(-50%);
		z-index: 999;
		width: 40rpx;
		height: 40rpx;
		background-image: url('@/static/staffAttendance/attendance-icon2.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}

	.search-icon_acitve {
		background-image: url('@/static/staffAttendance/attendance-icon2_active.png');
	}
</style>