<template>
  <view class="">
    <u-popup v-model="isShow" mode="bottom">
      <view class="popup_box">
        <view class="pop_title uni-flex space-between">
          <view class=""> 扫描{{ title }} </view>
          <view class="">
            <image class="icons_scan_close" src="/static/icons/icons_scan_close.svg" @click="closeScanPopup()"></image>
          </view>
        </view>
        <view class="">
          <view class="">
            <win-com-scan ref="scan" @getResult="getScanResult" :placeholder="title" :clearResult="false" :isShowHistory="false"> </win-com-scan>
          </view>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance } from 'vue'
import winComScan from '@/mycomponents/scan/winComScan.vue'

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  isShowRecord: {
    type: Boolean,
    default: true
  }
})
const code = ref('')
const isShow = ref(false)
const expand = ref(false)
const scanList = ref([])
const expendIcon = ref('arrow-down')
const scan = ref()
const openScanPopup = () => {
  setTimeout((res) => {
    isShow.value = true
  }, 500)
}
const closeScanPopup = () => {
  if(scan.value){
    scan.value.losefocus()
  }
  isShow.value = false
}
const getfocus = () => {
  if (isShow.value) {
    scan.value.getfocus()
  }
}
const scanClick = () => {
  scan.value.handelScanMsg()
}
const cancelClick = () => {
  scan.value.clearScanValue()
}
const getScanResult = (result) => {
  if (result.label.barType === 'BarCode') {
    code.value = result.label.code
  }
  callBack()
}
const callBack = () => {
  scan.value.clear()
  emit('getScanCode', code.value)
}
// 传递给父类
const emit = defineEmits(['getScanCode'])
defineExpose({ openScanPopup, closeScanPopup })
</script>

<style></style>
