<template>
	<a-card title="隔离数量曲线" style="margin-bottom: 10px">
		<template #extra>
			<div class="pcrForm">
				<a-row :gutter="20">
					<a-col :span="12">
						<a-form-item label="位置">
							<a-select v-model:value="typeLocation">
								<a-select-option v-for="item in locationList" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="12">
						<a-form-item label="日期">
							<a-select v-model:value="type">
								<a-select-option v-for="item in typeList" :key="item.id" :value="item.id">{{item.label}}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
				</a-row>
			</div>
		</template>
		<div class="chart_content">
			<chart-isolation v-if="lineChart.length > 0" :id="3" :list="lineChart"></chart-isolation>
			<a-empty v-else />
		</div>
	</a-card>
	<a-card>
		<a-form>
			<a-row :gutter="16">
				<a-col :span="4">
					<a-form-item label="关键字">
						<a-input v-model:value="name" placeholder="请输入姓名或手机号"></a-input>
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-form-item label="隔离状态">
						<a-select v-model:value="isolationType">
							<a-select-option v-for="item in isolationList" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-form-item label="隔离地点">
						<a-select v-model:value="locationId">
							<a-select-option v-for="item in isolationLocationList" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="隔离时间">
						<a-range-picker v-model:value="dateTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD" />
					</a-form-item>
				</a-col>
				<a-col :span="4">
					<a-space>
						<a-button type="primary" @click="table.refresh(true)">查询</a-button>
						<a-button @click="reset">重置</a-button>
<!--						<a-button type="primary" @click="derive">导出</a-button>-->
					</a-space>
				</a-col>
			</a-row>
		</a-form>
		<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 #operator class="table-operator">
				<a-space>
					<xn-batch-delete :selectedRowKeys="selectedRowKeys" @batchDelete="deleteAll" />
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'billStatus'">
					<a-tag v-if="record.billStatus === 0" color="#f50">待隔离</a-tag>
					<a-tag v-else-if="record.billStatus === 1" color="#f50">隔离中</a-tag>
					<a-tag v-else-if="record.billStatus === 2" color="#87d068">已完成</a-tag>
					<a-tag v-else-if="record.billStatus === 3" color="#1890FF">提前解除</a-tag>
				</template>
				<template v-if="column.dataIndex === 'action'">
					<a-popconfirm title="删除此消息吗？" @confirm="del(record)">
						<a-button type="link" danger size="small">删除</a-button>
					</a-popconfirm>
				</template>
			</template>
		</s-table>
	</a-card>
</template>

<script setup name="isolation">
	import chartIsolation from '../chart/chartIsolation.vue'
	import washEntranceApi from "@/api/wash/washEntranceApi"
	const typeLocation = ref(0)
	const locationList = ref([
		{
			label: '全部',
			value: 0,
		},
		{
			label: '人员二级洗消站',
			value: 1,
		},
		{
			label: '生产区',
			value: 2,
		},
	])
	const typeList = ref([
		{
			id: 1,
			label: '今日'
		},
		{
			id: 2,
			label: '本周'
		},
		{
			id: 3,
			label: '本月'
		},
	])
	const type = ref(2)
	const lineChart = ref([])
	const initLineChart = () => {
		let params = {
			type: typeLocation.value,
			dataType: type.value
		}
		washEntranceApi.getIsolateLineChart(params).then((res) => {
			lineChart.value = res
		})
	}

	const name = ref('')
	const isolationType = ref('')
	const isolationList = ref([
		{
			value: 0,
			label: '待隔离',
		},
		{
			value: 1,
			label: '隔离中',
		},
		{
			value: 2,
			label: '已完成',
		},
		{
			value: 3,
			label: '提前解除'
		}
	])
	const locationId = ref('')
	const isolationLocationList = ref([
		{
			value: 3,
			label: '净道二级洗消站'
		}
		// {
		// 	value: 5,
		// 	label: '生产区'
		// }
	])
	const dateTime = ref([])

	const reset = () => {
		name.value = ''
		isolationType.value = ''
		locationId.value = ''
		dateTime.value = []
		table.value.refresh(true)
	}

	// const derive = () => {}


	const table = ref()

	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const show = ref(true)
	const columns = [
		{
			title: '姓名',
			dataIndex: 'admissionUserName',
			width: 150,
			fixed: true
		},
		{
			title: '手机号',
			dataIndex: 'phone',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '目的地',
			dataIndex: 'destName',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '隔离状态',
			dataIndex: 'billStatus',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '隔离地点',
			dataIndex: 'isolateLocation',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '隔离天数',
			dataIndex: 'isolateDayNum',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '隔离开始时间',
			dataIndex: 'isolateStartDate',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '计划隔离结束时间',
			dataIndex: 'isolateEndDate',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '实际隔离结束时间',
			dataIndex: 'isolateRealEndDate',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			width: 200,
			fixed: 'right'
		}
	]
	const selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		// columns数字类型字段加入 needTotal: true 可以勾选自动算账
		alert: {
			show: true,
			clear: () => {
				selectedRowKeys.value = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}

	const loadData = (parameter) => {
		let params = {
			type: isolationType.value,
			locationId: locationId.value,
			word: name.value,
			startTime: dateTime.value.length ? dateTime.value[0] : '',
			endTime: dateTime.value.length ? dateTime.value[1] : '',
		}
		return washEntranceApi.getIsolationTableList(Object.assign(parameter, params)).then((res) => {
			return res
		})
	}

	const deleteAll = (params) => {
		let l = []
		params.forEach(item => {
			l.push(item.id)
		})
		let str = l.join(',')
		let data = {
			ids: str
		}
		washEntranceApi.delIsolationTableList(data).then(() => {
			table.value.clearRefreshSelected()
		})
	}

	const del = () => {
		let params = {
			ids: row.id
		}
		washEntranceApi.delIsolationTableList(params).then(() => {
			table.value.refresh(true)
		})
	}

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

<style scoped>
	.chart_content {
		width: 100%;
		height: 400px;
	}
	.pcrForm {
		width: 360px;
	}
</style>
