mui.plusReady(function() {

	var self = plus.webview.currentWebview();
	//console.log(self);


	var id = self.scid ? self.scid : '';
	JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
		applyLevel: 2
	}, function(data) {
		//console.log(data);
		if (1 == data.status && undefined != data.data) {
			var data = data.data;

			if (0 == data.status || 2 == data.status) {
				//console.log(id);
				if (id == "") {
					id = data.id
				}
				getShopList(data.shopId);

				$('#confirm').attr('src', hyhImgUrl(data.confirmImg))
				$('#confirmImg').val(data.confirmImg)

				var imgs = data.shopImg
				imgs = Array.from(imgs.split(','))
				//console.log(imgs);
				var html = "";
				mui.each(imgs, function(index, element) {
					//console.log(index, element);
					html += '<div class="galleryImg photo" data-id="' + index +
						'" ><div class="delete" data-id="' + index + '"><img src="../img/close.png" alt=""></div><img src="' +
						hyhImgUrl(element) + '" class="ossfile" data-src="' + element + '" data-id="' + index + '" id="galleryImg[' +
						index +
						']" alt=""><input type="hidden" name="gallery[]" value="' + element +
						'" class="gallery" id="gallery[' + index + ']"><span class=""></span></div>';
				})
				// var maxNum = $('.galleryImg').last().attr('data-id'); //$('.batchImg').children('.galleryImg').length - 1;
				var maxNum = imgs.length - 1;
				// 				//console.log(maxNum);
				// 				//console.log(num);
				// 				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").html(html);
				// }

				//获取协议
				JZL.ajax(qlgUrl('app/Tags/articleDetail'), {
					articleId: 115
				}, function(data) {
					//console.log(data);
					// if (1==data.status) {
					// $('.zcxycontent').html(data.data.articleContent)
					$('.zcxycontent').html(data.articleContent)

					// }

				})

			} else if (1 == data.status) {
				//tiaozhuandao shangdu yemian 
			}
		} else if ('' == data.data) {
			getShopList();
			JZL.ajax(qlgUrl('app/Tags/articleDetail'), {
				articleId: 115
			}, function(data) {
				//console.log(data);
				// if (1==data.status) {
				// $('.zcxycontent').html(data.data.articleContent)
				$('.zcxycontent').html(data.articleContent)

				// }

			})
		}
	})
	// 上传图片
	$('.photos_con').on('tap', '.confirm', function() {
		UP.init("confirmImg", "test", "confirm")
		openCamera()
	})
	$(".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);
			}
		});
	})
	//删除照片
	$(".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];
		}
	})
	//获取协议
	JZL.ajax(qlgUrl('app/Tags/articleDetail'), {
		articleId: 115
	}, function(data) {
		//console.log(data);
		// if (1==data.status) {
		// $('.zcxycontent').html(data.data.articleContent)
		$('.zcxycontent').html(data.articleContent)

		// }

	})
	//获取店铺信息
	getShopList()

	function getShopList(defaultShopId) {

		JZL.ajax(qlgUrl('app/shops/userShopList'), {
			shopType: 1
		}, function(data) {
			//console.log(data);
			if (1 == data.status) {
				var html = "";
				html = `<option value ="">选择店铺</option>`;
				if (undefined == typeof defaultShop) {

					mui.each(data.data, function() {
						// //console.log(index,  element);
						html += `<option value =${this.shopId}>${this.shopName}</option>`;
					})
				} else {
					mui.each(data.data, function() {
						if (this.shopId == defaultShopId) {
							selected = 'selected';
						} else {
							selected = '';
						}
						html += `<option value =${this.shopId} ${selected}>${this.shopName}</option>`;
					})

				}
				$("#shopId").html(html)
			} else {
				mui.alert(data.msg)
			}
			// })
		})


	}
	let click = 0;
	$('.down').on('tap', '.btn', function() {

		if (click == 1) {
			return;
		}
		click = 1
		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(','));
		$('#shopImg').val(imgs);
		if ('' == $('#shopId option:selected').val()) {
			mui.alert('请选择要升级的店铺名称')
			return;
		}

		if ('' == $('#confirmImg').val()) {
			mui.alert('请上传确认书照片')
			return;
		}
		if ('' == $('#shopImg').val()) {
			mui.alert('请上传店铺照片')
			return;
		}


		var params = JZL.getParams(".inp");
		params.applyLevel = 2;
		if ("" != id) {
			params.id = id;
			//console.log(params.id);
		}
		JZL.ajax(qlgUrl('app/shops/userUpdate'), params, function(data) {
			// //console.log(data);
			if (1 == data.status) {
				// mui.back()	
			} else {
				mui.alert(data.msg)
			}
		})
	})




})
