<template>
	<div class="table_item">
		<s-table ref="tableRef" :columns="columns" :data="loadData" :row-key="(record) => record.code">
			<template #operator>
				<!-- 搜索区域 -->
				<div class="table-search">
					<div class="table-search-form">
						<a-row :gutter="10">
							<a-form
								ref="searchFormRef"
								name="advanced_search"
								layout="inline"
								:label-col="{ style: { width: '70px', justifyContent: 'end' } }"
								:model="searchFormState"
								class="ant-advanced-search-form"
							>
								<a-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
									<a-form-item label="接口类型" name="type">
										<a-select v-model:value="searchFormState.type" placeholder="请选择接口类型">
											<a-select-option value="1">甘肃疾控</a-select-option>
											<a-select-option value="2">唐山</a-select-option>
											<a-select-option value="3">世窗</a-select-option>
										</a-select>
									</a-form-item></a-col
								>
								<a-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8"
									><a-form-item label="设备名称" name="name">
										<a-input v-model:value="searchFormState.name" placeholder="请输入设备名称" /> </a-form-item
								></a-col>
								<a-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8"
									><a-form-item label="所属部门" name="ssbm">
										<a-input v-model:value="searchFormState.ssbm" placeholder="请输入所属部门" /> </a-form-item
								></a-col>
							</a-form>
						</a-row>
					</div>
					<div class="table-search-buttons">
						<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
						<a-button class="xn-mg08" @click="reset">重置</a-button>
					</div>
				</div>
				<!-- 其他操作区域 -->
				<div class="table-head-btn">
					<div class="btn-left">
						<a-button type="primary">
							<template #icon><plus-outlined /></template>新增
						</a-button>
					</div>
				</div>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-button type="link" size="small">编辑</a-button>
					<a-popconfirm title="确定要删除吗？" @confirm="deleteData(record)">
						<a-button type="link" danger size="small">删除</a-button>
					</a-popconfirm>
					<a-button type="link" size="small">记录</a-button>
				</template>
			</template>
		</s-table>
	</div>
</template>

<script setup>
	import tool from '@/utils/tool'
	import jobApi from '@/api/dev/jobApi'
	const searchFormRef = ref()
	const searchFormState = ref({})
	const tableRef = ref()
	const columns = [
		{
			title: '接口类型',
			dataIndex: 'type',
			align: 'center',
			ellipsis: true
		},
		{
			title: '设备名称',
			dataIndex: 'name',
			align: 'center',
			ellipsis: true
		},
		{
			title: '所属部门',
			dataIndex: 'ssbm',
			align: 'center',
			ellipsis: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: 150
		}
	]

	const loadData = (parameter) => {
		return jobApi.jobPage(Object.assign(parameter, searchFormState.value)).then((res) => {
			// return res
			const obj = {
				current: 1,
				pages: 1,
				records: [
					{
						name: 'ABSL-1设备',
						type: '唐山',
						ssbm: '广州海关技术中心'
					},
					{
						name: 'ABSL-2设备',
						type: '甘肃市疾控',
						ssbm: '广州海关技术中心'
					},
					{
						name: 'ABSL-3设备',
						type: '唐山',
						ssbm: '广州海关技术中心'
					},
					{
						name: 'ABSL-4设备',
						type: '唐山',
						ssbm: '广州海关技术中心'
					},
					{
						name: 'ABSL-5设备',
						type: '唐山',
						ssbm: '广州海关技术中心'
					},
					{
						name: 'ABSL-6设备',
						type: '唐山',
						ssbm: '广州海关技术中心'
					}
				],
				size: 10,
				total: 6
			}
			return obj
		})
	}
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
	// 删除
	const deleteData = (record) => {
		console.log(record, '删除')
	}
</script>

<style lang="less" scoped>
	.table_item {
		padding: 15px 20px;
		background-color: #ffffff;

		:deep(.ant-table-pagination-right) {
			justify-content: center !important;
		}
	}
	.list {
		width: 60%;
		padding: 10px 20px;
		border-radius: 10px;
		background-color: #ffffff;

		:deep(.ant-descriptions) {
			margin-bottom: 10px;
		}
		:deep(.ant-descriptions-header) {
			margin: 0;
			padding: 10px;
			border: 1px solid #f0f0f0;
			border-bottom: none;
		}
	}
</style>
