<template>
	<view>
		<scroll-view :scroll-y="true">
			<uni-card>
				<uni-title title="" type="h1" align="center"></uni-title>
				<view>
					<uni-row>
						<uni-col :span="11"><uni-title title="姓名 " align="left" type="h5"></uni-title></uni-col>
						<uni-col :span="11" :push="2"><uni-title title="劳动合同号" align="left"
								type="h5"></uni-title></uni-col>
					</uni-row>
					<uni-row>
						<uni-col :span="11"><uni-easyinput v-model="xm" focus suffixIcon="search" clearable
								placeholder="姓名模糊查询" @change="Search" @iconClick="Search" /></uni-col>
						<uni-col :span="11" :push="2">
							<uni-easyinput v-model="ldhth" focus suffixIcon="search" clearable placeholder="劳动合同号模糊查询"
								@change="Search" @iconClick="Search" />
						</uni-col>
					</uni-row>
				</view>
				<view style="margin-bottom: 10rpx;">
					<uni-row>
						<uni-col :span="24"><uni-title title="所属单位" align="left" type="h5"></uni-title></uni-col>
					</uni-row>
					<uni-row>
						<uni-col :span="24">
							<trq-depart-select returnCodeOrID="orgCode" @change="departChange"></trq-depart-select>
						</uni-col>
					</uni-row>
				</view>
			</uni-card>
			<uni-card>
				<zb-table :show-header="true" :highlight="true" :columns="column" :stripe="true" :fit="false"
					:border="true" :data="ryDataList" @detail="detail"></zb-table>
				<uni-pagination :current="current" :pagerCount="pages" :total="total" prev-text="前一页" next-text="后一页"
					:show-icon="false" @change="pagechange" />
			</uni-card>
		</scroll-view>


	</view>
</template>

<script setup>
	import {
		onReady,
		onLoad

	} from '@dcloudio/uni-app';
	import {
		reactive,
		ref,
		onMounted
	} from 'vue';
	import {
		useStore
	} from '@/store';
	import {
		queryDepByCode,
		queryZbDepByLdhth
	} from '@/api/depart.js'
	import {
		queryRenyuanByDepartID
	} from '@/api/renyuan.js'
	let xm = ref("")
	let ldhth = ref("")
	let departID = ref("") //部门树选中的ID
	const ryDataList = ref([])

	let status = ref("")
	let contentText = reactive({
		contentdown: '点击查看更多',
		contentrefresh: '加载中',
		contentnomore: '没有更多'
	})

	let pageNo = ref(1)
	let pageSize = ref(10)
	let total = ref(0)
	let pages = ref(0)
	let current = ref(0)
	let params = reactive({
		pageNo: pageNo,
		pageSize: pageSize
	})
	let column = ref([{
			label: '序号',
			width: 60,
			type: 'index',
			color: 'blue',
			align: 'center'
		},

		{
			name: 'xm',
			label: '姓名',
			width: 70,
			align: 'center'
		},
		// {
		// 	name: 'gzdw',
		// 	label: '单位',
		// 	align: 'center',
		// 	width: 150
		// },
		{
			name: 'xb_dictText',
			label: '性别',
			align: 'center',
			width: 60
		},
		{
			name: 'nl',
			label: '年龄',
			align: 'center',
			width: 60
		},
		{
			name: 'operation',
			type: 'operation',
			fixed: true,
			label: '操作',
			align: 'center',
			renders: [{
				name: '详情',
				func: 'detail',
				size: 'mini'
			}]
		}
	])

	onLoad((e) => {

	})
	onMounted((e) => {
		departID.value = ""
		getRenyuanByDepID()
	})

	function detail(record) {
		// console.log(record)

		uni.navigateTo({
			url: "/pages/views/renliziyuan/renyuanxinxi/detail?data=" + encodeURIComponent(JSON.stringify(record))
		})
	}

	function pagechange(e) {
		current.value = e.current
		pageNo.value = e.current
		getRenyuanByDepID()
	}

	function departChange(e) {
		departID.value = e
		getRenyuanByDepID()
	}

	function getRenyuanByDepID() {
		ryDataList.value = []
		let queryParm = {
			pageNo: pageNo.value,
			pageSize: pageSize.value,
			current: current.value
		};
		queryParm.orgCode = departID.value
		queryRenyuanByDepartID(queryParm).then((res) => {
			if (res.success) {
				ryDataList.value = res.result.records
				total.value = res.result.total
				pages.value = res.result.pages


			}
		}).catch((err) => {
			console.log(err);
		})
	}

	function Search() {
		ryDataList.value = [];
		let queryParm = {
			pageNo: pageNo.value,
			pageSize: pageSize.value
		};
		if ((ldhth.value == '') & (xm.value == '')) {
			return;
		}
		if (xm.value !== '') {
			queryParm.xm = '*' + xm.value + '*';
		}
		if (ldhth.value !== '') {
			queryParm.ldhth = '*' + ldhth.value + '*';
		}
		queryRenyuanByDepartID(queryParm).then((res) => {
			if (res.success) {
				ryDataList.value = res.result.records
				total.value = res.result.total
				pages.value = res.result.pages
			}
		}).catch((err) => {
			console.log(err);
		})
	}
</script>

<style scoped>
	.uni-group {
		display: flex;
		align-items: center;
	}
</style>