<template>
	<view class="container">
		<view class="fixedheader">
			<view :style="{ height: mobileTopHeight + 'px' }" class="statusBar"></view>
			<view class="barBox" >
				<view>
					神华包头煤制烯烃升级示范项目
				</view>
			</view>
			<view class="searchBox">
				<form @submit="formSubmit">
					<view class="uni-form-item">
						<input class="uni-input" name="searchName" v-model="searchName" 
							placeholder="请输入" />
						<button class="mini-btn" type="primary" size="mini" @click="loadData">搜索</button>
						<!-- <uni-icons2 class="search-icon" type="search" @click="loadData"></uni-icons2> -->
					</view>
				</form>
			</view>
		</view>
		<view :style="{ 'padding-top': ((systemInfo.statusBarHeight * 1.5) + 44 + 55) * 2 + 'rpx' }">
			<view class="operateBar" v-for="(item,index) in listData" :key="item.id" @click="goHiidden(item)">
				<view class="left">
					<image src="@/static/bthgIcon/project_icon12.png" mode=""></image>
					<view>
						{{item.deptName}}
						<text>({{item.userCount}})</text>
					</view>
				</view>
				<uni-icons2 class="arrowright" type="arrowright"></uni-icons2>
			</view>
		</view>
		<view class="noData" v-if="listData.length==0">
			暂无数据~
		</view>
		<footers :activeTab="'addressBook'"></footers>
	</view>
</template>

<script>
	import footers from '../../../components/footers/footers.vue'
	export default {
		components: {
			footers
		},
		data() {
			return {
				listData: [],
				projectSn: '',
				pageNo: 1,
				pageSize: 20,
				systemInfo: {
					statusBarHeight: 0
				},
				userInfo: {},
				typeState: [{
					txt: '待发起',
					val: 1
				}, {
					txt: '已整改',
					val: 3
				}], //status：整改状态 1:待发起 ,2:待整改 3：已整改
				status: 1,
				searchName: '',
				mobileTopHeight: 0
			}
		},
		onLoad() {
			var that = this
			uni.getSystemInfo({
				success(res) {
					that.mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
					uni.setStorageSync('systemInfo', res)
					console.log(res)
				}
			})

		},
		onShow() {
			if (JSON.parse(uni.getStorageSync('projectDetail'))) {
				this.projectSn = JSON.parse(uni.getStorageSync('projectDetail')).projectSn;
			} else {
				this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).projectSn;
			}
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			if (this.userInfo.accountType == 6) { //整改人状态
				this.typeState = [];
				this.status = 2;

			} else {

				this.typeState = [{
					txt: '待发起',
					val: 1
				}, {
					txt: '已整改',
					val: 3
				}]
			}
			this.listData = [];
			this.pageNo = 1;
			this.getListData();

		},
		mounted() {
			this.systemInfo = uni.getStorageSync('systemInfo')
		},
		onPullDownRefresh() {
			this.getListData()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			console.log("============================")
			this.pageNo++;
			uni.showLoading({
				title: '加载中'
			})
			this.getListData()
		},
		methods: {
			
			formSubmit(e) {
				// console.log(e)
				this.searchName = e.detail.value.searchName
				this.loadData()
			
			},
			searchFile(e) {
				this.searchName = e.detail.value
			},
			typeStateEve(v) {
				this.status = v;
				this.pageNo = 1;
				this.listData = [];
				this.getListData();
			},
			loadData(){
				this.pageNo = 1;
				this.listData = [];
				this.getListData();
			},
			//获取列表数据
			getListData() {
				console.log(this.userInfo, "=======================================================")
				let qData = {
					projectSn: this.projectSn,
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					// accountType: this.userInfo.accountType,
					// status: this.status,
					// isPushed: 1
					deptName: this.searchName,
				}
				if (this.userInfo.accountType == 6) {
					qData.pushPersonId=this.userInfo.userId
				}
				this.sendRequest({
					url: 'xmgl/xzProjectOrg/page',
					method: "GET",
					data: qData,
					success: res => {
						if (res.code == 200) {
							console.log('res', res)

							if (this.pageNo == 1) {
								this.listData = []
							}
							// console.log('--------')
							// this.listData = res.result.records
							this.listData = [...this.listData, ...res.result.records]
							uni.hideLoading() //关闭加载中
						}
					}
				})
			},
			// goBack() {
			// 	uni.reLaunch({
			// 		url: "/pages/projectEnd/projectIndex/projectIndex"
			// 	});
			// },
			// 点击跳转
			goHiidden(item) {
				// uni.navigateTo({
				// 	url: "/pages/projectEnd/safeManage/addExamine"
				// });

				// uni.navigateTo({
				// 	url: "/pages/potentialRisk/potentialRisk?dangerInfo="+ encodeURIComponent(JSON.stringify(item))
				// });
				console.log(item)
				uni.navigateTo({
					url: "./addressBookDetail?id=" + item.id
				});

			},
			saveImage(url) {
				uni.showLoading({
					title: "保存中..."
				})
				uni.downloadFile({
					url: url, //网络路径，下载下来  
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath, //下载后的临时路径  
								success: res => { //下载完成后在相册里压根找不到  
									uni.hideLoading()
									uni.showToast({
										title: "保存成功！"
									})
									uni.navigateTo({
										url: "/pages/projectEnd/safeManage/addExamine"
									});
								}
							})
						}
					}
				});

			},

		}
	}
</script>

<style lang="scss" scoped>
	.fixedheader{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2;
		background-color: #F3F5F7;
		.statusBar{
			background-color: white;
		}
	}
	.operateBar {
		background-color: #FFFFFF;
		font-size: 28rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
		margin: 0 30rpx 0;
		padding: 0 30rpx;
		justify-content: space-between;
		// border-radius: 8rpx;
		color: #444444;
	
		.left {
			display: flex;
			align-items: center;
			> image {
				width: 70rpx;
				height: 70rpx;
			}
			> view {
				margin-left: 20rpx;
				> text {
					color: #9F9F9F;
				}
			}
		}
	
		.operateIcon {
			width: 40rpx;
			height: 40rpx;
			margin-right: 20rpx;
		}
	
		.arrowright {
			// opacity: 0.5;
			font-size: 40rpx !important;
			color: #2F8FF3 !important;
		}
	}
	.searchBox {
		// background-color: white;
	}
	
	.uni-input {
		border-radius: 40rpx;
		margin: 20rpx;
		background-color: white;
		border: 1px solid #F3F4FE;
		height: 70rpx;
		line-height: 60rpx;
		padding: 0 40rpx;
		font-size: 28rpx;
		// width: 70%;
	}
	
	.fileItem {
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 40rpx 0;
		margin: 0 20rpx;
		color: $uni-text-color;
		// border-bottom: 1px solid rgba(221, 221, 221, 0.8);
	
		.left {
			display: flex;
			align-items: center;
			width: 70%;
	
			.left_text {
				flex: 1;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				-o-text-overflow: ellipsis;
			}
		}
	
		.fileIcon {
			width: 56rpx;
			height: 56rpx;
			margin-right: 20rpx;
		}
	
		.ellipsis {
			width: 40rpx;
			height: 10rpx;
		}
	}
	
	.uni-form-item {
		position: relative;
	
		.search-icon {
			position: absolute;
			top: 50%;
			right: 50rpx;
			transform: translateY(-50%);
		}
	}
	.mini-btn {
		font-size: 28rpx;
		position: absolute;
		right: 30rpx;
		top: 50%;
		border-radius: 30rpx;
		height: 60rpx;
		line-height: 60rpx;
		transform: translateY(-50%);
	}
	.container {
		background-color: #F3F5F7;
		min-height: calc(100% - 120rpx);
		padding-bottom: 120rpx;
	}
	.noData {
		text-align: center;
		padding: 120rpx 0;
		color: #999;
	}

	.this_class {
		color: #007AFF;
	}

	.typeState {
		height: 80rpx;
		background-color: #fff;
		font-size: 28rpx;

		width: 100%;
	}
	// .statusBar {
	// 	background-color: white;
	// }
	.barBox {
		height: 88rpx;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 0 28rpx;
		> view {
			font-weight: bold;
			font-size: 28rpx;
			color: #171717;
		}
	}

	.title {
		height: 44px;
		line-height: 44px;
		font-size: 40rpx;
		width: 750rpx;
		background-color: #5181F6;
		color: #fff;
		text-align: center;
		position: relative;
	}

	.accessoryImg {
		margin-top: 10rpx;
		width: 100%;
	}

	.backBtn {
		font-size: 32rpx;
		position: absolute;
		left: 20%;
	}

	.back {
		font-size: 24rpx;
	}

	.tip{
		margin-left: 5rem;
	}

	.contain2 {
		width: 750rpx;
		content: " ";
		// background-color: #f8f8f8;
		// height: calc(100vh - 44px);
		// overflow: auto;
	}

	.alarm-item {
		width: 650rpx;
		margin: 20rpx auto;
		background-color: #fff;
		padding: 40rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		box-shadow: 0 0 10rpx #ccc;
	}

	.alarm-lable {
		display: flex;
	}

	.alarm-lable-1 {
		width: 200rpx;
	}

	.alarm-lable-2 {
		flex: 1;
		text-align: right;
		color: #888;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.center {
		justify-content: center;
	}

	.between {
		justify-content: space-between;
	}

	.warp {
		flex-wrap: wrap;
	}

	.evenly {
		justify-content: space-evenly;
	}
</style>
