<template>
	<view class="container">
		<!-- 匹配周期 -->
		<view class="matching mar_t20 flex_r flex_ac flex_jb">
			<view class="match_name">{{detail.status === 0 ? '寄卖中' : detail.status == 1 ? '寄卖成功' : detail.status == 2 ? '寄卖失败' : '寄卖转邮递'}}</view>
			<view class="match_day flex_r flex_ae">
				<block v-if="detail.status === 0">
					<text>{{dayNum}}</text>天 <view style="margin-left: 20rpx;">{{timeNum}}</view>
				</block>
				<block v-else>{{detail.typeTime}}</block>
			</view>
		</view>
		<!-- 匹配周期-end -->
		
		<!-- 加速 -->
		<view class="up flex_r flex_ac flex_jb mar_t20">
			<view class="up_con flex_c">
				<view class="up_name">已加速</view>
			</view>
			<view class="match_day flex_r flex_ae"><text>{{detail.speed_days }}</text>天</view>
		</view>
		<!-- 加速-end -->
		
		<!-- 签到加速 -->
		<view class="sign mar_t20">
			<view class="sign_con flex_r flex_ac flex_jb">
				<view class="sign_insfo flex_c flex_jc">
					<view class="sign_name">签到加速</view>
					<view class="sign_msg">每签到{{detail.qsCount}}次可加速1天，最多加速{{detail.oCountqd1}}天</view>
				</view>
				<view class="sign_up_con">
					<view style="display: flex;justify-content: center;position: relative;">
					  <cmd-progress type="circle" :percent="(detail.oCountqd2/detail.oCountqd1) * 100" stroke-color="#009688" :stroke-width="12" :width="168" :showInfo="false"></cmd-progress>
					  <view class="status flex_r flex_ac flex_jc">加速中</view>
					</view>
				</view>
			</view>
			<view class="sign_option flex_r flex_ac flex_jb">
				<view class="flex_r flex_ac">
					<image class="hint_img" src="/static/img/notice.png" mode=""></image>
					<view class="hint_msg">已达到最大签到次数或签到次数不足</view>
				</view>
				<view class="btn" @tap="gotoSign">立即加速</view>
			</view>
		</view>
		<!-- 签到加速-end -->
		
		<!-- 推广 -->
		<view class="promotion mar_t20">
			<view class="sign_con flex_r flex_ac flex_jb">
				<view class="sign_insfo flex_c flex_jc">
					<view class="sign_name">分享加速</view>
					<view class="sign_msg" style="max-width: 80%;">分享新用户在零售专区消费可获得加速，直至最快寄卖匹配周期。</view>
				</view>
				<view class="pro_con">
					<image src="/static/img/promotion.png" mode=""></image>
				</view>
			</view>
			<view class="sign_option flex_r flex_ac flex_je">
				<view class="btn" @tap="gotoImgTwo">立即分享</view>
			</view>
		</view>
		<!-- 推广-end -->
	</view>
</template>

<script>
let tim
let page = 1;
let app=getApp();
var appEv = app.$vm.$options;
import { post } from "@/request/api.js";
import cmdProgress from "@/components/cmd-progress/cmd-progress.vue"
	export default {
		components: {cmdProgress},
		data() {
			return {
				pro_num:0,
				detail: {},
				ojsId:'',
				time:'',

				dayNum: '', //剩余天数
				timeNum: '', //剩余时间（减去整天数过后的）
				// speedUpDayNum: "",//加速天数
			};
		},
		onLoad:function(e){
			this.ojsId = e.id;
			this.loadData()
		},
		onUnload:function(){
			clearInterval(tim)
		},
		methods:{
			loadData(){
				let data = {
					consignment_id:this.ojsId
				}
				post("v1/goods/consignmenDetail",data).then(res => {
					if(res.code === 0){
						let da = res.data.data;
						this.detail = da;
						if(da.status === 0) this.timeCalculate(da);


						// let num1 = da.oCountqd2 > da.oCountqd1 ? da.oCountqd1 : da.oCountqd2; //签到加速天数
						// let num2 = da.oCounttg2 > da.oCounttg1 ? da.oCounttg1 : da.oCounttg2; //推广签到天数
						// that.speedUpDayNum =  (num1 + num2) > da.oCountSX ? da.oCountSX : num1 + num2;

					}
				})
			},
			timeCalculate(data){
				console.log("寄卖结束：",this.$day(data.create_time).add(19 - data.speed_days, 'day').format("YYYY-MM-DD HH:mm:ss"));
				// console.log(this.$day().subtract(data.ojsDay - this.speedUpDayNum, 'day').format("YYYY-MM-DD HH:mm:ss"));

				let endTime = data.end_sell_time;
				let dayNum = parseInt((endTime - this.$day().unix()) / 86400); //剩余整天数
				let timeNum = (endTime - this.$day().unix()) % 86400; //剩余时间（减去整天数过后的）
				timeNum  = timeNum > 0 ? timeNum : 0;
				this.dayNum = dayNum;

				let that = this;
				let time = setInterval(()=>{
					if(timeNum > 1){
						timeNum --
					}else{
						if(dayNum >= 1){
							that.dayNum = dayNum - 1
							timeNum = 86399
						}else{
							clearInterval(time)
							uni.showModal({
							    title: '提示',
							    content: '寄卖完成，请返回列表查看结果',
							    success: function (res) {
							        if (res) {
							            uni.navigateBack({
							            	delta:1
							            })
									}
							    }
							});
						}
					}
					let hour = parseInt(timeNum/3600) > 9 ? parseInt(timeNum/3600) : '0' + parseInt(timeNum/3600)
					let min = parseInt(timeNum / 60 % 60) > 9 ? parseInt(timeNum / 60 % 60) : '0' + parseInt(timeNum / 60 % 60)
					let sec = parseInt(timeNum % 60) > 9 ? parseInt(timeNum % 60) : '0' + parseInt(timeNum % 60)
					that.timeNum = hour + ':' + min + ':' + sec;
				},1000);
			},
			getTimer:function(timer){
				var date;
				let that = this;
				tim = setInterval(()=>{
					if(timer>1){
						timer --
					}else{
						if(that.detail.ojsDaySurplus >= 1){
							that.detail.ojsDaySurplus = that.detail.ojsDaySurplus - 1
							timer = 86399
						}else{
							clearInterval(tim)
							uni.showModal({
							    title: '提示',
							    content: '寄卖完成，请返回列表查看结果',
							    success: function (res) {
							        if (res) {
							            uni.navigateBack({
							            	delta:1
							            })
									}
							    }
							});
						}
					}
					let hour = parseInt(timer/3600) > 9 ? parseInt(timer/3600) : '0' + parseInt(timer/3600)
					let min = parseInt(timer / 60 % 60) > 9 ? parseInt(timer / 60 % 60) : '0' + parseInt(timer / 60 % 60)
					let sec = parseInt(timer % 60) > 9 ? parseInt(timer % 60) : '0' + parseInt(timer % 60)
					date = hour + ':' + min + ':' + sec
					this.time = date
				},1000)
			},
			gotoSign(){
				uni.reLaunch({
					url:'/pages/sign/index'
				})
			},
			gotoImgTwo:function(){
				uni.navigateTo({
					url:'/pages/invi-img/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
// 页面配置
page{background: #F4F4F4;}
// 页面配置-end

// 匹配周期
.match_day{font-size: 24rpx;color:#2A2A2A;line-height: 1;}
.match_day text{font-size: 36rpx;color:#2A2A2A; line-height: 1;}
.match_name{font-size: 32rpx;color:#313131;font-family: "SourceHanSansCN-Medium";}
.matching{width: 100%;height: 88rpx;background: #fff;padding:0 30rpx;box-sizing: border-box;}
// 匹配周期-end

// 加速
.up_max{font-size: 22rpx;color: #686868;}
.up_name{font-size: 32rpx;color:#313131;font-family: "SourceHanSansCN-Medium";}
.up{width: 100%;height: 100rpx;background: #fff;padding:0 30rpx;box-sizing: border-box;}
// 加速-end

// 签到加速
.sign_msg{font-size: 24rpx;color: #3B3A3A;}
.sign_up_con{width: 168rpx;height: 168rpx;}
.hint_msg{font-size: 20rpx;color: #5D5C5C;}
.hint_img{width: 30rpx;height: 30rpx;margin-right: 20rpx;}
.sign_option{width: 100%;overflow: hidden;margin-top: 38rpx;}
.sign_con{width: 100%;overflow: hidden;align-items: initial;}
.sign{width: 100%;overflow: hidden;background: #fff;padding:30rpx;box-sizing: border-box;}
.status{font-size:22.63rpx;color:#5D5C5C;width: 100%;height: 100%;position: absolute;top: 0;left: 0;}
.sign_name{font-size: 32rpx;color:#313131;font-family: "SourceHanSansCN-Medium";margin-bottom: 30rpx;}
.btn{padding:10rpx 31rpx 8rpx 40rpx;background: #E35535;color:#fff;font-size: 26rpx;font-family: "SourceHanSansCN-Medium";border-radius: 12rpx;}
// 签到加速-end

// 推广
.pro_con{width: 84rpx;height: 78rpx;}
.pro_con image{width: 100%;height: 100%;}
.promotion .sign_con{align-items: center;}
.promotion{width: 100%;overflow: hidden;background: #fff;padding:30rpx;box-sizing: border-box;}

.y_color{color:#E56213;font-size: 24rpx;}
// 推广-end
</style>
