Vue.component('time-template', {
	props : ['type','curid','endtime'],
	data : function() {
		return {
			xqreturn : '',
			curids : '',
			flag : false
		}
	},
	template : '<span></span>',
	mounted : function() {
		var that = this;
		this.curids = this.curid;
		this.types = this.type;
		var time = setInterval(function() {
			if (that.flag == true) {
				clearInterval(time);
			}
			that.timeDown();
		}, 1000);
	},
	methods : {
		timeDown : function() {
			var daysms = 24 * 60 * 60 * 1000;
			var hoursms = 60 * 60 * 1000;
			var Secondms = 60 * 1000;
			var microsecond = 1000;
			var time = new Date();
			//alert(this.endtime);
			var leftTime = Math.floor(this.endtime * 1000) - Math.floor(Date.parse(time));
			//alert(leftTime);
			if (leftTime > 0) {
				var Hour = Math.floor(leftTime / daysms);
				leftTime -= Hour * daysms;
				var Minute = Math.floor(leftTime / hoursms);
				leftTime -= Minute * hoursms;
				var Second = Math.floor(leftTime / Secondms);
				leftTime -= Second * Secondms;
				var dSecs = Math.floor(leftTime / microsecond);
				Hour = this.formate(Hour);
				Minute = this.formate(Minute);
				Second = this.formate(Second);
				dSecs = this.formate(dSecs);
				var a = "<b>" + Hour + "</b>天";
				var b = "<b>" + Minute + "</b>时";
				var c = "<b>" + Second + "</b>分";
				var d = "<b>" + dSecs + "</b>秒";
				var self = this;
				this.$nextTick(function(){
					if(self.types=='promot'){
						$('#'+self.types+self.curids).html(a + b + c + d);
					}else if(self.types=='time_limit'){
						var Hours = (Hour*24)+Minute;
						$('#'+self.types+self.curids).html('<ins><i class="hour">'+Hours+'</i></ins>：<ins><i class="min">'+Second+'</i></ins>：<ins><i class="second">'+dSecs+'</i></ins>');
					}
					
					// 
				});
				
			} else {
				this.flag = true;
			}
		},
		formate : function(time) {
			if (time >= 10) {
				return time;
			} else {
				return "0" + time;
			}
		}
	}
})
var Hanchao = new Vue({
	el : '#HCtemplate',
	data : {
		//主列表
		HClist : [],
		//追加列表
		HCaddlist : '',
		//当前点击添加的模板类型
		type_con:'',
		//数据库存储的新数组
		HCnewlist:[],
		//数据库存储的新数组长度【用来遍历渲染】
		HCnewlistlen:0,
		//轮播组件数量
		HCowlnum:0,
	},
	methods : {
		init : function() {
			this.HCnewlist = HCinitlist;
			if(this.HCnewlist){
				this.HCnewlistlen = this.HCnewlist.length;
				this.initlist(0);
			}
		},
		initlist : function(index) {
			if(this.HCnewlistlen==index)return;
			this.settimeoutinit(index);
		},
		settimeoutinit:function(index){
			var that = this;
			this.left(that.HCnewlist[index]);
			this.$nextTick(function () {
				index++;
				that.initlist(index);
			});
		},
		left :function(ret){
			//left-module自定义事件添加
			var self = this;
			self.HCaddlist = ret;//模板赋值
			self.type_con = 'tpl_diy_con_type'+ret.data_type;//判断内容模板类型
			self.type_edit = 'tpl_diy_edit_type'+ret.data_type;//判断编辑模板类型
			if(ret.data_type==7){
				//支持实例多个轮播组件
				self.HCowlnum++;
			}
			self.$nextTick(function () {
				$('#content').append(self.formatStr($('#temphtml').html()));
			});
		},
		formatStr:function (str) {
			return str.replace(/\<\!\-\-\-\-\>/g, "")
		},
		check_con_show:function(code){
			//模板内容显示
			if(code=='tpl_diy_con_type7')this.ShowowlCarousel(code);
			if(this.type_con==code)return true;
			return false;
		},
		bind_type10_style:function(bgColor,height,liheight,marginstyle,type){
			if(type==1)return 'color:'+bgColor+';height:44px;line-height:44px;';
			return 'background-color:'+bgColor+';height:'+height+'px;line-height:'+liheight+'px;margin-right:'+marginstyle+'px;';
		},
		tpl_diy_con_type2_class:function(data){
			return 'members_titles titlestyle'+data.titlestyle+' '+data.direction;
		},
		ShowowlCarousel:function(id){
			var self = this;
			self.$nextTick(function () {
				for(var i=1;i<=self.HCowlnum;i++){
					$("#HCowldemo"+i).owlCarousel({
						autoPlay: 3000,
						navigation : true,
						slideSpeed : 300,
						paginationSpeed : 400,
						singleItem : true
					});
				}
			});	
		}
	},
});
Hanchao.init();
function reloadindex(){
    $.ajax({
        url:APP+'Home/Ajax/reloadindex.html',
        type:"get",
        dataType:"json",
        success:function(ret){
            if(ret.status == 1){
                if(ret.data){
                    Hanchao.HCaddlist='';
                    Hanchao.HCnewlist=[];
                    $('#content').html('');
                    Hanchao.init(ret.data);
                }
                if(ret.shop_data && ret.shop_data.count>0){
                    var htmlstr='<span class="toparrow"></span>';
                    htmlstr+='<h4>'+ret.shop_data.count+'个门店可为您配送</h4>';
                    for(var i in ret.shop_data.list){
                        var vo=ret.shop_data.list[i];
                        htmlstr+='<dl onclick="location.href=\''+APP+'mobile/index/index/main_shop_id/'+vo.id+'/eid/'+user_id+'\'" id="shopid_'+vo.id+'">';
                        if(vo.id==ret.main_shop_id){
                            htmlstr+='<dt class="on"><i class="hc-iconfont">&#xe601;</i></dt>';
                            $('.title').html(vo.name+'<i class="hc-iconfont header_icon">&#xe60f;</i>');
                        }else{
                            htmlstr+='<dt><i class="hc-iconfont">&#xe601;</i></dt>';
                        }
                        htmlstr+='<dd>'+vo.name+'</dd>';
                    }
                    $('.shop_switch').html(htmlstr);
                }
            }
        },error:function(){}
    });
}