<template>
	<div class="app-container">
		<div class="box-newcard">
			<div class="top-title">
				<span class="line"></span >
				<span class="title-text">报警设备管理</span>
			</div>
			<el-form
				:model="queryParams"
				ref="queryForm"
				size="small"
				:inline="true"
				label-width="80px"
				class="searchform"
			>
				<el-form-item label="设备名称:" prop="equipmentName">
					<el-select
					  v-model="queryParams.equipmentName"
					  clearable
					  placeholder="请选择设备"
					>
					  <el-option
					    v-for="item in selectList"
					    :key="item.value"
					    :label="item.name"
					    :value="item.value"
					  >
					  </el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="时间:" prop="time">
					<el-date-picker
						:default-time="['00:00:00', '23:59:59']"
						style="width: 350px !important;"
						v-model="queryParams.time"
						type="datetimerange"
						range-separator="至"
						start-placeholder="开始日期"
						end-placeholder="结束日期"
						clearable
						value-format="yyyy-MM-dd HH:mm:ss"
					/>
				</el-form-item>
				<el-form-item>
					<el-button
						type="primary"
						icon="el-icon-search"
						@click="toSearch"
					>搜索</el-button>
					<el-button
						type="info"
						icon="el-icon-setting"
						@click="resetTable"
						style="margin-left: 20px;"
					>重置</el-button>
				</el-form-item>
			</el-form>

			<el-table :data="dmList"  height="535">
				<el-table-column label="序号" align="center"  width="60" type="index"/>
				<el-table-column label="设备名称" align="center" prop="equipmentName" />
				<el-table-column label="监测项目" align="center" prop="equipmentType" />
				<el-table-column label="监测点位" align="center" prop="monitoringPoint" />
				<el-table-column label="监测值(mm)" align="center" prop="value" />
				<el-table-column label="报警时间" align="center" prop="alarmTime" />
				<el-table-column label="操作" align="center" width="180">
					<template slot-scope="scope">
						<el-button
							size="mini"
							type="primary"
							icon="el-icon-edit"
							@click.native.prevent="addEqupment(scope.row)"
							>解除报警</el-button
						>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				style="padding:10px 1px 10px 0px;margin-left:20px;"
				:page-sizes="[10, 20, 30, 40]"
				layout="total, sizes, prev, pager, next, jumper"
				:total="total"
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				@pagination="allData"
			/>

		</div>

	</div>
</template>

<script>
import { tableList,Equselect,jcalarm} from "@/api/monitor/logininfor";
import { parseTime } from "../../utils/index.js";
export default {
  data() {
    return {
      // 总条数
      total: 0,
      dmList: [],
	  selectList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipmentName: null,
        time:null
      },

    };
  },
  mounted(){
		this.allData();
		this.select();
  this.$watermark.set(" ",this.$refs.content)
  },
  beforeDestroy() {
    this.$watermark.set("",this.$refs.content);
  },
  methods: {
	  //设备下拉
		select(){
			Equselect().then((res) => {
				var body = res.data||[];
				this.selectList = body;
			});
		},
		allData() {
			var param ={
				pageNum:this.queryParams.pageNum,
				pageSize: this.queryParams.pageSize
			}
	  	tableList(param).then((res) => {
			var body = res.rows || [];
			this.dmList = body;
			this.total = res.total;
	  	});
	  },
	  handleSizeChange(val) {
		this.queryParams.pageSize =val;
		this.toSearch()
	  },
	  handleCurrentChange(val) {
		this.queryParams.pageNum = val;
		this.toSearch()
	  },
	toSearch() {
	var param = this.queryParams;
	if (this.queryParams.time instanceof Array) {
		param.startTime = parseTime(new Date(this.queryParams.time[0]));
		param.endTime = parseTime(new Date(this.queryParams.time[1]));
	}
		tableList(param).then((res) => {
			var body = res.rows || [];
			this.dmList = body;
			this.total = res.total;
		});
	},
	resetTable(){
			this.queryParams={};
			this.allData()
	},
	//解除报警
	addEqupment(e){
		 var param={
			 equipmentName:e.equipmentName
		 };
		this.$confirm('确定解除报警吗?, 是否继续?', '提示', {
			  confirmButtonText: '确定',
			  cancelButtonText: '取消',
			  type: 'warning'
		}).then(() => {
			jcalarm(param).then((res) => {
				this.allData()
				this.$message({
					type: 'success',
					message: '解除成功!'
				});
			});

		}).catch(() => {
		  this.$message({
			type: 'info',
			message: '解除失败'
		  });
		});

	}

  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scope>
	.box-newcard {
	  width: 100%;
	  background-color: #fff;
	  .top-title {
		width: 100%;
		height: 50px;
		display: flex;
		justify-content: flex-start;
		align-items:center;
		padding-left: 20px;
	    .line {
	      width: 6px;
	      height: 22px;
	      background: #0d85f4;
	    }
		.title-text{
			font-size: 18px;
			font-weight:bold;
			color: #333333;
			line-height: 30px;
			padding-left: 10px;
		}
	  }
	}
	.searchform{
		width: 100%;
		height: 75px;
		background-color: #fff;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding-left: 30px;
		.el-form-item{
			margin-bottom: 0px!important;
		}
	}
	.resetting{
		margin:20px 20px 20px 0px;
	}
	.el-table--scrollable-y .el-table__body-wrappe{
		overflow-y: scroll!important;
	}
	.tableline{
		width:50%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>
