<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-lx-calendar"></i> Manuscript detail
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container">
			<el-row>
				<el-col :span="16">
					<div class="form-box">
						<el-form ref="articleform" :model="form" label-width="200px">
							<el-form-item label="Status">
								<span>{{articleState}}</span>
							</el-form-item>
							<el-form-item v-if="form.accept_sn != ''" label="Manuscript ID">
								<span>{{form.accept_sn}}</span>
							</el-form-item>
							<el-form-item label="Journal">
								<span>{{form.journalname}}</span>
							</el-form-item>
							<el-form-item label="Title">
								<span>{{form.title}}</span>
							</el-form-item>
							<el-form-item label="Type">
								<span>{{form.type | jtName}}</span>
							</el-form-item>
							<el-form-item label="Repetition" v-show="form.repezip!=''">
								<el-link type="primary" icon="el-icon-download" :href="this.mediaUrl + form.repezip">Download</el-link>
							</el-form-item>
							<el-form-item label="Ethical Approval" v-show="form.type=='A'">
								<span>{{form.approval?'yes':'no'}}</span>
							</el-form-item>
							<el-form-item label="Author">
								<el-collapse>
									<el-collapse-item v-for="(item, index) in form.authorList" :key="index" :name="index+1">
										<template slot="title">Author {{index+1}} :{{item.firstname}} {{item.lastname}} {{item.isSuper?'#':''}}{{item.isReport?'*':''}}</template>
										<el-form-item label="E-mail:" label-width="100px">{{item.email}}</el-form-item>
										<el-form-item label="Name:" label-width="100px">{{item.firstname}} {{item.lastname}}</el-form-item>
										<el-form-item label="ORCID iD" label-width="100px">{{item.orcid}}</el-form-item>
										<el-form-item label="First author:" label-width="100px">
											<el-switch v-model="item.isSuper" active-text="yes" inactive-text="no"></el-switch>
										</el-form-item>
										<el-form-item label="Corresponding Author:" label-width="160px">
											<el-switch v-model="item.isReport" active-text="yes" inactive-text="no"></el-switch>
										</el-form-item>
										<el-form-item label="Address" label-width="100px" v-show="item.isReport">{{item.address}}</el-form-item>
										<el-form-item label="Affiliation:" label-width="100px">{{item.company}}</el-form-item>
										<el-form-item label="Department:" label-width="100px">{{item.department}}</el-form-item>
										<el-form-item label="Title:" label-width="100px">{{item.title}}</el-form-item>
										<el-form-item label="Country:" label-width="100px">{{item.country}}</el-form-item>
									</el-collapse-item>
								</el-collapse>
							</el-form-item>
							<el-form-item label="Abstract">
								<span>{{form.abstrart}}</span>
							</el-form-item>
							<el-form-item label="KeyWords">
								<span>{{form.keyWords}}</span>
							</el-form-item>
							<el-form-item label="Fund">
								<span>{{form.fund}}</span>
							</el-form-item>
							<el-form-item label="Cover letter">
								<!-- <el-link
                                    :underline="false"
                                    :href="coverLetterUrl"
                                    type="primary"
                                >download latest version</el-link>-->
								<el-popover placement="right" width="350" trigger="click">
									<el-table :data="coverLetterFileList" empty-text="New messages (0)">
										<el-table-column width="150" :formatter="filedateformate" property="ctime" align="center" label="date"></el-table-column>
										<el-table-column width="100" property="username" align="center" label="Uploader"></el-table-column>
										<el-table-column width="100" label="download" align="center">
											<template slot-scope="scope">
												<el-link type="primary" icon="el-icon-download" :href="getlinkurl(scope.row)"></el-link>
											</template>
										</el-table-column>
									</el-table>
									<el-button class="more_btn" icon="el-icon-download" type="text" slot="reference">Download</el-button>
								</el-popover>
							</el-form-item>
							<el-form-item label="Figures">
								<!-- <el-link
                                    :underline="false"
                                    :href="picturesAndTablesUrl"
                                    type="primary"
                                >download latest version</el-link>-->

								<el-popover placement="right" width="350" trigger="click">
									<el-table :data="picturesAndTablesFileList" empty-text="New messages (0)">
										<el-table-column width="150" :formatter="filedateformate" property="ctime" align="center" label="date"></el-table-column>
										<el-table-column width="100" property="username" align="center" label="Uploader"></el-table-column>
										<el-table-column width="100" label="download" align="center">
											<template slot-scope="scope">
												<el-link type="primary" icon="el-icon-download" :href="getlinkurl(scope.row)"></el-link>
											</template>
										</el-table-column>
									</el-table>
									<el-button class="more_btn" icon="el-icon-download" type="text" slot="reference">Download</el-button>
								</el-popover>
							</el-form-item>
							<el-form-item label="Title page">
								<el-popover placement="right" width="350" trigger="click">
									<el-table :data="totalpageFileList" empty-text="New messages (0)">
										<el-table-column width="150" :formatter="filedateformate" property="ctime" align="center" label="date"></el-table-column>
										<el-table-column width="100" property="username" align="center" label="Uploader"></el-table-column>
										<el-table-column width="100" label="download" align="center">
											<template slot-scope="scope">
												<el-link type="primary" icon="el-icon-download" :href="getlinkurl(scope.row)"></el-link>
											</template>
										</el-table-column>
									</el-table>
									<el-button class="more_btn" icon="el-icon-download" type="text" slot="reference">Download</el-button>
								</el-popover>
							</el-form-item>
							<el-form-item label="Manuscirpt">
								<!-- <el-link
                                    :underline="false"
                                    :href="manuscirptUrl"
                                    type="primary"
                                >download latest version</el-link>-->
								<el-popover placement="right" width="350" trigger="click">
									<el-table :data="manuscirptFileList" empty-text="New messages (0)">
										<el-table-column width="150" :formatter="filedateformate" property="ctime" align="center" label="date"></el-table-column>
										<el-table-column width="100" property="username" align="center" label="Uploader"></el-table-column>
										<el-table-column width="100" label="download" align="center">
											<template slot-scope="scope">
												<el-link type="primary" icon="el-icon-download" :href="getlinkurl(scope.row)"></el-link>
											</template>
										</el-table-column>
									</el-table>
									<el-button class="more_btn" icon="el-icon-download" type="text" slot="reference">Download</el-button>
								</el-popover>
							</el-form-item>
							<!-- <el-form-item>
                                <el-button type="primary" @click="onsubmit">Submit</el-button>
                            </el-form-item>-->
						</el-form>
					</div>
				</el-col>
				<el-col :span="8">
					<div class="tree_box">
						<h2>State tracking</h2>
						<div class="block">
							<el-timeline>
								<el-timeline-item :timestamp="formatDate(form.ctime)" placement="top">
									<el-card>
										<h4>Manuscript submission</h4>
										<p>{{form.username}} submit manuscript</p>
									</el-card>
								</el-timeline-item>
								<el-timeline-item v-for="(activity, index) in msgs" :key="index" :timestamp="formatDate(activity.ctime)"
								 placement="top">
									<el-card v-if="activity.ftype==0">
										<p>Status change :{{statetostr(activity.state_from)}} => {{statetostr(activity.state_to)}}</p>
										<p v-if="activity.content!=''">{{activity.content}}</p>
									</el-card>
									<el-card v-else>
										<p>Author message:</p>
										<p>{{activity.content}}</p>
									</el-card>
									<!-- <el-card>
                                        <p>status change :{{statetostr(activity.state_from)}} => {{statetostr(activity.state_to)}}</p>
                                        <p>{{activity.content}}</p>
                                    </el-card> -->
								</el-timeline-item>
							</el-timeline>
						</div>
					</div>
				</el-col>
			</el-row>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.Common.baseUrl,
				mediaUrl: this.Common.mediaUrl,
				items: '',
				editVisible: false,
				coverLetterFileList: [],
				picturesAndTablesFileList: [],
				totalpageFileList: [],
				manuscirptFileList: [],
				editform: {
					editname: localStorage.getItem('U_name'),
					articleId: this.$route.query.id,
					state: '',
					editormsg: ''
				},
				items: [{
						state: 0,
						title: this.$t('artstate.state0'),
						disabled: true
					},
					{
						state: 1,
						title: this.$t('artstate.state1')
					},
					{
						state: 2,
						title: this.$t('artstate.state2'),
						disabled: true
					},
					{
						state: 3,
						title: this.$t('artstate.state3')
					},
					{
						state: 4,
						title: this.$t('artstate.state4')
					},
					{
						state: 6,
						title: this.$t('artstate.state6')
					},
					{
						state: 5,
						title: this.$t('artstate.state5')
					}
				],
				form: {
					articleId: this.$route.query.id,
					journal: '',
					journalname: '',
					username: '',
					title: '',
					accept_sn: '',
					abstrart: '',
					keyWords: '',
					fund: '',
					type: '',
					approval: false,
					repezip: '',
					coverLetter: '',
					picturesAndTables: '',
					manuscirpt: '',
					state: '',
					ctime: '',
					authorList: []
				},
				msgs: []
			};
		},
		created: function() {
			this.initarticle();
			this.initFileList();
		},
		computed: {
			
			coverLetterUrl: function() {
				return this.baseUrl + this.form.coverLetter;
			},
			picturesAndTablesUrl: function() {
				return this.baseUrl + this.form.picturesAndTables;
			},
			manuscirptUrl: function() {
				return this.baseUrl + this.form.manuscirpt;
			},
			upload_coverLetter: function() {
				return this.baseUrl + 'api/Article/up_file/type/coverLetter';
			},
			upload_picturesAndTables: function() {
				return this.baseUrl + 'api/Article/up_file/type/picturesAndTables';
			},
			upload_manuscirpt: function() {
				return this.baseUrl + 'api/Article/up_file/type/manuscirpt';
			},
			articleState: function() {
				let str = '';
				switch (this.form.state) {
					case 0:
						str = this.$t('artstate.state0');
						break;
					case 1:
						str = this.$t('artstate.state1');
						break;
					case 2:
						str = this.$t('artstate.state2');
						break;
					case 3:
						str = this.$t('artstate.state3');
						break;
					case 4:
						str = this.$t('artstate.state4');
						break;
					case 5:
						str = this.$t('artstate.state5');
						break;
				}
				return str;
			}
		},
		methods: {
			//弹出编辑框
			testvis() {
				this.editVisible = true;
			},

			statetostr(mystate) {
				let str = '';
				switch (mystate) {
					case 0:
						str = this.$t('artstate.state0');
						break;
					case 1:
						str = this.$t('artstate.state1');
						break;
					case 2:
						str = this.$t('artstate.state2');
						break;
					case 3:
						str = this.$t('artstate.state3');
						break;
					case 4:
						str = this.$t('artstate.state4');
						break;
					case 5:
						str = this.$t('artstate.state5');
						break;
					case 6:
						str = this.$t('artstate.state6');
						break;
				}
				return str;
			},
			//修改文章状态
			saveEdit() {
				this.$api
					.post('api/Article/editArticleEditor', this.editform)
					.then((res) => {
						this.$message.success('success');
						this.editVisible = false;
						this.$router.go(0);
					})
					.catch((err) => {
						console.log(err);
					});
			},
			//初始化期刊信息
			initarticle() {
				this.$api
					.post('api/Admin/getArticleDetail', {
						articleId: this.editform.articleId,
						human: 'editor'
					})
					.then((res) => {
						this.form.username = res.article.account;
						this.form.title = res.article.title;
						this.form.journal = res.article.journal_id;
						this.form.journalname = res.article.journalname;
						this.form.abstrart = res.article.abstrart;
						this.form.accept_sn = res.article.accept_sn;
						this.form.keyWords = res.article.keywords;
						this.form.fund = res.article.fund;
						this.form.repezip = res.article.repeurl;
						this.form.type = res.article.type;
						this.form.approval = res.article.approval == 1 ? true : false;
						this.editform.state = this.form.state = res.article.state;
						this.form.ctime = res.article.ctime;
						this.msgs = res.msg;
						var alist = res.authors;
						for (var i in alist) {
							this.form.authorList.push({
								art_aut_id: alist[i].art_aut_id,
								firstname: alist[i].firstname,
								lastname: alist[i].lastname,
								orcid: alist[i].orcid,
								company: alist[i].company,
								department: alist[i].department,
								title: alist[i].author_title,
								country: alist[i].country,
								email: alist[i].email,
								address: alist[i].address,
								isSuper: alist[i].is_super == 1 ? true : false,
								isReport: alist[i].is_report == 1 ? true : false
							});
						}
					})
					.catch((err) => {
						console.log(err);
					});
			},
			//初始化filelist
			initFileList() {
				this.$api
					.post('api/Article/getFilelistByArticleID', {
						articleId: this.form.articleId
					})
					.then((res) => {
						this.coverLetterFileList = res.coverLetter;
						this.picturesAndTablesFileList = res.picturesAndTables;
						this.manuscirptFileList = res.manuscirpt;
						this.totalpageFileList = res.totalpage;
					})
					.catch((err) => {
						console.log(err);
					});
			},
			uperr_coverLetter(err) {
				this.$message.error('上传失败');
			},
			beforeupload() {},
			filedateformate(row, column, cellValue, index) {
				return this.formatDate(cellValue);
			},
			upSuccess_coverLetter(res, file) {
				if (res.code == 0) {
					this.form.coverLetter = 'coverLetter/' + res.upurl;
				} else {
					this.$message.error('服务器上传错误：' + res.msg);
				}
			},
			upSuccess_picturesAndTables(res, file) {
				if (res.code == 0) {
					this.form.picturesAndTables = 'picturesAndTables/' + res.upurl;
				} else {
					this.$message.error('服务器上传错误：' + res.msg);
				}
			},
			//超出传送文件个数限制
			alertlimit() {
				this.$message.error('超过最大上传文件个数');
			},
			upSuccess_manuscirpt(res, file) {
				if (res.code == 0) {
					this.form.manuscirpt = 'manuscirpt/' + res.upurl;
				} else {
					this.$message.error('服务器上传错误：' + res.msg);
				}
			},
			getlinkurl(row) {
				return this.mediaUrl + row.file_url;
			},
			//检验上传文件的格式
			beforeupload_coverLetter(file) {
				// const isWORd =
				//     file.type === 'application/msword' ||
				//     file.type === 'application/pdf' ||
				//     file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
				// if (!isWORd) {
				//     this.$message.error('Only word and pdf files can be uploaded(.pdf,.doc,.docx)');
				// }
				// return isWORd;
			},
			beforeupload_picturesAndTables(file) {
				// const iszip =
				//     file.type === 'image/jpeg' ||
				//     file.type === 'image/png' ||
				//     file.type === 'application/x-zip-compressed' ||
				//     file.name.split(".")[1] === 'rar';
				// if (!iszip) {
				//     this.$message.error('Only image and compressed files can be uploaded(.jpg,.png,.rar,.zip)');
				// }
				// return iszip;
			},
			beforeupload_manuscirpt(file) {
				// const ismau =
				//     file.type === 'application/msword' ||
				//     file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'||
				//     file.type === 'application/x-zip-compressed' ||
				//     file.name.split(".")[1] === 'rar';
				// if (!ismau) {
				//     this.$message.error('Only word and compressed files(.doc,.docx,.rar,.zip)');
				// }
				// return ismau;
			},
			//清除文件时的事件
			removefilecoverLetter(file, fileList) {
				this.form.coverLetter = '';
			},
			removefilepicturesAndTables(file, fileList) {
				this.form.picturesAndTables = '';
			},
			removefilemanuscirpt(file, fileList) {
				this.form.manuscirpt = '';
			},
			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 + ' ' + h + ':' + m + ':' + s;
			},
			onsubmit() {
				if (this.form.coverLetter == '' || this.form.picturesAndTables == '' || this.form.manuscirpt == '') {
					this.$message.error('请确保三个文档上传成功');
					console.log('file up error');
					return false;
				}
				this.$api
					.post('api/Article/changeArticleFileEditor', this.form)
					.then((res) => {
						this.$message.success('success');
						this.$router.go(0);
					})
					.catch((err) => {
						console.log(err);
					});
			}
		}
	};
</script>


<style scoped>
	.dwnbtn {
		margin-bottom: 5px;
	}

	.container {
		min-width: 800px;
	}

	.tree_box {
		padding: 15px 10px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
	}

	.el-row {
		border-bottom: rgb(230, 211, 211) solid 1px;
		margin-bottom: 5px;
		line-height: 3.5;
	}

	.author-title {
		color: #969595;
		text-align: center;
		background-color: #eceaea;
	}

	.author-delete {
		text-align: center;
	}

	.author-delete i {
		color: red;
	}
</style>
