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

 -->


<div id="pluguploaddiv1_four" style="display: none">
	<span class="layui-upload" >
	  <button type="button" class="layui-btn " id="pluguploadbutton1_four"><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_four"></span>
</div>


<script>
var sysUrl_four="[[${sysUrl}]]";
var imgUrl_four="[[${imgUrl}]]";
var type_four=$("#pluguploadid_four").data("type");
var width_four=$("#pluguploadid_four_four").data("imgwidth");
var height_four=$("#pluguploadid_four").data("imgheight");
var maxnum_four=$("#pluguploadid_four").data("maxnum");
var bindelem_four=$("#pluguploadid_four").data("bindelem");
var filePaths_four=$("#pluguploadid_four").data("filepaths");

if(type_four==undefined || type_four=='undefined' || type_four==null || type_four==''){
	type_four=1;
}
if(maxnum_four==undefined || maxnum_four=='undefined' || maxnum_four==null || maxnum_four==''){
	maxnum_four=10;
}
if(bindelem_four==undefined || bindelem_four=='undefined' || bindelem_four==null || bindelem_four==''){
	bindelem_four=null;
}
if(filePaths_four==undefined || filePaths_four=='undefined' || filePaths_four==null || filePaths_four==''){
	filePaths_four=null;
}

layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  if(bindelem_four!=null && filePaths_four!=null){
		$(bindelem_four).val(filePaths_four);
		var fps=filePaths_four.split(";");
		for (var i = 0; i < fps.length; i++) {
		 $('#pluguploadimg'+type+'_four').append('<span class="pluguploadimgcss"  style="width: 100px;height:100px"><i onclick="deletepulgimg_four(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+"_four").show();
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#pluguploadbutton1_four'
    ,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_four).val().split(";").length>=maxnum_four){
		  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_four').append('<span class="pluguploadimgcss"  style="width: 100px;height:100px"><i onclick="deletepulgimg_four(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_four!=null){
			$(bindelem_four).val($(bindelem_four).val()!=''? $(bindelem_four).val()+";"+filePath : filePath);
		 }
	   }
    },error: function(){
    	  $(".layui-icon-loading").hide();
    	  return layer.msg('上传失败,刷新后重试！');
    }
  });
});

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




</script>
