<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 revision
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="art_state_text">
			Dear author
		</div>
		<div class="container_state" v-loading="loading">
			<p class="art_suthor_message">
				ID : {{artMes.accept_sn}}
				<b>{{artMes.title}}
					<i @click="man_detal()" class="det_cssep">Manuscript Detail</i>
				</b>
			</p>

			<el-row :gutter="30">
				<el-col :span="15">
					<div class="art_author_">
						<h2>
							Coment from reviewers
						</h2>
						<div class="art_author_list">
							<b>1</b>reviewers <span>202-50-60</span>
							<p>reviewersreviewersreviewersreviewersreviewers</p>
						</div>
						<div class="art_author_list">
							<b>1</b>reviewers <span>202-50-60</span>
							<p>reviewersreviewersreviewersreviewersreviewers</p>
						</div>
					</div>
					<div class="art_author_">
						<h2>
							Coment from editor
						</h2>
						<div class="art_author_peng">
							files <span>202-50-60</span>
						</div>
						<div class="art_author_peng">
							files <span>202-50-60</span>
						</div>
					</div>

					<div class="art_caozuo_">
						<div class="art_author_btn">
							<div class="art_file_btn_text">
								author
							</div>
							<h4>Manuscirpt :</h4>
							<p>
								<el-upload class="upload-demo" :action="upload_coverLetter" accept=".pdf, .doc, .docx"
								 name="coverLetter" :before-upload="beforeupload_coverLetter" :on-error="uperr_coverLetter" :on-success="upSuccess_coverLetter"
								 :limit="1" :on-exceed="alertlimit" :on-remove="removefilecoverLetter">
									<div class="el-upload__text" style="padding:8px 5px;">
										<em>Click Upload</em>
									</div>
									<div class="el-upload__tip" slot="tip">Only pdf and word files can be uploaded(.pdf,.doc,.docx)</div>
								</el-upload>
							</p>
							<br clear="both">
							<h4>manuscirptFileList :</h4>
							<p>
								<el-upload class="upload-demo" :action="upload_manuscirpt" accept=".doc, .docx, .rar, .zip"
								 name="manuscirpt" :before-upload="beforeupload_manuscirpt" :on-error="uperr_coverLetter" :on-success="upSuccess_manuscirpt"
								 :limit="1" :on-exceed="alertlimit" :on-remove="removefilemanuscirpt">
									<div class="el-upload__text" style="padding:8px 5px;">
										<em>Click Upload</em>
									</div>
									<div class="el-upload__tip" slot="tip">Only word and compressed files(.doc,.docx,.rar,.zip)</div>
								</el-upload>
							</p>
							<br clear="both">
							<h4>Figures :</h4>
							<p>
								<el-upload class="upload-demo" :action="upload_picturesAndTables"
								 accept=".jpg, .png, .rar, .zip" name="picturesAndTables" :before-upload="beforeupload_picturesAndTables"
								 :on-error="uperr_coverLetter" :on-success="upSuccess_picturesAndTables" :limit="30" :on-exceed="alertlimit"
								 :on-remove="removefilepicturesAndTables">
									<div class="el-upload__text" style="padding:8px 5px;">
										<em>Click Upload</em>
									</div>
									<div class="el-upload__tip" slot="tip">Only compressed files can be uploaded(.rar,.zip)</div>
								</el-upload>
							</p>
							<br clear="both">
							<h4>Title page :</h4>
							<p>
								<el-upload class="upload-demo" :action="upload_totalpage" accept=".doc, .docx, .rar, .zip"
								 name="totalpage" :before-upload="beforeupload_totalpage" :on-error="uperr_coverLetter" :on-success="upSuccess_totalpage"
								 :limit="1" :on-exceed="alertlimit" :on-remove="removefiletotalpage">
									<div class="el-upload__text" style="padding:8px 5px;">
										<em>Click Upload</em>
									</div>
									<div class="el-upload__tip" slot="tip">Only word and compressed files(.doc,.docx,.rar,.zip)</div>
								</el-upload>
							</p>
							<br clear="both">
							<el-button type="primary" @click="onSubmit" style="margin: 0 0 0 170px;">Submit</el-button>
						</div>
					</div>
				</el-col>
				<el-col :span="9">
					<div class="kuang_communtion">
						<h2>
							Communication
						</h2>
						<div v-for="(item, index) in talkMsgs" class="kuang_communtion_conmt">
							<div v-if="item.username != username" class="talk_aued">
								<p>
									Author :
								</p>
								<el-card>
									<p>{{ item.ad_content }}</p>
								</el-card>
								<b>{{formatDate(item.ad_ctime)}}</b>
							</div>
							<div v-if="item.username == username" class="talk_aued talk_edit">
								<p>
									Editor :
								</p>
								<el-card>
									<p>{{ item.ad_content }}</p>
								</el-card>
								<b>{{formatDate(item.ad_ctime)}}</b>
							</div>
						</div>

						<div class="kuang_communtion_input">
							<p v-if="talkMsgs"></p>
							<el-input type="textarea" rows="3" v-model="msgform.ad_content" placeholder="Editor messages" resize="none"></el-input>
							<div class="kuang_communtion_input_text">
								Dear Author, through this window, you can have informal
								<el-button type="primary" @click="saveMsg">Send</el-button>
							</div>
						</div>
					</div>
				</el-col>
			</el-row>

		</div>
		<el-dialog title="Manuscript Detail" :visible.sync="Detailvisible" width="800px">
			<div class="art_state_message">
				<h3>Basic information</h3>
				<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>Institution : </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>
				<p>
					<font>Abstrart :</font><b>{{artMes.abstrart}}</b>
				</p>
				<p>
					<font>KeyWords :</font><b>{{artMes.keyWords}}</b>
				</p>
				<p v-if="artMes.fund">
					<font>Fund :</font><b>{{artMes.fund}}</b>
				</p>
			</div>

		</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
				},
				msgform: {
					username: localStorage.getItem('U_name'),
					article_id: this.$route.query.id,
					ad_content: ''
				},
				talkMsgs: []
			};
		},
		created: function() {
			this.initarticle();
		},
		computed: {
			journal_me: function() {
				var frag = this.artMes.journalname;
				if (this.artMes.special_num > 0) {
					frag += "(Special Issues)";
				}
				return frag;
			},
			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_totalpage: function() {
				return this.baseUrl + 'api/Article/up_file/type/totalpage';
			},
			upload_manuscirpt: function() {
				return this.baseUrl + 'api/Article/up_file/type/manuscirpt';
			},
		},
		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 = []
						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);
					});

				// 留言板列表
				this.$api
					.post('api/Article/getArticleDialogs', {
						article_id: this.$route.query.id
					})
					.then((res) => {
						this.talkMsgs = res.data.dialogs;
					})
					.catch((err) => {
						console.log(err);
					});
			},

			// 查看详情
			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;
			},


			// 保存留言
			saveMsg() {
				if (this.msgform.ad_content == '') {
					this.$message.error('Please input messages');
					return false;
				}
				this.loading = true;
				this.$api.post('api/Article/pushArticleDialog', this.msgform)
					.then((res) => {
						this.loading = false;
						this.$message.success('Sent successfully');
						this.initarticle()
					});
			},
			
			// 上传文件
			onSubmit() {
				this.$refs.articleform.validate((valid) => {
					//验证文件
					// if (this.form.manuscirpt == '') {
					//     this.$message.error('Manuscirpt is required');
					//     console.log('file up error');
					//     return false;
					// }
					// //验证文章作者
					// var alist = this.form.authorList;
					// for (var i in alist) {
					//     if (alist[i].author != '' && alist[i].isReport && alist[i].email == '') {
					//         this.$message.error("The corresponding author's email is required");
					//         return false;
					//     }
					// }
					if (valid) {
						this.loading = true;
						this.$api
							.post('api/Article/editArticle', this.form)
							.then((res) => {
								this.loading = false;
								if (res.code == 0) {
									this.$message.success('success');
									this.initarticle();
								} else {
									this.$message.error('Failed to submit, please contact administrator!');
									console.log(res.msg);
								}
							})
							.catch((err) => {
								console.log(err);
							});
					} else {
						this.$message.error('Failed to submit. Please ensure the integrity of the information');
						console.log('error submit!!');
						return false;
					}
				});
			},
			
			
			//检验上传文件的格式
			beforeupload_coverLetter(file) {},
			beforeupload_picturesAndTables(file) {},
			beforeupload_totalpage(file) {},
			beforeupload_manuscirpt(file) {},
			uperr_coverLetter(err) {
				this.$message.error('upload error!');
			},
			//超出传送文件个数限制
			alertlimit() {
				this.$message.error('The maximum number of uploaded files has been exceeded');
			},
			// 成功上传文件
			upSuccess_coverLetter(res, file) {
				if (res.code == 0) {
					this.msgform.coverLetter = 'coverLetter/' + res.upurl;
				} else {
					this.$message.error('service error：' + res.msg);
				}
			},
			upSuccess_picturesAndTables(res, file, fileList) {
				this.msgform.picturesAndTables = [];
				for (var ii in fileList) {
					var url = fileList[ii].response.upurl;
					this.msgform.picturesAndTables.push('picturesAndTables/' + url);
				}
			},
			upSuccess_totalpage(res, file) {
				if (res.code == 0) {
					this.msgform.totalpage = 'totalpage/' + res.upurl;
				} else {
					this.$message.error('service error:' + res.msg);
				}
			},
			upSuccess_manuscirpt(res, file) {
				if (res.code == 0) {
					this.msgform.manuscirpt = 'manuscirpt/' + res.upurl;
				} else {
					this.$message.error('service error：' + res.msg);
				}
			},
			//清除文件时的事件
			removefilecoverLetter(file, fileList) {
				this.msgform.coverLetter = '';
			},
			removefilepicturesAndTables(file, fileList) {
				this.msgform.picturesAndTables = [];
				for (var ii in fileList) {
					var url = fileList[ii].response.upurl;
					this.msgform.picturesAndTables.push('picturesAndTables/' + url);
				}
			},
			removefiletotalpage(file, fileList) {
				this.msgform.totalpage = '';
			},
			removefilemanuscirpt(file, fileList) {
				this.msgform.manuscirpt = '';
			},
			
			
			
			statetostr(mystate) {
				let str = '';
				switch (mystate) {
					case -1:
						str = 'Manuscript Submission';
						break;
					case 0:
						str = 'Received';
						break;
					case 1:
						str = 'With editor';
						break;
					case 2:
						str = 'Under review';
						break;
					case 3:
						str = 'Reject';
						break;
					case 4:
						str = 'Revision';
						break;
					case 5:
						str = 'Accepted';
						break;
					case 6:
						str = 'Fininal decision';
						break;
					default:
						str = 'error!!';
				}
				return str;
			},

			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 '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;
					default:
						frag = 'OTHERS';
				}
				return frag;
			},

		},
		filters: {

		}
	};
</script>


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

	.process_new {
		color: #333;
	}

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

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

	.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;
	}

	.art_author_ {
		border: 1px solid #dcdfe6;
		border-radius: 5px;
		background-color: #fff;
		padding: 20px;
		margin: 0 0 30px 0;
	}

	.art_author_>h2 {
		font-size: 18px;
		margin: 0 0 15px 0;
		letter-spacing: -0.8px;
	}

	.art_author_list {
		border-bottom: 1px solid #dcdfe6;
		padding: 15px 0 25px 0;
	}

	.art_author_list b {
		background-color: #006699;
		color: #fff;
		display: inline-block;
		width: 18px;
		height: 18px;
		line-height: 18px;
		text-align: center;
		margin: 0 10px 0 0;

	}

	.art_author_list span {
		color: #888;
		margin: 0 0 0 15px;
	}

	.art_author_list p {
		margin: 10px 0 0 28px;
	}

	.art_author_peng {
		margin: 20px 0 10px 0;
		line-height: 24px;
	}


	.art_author_peng span {
		color: #888;
		margin: 0 0 0 15px;
	}
	.art_author_btn>div{
		margin-bottom: 30px;
		color: #006699;
	}
	.art_author_btn>h4{
		float: left;
		width: 170px;
	}
	.art_author_btn>p{
		float: left;
		margin:  0 0 30px 0;
	}
</style>
