<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-good v-if="lineChart.length > 0" :id="0" :list="lineChart"></chart-good>
			<a-empty v-else style="padding-top: 100px" />
		</div>
	</a-card>
	<a-card style="margin-bottom: 10px">
		<a-form>
			<a-row :gutter="16">
				<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="search">查询</a-button>
						<a-button @click="reset">重置</a-button>
						<!--							<a-button type="primary" @click="derive">导出</a-button>-->
					</a-space>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card>
		<!--:alert="options.alert.show"-->
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			:expand-row-by-click="true"
			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 === 'goodsNums'">
					<span>{{record.goodsNums}}{{record.goodsUnit}}</span>
				</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="good">
	import chartGood from '../chart/chartGood.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: 2
		}
		washEntranceApi.getLuggageLineChart(params).then(res => {
			lineChart.value = res
		})
	}



	const dateTime = ref([])

	const reset = () => {
		dateTime.value = []
	}
	const table = ref()

	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const show = ref(true)
	const columns = [
		{
			title: '申请单',
			dataIndex: 'billAdmission',
			width: 150,
			fixed: true
		},
		{
			title: '申请时间',
			dataIndex: 'createDate',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '当前位置',
			dataIndex: 'currentLocation',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '物资类型',
			dataIndex: 'goodsTypeName',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '物资名称',
			dataIndex: 'goodsName',
			width: 150,
			resizable: true,
			ellipsis: true
		},
		{
			title: '物资数量',
			dataIndex: 'goodsNums',
			width: 150,
			resizable: true,
			ellipsis: true,
			sorter: 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 = {
			startTime: dateTime.value.length ? dateTime.value[0] : '',
			endTime: dateTime.value.length ? dateTime.value[1] : '',
			dataType: 3
		}
		return washEntranceApi.getWashingTableList(Object.assign(parameter, params)).then((data) => {
			return data
		})
	}

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

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

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

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