mui.plusReady(function() {
	var self = plus.webview.currentWebview();
	//console.log(self);
	var shopId = self.id;
	//获取店铺相册
	JZL.ajax(qlgUrl('app/shops/getShopImg'), {
		shopId: shopId
	}, function(data) {
		//console.log(data);
		if (1 == data.status && '' != data.data.shopImg) {
			$('#shop').attr('src', hyhImgUrl(data.data.shopImg))
			$('#shopImg').val(data.data.shopImg)
			if ('' != data.data.shopAds) {
				var shopAds = data.data.shopAds;

				ads = shopAds.split(",")
				//console.log(ads);
				var html = '';
				mui.each(ads, function(index, element) {
					//console.log(element);
					html += '<div data-id="' + index +
						'" data-src="" class="galleryImg photo"><div class="delete"><img src="../img/close.png" alt=""></div><img src= "' +
						hyhImgUrl(element) + '" class="ossfile" id="galleryImg[' + index + ']" alt=""><input type="hidden" value="' +
						element + '" name="gallery[]" class="gallery inp" id="gallery[' + index + ']"><span class=""></span></div>'
				})
				var maxNum = ads.length;
				html += '<div class="galleryImg photo" data-id="' + maxNum +
					'" ><img src="../img/pjimg.png" class="ossfile" id="galleryImg[' +
					maxNum + ']" alt=""><input type="hidden" name="gallery[]" value="" class="gallery" id="gallery[' + maxNum +
					']"><span class=""></span></div>';
				$('.batchImg').html(html)

			}

		} else {
			mui.alert(data.msg)
		}
	})

	$(".batchImg").on("tap", '.galleryImg', function() {
		var num = $(this).attr('data-id');
		UP.init("gallery[" + num + "]", "test", "galleryImg[" + num + "]", 1);
		var that = $(this);
		openCamera(function(t, status, fileName, serverName) {
			var html = '<div class="delete" data-id="' + num + '"><img src="../img/close.png" alt=""></div><img src="' +
				serverName + '" class="ossfile" data-src="' + fileName + '" data-id="' + num + '" id="galleryImg[' + num +
				']" alt=""><input type="hidden" name="gallery[]" value="' + fileName +
				'" class="gallery" id="gallery[' + num + ']"><span class=""></span>';

			that.html(html);

			var maxNum = $('.galleryImg').last().attr('data-id'); //$('.batchImg').children('.galleryImg').length - 1;
			if (num == maxNum) {
				maxNum++;
				html = '<div class="galleryImg photo" data-id="' + maxNum +
					'" ><img src="../img/pjimg.png" class="ossfile" id="galleryImg[' +
					maxNum + ']" alt=""><input type="hidden" name="gallery[]" value="" class="gallery" id="gallery[' + maxNum +
					']"><span class=""></span></div>';
				$(".batchImg").append(html);
			}
		});
	})


	$(".oneImg").on("tap", '#shop', function() {
		// UP.init("accountBookImg", "test", "accountBookImgTag")

		UP.init("shopImg", "test", "shop")
		openCamera()
	})
	// 删除图片
	$(".batchImg").on('tap', '.delete', function(e) {

		e.preventDefault();
		e.stopPropagation()

		// //console.log(this);
		var that = $(this)
		//var idx = that.parent().attr('data-id');
		//var maxNum = $('.galleryImg').last().attr('data-id'); //$('.batchImg').children('.galleryImg').length - 1;
		if (confirm('确认删除图片？')) {
			that.parent().remove()
			//delete galleryarr[idx];
		}
	})
	// 提交
	var click = false;
	$('.bc_btn').on('tap', function() {
		if (click == true) {
			return
		}

		var imgs = '';
		var data = $('input[name="gallery[]"]');
		// //console.log(data);
		$.each(data, function() {
			if ('' != $(this).val())
				imgs = $(this).val() + ',' + imgs;

		})
		imgs = imgs.substring(0, imgs.lastIndexOf(','));
		$('#shopAds').val(imgs);
		if ($.trim($('#shopImg').val()) == '') {
			mui.alert("请上传店铺主图")
			return
		}
		if ($.trim($('#shopAds').val()) == '') {
			mui.alert("请上传店铺图片")
			return
		}
		var params = JZL.getParams(".inp");
		params.shopId = shopId;
		click == true;
		JZL.ajax(qlgUrl('app/shops/uploadShopImg'), params, function(data) {
			if (data.status == 1) {
				mui.toast('保存成功');
				mui.back();
			} else {
				mui.alert(data.msg);
			}
		})
	})



})
