<template>
	<div style="text-align: center;">
		<div style="width:600px;float: left; margin: 10px;">
			<el-input v-model="queryTableName" placeholder="请输入查询条件" style="width :300px;float: left;"></el-input>
			<el-button type="primary" @click="search">查询</el-button>
			<el-button type="primary" @click="handleAdd">新增</el-button>
		</div>




		<el-table v-loading="loading" :data="tableData" stripe border class="el-table-user" row-style="height:0" cell-style="padding:0"
		 style="width: 99%;">
			<el-table-column prop="id" label="编号" width="60" v-if="isShow">
			</el-table-column>
			<el-table-column prop="tableName" label="表名" width="100">
			</el-table-column>
			<el-table-column prop="tableDesc" label="表描述" width="100">
			</el-table-column>
			<el-table-column prop="tableModel" label="实体类" width="100">
			</el-table-column>
			<el-table-column prop="tablePath" label="所属模块" width="100">
			</el-table-column>
			<el-table-column prop="tableSpase" label="表空间" width="100">
			</el-table-column>



			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
		 :page-sizes="pageSizes" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalRows">
		</el-pagination>


		<el-dialog title="表" :visible.sync="dialogVisible" width="800px">
			<el-form :model="form" label-width="80px">
				<el-row :gutter="20">
					<el-col :span="8">
						<el-form-item label="用户编码" v-if="isShow">
							<el-input v-model="form.id"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="表名">
							<el-input v-model="form.tableName"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="表描述">
							<el-input v-model="form.tableDesc"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="20">
					<el-col :span="8">
						<el-form-item label="实体类">
							<el-input v-model="form.tableModel"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="所属模块">
							<el-input v-model="form.tablePath"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="表空间">
							<el-input v-model="form.tableSpase"></el-input>
						</el-form-item>
					</el-col>
				</el-row>

				<table-col></table-col>




			</el-form>
		</el-dialog>
	</div>
</template>

<script>
	import axios from '@/axios';
	import TableCol from "@/components/TableCol.vue"
	export default {
		components: {
			TableCol 
		},
		
		data() {
			return {
				//表格初始化参数
				tableData: [],
				currentPage: 1,
				totalRows: 0,
				pageSizes: [10, 50, 100, 200],
				pageSize: 10,
				//查询条件
				queryTableName: '',
				//录入框
				dialogVisible: false,
				form: {
					id: '',
					userName: '',
					password: '',
					userDesc: ''
				},
				isShow: false,
				loading: true,
				// fullscreenLoading: false
			}
		},
		//界面渲染完毕调用   初始化表格参数
		mounted() {
			this.getTableData()
		},
		methods: {
			// 获取table数据
			getTableData() {
				//console.log("获取table数据getTableData")
				var url = 'SysUser/queryPage.do'
				var param = {
					page: this.currentPage,
					rows: this.pageSize,
					userDesc: this.queryUserDesc
				}
				axios.get(url, param).then(response => {
					this.tableData = response.data.list
					this.totalRows = response.data.total
					if (response) {
						this.loading = false
					} else {
						this.loading = true
					}
				});
			},
			// 修改每页条数事件
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.pageSize = val
				this.getTableData()
			},
			// 修改当前页事件
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.currentPage = val
				this.getTableData()
			},
			//保存按钮事件
			handleSave(row) {
				// 				const loading = this.$loading({
				//           lock: true,
				//           text: 'Loading',
				//           spinner: 'el-icon-loading'
				//         });

				var url = 'SysUser/saveVue.do'
				var param = {
					id: this.form.id,
					userName: this.form.userName,
					password: this.form.password,
					userDesc: this.form.userDesc,
					isUsed: 1,
					remark: 'Vue测试用',
				}
				axios.post(url, param).then(response => {
					if (response.data === 'success') {
						this.$message({
							type: 'success',
							message: '保存成功!',
						});
						this.getTableData()
						this.dialogVisible = false
					} else {
						this.$message({
							type: 'error',
							message: '保存失败' + response.data,
						});
					}
					// loading.close();
				});



			},
			//保存取消按钮事件   关闭编辑对话框
			handleCancelSave(row) {
				this.dialogVisible = false
			},

			// 新增按钮事件
			handleAdd() {
				this.dialogVisible = true
				this.form = {
					id: '',
					userName: '',
					password: '',
					userDesc: ''
				}
			},
			// 编辑按钮事件
			handleEdit(row) {
				this.dialogVisible = true
				this.form = {
					id: row.id,
					userName: row.userName,
					password: row.password,
					userDesc: row.userDesc
				}
			},
			// 删除按钮事件
			handleDelete(id) {
				this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					var url = 'SysUser/remove.do'
					var param = {
						id: id
					}
					axios.post(url, param).then(response => {
						if (response.data === 'success') {
							this.$message({
								type: 'success',
								message: '删除成功!',
							});
							this.getTableData()
						} else {
							this.$message({
								type: 'error',
								message: '删除失败' + response.data
							});
						}
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			// 查询按钮事件
			search() {
				this.getTableData()
			}
		}
	}
</script>
<style>
	.el-table-user th {
		background-color: #DCDFE6;
		color: black;
		font-size: 16px Medium;
	}

	.el-table-user tr {
		font-size: 15px;
	}
</style>
