<template>
	<a-card :bordered="false" style="margin-bottom: 10px">
		<a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
			<a-row :gutter="24">
				<a-col :span="4">
					<a-form-item name="eventType" label="巡检类型">
						<a-select v-model:value="searchFormState.eventType" 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-option :value="4">设备镜头脏污</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-space>
						<a-button type="primary" @click="table.refresh(true)">
							<template #icon><SearchOutlined /></template>
							查询
						</a-button>
						<a-button @click="reset">重置</a-button>
					</a-space>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false">
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			:expand-row-by-click="true"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:row-selection="options.rowSelection"
			@resizeColumn="(w, col) => {
				col.width = w
			}"
		>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'eventType'">
					<span v-if="record.eventType === 1">人员行为识别</span>
					<span v-else-if="record.eventType === 2">车辆识别</span>
					<span v-else-if="record.eventType === 3">外来生物识别</span>
					<span v-else-if="record.eventType === 4">设备镜头脏污</span>
				</template>
				<template v-if="column.dataIndex === 'imgUrl'">
					<div>
						<div v-viewer>
							<img v-if="record.imgUrl" class="record-img" :src="record.imgUrl" alt="/">
							<span v-else>暂无图片</span>
						</div>
					</div>
				</template>
				<template v-if="column.dataIndex === 'action'">
					<a-popconfirm title="确定要取消关注此条数据吗？" @confirm="cancel(record)">
						<a-button type="link" danger size="small">取消关注</a-button>
					</a-popconfirm>
				</template>
			</template>
		</s-table>
	</a-card>
</template>

<script setup name="attention">

	import bizAiPollingApi from "@/api/biz/ai/bizAiPollingApi";
	import {message} from "ant-design-vue";

	const reset = () => {
		searchFormRef.value.resetFields()
		table.value.refresh(true)
	}
	const table = ref()
	const formRef = ref()
	const giveRef = ref()
	const searchFormRef = ref()
	const searchFormState = ref({})
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const show = ref(true)
	const columns = [
		{
			title: '巡检类型',
			dataIndex: 'eventType',
			width: 150,
			fixed: true
		},
		{
			title: '姓名/车牌号',
			dataIndex: 'name',
			width: 200,
			resizable: true,
			ellipsis: true
		},
		{
			title: '照片',
			dataIndex: 'imgUrl',
			resizable: true,
			width: 150,
			ellipsis: true
		},
		{
			title: '类型',
			dataIndex: 'type',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '触发时间',
			dataIndex: 'capTime',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '尝试进入区域',
			dataIndex: 'devName',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '关注时间',
			dataIndex: 'createTime',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '通知人',
			dataIndex: 'notifierName',
			width: 150,
			resizable: true,
			ellipsis: true,
			sorter: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			width: 200,
			fixed: 'right'
		}
	]
	// 操作栏通过权限判断是否显示
	if (hasPerm(['basePigpenEdit', 'basePigpenDelete'])) {
		columns.push({
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: '150px'
		})
	}
	const selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		// columns数字类型字段加入 needTotal: true 可以勾选自动算账
		alert: {
			show: true,
			clear: () => {
				selectedRowKeys.value = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	const loadData = async (parameter) => {
		return bizAiPollingApi.getFollowPage(Object.assign(parameter, searchFormState.value)).then(res => {
			return res
		})
	}

	const cancel = (item) => {
		let params = {
			eventId: item.id,
			eventType: item.eventType
		}
		bizAiPollingApi.cancelFollow(params).then((res) => {
			table.value.refresh(true)
		})
	}
</script>

<style scoped>
.record-img {
	width: 40px;
	height: 40px;
}
</style>
