<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-user"></i> Editorial board Apply list
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container">
			<el-table :data="tableData" border stripe class="table" ref="multipleTable"
				header-cell-class-name="table-header">
				<el-table-column label="No." align="center" width="50">
					<template slot-scope="scope">
						{{scope.$index+1}}
					</template>
				</el-table-column>
				<el-table-column prop="title" label="Targeted Journal" width="300"></el-table-column>
				<el-table-column prop="account" label="Name"></el-table-column>
				<el-table-column prop="technical" label="Title"></el-table-column>
				<el-table-column prop="realname" label="Realname"></el-table-column>
				<el-table-column prop="email" label="Email"></el-table-column>
				<el-table-column label="Application Date" align="center" width="110">
					<template slot-scope="scope">
						 {{formatDate(scope.row.ctime)}}
					</template>
				</el-table-column>
				<el-table-column align="center" width="120">
					<template slot-scope="scope">
						<p style="margin-bottom: 10px;">
							<el-button type="primary" plain icon="el-icon-user" @click="handleDtail(scope.row)">
							Detail
						</el-button>
						</p>
						<el-button type="danger" plain icon="el-icon-delete" @click="deleteApply(scope.row)">
							Delete
						</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				tableData: [],
			};
		},
		created() {
			this.getDate();
		},
		methods: {
			// 获取编委申请列表数据
			getDate() {
				this.$api
					.post('api/User/getBoardApplys', {
						editor_id: localStorage.getItem('U_id')
					})
					.then(res => {
						if (res.code == 0) {
							this.tableData = res.data.applys;
						} else {
							this.$message.error(res.msg);
						}

					})
					.catch(err => {
						console.log(err);
					});
			},

			// 删除
			deleteApply(e) {
				// 二次确认删除
				this.$confirm('Are you sure you want to delete the apply?', 'Tip', {
						type: 'warning'
					})
					.then(() => {
						this.$api
							.post('api/User/delBoardApply', e)
							.then(res => {
								if (res.code == 0) {
									this.$message.success('Delete succeeded!');
									this.getDate();
								} else {
									this.$message.error(res.msg);
								}
							})
							.catch(err => {
								console.log(err);
							});
					})
					.catch(() => {});
			},
			
			
			// 详情
			handleDtail(e) {
				let routerJump = this.$router.resolve({
					path: '/partyRole',
					query: {
						id: e.user_id
					}
				});
				window.open(routerJump.href, '_blank');
			
			},
			
			// 时间格式
			formatDate(timestamp) {
				var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var Y = date.getFullYear() + '-';
				var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
				var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
				var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
				var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
				return Y + M + D;
			},
		}
	};
</script>

<style scoped>
	.table {
		width: 100%;
		font-size: 14px;
	}

	.red {
		color: #ff0000;
	}
</style>
