
<!-- 
	data-bindelem:
		绑定元素
		
	data-filepaths：
		回显数据图片路径	
		
	data-type:
		1:图片上传
		2:文件上传
		
	data-maxnum：
		可最大上传的数量	
		
		

 -->


<div id="pluguploaddiv1_three" style="display: none">
	<span class="layui-upload" >
	  <button type="button" class="layui-btn " id="pluguploadbutton1_three"><i class="layui-icon">&#xe60d;</i>上传图片 <i style="margin-left: 10px;display: none" class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i></button>
	  </span>
	 <span class="layui-upload-list" id="pluguploadimg1_three"></span>
</div>


<script>
var sysUrl_three="[[${sysUrl}]]";
var imgUrl_three="[[${imgUrl}]]";
var type_three=$("#pluguploadid_three").data("type");
var width_three=$("#pluguploadid_three_three").data("imgwidth");
var height_three=$("#pluguploadid_three").data("imgheight");
var maxnum_three=$("#pluguploadid_three").data("maxnum");
var bindelem_three=$("#pluguploadid_three").data("bindelem");
var filePaths_three=$("#pluguploadid_three").data("filepaths");

if(type_three==undefined || type_three=='undefined' || type_three==null || type_three==''){
	type_three=1;
}
if(maxnum_three==undefined || maxnum_three=='undefined' || maxnum_three==null || maxnum_three==''){
	maxnum_three=10;
}
if(bindelem_three==undefined || bindelem_three=='undefined' || bindelem_three==null || bindelem_three==''){
	bindelem_three=null;
}
if(filePaths_three==undefined || filePaths_three=='undefined' || filePaths_three==null || filePaths_three==''){
	filePaths_three=null;
}

layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  if(bindelem_three!=null && filePaths_three!=null){
		$(bindelem_three).val(filePaths_three);
		var fps=filePaths_three.split(";");
		for (var i = 0; i < fps.length; i++) {
		 $('#pluguploadimg'+type+'_three').append('<span class="pluguploadimgcss"  style="width: 100px;height:100px"><i onclick="deletepulgimg_three(this,\''+fps[i]+'\')" class="layui-icon layui-icon-close g_icon"></i><img onclick="openpulgimg(this)" src="'+ imgUrl+fps[i] +'"  style="width:100%"  class="layui-upload-img "></span>') 
		}
	}
	$("#pluguploaddiv"+type+"_three").show();
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#pluguploadbutton1_three'
    ,url: '[[${sysUrl}]]/file/uploads'
    ,before: function(obj){
      $(".layui-icon-loading").show();
      obj.preview(function(index, file, result){//预读本地文件示例，不支持ie8
    	
      });
    },done: function(res){
      $(".layui-icon-loading").hide();
      if($(bindelem_three).val().split(";").length>=maxnum_three){
		  return layer.msg('上传文件已超过最大值');
	  }
      if(res.code == '000'){
    	  return layer.msg('上传失败,刷新后重试！');
      }
      layer.msg('上传成功');
      if(res != null && res != ""){
		 var obj = res;
		 var filePath = obj.data.pics[0].filePath;
		 var fileCode = obj.data.pics[0].fileCode;
		 var fileExt = obj.data.pics[0].fileExts;
		 var id = obj.data.pics[0].id;
		 var name = obj.data.pics[0].name;
		 var fileWidth = obj.data.pics[0].fileWidth;
		 var fileHeight = obj.data.pics[0].fileHeight;
		 var fileName = obj.data.pics[0].fileName;
		 var fileSize = obj.data.pics[0].fileSize;
		 var fileThumPath = obj.data.pics[0].fileThumPath;
		 $('#pluguploadimg1_three').append('<span class="pluguploadimgcss"  style="width: 100px;height:100px"><i onclick="deletepulgimg_three(this,\''+filePath+'\')" class="layui-icon layui-icon-close g_icon"></i><img onclick="openpulgimg(this)" src="'+ fileThumPath +'"  style="width:100%"  class="layui-upload-img "></span>') //图片链接（base64）
		 if(bindelem_three!=null){
			$(bindelem_three).val($(bindelem_three).val()!=''? $(bindelem_three).val()+";"+filePath : filePath);
		 }
	   }
    },error: function(){
    	  $(".layui-icon-loading").hide();
    	  return layer.msg('上传失败,刷新后重试！');
    }
  });
});

function deletepulgimg_three(obj,filePath){
	$(obj).parent().remove();
	$(bindelem_three).val($(bindelem_three).val().replace(filePath+";",""));
	$(bindelem_three).val($(bindelem_three).val().replace(";"+filePath,""));
	$(bindelem_three).val($(bindelem_three).val().replace(filePath,""));
}




</script>
