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

 -->


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


<script>
var sysUrl_to="[[${sysUrl}]]";
var imgUrl_to="[[${imgUrl}]]";
var type_to=$("#pluguploadid_to").data("type");
var width_to=$("#pluguploadid_to_to").data("imgwidth");
var height_to=$("#pluguploadid_to").data("imgheight");
var maxnum_to=$("#pluguploadid_to").data("maxnum");
var bindelem_to=$("#pluguploadid_to").data("bindelem");
var filePaths_to=$("#pluguploadid_to").data("filepaths");

if(type_to==undefined || type_to=='undefined' || type_to==null || type_to==''){
	type_to=1;
}
if(maxnum_to==undefined || maxnum_to=='undefined' || maxnum_to==null || maxnum_to==''){
	maxnum_to=10;
}
if(bindelem_to==undefined || bindelem_to=='undefined' || bindelem_to==null || bindelem_to==''){
	bindelem_to=null;
}
if(filePaths_to==undefined || filePaths_to=='undefined' || filePaths_to==null || filePaths_to==''){
	filePaths_to=null;
}

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

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




</script>
