<template>
  <u-popup v-model="show" mode="bottom" :mask-close-able="false">
    <view class="popup_box">
      <view class="pop_title uni-flex space-between">
        <view class="" style="font-size: 35rpx"> 扫描{{ title }} </view>

        <view class="">
          <image class="fr icons_scan_close" src="/static/icons/icons_scan_close.svg" @click="closeScanPopup()"></image>
        </view>
      </view>
      <view class="">
        <view class="">
          <win-com-scan ref="comscan" :placeholder="title" @getResult="getScanResult" :isShowHistory="isShowHistory" :clearResult="true" :headerType="headerType"></win-com-scan>
        </view>
      </view>
    </view>
  </u-popup>
  <com-message ref="comMessageRef" />
</template>

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

import { getPutawayJobList } from '@/api/request2.js'

import { getListLocationTypeDesc, checkDirectoryItemExist, getDirectoryItemArray, getLocationTypeName, getInventoryStatusDesc } from '@/common/directory.js'

const props = defineProps({
  title: {
    type: String,
    default: '箱标签'
  },
  isShowHistory: {
    type: Boolean,
    default: true
  },
  headerType: {
    type: String,
    default: 'HPQ,HMQ'
  }
})
const comscan = ref()
const show = ref(false)
// 弹出
const openScanPopup = () => {
  show.value = true
  setTimeout(()=>{
    packGetFocus()
  },500)
}
// 关闭
const closeScanPopup = (content) => {
  show.value = false
  packLoseFocus()
  emit('close', '')
}
// 扫描结果

const getScanResult = (result) => {
  emit('getResult', result)
}
const packGetFocus = () => {
  if (comscan.value) {
    comscan.value.getfocus()
  }
}

const packLoseFocus = () => {
  if (comscan.value) {
    comscan.value.losefocus()
  }
}
const showMessage = (message, callback) => {
  setTimeout((r) => {
    packLoseFocus()
    comMessageRef.value.showMessage(message, callback)
  })
}

const showErrorMessage = (message, callback) => {
  setTimeout((r) => {
    packLoseFocus()
    comMessageRef.value.showMessage(message, callback)
  })
}

const change = (e) => {
  show.value = e.show
}
const selectItem = (item, index) => {}
// 传递给父类
const emit = defineEmits(['getResult', 'close', 'getCountScanResult'])
defineExpose({
  openScanPopup,
  closeScanPopup
})
</script>

<style lang="scss">
.scroll-view {
  overflow-y: scroll;
  height: auto;
  max-height: 300rpx;
}
</style>
