<template>
	<div class="common-page">
		<div class="option page-row">
			<!--工具栏-->
			<div class="head-container">
				<!-- 搜索 -->
				<!--<label class="el-form-item-label" style="font-weight: 500;">设备编号</label>-->
				<el-input v-model="query.username" clearable placeholder="请输入用户名" style="width:200px;" @clear="clearLimit"/>

				<el-date-picker
				  v-model="query.createTime"
          type="daterange"
          value-format="yyyy-MM-dd"
				  range-separator="至"
				  start-placeholder="开始日期"
				  end-placeholder="结束日期">
				</el-date-picker>

				<el-button size="mini" type="success" icon="el-icon-search" @click="toSearch">搜索</el-button>

				<!--<el-button
					:loading="download.loading"
					:disabled="!tableData.length"
					size="mini"
					type="warning"
					icon="el-icon-download"
					@click="doExport"
					style="margin-left:10px;"
				  >导出</el-button>-->
			</div>
		</div>
		<div class="panel-bottom page-row">
			<h3>日志管理列表</h3>
			<div class="ctin-box">
				<div class="content-within">
					<div class="content-fix">
						<div class="content">
							<el-table :data="tableData" v-loading="loading" border style="width:auto" :row-class-name="tableRowClassName">
								<el-table-column prop="username" label="用户姓名" width="135px"></el-table-column>
								<el-table-column prop="name" label="日志详情"></el-table-column>
								<el-table-column prop="remark" label="备注"></el-table-column>
								<el-table-column prop="createTime" label="操作时间" ></el-table-column>
							</el-table>
							<!--分页组件-->
							<el-pagination :total="total" :current-page="page" style="margin-top: 8px;" layout="total, prev, pager, next, sizes" @size-change="sizeChange" @current-change="pageChange" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import { Tools, HttpReq, FileStream, Dates} from '@/assets/js/common.js';
import DateRangePicker from '@/components/DateRangePicker';
import cuAmap from '@/components/AMap';
// style
import '@/assets/styles/common.css';

export default {
	name: 'Dashboard',
	components: {
		DateRangePicker, cuAmap
	},
	data() {
		return {
			loading: false,
			page: 1,
			size: 10,
			total: 0,
			query:{},
			tableData: [],
			download:{
				loading:false,
			}
		}
	},
	mounted() {
		var that = this;

		this.$nextTick(() => {
			this.loadData();
		})
	},
	methods: {
		tableRowClassName({row, rowIndex}) {
			if (rowIndex === 1) {
				return 'warning-row';
			} else if (rowIndex === 3) {
				return 'success-row';
			}
			return '';
		},
		// 点击搜索
		toSearch() {
			this.page = 1
			this.loadData()
		},
		clearLimit(){		// 清除限制
			this.loadData()
		},
		loadData() {
			var that = this, sort = 'createTime,desc';
			var param = this.query;
			param.page = this.page - 1;
			param.size = this.size;
			param.sort = sort;


			this.loading = true;
			HttpReq.reoperationlog.getLog(param).then((res) => {
				this.loading = false;
				if(res.code === 200){
					var body = res.data || {};
					var list = body.content || [];
					this.tableData = list;
					this.total = body.totalElements
				};
			}).catch(function(error) {
				this.loading = false;
			})
		},
		pageChange(e) {
			this.page = e
			this.loadData()
		},
		sizeChange(e) {
			this.page = 1
			this.size = e
			this.loadData()
		},

		/**
		* 导出
		*/
		doExport() {
			this.download.loading = true;

			var that = this, sort = 'date,desc';
			var param = this.query;
			param.page = this.page - 1;
			param.size = this.size;
			param.sort = sort;
			param.table = {
				title:'华菱光电－历史监控记录表',
				header:{
					"subcode":"设备识别码",
					"ename":"设备名称",
					"helement":"电量",
					"htemperature":"温度值",
					"hhumidity":"湿度值",
					"hlenght1":"宽度一",
					"hlenght2":"宽度二",
					"hlenght3":"宽度三",
					"hsignal":"信号强度",
					"createTime":"记录时间",
				}
			};
			HttpReq.export.historyRecord(param).then((res) => {
				if(res.head.code === '0000'){
					this.download.loading = false;
					var blob = FileStream.toBlob(res.body);
					FileStream.download(blob, '华菱光电-历史数据' + Dates.format('yyyy-MM-dd HH-mm-ss')+'.xlsx')
				};
			}).catch(function(error) {
				this.download.loading = false
			})
		},
	}
}
</script>

<style rel="stylesheet/scss" lang="scss">
	.el-table .warning-row {
		background: oldlace;
	}

	.el-table .success-row {
		background: #f0f9eb;
	}

	.dialog-map{border:1px solid green;height:300px;width:480px;}

</style>
