<template>
	<div>
		<a-space class="header">
			<div class="input-box">
				<div class="silt-title">
					<span style="width: 70px; margin-right: 12px; display: block">{{ '单位信息' }}</span>
					<a-input style="width: 220px" v-model:value="informationData.dwmc" placeholder="请输入" />
				</div>
				<div class="input-box-sle">
					<span class="title-box">{{ '法定代表人' }}</span>
					<a-input style="width: 220px" v-model:value="informationData.fddbr" placeholder="请输入" />
				</div>
			</div>
			<div class="btnBox">
				<a-button style="margin-right: 16px" @click="searchData">查询</a-button>
				<a-button style="margin-right: 16px" @click="reset">重置</a-button>
				<a-button type="primary" @click="addData">新增</a-button>
			</div>
		</a-space>
		<a-table :dataSource="dataSource" :row-key="(record) => record.key" :pagination="tablePage" @change="onChangePage"
			:columns="columns">
			<template #bodyCell="{ column, record }">
				<template v-if="column.key === 'action'">
					<span>
						<a-button class="check" @click="check(record)">查看</a-button>
						<a-button class="edit" @click="edit(record)">编辑</a-button>

						<a-popconfirm title="确定删除此条数据？" @confirm="deleteData(record)">
							<a-button class="delete">删除</a-button>
						</a-popconfirm>
					</span>
				</template>
			</template>
		</a-table>
		<!-- <a-pagination
			@change="onChange"
			size="small"
			:total="informationData.total"
			:show-total="(total) => `共 ${informationData.total} 条`"
		/> -->
		<!-- 查看--编辑--新增等操作 -->
		<DetailedList :dataObj="dataObj" @isVisible="isVisible" />
	</div>
</template>

<script setup name="unitInfo">
import unitInfoApi from '@/api/basic.info/unitInfoApi'
import DetailedList from './detailedList.vue'
const columns = [
	{
		title: '序号',
		dataIndex: 'Index',
		align: 'center',
		customRender: ({ text, record, index }) => {
			return `${index + 1}`
		}
	},
	{
		title: '单位信息',
		dataIndex: 'dwmc',
		align: 'center',
		key: 'dwmc'
	},
	{
		title: '法定代表人',
		dataIndex: 'fddbr',
		align: 'center',
		key: 'fddbr'
	},
	{
		title: '统一社会信用代码',
		dataIndex: 'dwdm',
		align: 'center',
		key: 'dwdm'
	},
	{
		title: '单位类型',
		dataIndex: 'dwlx',
		align: 'center',
		key: 'dwlx'
	},
	{
		title: '操作',
		dataIndex: 'action',
		align: 'center',
		key: 'action'
	}
]
const dataSource = ref([])
const dataObj = ref({
	visible: false,
	titleText: '',
	showLock: false,
	isType: '',
	id: ''
})
const unitInfoIdParamList = ref([])
const informationData = ref({
	dwmc: '',
	fddbr: '',
	current: 1,
	size: 10
})
// 表格分页
const onChangePage = (ev) => {
	Object.assign(informationData, ev)
	onSearch()
}
// 列表分页
const onSearch = () => {
	const fd = { ...informationData.value }
	console.log(fd, 'fa')
	unitInfoApi.unitInfoPage(fd).then((res) => {
		dataSource.value = []
		res.records.forEach((item) => {
			if (item.dwlx === '1') {
				item.dwlx = '粮食仓储企业'
			} else if (item.dwlx === '2') {
				item.dwlx = '粮食购销企业'
			} else if (item.dwlx === '3') {
				item.dwlx = '粮食加工企业'
			} else if (item.dwlx === '4') {
				item.dwlx = '粮食设备制造企业'
			} else if (item.dwlx === '9') {
				item.dwlx = '其他粮食企业'
			} else if (item.dwlx === '11') {
				item.dwlx = '中央直属储备粮库'
			} else if (item.dwlx === '12') {
				item.dwlx = '中谷粮油集团'
			} else if (item.dwlx === '13') {
				item.dwlx = '省级储备粮库'
			} else if (item.dwlx === '14') {
				item.dwlx = '第十集储备粮库'
			} else if (item.dwlx === '15') {
				item.dwlx = '县级储备粮库'
			} else {
				item.dwlx = '其他仓储企业'
			}
		})
		dataSource.value = res.records
	})
}
// 查询
const searchData = () => {
	onSearch()
}
// 重置
const reset = () => {
	dataObj.value.isType = ''
	informationData.value = {
		dwmc: '',
		fddbr: '',
		current: 1,
		size: 10
	}
	onSearch()
}
// 新增
const addData = () => {
	dataObj.value.isType = '1'
	dataObj.value.titleText = '新增详细信息'
	dataObj.value.visible = true
	dataObj.value.showLock = false
}
// 查看
const check = (row) => {
	dataObj.value.id = row.id
	dataObj.value.isType = '3'
	dataObj.value.titleText = '查看详细信息'
	dataObj.value.visible = true
	dataObj.value.showLock = true
}
// 编辑
const edit = (row) => {
	dataObj.value.id = row.id
	dataObj.value.isType = '2'
	dataObj.value.titleText = '编辑详细信息'
	dataObj.value.visible = true
	dataObj.value.showLock = false
}
// 删除
const deleteData = (row) => {
	unitInfoIdParamList.value = [{ id: row.id }]
	unitInfoApi.unitInfoDelete(unitInfoIdParamList.value).then((res) => {
		onSearch()
	})
}
// 子组件传递
const isVisible = (val) => {
	console.log(val, 'valaaa')
	dataObj.value.visible = false
	dataObj.value.showLock = false
	dataObj.value.titleText = ''
	onSearch()
}

onMounted(() => {
	onSearch()
})
</script>
<style scoped>
.header {
	display: flex;
	padding: 20px;
	width: 100%;
}

.input-box {
	display: flex;
	width: 100%;
}

.input-box-sle {
	width: 56%;
	display: flex;
	justify-content: center;
	align-items: center;
	margin-right: 24px;
}

.title-box {
	margin-right: 12px;
}

.inputBoxContent {
	width: 400px;
}

.silt-title {
	width: 280px;
	display: flex;
	align-items: center;
	margin-right: 32px;
}

.btnBox {
	display: flex;
}

.ant-input-group-addon {
	border: 0;
}

.ant-input,
.ant-btn {
	border-radius: 5px;
}

.ant-pagination {
	margin-top: 12px;
	float: right;
	margin-right: 16px;
}

.add-btn {
	background-color: rgba(112, 125, 233);
}

.check {
	background-color: rgba(112, 125, 233);
	color: #fff;
	margin-left: 8px;
}

.edit {
	background-color: rgba(222, 186, 80);
	color: #fff;
	margin-left: 8px;
}

.delete {
	background-color: rgba(255, 70, 70);
	color: #fff;
	margin-left: 8px;
}

.audit {
	background-color: rgba(83, 184, 36);
	color: #fff;
	margin-left: 8px;
}

.ant-table-thead>tr>th {
	text-align: center;
}

.ant-table-tbody>tr>td {
	text-align: center;
}</style>
