<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-lx-calendar"></i> Manuscript Received
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="art_state_text">
			<p style="margin-bottom: 10px;">
				Dear editor, this manuscript (<b>{{form.accept_sn}}</b>) was submitted by the author (uploader: <b>{{form.username}}</b>)
				at <b>
					<!-- 19：00 New Zealand time -->
				{{formatDateNewCHz(form.ctime)}}</b> to the journal <b>{{journal_me}}</b>.
				Please check the content of the manuscript and start the process.
			</p>
			<p>
				<b>On this page</b>
				<br />1. You need to check whether the manuscript subject and type are within the scope of the journal.
				<br />2. You need to check the plagiarism rate.
				<br />3. You need to make sure the manuscript meets the ethical guidelines of the Committee on Publication
				Ethics
				(COPE).
			</p>
		</div>
		<div class="container_state" v-loading="loading">
			<el-row :gutter="30">
				<el-col :span="24">
					<div class="art_state_">
						<div class="art_state_message">
							<div class="art_state_message_id">
								ID : <b style="margin-right: 60px;">{{form.accept_sn}}</b>
								Status : <b>{{articleState}}</b>
							</div>
							<h3>Basic information</h3>
							<p>
								<font>Title :</font><b>{{form.title}}</b>
							</p>
							<p>
								<font>Type :</font><b>{{form.type | jtName}}</b>
							</p>
							<p v-show="form.type=='A'">
								<font>Ethical Approval :</font><b>{{form.approval?'Yes':'No'}}</b>
							</p>
							<p>
								<font>Journal :</font><b>{{journal_me}}</b>
							</p>
							<p v-if="form.special_num > 0">
								<font>Special Issues :</font><b>{{ form.special_title }}</b>
							</p>
							<p>
								<font>Major :</font><b>{{form.major}}</b>
							</p>
							<el-collapse v-model="activeNames" class="auth_colla">
								<el-collapse-item :title="authorList_name" name="1">
									<div v-for="(item, index) in form.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>
							<p>
								<font>Abstract :</font><b>{{form.abstrart}}</b>
							</p>
							<p>
								<font>KeyWords :</font><b>{{form.keyWords}}</b>
							</p>
							<p v-if="form.fund">
								<font>Fund :</font><b>{{form.fund}}</b>
							</p>
						</div>


						<div class="art_file">
							<h3 style="margin-bottom: 20px;">Files</h3>
							<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>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>
					</div>
					<div class="art_caozuo_">
						<div class="art_state_repet">
							<h3>Repetition rate check</h3>
							<p>
								Dear editor
								<br>According to the rules of ICMJE and COPE, you need to check the plagiarism rate of the manuscript.
								<br>The manuscripts or papers in which the plagiarism is detected are handled based on the extent of the
								plagiarism.
								<br>&lt;30% Plagiarism: The manuscript will be given an ID and the manuscript is sent to the author for content
								revision.
								<br>&gt;30% Plagiarism: The manuscript will be rejected without review. The authors are advised to revise the
								<br>manuscript and resubmit the manuscript.
							</p>
							<el-form ref="repetition" :model="repeform" label-width="150px" style="margin: 20px 0 0 15px;">
								<el-form-item label="Repetition Content :">
									<el-input maxlength="3" style="width:100px;" v-model="repeform.repefen">
										<template slot="append">%</template>
									</el-input>
								</el-form-item>
								<el-form-item label="Zip :">
									<el-upload class="upload-demo" :action="upload_zip" accept=".rar, .zip" name="repezip" :on-success="upSuccess_repezip"
									 :limit="1" :on-exceed="alertlimit" :on-remove="removefilerepezip">
										<div class="el-upload__text" style="padding:0 5px;">
											<em>Click Upload</em>
										</div>
										<div class="el-upload__tip text_upload_tip" slot="tip">Only pdf and word files can be uploaded(.pdf,.doc,.docx)</div>
									</el-upload>
								</el-form-item>
							</el-form>
							<el-button type="primary" @click="saveRepe" style="margin: 0 0 0 165px;">Save</el-button>
						</div>

						<div class="art_state_btn">
							<h3>Please click the button to choose the next step following the editorial workflow.</h3>
							<div class="a_s_t1" @click="testvis(1)">
								With editor
							</div>
						</div>
					</div>

				</el-col>

			</el-row>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.Common.baseUrl,
				mediaUrl: this.Common.mediaUrl,
				items: '',

				loading: false,
				editVisible: false,
				editbox: false,
				reverse: false,
				dialogFormVisible: false,
				editortVisible: false,
				questionform: {},
				coverLetterFileList: [],
				picturesAndTablesFileList: [],
				totalpageFileList: [],
				manuscirptFileList: [],
				authorList_name: '',
				review_Data: [],
				Total_review: 0,
				msgform: {
					username: localStorage.getItem('U_name'),
					article_id: this.$route.query.id,
					ad_content: ''
				},
				query_review: {
					articleId: this.$route.query.id,
					pageIndex: 1,
					pageSize: 10
				},
				editform: {
					editname: localStorage.getItem('U_name'),
					articleId: this.$route.query.id,
					state: 0,
					trsjournal: 0,
					editormsg: ''
				},
				repeform: {
					articleId: this.$route.query.id,
					repefen: '',
					zipurl: ''
				},
				activeNames: ['2'],
				journals: [],
				items: [{
						state: 0,
						title: this.$t('artstate.state0'),
						disabled: true
					},
					{
						state: 1,
						title: this.$t('artstate.state1')
					},
					{
						state: 2,
						title: this.$t('artstate.state2'),
					},
					{
						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: '',
					major: '',
					approval: false,
					repetition: '',
					manuscirpt: '',
					remarks: '',
					state: '',
					ctime: '',
					authorList: [],
					transList: []
				},
			};
		},
		created: function() {
			this.initarticle();
			this.initFileList();

		},
		computed: {
			
			manuscirptUrl: function() {
				return this.baseUrl + this.form.manuscirpt;
			},
			upload_zip: function() {
				return this.baseUrl + 'api/Article/up_file/type/repezip';
			},
			journal_me: function() {
				var frag = this.form.journalname;
				if (this.form.special_num > 0) {
					frag += "(Special Issues)";
				}
				return frag;
			},
			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;
					case 6:
						str = this.$t('artstate.state6');
						break;
				}
				return str;
			}
		},
		methods: {
			//初始化文章信息
			initarticle() {
				this.$api
					.post('api/Article/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.type = res.article.type;
						this.form.special_num = res.article.special_num;
						this.form.special_title = res.article.special_title;
						this.form.major = res.major;
						this.form.approval = res.article.approval == 1 ? true : false;
						this.form.repetition = res.article.repetition;
						this.form.remarks = res.article.remarks;
						this.repeform.repefen = res.article.repetition;
						this.editform.state = this.form.state = res.article.state;
						this.form.ctime = res.article.ctime;
						this.form.transList = res.transfer;
						let alist = res.authors;
						let alist_name = [];
						for (let 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
							});
							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("");

						this.form.repetition = '';
						this.repeform.repefen = '';
					})
					.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);
					});
			},
			//弹出编辑框
			testvis(e) {
				if (this.form.repetition == '') {
					this.$message.error('Please fill in the duplicate check rate!');
				} else {
					this.editform.state = e
					this.editform.state_name = this.statetostr(e)
					this.$confirm('Are you sure about this process ' + this.editform.state_name + ' ?', 'Tips', {
							type: 'warning'
						})
						.then(res => {
							this.loading = true;
							this.$api
								.post('api/Article/editArticleEditor', this.editform)
								.then(res => {
									if (res.code == 0) {
										this.$message.success('Success!');
										let stat_num = ''
										stat_num = 'articleDetailEditor_b'
										this.$router.push({
											path: stat_num,
											query: {
												id: this.form.articleId
											}
										});

									} else {
										this.$message.error(res.msg);
									}
								})
								.catch(err => {
									console.log(err);
								});
						}).catch(() => {});
				}
			},
			testedit() {
				this.editbox = true;
			},

			statetostr(mystate) {
				let str = '';
				switch (mystate) {
					case -1:
						str = 'Manuscript Submission';
						break;
					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;
			},
			//修改查重查重状态
			saveRepe() {
				if (this.repeform.zipurl == '') {
					this.$message.error('please upload zip');
					return false;
				}
				this.loading = true;
				this.$api.post('api/Article/changeRepetition', this.repeform)
					.then(res => {
						this.loading = false;
						this.form.repetition = this.repeform.repefen;
						this.$message.success('success');
					});
			},


			// 压缩包上传
			upSuccess_repezip(res, file) {
				if (res.code == 0) {
					this.repeform.zipurl = 'repezip/' + res.upurl;
				}
			},
			//超出传送文件个数限制
			alertlimit() {
				this.$message.error('The maximum number of uploaded files has been exceeded');
			},
			removefilerepezip(file, fileList) {
				this.repeform.zipurl = '';
			},
			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;
			},

			formatDateNewCHz(timestamp) {
				var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var Y = date.getFullYear();
				var M = date.getMonth();
				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();
				var M_m = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
					'November', 'December'
				];
				return '(' + h + ':' + m + ' Beijing time) on ' + D + ' ' + M_m[M];
			},
		},
	};
</script>


<style>

</style>
