<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-collection-tag"></i> 领域同步
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container">
			<div>
				<el-button type="warning" icon="el-icon-refresh" @click="syn_Chro" style="margin-bottom: 20px;">同步</el-button>
				<p style="font-size: 16px;color: #606266;margin-bottom: 15px;">大池子最新同步时间： {{syn_Time}}</p>
				<p style="font-size: 16px;color: #606266;margin-bottom: 15px;">官网最新同步时间： {{guw_Time}}</p>
				<p style="font-size: 16px;color: #606266;">排版系统最新同步时间： {{pab_Time}}</p>
			</div>
		</div>
		<!-- 同步中弹出框 -->
		<el-dialog title="" :close-on-click-modal="false" :show-close="false" :visible.sync="synVisible" width="440px">
			<div style="margin: 0 0 60px 0;text-align: center;" v-if="re_finsh==1">
				<img src="../../assets/img/Fidget-load.gif" style="width: 400px;">
				<p style="font-size: 18px;font-weight: bold; background-image:-webkit-linear-gradient(left,#0a70f7,#49e1e7);-webkit-background-clip:text;-webkit-text-fill-color:transparent; ">正在同步中，请稍后...</p>
			</div>
			<div v-if="re_finsh==0" style="text-align: center;">
				<img src="../../assets/img/Fidget-right.png" alt="" style="width: 120px;">
				<p style="font-size: 18px;font-weight: bold;margin: 20px 0;color: #4e94cf;">同步成功！</p>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				Uw_url: 'special',
				// Uw_url: 'api',
				syn_Time: '0000-00-00',
				guw_Time: '0000-00-00',
				pab_Time: '0000-00-00',
				re_finsh: 1,
				synVisible: false,
			};
		},
		created() {
			this.getTime();
		},
		methods: {
			// 上次同步时间
			getTime() {
				this.$api
					.post(this.Uw_url + '/Major/getLastSyncTime')
					.then(res => {
						if (res.code == 0) {
							let date1 = new Date(parseInt(res.data.sync.all_major) * 1000);
							let Q = date1.getFullYear() + ' - ';
							let W = date1.getMonth() + 1 < 10 ? '0' + (date1.getMonth() + 1) + ' - ' : date1.getMonth() + 1 + ' - ';
							let E = date1.getDate() < 10 ? '0' + date1.getDate() : date1.getDate();
							this.syn_Time = Q + W + E
							
							let date2 = new Date(parseInt(res.data.sync.journal_major) * 1000);
							let A = date2.getFullYear() + ' - ';
							let S = date2.getMonth() + 1 < 10 ? '0' + (date2.getMonth() + 1) + ' - ' : date2.getMonth() + 1 + ' - ';
							let D = date2.getDate() < 10 ? '0' + date2.getDate() : date2.getDate();
							this.guw_Time = A + S + D
							
							let date3 = new Date(parseInt(res.data.sync.ts_major) * 1000);
							let Z = date3.getFullYear() + ' - ';
							let X = date3.getMonth() + 1 < 10 ? '0' + (date3.getMonth() + 1) + ' - ' : date3.getMonth() + 1 + ' - ';
							let C = date3.getDate() < 10 ? '0' + date3.getDate() : date3.getDate();
							this.pab_Time = Z + X + C
						} else {
							this.$message.error(res.msg);
						}
					})
					.catch(err => {
						this.$message.error(err);
					});
			},

			// 同步大池子按钮
			syn_Chro() {
				this.re_finsh = 1
				this.synVisible = true
				this.$api
					.post(this.Uw_url + '/Major/synchroniz')
					.then(res => {
						if (res.code == 0) {
							this.getTime()
							this.re_finsh = 0
							setTimeout(() => {
								this.synVisible = false
							}, 2000)
							setTimeout(() => {
								this.re_finsh = 1
							}, 2500)
						} else {
							this.$message.error(res.msg);
						}
					})
					.catch(err => {
						this.$message.error(err);
					});
			}

		},
	};
</script>

<style>

</style>
