<template>
  <div>
    <liang-tian-device
      v-if="getComponentsName ==='LiangTianDevice'"
      @resultAction="resultAction"
      :is-open="isOpen"
      :type="type"
      :file-name="fileName"
      :file-path="filePath"
      :ref="getComponentsName">
    </liang-tian-device>

    <zi-tu-device
      v-if="getComponentsName ==='ZiTuDevice'"
      @resultAction="resultAction"
      @getPath="getPath"
      @setMsg="setMsg"
      :is-open="isOpen"
      :type="type"
      :file-name="fileName"
      :file-path="filePath"
      :user_idcard="idcard"
      :ref="getComponentsName"
      @goonTodo="goonTodo">
    </zi-tu-device>

    <de-yi-pai-device
      v-if="getComponentsName ==='DeYiPaiDevice'"
      @resultAction="resultAction"
      :is-open="isOpen"
      :type="type"
      :file-name="fileName"
      :file-path="filePath"
      :ref="getComponentsName">
    </de-yi-pai-device>
    <dian-yi-pai-device
      v-if="getComponentsName ==='DianYiPaiDevice'"
      @resultAction="resultAction"
      :is-open="isOpen"
      :type="type"
      :file-name="fileName"
      :file-path="filePath"
      :ref="getComponentsName">
    </dian-yi-pai-device>

    <wei-shan-device
      v-if="getComponentsName ==='WeiShanDevice'"
      @resultAction="resultAction"
      :is-open="isOpen"
      :type="type"
      :file-name="fileName"
      :file-path="filePath"
      :ref="getComponentsName">
    </wei-shan-device>
  </div>
</template>

<script>
import LiangTianDevice from '@/components/wl-equipment/liang-tian-device/index'
import ZiTuDevice from '@/components/wl-equipment/zi-tu-device/index'
import DeYiPaiDevice from '@/components/wl-equipment/de-yi-pai-device/index'
import DianYiPaiDevice from '@/components/wl-equipment/dian-yi-pai-device/index'
import WeiShanDevice from '@/components/wl-equipment/wei-shan-device/index'
export default {
  name: 'WlEquipment',
  components: { WeiShanDevice, LiangTianDevice, ZiTuDevice, DeYiPaiDevice, DianYiPaiDevice },
  props: {
    type: {
      type: String,
      default: () => {
        return '' // heightCamera----faceCamera----idcard
      }
    },
    value: {
      type: Object,
      default: () => {
        return {}
      }
    },
    isOpen: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    filePath: {
      type: String,
      default: () => {
        return 'liang-tian'
      }
    },
    fileName: {
      type: String,
      default: () => {
        return 'liang-tian'
      }
    },
    idcard: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  model: {
    prop: 'value',
    event: 'change'
  },
  computed: {
    getComponentsName () {
      // TODO-测试的时候先返回一个字符串，正式用的时候是在登录信息里取的
      return this.$store.state.user.severUserInfo.email
    }
  },
  watch: {
    type (val) {
      console.log(val, 'aaaa')
      if (val === 'idcard') {
        this.getResult()
      }
    }
  },
  methods: {
    getPath (e) {
      this.$emit('getPath', e)
    },
    setMsg (e) {
      this.$emit('setMsg', e)
    },
    resultAction (data, base64) {
      if (this.type === 'heightCamera') {
        this.$emit('change', { url: data.data })
      }
      if (this.type === 'faceCamera') {
        console.log(data.data, '!#@!@#!@#')
        this.$emit('change1', { url: data.data, base64: base64 })
      }
      if (this.type === 'idcard') {
        console.log('持证办理')
        this.$emit('change', data)
      }
    },
    getResult () {
      console.log('++++++', this.type)
      if (this.type === 'heightCamera') {
        this.$refs[this.getComponentsName].getIdcardInfo()
      }
      if (this.type === 'faceCamera') {
        console.log('23232')
        this.$refs[this.getComponentsName].getIdcardInfo()
      }
      if (this.type === 'idcard') {
        console.log('77777')
        this.$refs[this.getComponentsName].getIdcardInfo()
      }
    },
    imgResult (idcard) {
      that.$emit('get_info', idcard)
    },
    setPath () {
      this.$refs.ZiTuDevice.setPath()
    },
    merge (e1, e2) {
      this.$refs.ZiTuDevice.merge(e1, e2)
    },
    recognition (e) {
      console.log(222)
      this.$refs.ZiTuDevice.recognition(e)
    },
    readIdCard (item) {
      console.log('杜卡卡卡卡', item)
      this.$refs[this.getComponentsName].getCardInfo(item)
    },
    goonTodo () {
      this.$emit('goonTodo')
    }
  },
  mounted () {
    console.log(this.$store.state.user.severUserInfo.email, '%%%%%', this.type)
  }
}
</script>

<style scoped>

</style>
