<template>
	<view class="uni-container uni-container-bg">
		<view class="example container" :style="'height: ' + (screenHeight - 75) + 'px'">
			<!-- 搜索框 -->
			<uni-row class="demo-uni-row padding-tb-sm" :gutter="20" width="100%">
				<uni-col :span="24">
					<view class="u-page__tag-item">
						<u-search placeholder="请输入单位人员名称" bgColor="#edf6f9" borderColor="#4cb2b6" v-model="keyword"
							:showAction="true" @custom="search(keyword)"></u-search>
					</view>
				</uni-col>
			</uni-row>
			<!-- 下拉框 -->
			<view class="u-page__tag-item"
				style="margin-bottom: 26upx;width: 700upx;border-bottom: 2px solid #55cbbf;background-color: #f5f7fa;">
				<u-form>
					<u-form-item prop="orgName" @click="
						showOrg = true;
						hideKeyboard();
					" label="单位选择:" labelWidth="120px">
						<u--input border="none" disabled v-model="formData.orgName" placeholder="请选择所属单位"></u--input>
						<u-icon slot="right" name="arrow-down"></u-icon>
					</u-form-item>
				</u-form>
			</view>
			<!-- v-for="(item, index) in tableData" -->
			<view v-if="tableData.length>0 && isLoaded">
				<!-- 宫格 -->
				<uni-card v-for="(item, index) in tableData" :key="index"
					@click.native="onClick(item, formData.orgName)">
					<!-- <u-icon
						v-if="item.avatar == '' || item.avatar == null || item.avatar == undefined"
						customStyle="margin-top:20px; border-radius: 50%;"
						:name="avatar"
						:size="70"
					></u-icon>
					<u-icon v-else customStyle="margin-top:20px; border-radius: 50%;" :name="item.avatar" :size="70"></u-icon> -->
					<!-- 姓名 -->
					<view class="grid-text"><text class="name-align-task">姓名:</text>{{ item.empRyxm }}</view>
					<!-- 岗位 -->
					<view v-if="item.empGw == '' || item.empGw == null || item.empGw == undefined" class="grid-text">无
					</view>
					<view v-else class="grid-text"><text class="name-align-task">岗位:</text>{{ item.empGw }}</view>
					<view class="grid-text"><text class="name-align-task">联系电话:</text>{{ item.linkTel }}</view>
					<view class="grid-text"><text class="name-align-task" style="width: 200rpx;">职业资格证书:</text>{{ item.empGw }}</view>
				</uni-card>
				</uni-card>
			</view>

			<!-- tableData为空时显示  -->
			<view v-else-if="tableData.length==0 && isLoaded" style="text-align: center;">
				<view class="text-gray" style="padding-top: 20px;">
					<img :src="tan90" alt="暂无数据" />
				</view>
			</view>
			<view>
				<image :src="Group" @click="addClick" class="tiantupian"></image>
			</view>
			<u-action-sheet :show="showOrg" :actions="actions" title="请选择单位" @close="showOrg = false"
				@select="sexSelect">
			</u-action-sheet>
			<!-- 加载中 -->
			<isLodingModel></isLodingModel>

		</view>
	</view>
</template>
<script>
	var that = '';
	import {
		getStaff, //获取人员信息列表
		delStaff, //删除人员信息
		getOrgId
	} from '@/api/staff_info';
	import config from '@/config'
	const baseUrlImg = config.baseUrlImg
	export default {
		data() {
			return {
				isLoaded: false,
				// avatar: `${baseUrlImg}/avatar.jpg`,
				showOrg: false,
				actions: [],
				searchVal: '',
				Group: `${baseUrlImg}/checkActive/Group.png`,
				orgId: '',
				// 数据
				tableData: {
					// avatar:''
				},
				title: '是否删除该数据项?',
				content: '确认删除？',
				id: '',
				tan90: `${baseUrlImg}/tan90.png`,
				// 每页数据量
				pageSize: 5,
				// 当前页
				pageNo: 1,
				// 数据总量
				total: 0,
				// tableData数据加载中
				loading: false,
				// 初始化时搜索框的值
				keyword: '',
				// 开始时间与结束时间
				formData: {},
				show: false,
				screenHeight: this.$screenHeight,
				wheight: ''

			};
		},
		// 在 vue页面，向起始页通过事件传递数据
		onLoad: function(option) {
			getOrgId({
				pageNo: this.pageNo,
				pageSize: this.pageSize,
				userId: this.$store.state.user.id
			}).then(response => {
				// 取到用户对应的单位名称与id
				response.data.map(v => {
					this.actions.push({
						id: v.dwid,
						name: v.orgName
					});
				});
				if (response.data.length > 0) {
					this.formData.orgName = response.data[0].orgName;
					this.formData.orgId = response.data[0].dwid;
				}
			});
		},
		watch: {
			loading: {
				handler(newLength, oldLength) {
					this.$modal.isLoadingModel(this.loading)
				},
				immediate: true
			}
		},
		onShow() {
			this.actions = []
			this.tableData = []
			this.getData();
		},
		mixins: [uni.$u.mixin],
		methods: {
			search(val) {
				this.isLoaded = false
				this.loading = true
				this.tableData = []
				this.getData(1)
			},
			// 模态框内容
			showModal(val) {
				this.show = true;
				this.id = val.id;
			},
			confirm() {
				this.show = false;
				delStaff({
					id: this.id
				}).then(response => {
					this.isLoaded = false
					this.tableData = []
					this.getData();
					// this.tableData = response.data;
				});
			},
			close() {
				this.show = false;
			},
			cancel() {
				this.show = false;
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection();
				this.getData(e.current);
			},
			sexSelect(e) {
				this.formData.orgId = e.id;
				this.formData.orgName = e.name;
				// 获取培训演练信息详细信息
				getStaff({
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					sjjg: this.formData.orgId,
				}).then(response => {
					this.tableData = response.data;
				});
			},
			//查看详情
			addClickDetail(val) {
				this.isLoaded = false
				uni.navigateBack({
					delta: 1
				});
			},
			// 获取数据
			getData(pageNo, value = '') {
				that = this;
				this.loading = true;
				// 获取人员信息详细信息
				getStaff({
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					sjjg: this.formData.orgId,
					empRyxm: this.keyword
				}).then(response => {
					this.isLoaded = true
					this.tableData = [...this.tableData, ...response.data]
					this.loading = false
				});
			},

			// 传递数据
			onClick(val, orgName) {
				this.isLoaded = false
				uni.navigateTo({
					url: '/pagesA/fire/staff_info/staff_details/staff_details?id=' + val.id + '&orgName=' +
						orgName,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						acceptDataFromOpenedPage: function(val) {
						}
					},
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('acceptDataFromOpenerPage', val);
					}
				});
			},

			// 删除单位人员信息
			onClickDel(val) {
				this.id = val.id;
				delStaff({
					id: this.id
				}).then(response => {
					this.tableData = []
					this.getData();
					// this.tableData = response.data;
				});
			},
			// 隐藏键盘
			hideKeyboard() {
				uni.hideKeyboard();
			},
			// 添加
			addClick() {
				uni.navigateTo({
					url: '/pagesA/fire/staff_info/add_staff/add_staff'
				});
			},
			// 触底的事件
			onReachBottom() {
				// 判断是否还有下一页数据
				if (this.pageNo * this.pageSize >= this.total)
					return uni.showToast({
						title: `数据加载完毕`
					});
				// 判断是否正在请求其它数据，如果是，则不发起额外的请求
				if (this.loading) return;
				this.pageNo += 1;
				this.getData(this.pageNo);
			}
		}
	};
</script>
<style lang="scss" scoped>
	body {
		background-color: #f5f7f9;
	}

	page {
		background-color: #f5f7f9;
	}

	/deep/ .u-tabs__wrapper[data-v-0de61367],
	.u-tabs__wrapper.data-v-0de61367,
	/deep/ .u-tabs__wrapper {
		width: 99%;
	}

	/deep/.u-tabs__wrapper__nav__item[data-v-0de61367],
	/deep/.u-tabs__wrapper__nav__item,
	/deep/.u-tabs__wrapper__nav__item.data-v-0de61367 {
		padding: 0 60rpx;
	}

	.uni-container {
		padding-right: 20upx;
	}

	.addInsp {
		width: 40px;
		position: fixed;
		right: 4px;
		z-index: 99999;
	}

	::v-deep .u-icon__icon {
		margin-right: 0px !important;
	}

	.an-niu {
		float: left;
		font-size: 10px;
		text-align: center;
		color: #fff;

		.detail {
			width: 72px;
			height: 60rpx;
			padding: 8px;
			border-radius: 30px;
			background-color: #f7c41e;
			margin-right: 20rpx;
			text-align: center;
			line-height: 60rpx;
		}

		.detailDel {
			width: 60px;
			height: 60rpx;
			border-radius: 30px;
			background-color: #ff2e31;
			color: white;
			margin-right: 20rpx;
			text-align: center;
			line-height: 60rpx;
		}
	}

	/deep/.segmented-control__item--button {
		background-color: rgb(76, 178, 182) !important;
	}

	/deep/.segmented-control__item--button--active {
		background-color: #ffffff !important;
	}

	/deep/.uni-card {
		box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.63) !important;
		border-radius: 30rpx;
	}

	.tiantupian {
		width: 110rpx;
		height: 110rpx;
		position: fixed;
		right: 15px;
		bottom: 80rpx;
	}

	//列表样式
	.titles {
		font-weight: 600;
		margin-bottom: 10rpx;
		color: black;
		font-size: 32rpx;
	}

	.grid-text {
		font-size: 15px;
		color: #434548;
		padding: 10rpx 0 5rpx 0rpx;
		/* #ifndef APP-PLUS */
		box-sizing: border-box;
		/* #endif */
	}

	.conts {
		max-width: 470rpx;
		display: -webkit-box;
		/*弹性伸缩盒子模型显示*/
		-webkit-box-orient: vertical;
		/*排列方式*/
		-webkit-line-clamp: 1;
		/*显示文本行数*/
		overflow: hidden;
		/*溢出隐藏*/
		color: #274647;
		text-overflow: ellipsis;
		/*不知道干嘛的*/

		.conts-title {
			margin-right: 10rpx;
			color: #728f90;
		}
	}

	/deep/ .u-form-item__body__left__content__label {
		font-size: 28upx !important;
	}

	/deep/.u-action-sheet {
		overflow-y: auto;
		height: 1000rpx;
		background-color: #fff;
	}
	.example{
		overflow-y: auto;
	}
</style>