var tmpl=`
<el-upload ref="upload"
  class="upload"
  :action="action"
  :data="d"
  :multiple="multiple"
  :on-exceed="onExceed"
  :accept="accept"
  :before-upload="beforeUpload"
  :on-success="success"
  :on-remove="remove"
  :on-error="error"
  :on-progress="progress"
  :show-file-list="showlist"
  :on-preview="preview">
  <slot><el-button type="primary" >文件上传</el-button></slot>
</el-upload>
`
module.exports=
`{
   template:'${tmpl}',
   model:{
    prop: 'value',
    event: 'uploadsuccess'
   },
   props:["d","action","listtype","filetype","ifshowlist","value","flag","dataSouce"],
   data:function(){
     return {
       data:this.d,
       action:this.action,
       result:"",
       multiple:false,
       accept:"",
       showlist:true,
       drag:false,
       listtype:"text",
       flag:this.flag,
       dataSouce:this.dataSouce,
     };
   },
   mounted:function(){
    if(this.filetype!=undefined && this.filetype!=null){
      this.accept=this.filetype;
    }
    if(this.ifshowlist!=undefined && this.ifshowlist!=null){
      this.showlist=this.ifshowlist;
    }
   },
   created:function(){

   },
   methods:{
     abort(file){
        this.$refs.upload.abort(file);
     },
     getResult(){
        return this.result;
     },
     onExceed(files, fileList){
       this.$emit('onExceed',files, fileList);
     },
     beforeUpload(file){
       this.$emit('beforeUpload',file);
       if(this.accept!="" && (this.accept.indexOf(file.type) == -1 || file.type=="" || file.type==null)){
          this.$message.warning('文件格式错误，请上传'+this.accept+'格式文件');
          return false;
       }
       this.result="";
       var myDate = new Date();
       var key = "zc_"+Math.round(Math.random()*500)+myDate.getMonth()+myDate.getTime()+myDate.getFullYear()+myDate.getDate()+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds()+file.name.replace(" ","");
       this.d.key=key;
       this.$emit('setKey',file.name,this.flag);
     },

     remove(file, fileList){
       this.$emit('remove',file, fileList);
     },
     error(err, file, fileList){
       this.$emit('error',err);
     },
     progress(event, file, fileList){
       console.log("progress");
     },
     preview(file){
       console.log("preview");
     },
     success(response, file, fileList){
       var xml= this.loadXML(response);
       this.result=xml.documentElement.getElementsByTagName("Location")[0].textContent;
       this.$emit('uploadsuccess',{result:this.result,file:file,fileList:fileList,key:this.d.key,flag:this.flag,dataSouce:this.dataSouce});
     },
     loadXML(xmlString){
       var xmlDoc=null;
       if(!window.DOMParser && window.ActiveXObject){
           var xmlDomVersions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
           for(var i=0;i<xmlDomVersions.length;i++){
               try{
                   xmlDoc = new ActiveXObject(xmlDomVersions[i]);
                   xmlDoc.async = false;
                   xmlDoc.loadXML(xmlString);
                   break;
               }catch(e){
               }
           }
       }
       else if(window.DOMParser && document.implementation && document.implementation.createDocument){
           try{
               domParser = new  DOMParser();
               xmlDoc = domParser.parseFromString(xmlString, 'text/xml');
           }catch(e){
           }
       }
       else{
           return null;
       }
       return xmlDoc;
     },
   },
   vname:"gsb-upload"
}`
