<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-lx-calendar"></i>
					<router-link :to="{path:'/articleList'}">
						<span class="top_dao"> Manuscript list</span>
					</router-link>
					>> Manuscript process switch
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container_state" v-loading="loading">
			<p class="art_suthor_message">
				<font style="color: #888;">ID : {{artMes.accept_sn}}</font>
				<b>{{artMes.title}}
					<i @click="man_detal()" class="det_cssep">Manuscript Detail</i>
				</b>
			</p>
			<div class="art_caozuo_">
				<p style="line-height: 22px;">
					I am writing just to follow up on the suggestion from the editor of <b>{{ artMes.journalname }}</b> that you might
					be interested in submitting your paper to <b>{{ transinfo.jourtitle }}</b> instead.
				</p>
				<div style="text-align: center;margin-top: 30px;">
					<el-button type="success" @click="saveAgr()" style="margin-right: 20px;width: 250px;">Agree</el-button>
					<el-button type="danger" @click="saveRef()" style="width: 250px;">Refuse</el-button>
				</div>
			</div>
		</div>
		<el-dialog title="Manuscript Basic Information" :visible.sync="Detailvisible" width="800px" :close-on-click-modal="false">
			<div class="art_state_message">
				<p>
					<font>Title :</font><b>{{artMes.title}}</b>
				</p>
				<p>
					<font>Type :</font><b>{{ellType(artMes.type)}}</b>
				</p>
				<p v-show="artMes.type=='A'">
					<font>Ethical Approval :</font><b>{{artMes.approval?'Yes':'No'}}</b>
				</p>
				<p>
					<font>Journal :</font><b>{{journal_me}}</b>
				</p>
				<p v-if="artMes.special_num > 0">
					<font>Special Issues :</font><b>{{ artMes.special_title }}</b>
				</p>
				<p>
					<font>Major :</font><b>{{artMes.major}}</b>
				</p>
				<el-collapse v-model="activeNames" class="auth_colla auth_colla_new">
					<el-collapse-item :title="authorList_name" name="1">
						<div v-for="(item, index) in artMes.authorList" class="auth_mess">
							<h4 style="font-weight: bolder;">
								<img src="../../assets/img/state_one.png" v-if="item.isSuper" style="width: 15px;margin: 0 2px 0 0;vertical-align: text-bottom;">
								{{item.firstname}} {{item.lastname}} {{item.isSuper?'#':''}}{{item.isReport?'*':''}}
							</h4>
							<div>
								<p v-if="item.email">
									<img src="../../assets/img/state_email.png" v-if="item.isReport" style="width: 14px;margin: 0 8px 0 0;vertical-align: text-bottom;">
									<font>Email : </font>{{item.email}}
								</p>
								<p v-if="item.orcid">
									<font>ORCID iD : </font>{{item.orcid}}
								</p>
								<p>
									<font>First Author : </font>
									<b v-if="item.isSuper">Yes</b>
									<b v-if="!item.isSuper">No</b>
								</p>
								<p>
									<font>Corresponding Author :</font>
									<b v-if="item.isReport">Yes</b>
									<b v-if="!item.isReport">No</b>
								</p>
								<p v-if="item.address">
									<font>Address : </font>{{item.address}}
								</p>
								<p v-if="item.company">
									<font>Affiliation : </font>{{item.company}}
								</p>
								<p v-if="item.department">
									<font>Department : </font>{{item.department}}
								</p>
								<p v-if="item.title">
									<font>Title : </font>{{item.title}}
								</p>
								<p v-if="item.country">
									<font>Country : </font>{{item.country}}
								</p>
							</div>
						</div>
					</el-collapse-item>
				</el-collapse>
				<el-collapse class="auth_colla auth_colla_new" style="margin-top: -15px;border-top: 0;">
					<el-collapse-item>
						<template slot="title">
							Abstract
							<font v-if="artMes.keywords" style="margin-left: 3px;">, Keywords</font>
							<font v-if="artMes.fund" style="margin-left: 3px;">, Fund</font>
						</template>
						<p>
							<font>Abstract :</font><b>{{artMes.abstrart}}</b>
						</p>
						<p v-if="artMes.keywords">
							<font>Keywords :</font><b>{{artMes.keywords}}</b>
						</p>
						<p v-if="artMes.fund">
							<font>Fund :</font><b>{{artMes.fund}}</b>
						</p>
					</el-collapse-item>
				</el-collapse>
			</div>

			<div class="art_file">
				<h4 v-if="coverLetterFileList">Cover letter : </h4>
				<p v-if="coverLetterFileList">
					<a v-for="item in coverLetterFileList" :href="mediaUrl + item.file_url">
						<img src="../../assets/img/icon_0.png">
						<span>
							<font>Uploader : </font>{{item.username}}
							<i><i class="el-icon-time"></i>{{formatDate(item.ctime)}}</i>
						</span>
						<i class="el-icon-download download"></i>
					</a>
				</p>
				<br clear="both" v-if="coverLetterFileList">
				<h4 v-if="picturesAndTablesFileList">Figures : </h4>
				<p v-if="picturesAndTablesFileList">
					<a v-for="item in picturesAndTablesFileList" :href="mediaUrl + item.file_url">
						<img src="../../assets/img/icon_0.png">
						<span>
							<font>Uploader : </font>{{item.username}}
							<i><i class="el-icon-time"></i>{{formatDate(item.ctime)}}</i>
						</span>
						<i class="el-icon-download download"></i>
					</a>
				</p>
				<br clear="both" v-if="picturesAndTablesFileList">
				<h4 v-if="totalpageFileList">Title page : </h4>
				<p v-if="totalpageFileList">
					<a v-for="item in totalpageFileList" :href="mediaUrl + item.file_url">
						<img src="../../assets/img/icon_0.png">
						<span>
							<font>Uploader : </font>{{item.username}}
							<i><i class="el-icon-time"></i>{{formatDate(item.ctime)}}</i>
						</span>
						<i class="el-icon-download download"></i>
					</a>
				</p>
				<br clear="both" v-if="totalpageFileList">
				<h4 v-if="supplementaryFileList">Supplementary Material : </h4>
				<p v-if="supplementaryFileList">
					<a v-for="item in supplementaryFileList" :href="mediaUrl + item.file_url">
						<img src="../../assets/img/icon_0.png">
						<span>
							<font>Uploader : </font>{{item.username}}
							<i><i class="el-icon-time"></i>{{formatDate(item.ctime)}}</i>
						</span>
						<i class="el-icon-download download"></i>
					</a>
				</p>
				<br clear="both" v-if="supplementaryFileList">
				<h4>Manuscript : </h4>
				<p>
					<a v-for="item in manuscirptFileList" :href="mediaUrl + item.file_url">
						<img src="../../assets/img/icon_0.png">
						<span>
							<font>Uploader : </font>{{item.username}}
							<i><i class="el-icon-time"></i>{{formatDate(item.ctime)}}</i>
						</span>
						<i class="el-icon-download download"></i>
					</a>
				</p>
				<br clear="both">
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="Detailvisible=false">OK</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.Common.baseUrl,
				mediaUrl: this.Common.mediaUrl,
				articleId: this.$route.query.id,
				userName: localStorage.getItem('U_name'),
				loading: false,
				Detailvisible: false,
				activeNames: ['2'],
				authorList_name: '',
				artMes: {
					articleId: this.$route.query.id,
				},
				transinfo: {},
				coverLetterFileList: [],
				picturesAndTablesFileList: [],
				totalpageFileList: [],
				manuscirptFileList: [],
				supplementaryFileList: [],
			};
		},
		created: function() {
			this.initarticle();
		},
		computed: {
			journal_me: function() {
				var frag = this.artMes.journalname;
				if (this.artMes.special_num > 0) {
					frag += "(Special Issues)";
				}
				return frag;
			},

		},
		methods: {
			//初始化文章信息
			initarticle() {
				this.$api
					.post('api/Article/getArticleDetail', {
						articleId: this.articleId,
						human: 'author'
					})
					.then((res) => {
						this.artMes = res.article;
						this.artMes.major = res.major;
						this.artMes.authorList = []
						this.transinfo = res.transinfo
						let alist = res.authors;
						let alist_name = [];
						for (let i in alist) {
							this.artMes.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
							});
							if (i == alist.length - 1) {
								alist_name.push(alist[i].firstname + ' ' + alist[i].lastname)
							} else {
								alist_name.push(alist[i].firstname + ' ' + alist[i].lastname + ' , ')
							}
						}
						this.authorList_name = "Author : " + alist_name.join("");

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

				//初始化filelist
				this.$api
					.post('api/Article/getFilelistByArticleID', {
						articleId: this.articleId
					})
					.then(res => {
						this.coverLetterFileList = res.coverLetter;
						this.picturesAndTablesFileList = res.picturesAndTables;
						this.manuscirptFileList = res.manuscirpt;
						this.totalpageFileList = res.totalpage;
						this.supplementaryFileList = res.supplementary;
					})
					.catch(err => {
						console.log(err);
					});

			},

			// 同意转投
			saveAgr() {
				// 二次确认更改状态
				this.$confirm('Your sure transfer your manuscript?', 'Tip', {
						type: 'warning'
					})
					.then(() => {
						this.$api
							.post('api/article/trans_manu', this.transinfo)
							.then((res) => {
								this.$message.success('Successful switching!');
								this.$router.push({
									path: '/articleProcess',
									query: {
										id: this.articleId
									}
								});
							});
					})
					.catch(() => {});
			},
			// 拒绝转投
			saveRef() {
				// 二次确认更改状态
				this.$confirm('Your sure refuse transfer your manuscript?', 'Tip', {
						type: 'warning'
					})
					.then(() => {
						this.$api
							.post('api/Article/trans_manu_no', this.transinfo)
							.then((res) => {
								this.$message.success('Successful refuse switching!');
								this.$router.push({
									path: '/articleProcess',
									query: {
										id: this.articleId
									}
								});
							});
					})
					.catch(() => {});
			},

			// 查看详情
			man_detal() {
				this.Detailvisible = true
			},

			// 时间
			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;
			},


			ellType(e) {
				let frag = '';
				switch (e) {
					case "A":
						frag = 'Article';
						break;
					case 'B':
						frag = 'Review';
						break;
					case 'C':
						frag = 'Case report';
						break;
					case 'P':
						frag = 'Research proposal';
						break;
					case 'N':
						frag = 'News';
						break;
					case 'T':
						frag = 'Comment';
						break;
					case 'CT':
						frag = 'Correction';
						break;
					case 'HT':
						frag = 'Hypothesis';
						break;
					case 'PF':
						frag = 'Preface';
						break;
					case 'ET':
						frag = 'Editorial';
						break;
					case 'RP':
						frag = 'Report';
						break;
					case 'LR':
						frag = 'Letter';
						break;
					case 'EF':
						frag = 'Empirical formula';
						break;
					case 'EM':
						frag = 'Evidence-based medicine';
						break;
					case 'EC':
						frag = 'Expert consensus';
						break;
					case 'LTE':
						frag = 'Letter to editor';
						break;
					case 'QI':
						frag = 'Questionnaire investigation';
						break;
					case 'PT':
						frag = 'Protocol';
						break;
					case 'CS':
						frag = 'Case Series';
						break;
					case 'RT':
						frag = 'Retraction';
						break;
					case 'MR':
						frag = 'Mini Review';
						break;
					default:
						frag = 'Others';
				}
				return frag;
			},

		},
		filters: {

		}
	};
</script>


<style scoped>
	.top_dao:hover {
		text-decoration: underline;
		cursor: pointer;
	}

	.art_suthor_message {
		margin: 0 0 30px 0;
	}

	.art_suthor_message>b {
		font-size: 16px;
		display: block;
		margin: 5px 0 0 0;
		letter-spacing: -0.5px;
	}

	.art_suthor_message .det_cssep {
		background-color: #006699;
		color: #fff;
		font-size: 12px;
		margin: 0 0 0 15px;
		padding: 2px 5px;
		border-radius: 5px;
		cursor: pointer;
		font-style: normal;
		letter-spacing: 0;
	}

	.art_suthor_message .det_cssep:hover {
		text-decoration: underline;
	}
</style>
