var tmpl=`
/**说明：添加了获取焦点时显示历史客户的功能 目前应用于agencytmreg页面 */
 <div>
     <el-select style="width:353px" size="small" :value="value" @change="onchange" @blur="blur"  v-model="sels" clearable
     @focus="focus"
       :placeholder="placeHolder"
       :default-first-option="isFirstDefault"
       :filterable="isFilter"
       :multiple="isMulti"
       :remote="autoComplete"
       :reserve-keyword="autoComplete"
       :remote-method="remoteMethod"
       :disabled="isDisabled"
       :allow-create="allowcreatedata"
       :loading="loading">
       <template v-if="!isGrouped">
  <el-option
    v-for="(item,index) in dataSouce"
    :key="index"
    :label="labelFieldM(item)"
    :value="valueFieldM(item)"
  ></el-option>
</template>
       <template v-else>
  <el-option-group v-for="group in dataSouce" :key="group.title" :label="group.title">
    <el-option
      v-for="(item,index) in group.options"
      :key="index"
      :label="labelFieldM(item)"
      :value="valueFieldM(item)"
    ></el-option>
  </el-option-group>
</template>
     </el-select>
 </div>
`
module.exports=
`{
   template:'${tmpl}',
   model:{
    prop: 'value',
    event: 'change'
   },
   props:["frombrowser","showhistory","refwhere2","parentcode","parentfield","level","levelfield","value","refMethod","dicKey","refModel","placeHolder","autoComplete","isGrouped","isFirstDefault","isFilter","isMulti","labelField","valueField", "isDisabled","allowcreate"],
   data:function(){
     return {
       fetchtype:"bigdata",
       dataSouce:[],
       loading:false,
       sels:this.value?this.value:[],
       allowcreatedata:this.allowcreate?true:false,
       refwhere:this.refwhere2?this.refwhere2:{},
       showhistory:this.showhistory,
       frombrowser:this.frombrowser?this.frombrowser:false,
     };
   },
   mounted:function(){

   },
   watch:{
       value:function(v,old){
        if(v && this.autoComplete){
            var k=this.valueField?this.valueField:"id";
            this.refwhere={};
            this.refwhere[k]=v;
            this.fetchData();
        }else{
            this.refwhere={};
        }
        this.sels=v;
     },
     parentcode:function(v){
        this.fetchData();
     },
   },
   created:function(){
     if(!this.autoComplete){
        if(this.dicKey || this.refModel){
           this.fetchData();
        }
     }
   },
   computed:{

   },
   methods:{
     focus(){
       if(!this.sels && this.showhistory){
          this.fetchHistoryData();
       }
     },
     blur(e){
       this.$emit("input",this.sels,e);
     },
     fetchHistoryData(){
       console.log("this.frombrowser");
       console.log(this.frombrowser);
       if(this.frombrowser){
         var entList=[];
         var historyentdata = localStorage.getItem("historyentlist");
         console.log(historyentdata);
         if(historyentdata){
            historyentdata=JSON.parse(historyentdata);
            entList = historyentdata.data;
            this.fetchtype="history";
            this.dataSouce=entList;
            this.loading=false;
         }
       }else{
          this.$root.getReq("/web/customerinfoCtl/getMyCustomerEntInfo",{}).then(d=>{
            if(d && d.code==1 && d.data && d.data.length>0){
              this.fetchtype="history";
              this.dataSouce=d.data;
              this.loading=false;
            } 
          })
        }
       
     },
     setrefwhere2(v){
       this.refwhere=v;
       this.fetchData();
     },
     labelFieldM:function(item){
       return item[this.labelField];
     },
     valueFieldM:function(item){
       return item[this.valueField];
     },
     buildQuery:function(){
       var qc={};
       qc.selects=[this.labelField,this.valueField];
       return qc;
     },
     fetchData:function(slike){
       
       if(this.dicKey){
         this.$root.getReq("/web/metaCtl/getDicConfig",{"dicKey":this.dicKey}).then(cfg=>{
           console.log("cccc1111111111111ccccccc");
            this.fetchtype="bigdata";
            Object.keys(cfg.data).forEach(key=>{
               this.dataSouce.push({"label":cfg.data[key],"value":key});
            });
         });
         return;
       }else{
         var query={};
         if(this.level && this.levelfield){
           query.levelinfo={
             level:this.level,
             levelfield:this.levelfield,
           };
         }
         if(this.parentcode && this.parentfield){
            query.parentinfo={
             parentcode:this.parentcode,
             parentfield:this.parentfield,
           };
         }
         query.fields=[this.labelField,this.valueField];
         query.likestr=slike;
         query.refwhere=this.refwhere?this.refwhere:{};
         var method="refQuery";
         if(this.refMethod){
           method=this.refMethod;
           var firmObj = this.$root.copyParams(query,"getCompanyInfoByLikeName","/action/tmTools/springBoard");
         }
         var url="/web/trademark/tmqueryCtl/doPost";
         this.loading=true;
         this.$root.postReq(url,firmObj).then(d=>{
             this.fetchtype="bigdata";
             this.dataSouce=d.data;
             this.loading=false;
         });
       }

       
     },
     onchange:function(curval){
       console.log(this.sels,curval,"bbbbbbbbbbbbbbbbbb");
       if(this.fetchtype=="history" && this.showhistory){
         if(this.dataSouce && this.dataSouce.length>0){
           for(var i=0;i<this.dataSouce.length;i++){
             var data = this.dataSouce[i];
             if(data.entName==curval){
               this.$emit("historychange",data);
               return;
             }
           }
         }
       }else{
          this.$emit("change",curval);
          console.log('change触发');
       }
        
     },
     remoteMethod(query) {
       if(query !== ''){
         this.fetchData(query);
       } else {
         this.options4 = [];
       }
    },
    oninput:function(e){
      this.$emit("input",e);
    }
   },
   vname:"gsb-selectentjd"
}`
