<template>
	<a-card title="行李寄存数量曲线" style="margin-bottom: 10px">
		<template #extra>
			<a-select style="width: 100px" v-model:value="type">
				<a-select-option v-for="item in typeList" :value="item.id" :key="item.id">{{item.label}}</a-select-option>
			</a-select>
		</template>
		<div class="chart_content">
			<chart-luggage v-if="lineChart.length > 0" :id="0" :list="lineChart"></chart-luggage>
			<a-empty v-else style="padding-top: 100px" />
		</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="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 === 'vistitType'">
					<a-tag color="#2db7f5">
						<template v-if="record.vistitType === 0">人员</template>
						<template v-else-if="record.vistitType === 1">环保车</template>
						<template v-else-if="record.vistitType === 2">拉猪车</template>
						<template v-else-if="record.vistitType === 3">饲料车</template>
						<template v-else-if="record.vistitType === 4">送猪车</template>
						<template v-else-if="record.vistitType === 5">物资</template>
						<template v-else-if="record.vistitType === 6">餐车</template>
					</a-tag>
				</template>
				<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="#87d068">审核通过</a-tag>
					<a-tag v-else-if="record.billStatus === 2" color="#f50">审核拒绝</a-tag>
					<a-tag v-else-if="record.billStatus === 3" color="#87d068">审核通过</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="luggage">
	import chartLuggage from '../chart/chartLuggage.vue'
	import washEntranceApi from "@/api/wash/washEntranceApi"
	const type = ref(2)
	const typeList = ref([
		{
			id: 1,
			label: '今日'
		},
		{
			id: 2,
			label: '本周'
		},
		{
			id: 3,
			label: '本月'
		}
	])
	const lineChart = ref([])

	watch(type, () => {
		initLineChart()
	})

	const initLineChart = () => {
		let params = {
			type: type.value,
			dataType: 1
		}
		washEntranceApi.getLuggageLineChart(params).then(res => {
			lineChart.value = res
		})
	}


	const name = ref('')
	const dateTime = ref([])

	const reset = () => {
		name.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: 'userName',
			width: 150,
			fixed: true
		},
		{
			title: '寄存时间',
			dataIndex: 'luggageDate',
			width: 150,
			resizable: true,
			ellipsis: true,
			sorter: true
		},
		{
			title: '寄存位置',
			dataIndex: 'luggageLocation',
			width: 150,
			resizable: true,
			ellipsis: true,
		},
		{
			title: '寄存件数',
			dataIndex: 'luggageNum',
			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 = {
			word: name.value,
			startTime: dateTime.value.length ? dateTime.value[0] : '',
			endTime: dateTime.value.length ? dateTime.value[1] : ''
		}
		return washEntranceApi.getLuggageTableList(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.delLuggageTableList(params).then(() => {
			table.value.clearRefreshSelected()
		})
	}

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

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

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