import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
import lodash from 'lodash' //导入深度拷贝
import { MessageBox, Message } from 'element-ui'

export default class VueViews extends Vue{
  value:any=null;
  config:any={}

  get requestConfig(){
    return this.config?.request ? this.config.request : null;
  }

  get attrs(){
    return  this.config?.attr ? this.config.attr : {};
  }

  @Prop()
  propConfig: any

  @Prop()
  propValue?:any

  @Prop()
  parentValue:any

  constructor() {
    super()
  }


  // 初始化
  ini(option?: any): any {
    return this
  }

  //设置配置
  setConfig(c:any){
    if(c){
      this.config = c;
    }
    this.setConfigAfter()
  }

  //获取配置
  getConfig(){
    return lodash.cloneDeep(this.config)
  }

  setConfigAfter(){}

  requestHandle(requestParames:any){
    if(requestParames && requestParames.url){
      (this as any).$request(requestParames).then((res:any) => {
        if(requestParames.success){
          requestParames.success(res)
        }
      }).catch((err:any) => {
        if(requestParames.fail){
          requestParames.fail(err);
        }
      })
    }
  }
}