<template>
	<div class="head">
		<el-row>
			<el-form-item>
				<el-input v-model="searchInfo.name" placeholder="请输入名称" style="margin-left: 10px;"/>
			</el-form-item>
			<el-button   @click="getList()" style="margin-left: 10px;">搜索</el-button>
			<!-- <el-button type="primary" @click="Add()" style="margin-left: 10px;">添加</el-button> -->
		</el-row>
	</div>
	<el-table  :data="tableData" style="width: 100%;" row-key="id" v-loading="loading">
		<el-table-column prop="reg_num" label="Id" width="100"  />
		<el-table-column prop="name" label="姓名" />
		 <el-table-column prop="sfz" label="卡号" />
		 <el-table-column prop="note" label="原因" />
		 <el-table-column prop="created_at" label="加入时间" />
		<el-table-column prop="" label="操作">
			<template #default="scope">
				 <el-button type="danger" @click="Del(scope.row.id)" size="small" style="margin-left: 10px;">删除</el-button>
			</template>
		</el-table-column>
	</el-table>
	<div class="page">
		<el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize"
			:page-sizes="[15, 50, 100, 200]" layout="total,sizes, prev, pager, next" :total="total"
			@size-change="PageSizeChange" @current-change="PageCurrentChange" />
	</div>
	
	<el-dialog v-model="dialogVisible" title="病区信息" width="30%">
		<el-form :model="Info" label-width="100px" v-loading="loading" style="padding-right: 40px;">
			<el-form-item label="病区名称:">
				<el-input v-model="Info.name" />
			</el-form-item>
			<el-form-item label="病区状态:">
				<el-switch v-model="Info.status" size="large" active-text="正常" inactive-text="关闭"
					:active-value="1" :inactive-value="0" />
			</el-form-item>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="dialogVisible = false">取消</el-button>
				<el-button type="primary" @click="Save">
					确定
				</el-button>
			</span>
		</template>
	</el-dialog>
	<el-dialog v-model="addUserdialogVisible" title="添加用户" width="30%">
		<el-form :model="addUserInfo" label-width="100px" v-loading="loading" style="padding-right: 40px;">
			<el-form-item label="姓名:">
				<el-input v-model="addUserInfo.cname" />
			</el-form-item>
			<el-form-item label="账号:">
				<el-input v-model="addUserInfo.uname" />
			</el-form-item>
			<el-form-item label="角色:">
				 <el-select :filterable="true" clearable v-model="addUserInfo.groupId" placeholder="选择角色"
				 	style="margin-left: 10px;">
				 	<el-option v-for="(item ,index) in groupList_new"   :label="item.group_name" :value="item.id" />
				 </el-select>
			</el-form-item>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="addUserdialogVisible = false">取消</el-button>
				<el-button type="primary" @click="addUserSave()">
					确定
				</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup>
	import {
		ref,
		onMounted,computed 
	} from 'vue'
	import {
		 adminBlackListDelete,adminBlackListGetList
	} from '@/api/api.js'
	import { ElMessage, ElMessageBox } from 'element-plus'
	const groupList_new = computed(() => {
	     return groupList.value.filter(item => (item.id ==2));
	   });
	let loading=ref(false);
	let searchInfo=ref({
		name:''
	})
	let Info=ref({
		id:null,
		name:'',
		status:1
	})
	
	let dialogVisible=ref(false);
	
	//获取设备list
	let tableData = ref([])
	let currentPage = ref(1) //当前页码
	let pageSize = ref(15) //每页数量
	let total = 0 //总数量
	const getList=()=>{
		loading.value = true
		adminBlackListGetList({searchInfo:searchInfo.value,page:currentPage.value,pageSize:pageSize.value}).then(res => {
			loading.value = false
			if (res.status) {
				tableData.value=res.data.list
				total=res.data.count
			} else {
				ElMessage.error(res.msg)
			}
		
		})
	}
	const Del=(id)=>{
		loading.value = true
		adminBlackListDelete({id:id}).then(res => {
			loading.value = false
			if (res.status) {
				 getList()
			} else {
				ElMessage.error(res.msg)
			}
		
		})
	}
	const PageSizeChange = (e) => { // 修改每页数量
		pageSize.value = e
		getList()
	}
	const PageCurrentChange = (e) => { //切换页码
		currentPage.value = e
		getList()
	}
	

	onMounted(()=>{
		getList() 
	})
</script>

<style scoped>
	.page {
		display: flex;
		justify-content: flex-end;
		margin-top: 10px;
	}
</style>