<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="yhName" label="养护名称" show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" prop="yhType" label="养护类型" :formatter="forYhType" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="yhUser" label="养护人员" show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" prop="yhLevel" label="优先级别" :formatter="forYhLevel" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="yhSDate" label="养护开始时间" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="yhEDate" label="养护结束时间" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="yhContent" label="养护内容" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="yhMoney" label="经费" show-overflow-tooltip></el-table-column>
				<el-table-column min-width="120" prop="yhDuty" 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 './mainForm-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,
				yhLevels: [{ name: '高',value: '1'},
							{ name: '中',value: '2'},
							{ name: '低',value: '3'}
				],
				yhTypes:[
					{ name: '日常养护',value: '1'},{ name: '专项养护',value: '2'},
				],
			}
		},
		created() {
			this.getDateList()
		},
		methods: {
			forYhType(row, column, cellValue){
				return  this.yhTypes.map((ee)=>{
					if(cellValue==ee.value){
						return ee.name
					}
				})
			},
			forYhLevel(row, column, cellValue){
				return  this.yhLevels.map((ee)=>{
					if(cellValue==ee.value){
						return ee.name
					}
				})
			},
			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.ListGetMain(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;
			},
			//修改
			handleUpdate(row) {
				this.title = '修改';
				this.plId = row.id;
				this.showFormDia = true;
			},
			// // 批量删除
			deleteSelect() {
				this.$confirm('确定删除选中数据？', '提示', {
						confirmButtonText: '确 定',
						cancelButtonText: '取 消',
						type: 'warning',
					})
					.then(() => {
						reinforcement
							.removeMain(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>
