mui.init({
	beforeback: function() { //获得父页面的webview
		var list = plus.webview.currentWebview().opener(); //触发父页面的自定义事件(refresh),从而进行刷新
		mui.fire(list, 'reload');
		//返回true,继续页面关闭逻辑
		return true;
	}
});
$(".pricset_con").hide();
function escape2Html(str) {
	var arrEntities = {
		'lt': '<',
		'gt': '>',
		'nbsp': ' ',
		'amp': '&',
		'quot': '"'
	};
	return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, i) {
		return arrEntities[i];
	});
};
mui.plusReady(function() {

	var self = plus.webview.currentWebview();
	// ////console.log(self);
	var shopId = self.id;
	var goodsId = self.goodsId;
	var richText = '';

	var E = window.wangEditor
	var editor = new E('#goodsDesc')
	// 			 editor.customConfig.showLinkImg = false  // 隐藏“网络图片”tab  
	// 			    editor.customConfig.uploadFileName = 'yourFileName'      //给上传的本地图片文件命名的统一名称  
	// 			    editor.customConfig.uploadImgServer = '/upload'; //官方文档上写的是服务器地址，也就是上传图片的方法名 

	// 允许上传到七牛云存储
	editor.customConfig.qiniu = true;
	editor.customConfig.debug = true;
	// 			editor.customConfig.onchange = function (html) {
	// 					// 监控变化，同步更新到 textarea
	// 					// $text1.val(html)
	// 			};
	editor.create();
	// 初始化七牛上传


	if (goodsId > 0) {
		$(".title").text("编辑商品")

		JZL.ajax(qlgUrl("app/shops/getGoodsInfo"), {
			shopId: shopId,
			goodsId: goodsId
		}, function(data) {
			//console.log(data);
			if (data.status == 1) {
				var html1 = '';
				var data = data.data;
				var i = 0,
					j = 0;
				var res = '';
				var bjSpec = data.isSpec;
				if (1 == data.isSpec) {
					$(".pricset_con").show()
					var id = data.setNameId;

					// ////console.log(id);
					getRecommend(page, pageSize, id)

					JZL.ajax(qlgUrl('app/shops/getGoodsSpecCats'), {
						shopId: shopId,
						id: id
					}, function(data1) {
						//console.log(data1);
						if (1 == data1.status) {
							var that = this
							var arr = [];
							var arr2 = {};
							for (var i = 0; i < data1.data.length; i++) {
								arr.push(data1.data[i].list);
								arr2[data1.data[i].catId] = data1.data[i].list;
							}

							// ////console.log(a);
							var cLength = 0;
							var catId = 0;
							var goodsRes = "";
							if (arr.length > 0) {
								var tmpI = 0;
								var a = combins(arr);
								while (true) {
									if (arr.length > 1) {
										c = a.next();
										if (!c) break;
										cLength = c.length;
										res = c.join(' ');
									} else {
										if (tmpI >= arr[0].length) {
											break;
										}
										c = arr[0];
										res = arr[0][tmpI];
										cLength = arr[0].length;
									}
									tmpI++;
									// ////console.log(c);
									// ////console.log(res);
									for (i = 0; i < cLength; i++) {
										$.each(arr2, function(ind, val) {
											$.each(val, function(index, value) {
												if (value == c[i]) {
													catId = ind;
													return;
												}
											});

										})
										html1 += '<input type="hidden" name="specItemIds[]" id="specItemIds[' + j + '][' + i +
											']" class="inp" value="0" />' + //属性值id
											'<input type="hidden" name="specNamesId[]" id="specNamesId[' + j + '][' + i + ']" class="inp" value="' +
											catId + '" />' + //分类ID
											'<input type="hidden" name="specItems[]" id="specItems[' + j + '][' + i + ']" class="inp" value="' + c[
												i] + //属性值
											'" />';
									}
									//console.log(j);
									html1 += '<input type="hidden" name="specIds[]" id="specIds[' + j + ']" class="inp" value="0" />' + //规格表ID 新增传0
										'<div class="addcon_con shadown_wai"><div class="radio"><input  name="defaultId" type="radio" value="' +
										j + '" /></div><label for="" data-id = "' + j +
										'"  name="showSpecNames[]" class="">' + res +
										'</label><input type="text" name="specPrice[]" id="specPrice[' + j +
										']" class="inp label-t" value="" /><input type="text" name="specStock[]" id="specStock[' + j +
										']" class="inp label-t" value=""/></div>';
									j++;
								}

								$('.pricset_con_con').html(html1);
								var setNum = 0;
								mui.each(data.spec, function(idx, val) {
									if (cLength != val.names.length) return false;
									goodsRes = '';
									i = 0;
									if (arr.length > 1) {
										mui.each(val.names, function(index, value) {
											goodsRes += value.itemName + ' '; //hongse 39ma
										})
									} else {
										// //console.log(val);
										//console.log(val.names);
										goodsRes = val.names[setNum].itemName;
										setNum++;
									}
									var showSpecNames = $('label[name="showSpecNames[]"]');
									var specNameArr = [];
									for (var k = 0; k < showSpecNames.length; k++) {
										specNameArr[$(showSpecNames[k]).attr('data-id')] = $(showSpecNames[k]).text();
									}
									$.each(specNameArr, function(sitem, sval) {
										if ($.trim(goodsRes) == $.trim(sval)) { //去除空格  不然报错
											i = 0;
											mui.each(val.names, function(index, value) {
												// ////console.log(i);
												document.getElementById('specItemIds[' + +sitem + '][' + i + ']').value = value.itemId //属性值ID 新增传0
												i++;
											});
											document.getElementById('specIds[' + +sitem + ']').value = val.id //规格表ID，新增传0
											document.getElementById('specPrice[' + +sitem + ']').value = val.specPrice
											document.getElementById('specStock[' + +sitem + ']').value = val.specStock
											if (1 == val.isDefault) {

												//checked
												var inputList = $('input[name=defaultId]')


												$.each(inputList, function(index, value) {
													// ////console.log(value, index);
													this.previousElementSibling
													if (sitem == this.value) {
														this.checked = true
													}
												})
											}

										}
									})

								})
							}
						}
					})


				} else if (0 == data.isSpec) {
					// $('#setNameId').html('<option value="0">选择属性</option>')
					getRecommend(page, pageSize)
				}
				if (1 == data.isSale) {
					$('#isSale').prop("checked", "checked");
				}
				mui.each(data, function(index, element) {
					if ($('#' + index).attr("type") == "hidden" & $('#' + index).hasClass('inp')) {
						var imgindex = index.substring(0, index.length - 3);
						var obj = '#' + imgindex;
						if ($(obj).is('img')) {
							$(obj).attr("src", hyhImgUrl(element))
							$('#' + index).val(element)
						} else if ($('#' + index).hasClass('gallery')) {
							var html = '';
							if (element.length > 0) {
								var imgurls = element.split(",") ? imgurls = element.split(",") : imgurls = element;
								html = ''
								for (var i = 0; i < imgurls.length; i++) {
									html += '<div data-id="' + i +
										'"  data-src="" class="galleryImg photo"><div class="delete"><img src="../img/close.png" alt=""></div><img src=' +
										hyhImgUrl(imgurls[i]) + ' class="ossfile" id="galleryImg[' + i +
										']" alt=""><input type="hidden" value="' + imgurls[i] +
										'" name="gallery[]" class="gallery" id="gallery[' + i + ']"><span class=""></span></div>'
									// $('#' + index+'Img['+i+']').val(hyhImgUrl(imgurls[i]))
								}
								var maxNum = +$('.galleryImg').last().attr('data-id') + 1; //$('.batchImg').children('.galleryImg').length - 1;
								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 {
								html = "";
								html =
									'<div class="galleryImg photo" data-id="0" ><img src="../img/pjimg.png" class="ossfile" id="galleryImg[0]" alt=""><input type="hidden" name="gallery[]" value="" class="gallery" id="gallery[0]"><span class=""></span></div>';
								$(".batchImg").html(html)
							}
						}
					} else if (index == 'goodsCatIdPath') {
						// data.goodsCatIdPath  三级目录
						var goodsCatIdPathArr = [];
						var pathArr = ["largeCat", "mediumCat", "smallCat"]
						// ////console.log(data.goodsCatIdPath);
						goodsCatIdPathArr = data.goodsCatIdPath.split('_')
						goodsCatIdPathArr.pop() //移除最后一个数组元素 _
						mui.each(pathArr, function(idx, ele) {
							// ////console.log(idx);
							switch (ele) {
								case 'largeCat':
									getCatIdPathName(goodsCatIdPathArr[0], function(data) {
										getGoodsCats('largeCat', 0, goodsCatIdPathArr[0]);
									})
									break;
								case 'mediumCat':
									getCatIdPathName(goodsCatIdPathArr[1], function(data) {
										$('#mediumCat').html('<option selected value="' + goodsCatIdPathArr[1] + '">' + data.data.catName +
											'</option>')
									});
									break;
								case 'smallCat':
									getCatIdPathName(goodsCatIdPathArr[2], function(data) {
										$('#smallCat').html('<option selected value="' + goodsCatIdPathArr[2] + '">' + data.data.catName +
											'</option>')
									});
									break;
							}
						})

					} else {
						$('#' + index).val(element)
					}
				})
				if ('' != data.goodsDesc) {
					var Desc = escape2Html(data.goodsDesc)
					// var Desc= HtmlUtils.htmlUnescape(data.goodsDesc)
					////console.log(Desc)
					// $('#goodsDesc').val(Desc)
					// $('#goodsDesc').html(Desc)
					editor.txt.html(Desc)
				}

				// params.goodsDesc = editor.txt.html();

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

	} else {
		getGoodsCats("largeCat", 0)
		getRecommend(page, pageSize);

		$(".title").text("添加商品")
	}


	function getCatIdPathName(catId, callback) {
		JZL.ajax(qlgUrl("app/goodscats/getCatName"), {
			catId: catId
		}, function(data) {
			callback(data);
		})
	}

	//获取商品总规格列表
	var page = 1;
	var pageSize = 100;
	var isjiazai = 1;

	function getRecommend(page, pageSize, defaultVal) {

		var recommenddata = {
			page: page ? page : 1,
			pageSize: pageSize ? pageSize : 100
		}
		recommenddata.shopId = shopId
		if (isjiazai == 0) {
			return;
		} else {
			isjiazai = 0;
		}
		JZL.ajax(qlgUrl('app/shops/getSpecs'), recommenddata, function(data) {


			// ////console.log(data);
			data = toJson(data);
			if (data.status == 1) {
				data = data.data;
				var html = '<option value="0">无规格属性</option>';
				if (typeof(defaultVal) == "undefined") {
					// ////console.log(1);
					$.each(data.Rows, function() {
						html += '<option  value= "' + this.id + '" data-id="' + this.id + ' ">' + this.setName + '</option>'
					});
					if (page == 1) {
						$('#setNameId').html(html);

					} else {
						$('#setNameId').append(html);

					}
				} else {
					// ////console.log(defaultVal);
					$.each(data.Rows, function() {
						if (this.id == defaultVal) {
							selected = 'selected';
						} else {
							selected = '';
						}
						html += '<option  data-id="' + this.id + '" value="' + this.id + '" ' + selected + '>' + this.setName +
							'</option>';

					});
					if (page == 1) {
						$('#setNameId').html(html);

					} else {
						$('#setNameId').append(html);

					}

				}

			} else {
				// mui.alert('发生错误请刷新后重试！');
				mui.alert(data.msg);
				//							location.reload();
			}
			isjiazai = 1;
		})
	}

	//获取商品规格
	// 笛卡尔积
	combins = function(args) {

		if (args.length < 2) return args[0] || [];
		// if (arguments.length < 2) return arguments[0] || [];
		//var args = Array.prototype.slice.call(arguments);
		var that = {
			index: 0,
			nth: function(n) {
				var result = [],
					d = 0;
				for (; d < this.dim; d++) {
					var l = this[d].length;
					var i = n % l;
					result.push(this[d][i]);
					n -= i;
					n /= l;
				}
				return result;
			},
			next: function() {
				if (this.index >= size) return;
				var result = this.nth(this.index);
				this.index++;
				return result;
			}
		};
		var size = 1;
		for (var i = 0; i < args.length; i++) {
			size = size * args[i].length;
			that[i] = args[i];
		}
		that.size = size;
		that.dim = args.length;
		return that;
	}



	$('#setNameId').change(function() {
		var id = $('#setNameId option:selected').attr('data-id')
		// ////console.log(id);

		var html1 = "";
		if (typeof id == "undefined" || 0 == id) {
			$(".pricset_con").hide()
		} else {
			$(".pricset_con").show()
			JZL.ajax(qlgUrl('app/shops/getGoodsSpecCats'), {
				shopId: shopId,
				id: id
			}, function(data) {
				// ////console.log(data);
				if (1 == data.status) {
					html1 = "";
					var arr = [];
					var arr2 = {};
					for (var i = 0; i < data.data.length; i++) {
						arr.push(data.data[i].list);
						arr2[data.data[i].catId] = data.data[i].list;
					}

					var j = 0;
					var res = '';
					var cLength = 0;
					var catId = 0;
					var tmpI = 0;
					var a = combins(arr);
					while (true) {
						if (arr.length > 1) {
							c = a.next();
							if (!c) break;
							cLength = c.length;
							res = c.join(' ');
						} else {
							if (tmpI >= arr[0].length) {
								break;
							}
							c = arr[0];
							res = arr[0][tmpI];
							cLength = arr[0].length;
						}
						tmpI++;
						for (i = 0; i < cLength; i++) {
							$.each(arr2, function(ind, val) {
								$.each(val, function(index, value) {
									if (value == c[i]) {
										catId = ind;
										return;
									}
								});

							})
							html1 += '<input type="hidden" name="specItemIds[]" id="specItemIds[' + j + '][' + i +
								']" class="inp" value="0" />' +
								'<input type="hidden" name="specNamesId[]" id="specNamesId[' + j + '][' + i + ']" class="inp" value="' +
								catId + '" />' +
								'<input type="hidden" name="specItems[]" id="specItems[' + j + '][' + i + ']" class="inp" value="' + c[i] +
								'" />';

						}
						html1 += '<input type="hidden" name="specIds[]" id="specIds[' + j + ']" class="inp" value=\'0\' />' +
							'<div class="addcon_con shadown_wai"><div class="radio"><input name="defaultId" type="radio" value="' + j +
							'" /></div><label for="" class="">' +
							res +
							'</label><input type="text" name="specPrice[]" id="specPrice[' + j +
							']" class="inp label-t" value="" /><input type="text" name="specStock[]" id="specStock[' + j +
							']" class="inp label-t" value=""/></div>'
						j++;
					}
					$('.pricset_con_con').html(html1);
				} else {
					mui.alert(data.msg)
				}
			})
		}
	})

	// 下一页
	var check = true;
	mui("body").on('tap', '.next_btn', function() {
		check = true;
		$('.isemptyinp').each(function() {
			if (!this.value || "" == $.trim(this.value)) {
				var label = this.previousElementSibling;
				mui.alert(label.innerText + "不允许为空")
				check = false;
				return false;
			}
		})

		if ($("#shopPrice").val() == "" & $("#setNameId option:selected").val() == "0" & check == true) {
			mui.alert("商品没有属性必须输入商品价格")
			check = false;
			return false;
		}
		if ($("#setNameId option:selected").val() != 0 && check == true) {

			if ($('input[name="defaultId"]:checked').length == 0) {
				mui.alert("请选择默认规格")
				check = false;
				return false
			}
			$('.pricset_con_con input').each(function() {
				if ((!$(this).val() || "" == $.trim(this.value))) {


					mui.alert("请输入数据")
					$(this).focus();
					check = false;
					return false;
				}
			})
		}
		// var shopPrice= $('input[name="defaultId"]:checked').parent().parent().find('input[name="specPrice[]"]').val();
		// 			////console.log(shopPrice)
		if ($("#isSale").prop("checked")) {
			isSale = "1";
		} else {
			isSale = "0";
		}
		if (check == true) {
			$(".addcon").css("display", "none")
			$(".pre").css("display", "block");
			backTop();

		}


	})
	//预览
	$('.prelook').hide();
	// 	mui("body").on('tap', '.prelook', function() {
	// 
	// 
	// 
	// 	})
	// 上一页
	mui('body').on('tap', '.pre_btn', function() {
		$(".addcon").css("display", "block")
		$(".pre").css("display", "none")
	})
	// ////console.log($("#goodsDesc").text());

	//提交
	// 判断是否上架
	var isSale = "",
		setNameId,
		isSpec;

	// ////console.log(typeof($("#setNameId option:selected").val()));


	//提交
	var click = false;
	mui('.btn').on('tap', '.submit_btn ', function() {
		richText = editor.txt.text()
		// 判断有没有商品属性	
		if ($("#setNameId option:selected").val() != 0) {
			isSpec = 1;
		} else {
			isSpec = 0;
		}
		if (click == true) {
			return
		}

		if ($("#isSale").prop("checked")) {
			// ////console.log(1);
			isSale = "1";
		} else {
			// ////console.log(0);
			isSale = "0";
		}
		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(','));


		$('#gallery').val(imgs);
		//默认选中
		var defaultPrice = $('input[name="defaultId"]:checked').parent().parent().find('input[name="specPrice[]"]').val();
		var params = JZL.getParams(".inp");
		params.shopId = shopId;
		params.isSale = isSale;
		params.isSpec = isSpec;
		params.defaultId = $('input[name="defaultId"]:checked').val();
		params.goodsDesc = editor.txt.html();
		params.setNameId = $('#setNameId option:selected').val()
		if (isSpec == 1) {
			// params.shopPrice = shopPrice
			$('#shopPrice').val(defaultPrice);

		}
		params.shopPrice = $('#shopPrice').val()
		click = true;
		if (goodsId > 0) {
			params.goodsId = goodsId;

		}
		// alert(editor.txt.html())
		JZL.ajax(qlgUrl('app/shops/addGoods'), params, function(data) {
			// ////console.log(data);
			if (data.status == 1) {
				mui.toast(data.msg);
				mui.back();
			} else {
				// mui.alert('发生错误请刷新后重试！');
				//							location.reload();
				mui.alert(data.msg)
			}

		})


	})

	//获取类目
	$('.selectarea').on("change", ".area", function() {
		var objs = ['largeCat', 'mediumCat', 'smallCat'];
		// var areaStr = ['请选择', '请选择', '请选择'];
		var level = +$(this).attr('data-level') + 1; //0
		pid = $('#' + objs[level - 1] + ' option:selected').val();
		getGoodsCats(objs[level], pid);

	})

	//三级类目
	function getGoodsCats(obj, pid, defaultId) {
		JZL.ajax(qlgUrl('app/shops/getGoodsCats'), {
				pid: pid
			},
			function(data) {
				// ////console.log(data);
				if (data.status == 1) {
					data = data.data;
					var html = '<option value="">' + "请选择" + '</option>';
					if ('undefined' == typeof(defaultId)) {
						$.each(data, function() {
							// ////console.log(this);
							html += '<option value="' + this.catId + '">' + this.catName + '</option>'
						});
					} else {
						$.each(data, function() {
							if (this.catId == defaultId) {
								selected = 'selected';
							} else {
								selected = '';
							}
							html += '<option value="' + this.catId + '" ' + selected + '>' + this.catName + '</option>'
						});
					}
					$('#' + obj).html(html);
				}
			})
	}

	// 上传图片
	$(".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>';
			//	////console.log($('#galleryImg[' + num + ']'));
			//if ($('#galleryImg[' + num + ']').length > 0) {
			that.html(html);
			//} else {
			//	$(".batchImg").append(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", '#goods', function() {
		// UP.init("accountBookImg", "test", "accountBookImgTag")

		UP.init("goodsImg", "test", "goods")
		openCamera(function(t, status, fileName, serverName) {
			var html = '<img src="' + serverName + '" class="ossfile" data-src="' + fileName +
				'" id="goods" alt=""><input type="hidden" value="' + fileName +
				'" class="goodsImg inp" id="goodsImg"><span class=""></span>';

			$(".goods").html(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];
		}
	})
	//上传图片到七牛；

	var uptoken = '';
	var rs = send_request();
	rs = JSON.parse(rs);

	uptoken = rs.token;

	function send_request() {
		var xmlhttp = null;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if (xmlhttp != null) {
			//		////console.log(dir)
			serverUrl = hyhUrl('oss/qiniu.php');
			xmlhttp.open("GET", serverUrl, false);
			xmlhttp.send(null);
			return xmlhttp.responseText
		} else {
			mui.alert("Your browser does not support XMLHTTP.");
		}

	};


	// 初始化七牛上传的方法
	function uploadInit() {
		var btnId = editor.imgMenuId;
		var containerId = editor.toolbarElemId;
		var textElemId = editor.textElemId;
		// 创建上传对象
		var uploader = Qiniu.uploader({
			runtimes: 'html5,flash,html4', //上传模式,依次退化
			browse_button: btnId, //上传选择的点选按钮，**必需**
			//uptoken_url: rs,
			//Ajax请求upToken的Url，**强烈建议设置**（服务端提供）
			uptoken: uptoken,
			// url: 'http://up-z1.qiniup.com',

			// uptoken : '<Your upload token>',
			//若未指定uptoken_url,则必须指定 uptoken ,uptoken由其他程序生成
			// unique_names: true,
			// 默认 false，key为文件名。若开启该选项，SDK会为每个文件自动生成key（文件名）
			// save_key: true,
			// 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`，则开启，SDK在前端将不对key进行任何处理
			// domain: 'http://7xrjl5.com1.z0.glb.clouddn.com/',
			// domain:$('#domain').val(),
			domain: rs.url,

			//bucket 域名，下载资源时用到，**必需**
			container: containerId, //上传区域DOM ID，默认是browser_button的父元素，
			max_file_size: '100mb', //最大文件体积限制
			flash_swf_url: '../js/plupload/Moxie.swf', //引入flash,相对路径
			filters: {
				mime_types: [
					//只允许上传图片文件 （注意，extensions中，逗号后面不要加空格）
					{
						title: "图片文件",
						extensions: "jpg,gif,png,bmp"
					}
				]
			},
			max_retries: 3, //上传失败最大重试次数
			dragdrop: true, //开启可拖曳上传
			drop_element: textElemId, //拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传
			chunk_size: '4mb', //分块上传时，每片的体积
			auto_start: true, //选择文件后自动上传，若关闭需要自己绑定事件触发上传
			init: {
				'FilesAdded': function(up, files) {
					plupload.each(files, function(file) {
						// 文件添加进队列后,处理相关的事情
						// printLog('on FilesAdded');
					});
				},
				'BeforeUpload': function(up, file) {
					// 每个文件上传前,处理相关的事情
					// printLog('on BeforeUpload');
				},
				'UploadProgress': function(up, file) {
					// 显示进度
					// printLog('进度 ' + file.percent)
				},
				'FileUploaded': function(up, file, info) {
					// 每个文件上传成功后,处理相关的事情
					// 其中 info 是文件上传成功后，服务端返回的json，形式如
					// {
					//    "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
					//    "key": "gogopher.jpg"
					//  }
					// printLog(info);
					// 参考http://developer.qiniu.com/docs/v6/api/overview/up/response/simple-response.html

					var domain = up.getOption('domain');
					var res = $.parseJSON(info);
					var sourceLink = domain + res.key; //获取上传成功后的文件的Url
					// 插入图片到editor
					editor.cmd.do('insertHtml', '<img src="' + sourceLink + '" style="max-width:100%;"/>')
				},
				'Error': function(up, err, errTip) {
					//上传出错时,处理相关的事情
					// printLog('on Error');
				},
				'UploadComplete': function() {
					//队列文件处理完毕后,处理相关的事情
					// printLog('on UploadComplete');
				}
				// Key 函数如果有需要自行配置，无特殊需要请注释
				//,
				// 'Key': function(up, file) {
				//     // 若想在前端对每个文件的key进行个性化处理，可以配置该函数
				//     // 该配置必须要在 unique_names: false , save_key: false 时才生效
				//     var key = "";
				//     // do something with key here
				//     return key
				// }
			}
			// domain 为七牛空间（bucket)对应的域名，选择某个空间后，可通过"空间设置->基本设置->域名设置"查看获取
			// uploader 为一个plupload对象，继承了所有plupload的方法，参考http://plupload.com/docs
		});
	}
	uploadInit();
	// 封装 ////console.log 函数
	function printLog(title, info) {
		window.console && console.log(title, info);
	}
})
