<template>
	<!-- 安全鉴定 -->
	<div class="wrap">
		<div style="min-height: 500px;" ref="contentPanel">
			<div class="bbsl-btn-content" ref="btnPanel">
				<el-button size="mini" icon="el-icon-plus" type="primary" @click="openFormDiao">添加</el-button>
				<el-button :disabled="!multipleSelection.length" size="mini" icon="el-icon-delete" type="danger"
					@click="deleteSelect">删除</el-button>
			</div>
			<el-table stripe :max-height="tableMaxHeight" @row-dblclick="handleDbClick" :style="{ width: '100%' }"
				ref="multipleSelection" v-loading="loading" border :data="tableData" :row-key="getRowKey"
				@selection-change="handleSelectionChange" :header-cell-style="{ 'text-align': 'center' }"
				:cell-style="{ 'text-align': 'center' }">
				<el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column>
				<el-table-column min-width="120" prop="rsnm" label="水库名称" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="appraisalCompany" label="安全鉴定单位" show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" prop="appraisalDate" label="安全鉴定时间" show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" prop="appraisalLevel" label="安全鉴定级别" show-overflow-tooltip>
				</el-table-column>
			</el-table>
			<el-footer>
				<el-pagination style="position: absolute;right: 0;bottom: 0;" ref="paginationPanel" align="right"
					background @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:current-page="queryParam.pageBean.page" :page-sizes="[5, 10, 20, 50]"
					:page-size="queryParam.pageBean.pageSize" layout="total, sizes, prev, pager, next, jumper"
					:total="total"></el-pagination>
			</el-footer>
		</div>
		<form-dialog v-if="showFormDia" @closeFormDiao="closeFormDiao" @refList="getDateList" :showFormDia="showFormDia"
			:title="title" :wId='wId' :plId="plId" :rscd="this.rscd"></form-dialog>
	</div>
</template>

<script>
import req from '@/request.js'
import reinforcement from '@/api/reservoirManagement/resFrom.js'
import FormDialog from './safForm-dialog.vue'
import {
	TableMixin
} from '@/mixins/tableMixin'
export default {
	name: 'reinforcement',
	mixins: [TableMixin],
	components: {
		FormDialog
	},
	props: {
		rscd: {
			type: String,
			default: '',
		},
		wId: {
			type: String,
			default: '',
		},
	},
	data() {
		return {
			queryParam: {
				pageBean: {
					pageSize: 10,
					page: 1,
				},
				params: {
					rscd: this.rscd,
				},
			},
			total: 0,
			loading: false,
			tableData: [], //表格数据
			multipleSelection: [], // 复选框
			title: null,
			showFormDia: false,
			plId: null,
		}
	},
	created() {
		console.log(123);
		this.getDateList()
	},
	methods: {
		handleSizeChange(val) {
			this.queryParam.pageBean.pageSize = val
			this.getDateList()
		},
		handleCurrentChange(val) {
			this.queryParam.pageBean.page = val
			this.getDateList()
		},
		//查询
		getDateList() {
			this.loading = true
			this.tableData = []
			reinforcement.ListGetSaf(this.queryParam, (res) => {
				if (res.state) {
					this.total = res.value.total
					this.tableData = res.value.rows
					this.loading = false
				}
			})
		},
		//新增
		openFormDiao() {
			this.title = '新增'
			this.showFormDia = true;
			console.log(this.showFormDia);
		},
		//修改
		handleUpdate(row) {
			this.title = '修改';
			this.plId = row.id;
			this.showFormDia = true;
		},
		// // 批量删除
		deleteSelect() {
			this.$confirm('确定删除选中数据？', '提示', {
				confirmButtonText: '确 定',
				cancelButtonText: '取 消',
				type: 'warning',
			})
				.then(() => {
					reinforcement
						.removeSaf(this.multipleSelection, (res) => {
							if (res.state) {
								this.$notify({
									type: 'success',
									message: '删除成功',
									duration: 2000,
									// offset: 80
								})
								// this.multipleSelection = [];
								this.$refs.multipleSelection.clearSelection()
								this.queryParam.pageBean.page = 1
								this.getDateList()
							}
						})
						.catch((res) => {
							this.$notify({
								type: 'error',
								message: res.message,
								duration: 2000,
								offset: 80,
							})
							this.getDateList()
						})
				})
				.catch(() => { })
		},
		// 指定一个key标识这一行的数据
		getRowKey(row) {
			return row.id
		},
		handleSelectionChange(val) {
			this.multipleSelection = val.map((item) => {
				return item.id
			})
		},
		closeFormDiao() {
			this.showFormDia = false
			this.getDateList()
		},
	}
}
</script>

<style lang="scss" scoped>
.wrap {
	width: 100%;
}
</style>
