mui.ready(function() {
	mui.ajax(base_path + '/indexData?dates=' + new Date().getTime(), {
		dataType: 'json',
		type: 'post',
		timeout: 15000,
		success: function(dt) {
			//console.log(dt);
			var bannerstr = "",prostr = "",dian = "",advsstr = "";
			if(dt.status) {
				var banner_data = dt.data.banners;
				mui(banner_data).each(function(index) {
					if(index == 0) {
						bannerstr += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="' + banner_data[banner_data.length-1].bannerImageCheckOutUrl + '"><img src="' + (banner_data[banner_data.length-1].bannerImageUrl) + '"></a></div><div class="mui-slider-item mui-active"><a href="' + this.bannerImageCheckOutUrl + '"><img src="' + (this.bannerImageUrl) + '"></a></div>';
						dian += '<div class="mui-indicator mui-active"></div>';
					} else {
						bannerstr += '<div class="mui-slider-item"><a href="' + this.bannerImageCheckOutUrl + '"><img src="' + (this.bannerImageUrl) + '"></a></div>';
						dian += '<div class="mui-indicator"></div>';
					}
					if(index == (banner_data.length - 1) || (banner_data.length - 1) == 0) {
						bannerstr += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="' + banner_data[0].bannerImageCheckOutUrl + '"><img src="' + (banner_data[0].bannerImageUrl) + '"></a></div>';
					}
				});
//				dc('mui-slider-loop').innerHTML = bannerstr;
//				dc('my-slider-indicator').innerHTML = dian;
console.log(dian);
				$("<div id='banner-slider' class='mui-slider'><div class='mui-slider-group mui-slider-loop' id='mui-slider-loop'>"+bannerstr+"</div><div id='my-slider-indicator' class='mui-slider-indicator my-slider-indicator'>"+dian+"</div></div>").insertBefore(".chanpin-box");

				var pro_data = dt.data.products;
				mui(pro_data).each(function(index) {
					var img_str = "";
					/*var pro_color = switchcolor(this.productColor)*/
					var pro_color = this.productColor;

					if(index == 0) {
						img_str = '<img val="' + this.productIntroduceImg + '"  src="' + this.productIntroduceImg + '">';
					} else {
						img_str = '<img val="' + this.productIntroduceImg + '" src="">';
					}
					var test = '';
					if(this.productName.indexOf("水时代") != -1) {
						test = '美国品质 专业净水';
					} else {
						test = '让更多妈妈睡个好觉';
					}
					prostr += '<div class="mui-slider-item"><a proid=' + this.productId + ' class="go_chanpin_details">' + img_str + '<div class="chanpin-cell opacity_0"><div><div class="tit">' + this.productName + ' <span class="ft-12">(' + pro_color + ')</span></div><div class="dic">' + this.productColorDes + '</div><span class="dic-bt">' + test + '</span><div class="price_box"><span class="price1 cl-red">' + accDiv(this.productDiscount, 100) + '元</span><s class="price2">原价¥' + accDiv(this.productPrice, 100) + '元</s></div><div><a proid=' + this.productId + ' class="mui-btn my-btn-red" style="background-color:#c7c7cc;border: 1px solid #c7c7cc;color:#fff;">立即抢购</a></div></div></div></a></div>';
//					if(this.productId == 28) {
//						prostr += '<div class="mui-slider-item"><a proid=' + this.productId + ' class="go_chanpin_details">' + img_str + '<div class="chanpin-cell opacity_0"><div><div class="tit">' + this.productName + ' <span class="ft-12">(' + pro_color + ')</span></div><div class="dic">' + this.productColorDes + '</div><span class="dic-bt">' + test + '</span><div class="price_box"><span class="price1 cl-red">' + accDiv(this.productDiscount, 100) + '元</span><s class="price2">原价¥' + accDiv(this.productPrice, 100) + '元</s></div><div><a proid=' + this.productId + ' class="mui-btn my-btn-red" style="background-color:#c7c7cc;border: 1px solid #c7c7cc;color:#fff;">立即抢购</a></div></div></div></a></div>';
//					} else {
//						prostr += '<div class="mui-slider-item"><a proid=' + this.productId + ' class="go_chanpin_details">' + img_str + '<div class="chanpin-cell opacity_0"><div><div class="tit">' + this.productName + ' <span class="ft-12">(' + pro_color + ')</span></div><div class="dic">' + this.productColorDes + '</div><span class="dic-bt">' + test + '</span><div class="price_box"><span class="price1 cl-red">' + accDiv(this.productDiscount, 100) + '元</span><s class="price2">原价¥' + accDiv(this.productPrice, 100) + '元</s></div><div><a proid=' + this.productId + ' class="mui-btn my-btn-red go-clearing">立即抢购</a></div></div></div></a></div>';
//					}
				});
				dc('chanpin-slider-box').innerHTML = prostr;
				dc('chanpin-slider').style.display = 'block';
				dc('jifen-daili-menu').style.display = 'block';

				var advs_data = dt.data.advs;
				mui(advs_data).each(function(index) {
					advsstr += '<a href="' + this.bannerImageCheckOutUrl + '"><img src="' + this.bannerImageUrl + '" /></a>'
				});
				dc('advs_banner').innerHTML = advsstr;

				dc('advs_banner').style.display = 'block';
				dc('banner-slider').style.display = 'block';
				//获得slider插件对象
				var banner = mui('#banner-slider');
				banner.slider({
					interval: 5000
				});
				var chanpin_slider = mui('#chanpin-slider');
				chanpin_slider.slider({
					interval: 0
				});
				mui.each(document.querySelectorAll('#banner-slider a'), function(index, el) {
					el.addEventListener('tap', function() {
						document.querySelector('.loading-bg').style.display = 'block';
						location.href = this.getAttribute('href');
					}, false);
				});
				mui.each(document.querySelectorAll('#advs_banner a'), function(index, el) {
					el.addEventListener('tap', function() {
						document.querySelector('.loading-bg').style.display = 'block';
						location.href = this.getAttribute('href');
					}, false);
				});
				var a = 0,
					wait = 0,
					prev = document.querySelector('.prev'),
					next = document.querySelector('.next');
				mui('body').on('tap', '.next', function() {
					if(wait == 0) {
						wait = 1;
						if(a < document.querySelectorAll('#chanpin-slider .mui-slider-item').length - 1) {
							a++;
						}
						chanpin_slider.slider().gotoItem(a);
						setTimeout(function() {
							wait = 0
						}, 1500);
					}
				});
				mui('body').on('tap', '.prev', function() {
					if(wait == 0) {
						wait = 1;
						if(a > 0) {
							a--;
						}
						chanpin_slider.slider().gotoItem(a);
						setTimeout(function() {
							wait = 0
						}, 1500);
					}
				});
				dc('chanpin-slider').addEventListener('slide', function(event) {
					var e = event.detail.slideNumber;
					if(e == 0) {
						prev.style.color = "#ccc";
						next.style.color = "#f64e78";
					} else if(e == document.querySelectorAll('#chanpin-slider .mui-slider-item').length - 1) {
						next.style.color = "#ccc";
						prev.style.color = "#f64e78";
					} else {
						prev.style.color = "#f64e78";
						next.style.color = "#f64e78";
					}
				});
				var shareOpenid = dt.data.memberOpenid;
				var link = domanUrl + "/iamberry/wechat/index?shareOpenid=" + shareOpenid;
				//添加分享
				window.repleFlag = false;
				window.wxFriend = {
					"appId": "",
					"imgUrl": domanUrl + '/iamberry/common/shop/images/index.jpg',
					"link": link,
					"desc": "智能冲奶机，让全中国的妈妈睡个好觉！点击进入更多活动，粉丝福利，积分返现....", //描述
					"title": "爱贝源，一家主打中国母婴智能硬件产品官方商城", //标题
					"netError": "您的网络异常，请刷新重试!如多次刷新无效，请向我们反应 ~",
					"shareTimeSuccess": "分享成功", //分享朋友圈后回调
					"shareTimeCancel": "已取消分享", //取消分享朋友圈后回调
					"shareAppSuccess": "分享成功!", //分享好友后回调
					"shareAppCancel": "已取消分享" //取消分享好友后回调
				};
				getConfig();
				document.querySelector('.loading-bg').style.display = 'none';
			} else {
				mui.alert(dt.message, ' ', '朕知道了', function() {
					mui.openWindow({
						url: domanUrl + "/iamberry/wechat/index?dates=" + new Date().getTime()
					});
				});
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
			errorfn(xhr);
		}
	});
	mui('body').on('tap', '.go_jifen_shop', function() {
		mui.alert('敬请期待', ' ', '朕知道了', function() {});
	});
	setTimeout(function() {
		$("#chanpin-slider .mui-slider-item").each(function(){
			if($(this).find('.opacity_0').length>0){
					$(this).find('img').prop('src',$(this).find('img').attr('val'));
					$(this).find('.opacity_0').removeClass('opacity_0')
				}
			});
	}, 1500);
});