var msort = 1;
var page = 1;
var condition = 1;
var desc = 0;
var keyword;
var isjiazai = 1;
var count = 1;
var pagesize = 10;
var ct1;
var ct2;

function pullupRefresh(shopId, msort, desc, pagesize, page, goodsName, ct1, ct2) {
	//				setTimeout(function() {

	//				mui('#pullrefresh').pullRefresh().endPullupToRefresh();

	var data_set = {
		page: page,
		pagesize: pagesize,
		shopId: shopId,
		mdesc: desc,
		msort: msort
		goodsName: goodsName
	}
	//				console.log(order_class)
	if(isjiazai == 0) {
		return;
	}else{
		isjiazai = 0;
	mui.ajax(hyhUrl('app/Shops/getShopGoods'), { 

		data: data_set,
		dataType: 'json', //服务器返回json格式数据  
		type: 'post', //HTTP请求类型  
		timeout: 10000, //超时时间设置为10秒;  
		success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
			//					console.log(data.data.goodsFavoritesNum)
			//					console.log(data.data.Rows)

			var data = toJson(data);
			data = data.data;
			var html = '';
			if(data.Rows == '') {
				$('.mui-scroll').append('<p style="float: left;width: 100%;text-align: center;padding-bottom: 9px;">没有更多商品</p>');
				isjiazai = 0;
				return;
			}
			$.each(data.Rows, function() {
				html += '<div class="cnxh_block con_goods" data-id="' + this.goodsId + '"><img src="' + hyhImgUrl(this.goodsImg) + '" /><div class="cnxh_block_info"><p class="s_name">' + this.goodsName + '</p><p class="cost">¥' + Math.round(this.shopPrice * 0.8 * 100) / 100 + '<o>到手价</o><del>¥' + this.shopPrice + '</del></p><p class="cost_info">可用惠宝抵扣20%货款</p></div></div>'
			});
			if(page == "1") {
				$('.cnxh_con').html(html);
			} else {
				$('.cnxh_con').append(html);
			}
			isjiazai = 1;
			$('.cnxh_block img').height($('.cnxh_block img').width());
			$('.cnxh_block').height($('.cnxh_block').width() * 266 / 198);

		},
		error: function(xhr, type, errorThrown) {           //异常处理;  
			//					alert(type);    
		}  
	}); 
	//				}, 500);
}

mui.plusReady(function() {
	var shopId = localStorage.getItem('shopId')
	var costnum = 0;
	var self = plus.webview.currentWebview();
	keyword = self.data_keyword;

	$('.commoditylistnav').on('tap', '.nav_block', function() {
		page = 1;
		isjiazai = 1;
		$(this).addClass('on').siblings().removeClass('on');

		msort = $(this).attr('data-condition');

		if($('#cost_btn').hasClass('on')) {

			costnum += 1;

			if(costnum % 2 == 1) {

				$('#cost_btn').html('价格 <img src="../img/cost3.png"/>');

				desc = 1;

			} else if(costnum % 2 == 0) {

				$('#cost_btn').html('价格 <img src="../img/cost2.png"/>');

				desc = 0;

			}

		} else {

			$('#cost_btn').html('价格 <img src="../img/cost1.png"/>')

			costnum = 0;
			desc = 0
		}
		pullupRefresh(shopId, msort, desc, pagesize, page, goodsName, ct1, ct2)

	})

	$('.cnxh_con').on('tap', '.con_goods', function() {
		var good_id = $(this).attr('data-id');
		mui.openWindow({
			url: 'details.html',
			id: 'details.html'+good_id,
			styles: {
				top: '0px', //新页面顶部位置
				bottom: '0px', //新页面底部位置
				width: '100%', //新页面宽度,默认为100%
				height: '100%' //新页面高度,默认为100%
			},
			extras: {
				data_id: good_id
				//					..... //自定义扩展参数,可以用来处理页面间传值
			},
			createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
			show: {
				//					autoShow: true, //页面loaded事件发生后自动显示,默认为true
				//					aniShow: animationType, //页面显示动画,默认为”slide-in-right“;
				//					duration: animationTime, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
				//					event: 'titleUpdate', //页面显示时机,默认为titleUpdate事件时显示
				//					extras: {} //窗口动画是否使用图片加速
			},
			waiting: {
				autoShow: true, //自动显示等待框,默认为true
				title: '正在加载...', //等待对话框上显示的提示内容
				options: {
					//						width: waiting - dialog - widht, //等待框背景区域宽度,默认根据内容自动计算合适宽度
					//						height: waiting - dialog - height, //等待框背景区域高度,默认根据内容自动计算合适高度
					//						......
				}
			}
		})
	})

	document.querySelector('.mui-scroll-wrapper').addEventListener('scroll', function(e) {
		if(scroll.y == scroll.maxScrollY) {
			if(isjiazai == 1) {
				page++;
				pullupRefresh(shopId, msort, desc, pagesize, page, goodsName, ct1, ct2);
			}

		}
	})

})

//			setInterval(function() {
//				$('.cnxh_block img').height($('.cnxh_block img').width());
//				$('.cnxh_block').height($('.cnxh_block').width() * 266 / 198);
//			}, 100)