<template>
  <view class="" style="background-color: #fff">
    <u-collapse ref="collapse">
      <u-collapse-item :open="true">
        <template v-slot:title>
          <itemCompareQty :dataContent="dataContent" :handleQty="dataContent.handleQty" :isShowPackUnit="false" style="width: 100%"></itemCompareQty>
        </template>
        <package-list :dataContent="dataContent.subList" :isEdit="settingParam.allowModifyQty == 'TRUE'" :settingParam="settingParam" @collapseChange="collapseChange" @updateData="updateData" :isShowFromLocation="false"></package-list>
      </u-collapse-item>
    </u-collapse>

    <recommend-qty-edit ref=" receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm"> </recommend-qty-edit>
    <win-scan-location ref="scanLocationCode" title="目标库位" @getLocation="getLocation" :locationAreaTypeList="locationAreaTypeList"></win-scan-location>
    <receipt-detail-info-popup ref="jobDetailPopup" :dataContent="showItem"></receipt-detail-info-popup>
    <com-message ref="comMessageRef" />
  </view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance, onMounted, nextTick } from 'vue'
import { onLoad, onNavigationBarButtonTap, onPullDownRefresh } from '@dcloudio/uni-app'
import itemCompareQty from '@/mycomponents/item/itemCompareQty.vue'
import recommend from '@/mycomponents/recommend/recommend.vue'
import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
import jobDetailPopup from '@/mycomponents/detail/jobDetailPopup.vue'
import receiptDetailInfoPopup from '@/pages/purchaseReceipt/coms/receiptDetailInfoPopup.vue'
import winScanLocation from '@/mycomponents/scan/winScanLocation.vue'
import pack from '@/mycomponents/balance/pack.vue'
import detailList from '@/mycomponents/detail/detailList.vue'
import packageList from '@/mycomponents/package/packageList.vue'
import { getDetailOption, getPurchaseReceiptOption } from '@/common/array.js'

const props = defineProps({
  dataContent: {
    type: Object,
    default: null
  },
  settingParam: {
    type: Object,
    default: null
  },
  locationAreaTypeList: {
    type: Object,
    default: null
  }
})
const showItem = ref({})
const editItem = ref({
  record: {}
})
const locatonItem = ref({})
const detailOptions = ref([])
const scanOptions = ref([])
const collapse = ref()
const comMessageRef = ref()
const receiptEdit = ref()
onMounted(() => {
  if (detailOptions.value.length == 0) {
    detailOptions.value = getDetailOption()
  }
  if (scanOptions.value.length == 0) {
    scanOptions.value = getPurchaseReceiptOption(props.settingParam.allowModifyQty, props.settingParam.allowModifyLocation)
  }
})
const collapseChange = () => {
  setTimeout(() => {
    resizeCollapse()
  }, 500)
}
const resizeCollapse = () => {
  nextTick((r) => {
    collapse.value.init()
  })
}
const refreshCollapse = () => {
  nextTick((r) => {
    collapse.value.forEach((r) => {
      r.childrens.forEach((i) => {
        i.init()
      })
      r.init()
    })
  })
}
const edit = (item) => {
  editItem.value = item
  receiptEdit.value.openTaskEditPopup(item.qty, item.handleQty, item.labelQty)
}
const showLocation = () => {
  locatonItem.value = item
  scanLocationCode.value.openScanPopup()
}
// 扫描源库位
const getLocation = () => {
  locatonItem.value.LocationCode = code
  emit('updateData')
}
const detail = (item) => {
  showItem.value = item
  jobDetailPopup.value.openPopup()
}
const remove = (item) => {
  comMessageRef.value.showQuestionMessage('确定移除扫描信息?', (res) => {
    if (res) {
      item.scaned = false
      item.handleQty = null
      emit('remove', item)
    }
  })
}
const confirm = (qty) => {
  editItem.value.handleQty = qty
  emit('updateData')
}
const updateData = () => {
  emit('updateData')
}
// 传递给父类
const emit = defineEmits(['updateData', 'remove'])
defineExpose({
  resizeCollapse
})
</script>

<style></style>
