<template>
  <view class="" style="background-color: #fff">
    <view class="uni-flex uni-column">
      <work-station :fromWarehouseCode="dataContent.fromWarehouseCode" :workshopCode="dataContent.workshopCode" :productionLineCode="dataContent.productionLineCode" :workStationCode="dataContent.workStationCode" :rawLocationCode="dataContent.toLocationCode"></work-station>
      <view class="u-p-l-20 u-p-r-20">
        <u-swipe-action :show="item.show" :index="index" v-for="(item, index) in dataContent.subList" :key="index" :options="options" bg-color="rgba(255,255,255,0)" @click="(...event) => swipeClick(event, item)">
          <item-qty :dataContent="item" :isShowStdPack="false"> </item-qty>
          <view class="split_line"></view>
        </u-swipe-action>
      </view>
    </view>
    <request-detail-info-popup ref="jobDetailPopup"></request-detail-info-popup>
    <com-message ref="comMessageRef" />
  </view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance, nextTick, onMounted } from 'vue'
import itemCompareQty from '@/mycomponents/item/itemCompareQty.vue'
import recommend from '@/mycomponents/recommend/recommend.vue'
import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
import itemQty from '@/mycomponents/item/itemQty.vue'
import comIssueRequestInfo from '@/pages/issue/coms/comIssueRequestInfo.vue'
import requestDetailInfoPopup from '@/pages/issue/coms/requestDetailInfoPopup.vue'
import workStation from '@/mycomponents/workStation/workStation.vue'

import { getDetailOption, getDetailEditRemoveOption, getDetailRemoveOption } from '@/common/array.js'

const props = defineProps({
  dataContent: {
    type: Object,
    default: {}
  },
  settingParam: {
    type: Object,
    default: {}
  },
  isShowPack: {
    type: Boolean,
    default: true
  },
  isShowBatch: {
    type: Boolean,
    default: true
  },
  isShowLocation: {
    type: Boolean,
    default: true
  },
  isSwipe: {
    type: Boolean,
    default: true
  }
})
const option = ref([])
const showItem = ref({})
const editItem = ref({
  record: {}
})
const detailOptions = ref([])
const scanOptions = ref([])
const options = ref([])
const jobDetailPopup = ref()
const comMessageRef = ref()
onMounted(() => {
  if (detailOptions.value.length == 0) {
    detailOptions.value = getDetailOption()
  }
  if (scanOptions.value.length == 0) {
    scanOptions.value = getDetailRemoveOption()
  }
  options.value = scanOptions.value
})
const swipeClick = (params, item) => {
  // if (e.content.text == "详情") {
  // 	detail(item)
  // } else if (e.content.text == "编辑") {
  // 	edit(item)
  // } else if (e.content.text == "移除") {
  // 	remove(item, index)
  // }
  const { text } = scanOptions.value[params[1]]
  if (text == '详情') {
    detail(item)
  } else if (text == '编辑') {
    edit(item)
  } else if (text == '库位') {
    showLocation(item)
  } else if (text == '移除') {
    remove(item)
  }
}
const edit = (item) => {
  editItem.value = item
  qtyEdit.value.openEditPopup(item.balance, item.record.qty)
}
const detail = (item) => {
  jobDetailPopup.value.openPopup(item)
}
const remove = (item, index) => {
  comMessageRef.value.showQuestionMessage('确定移除扫描信息?', (res) => {
    if (res) {
      props.dataContent.subList.splice(index, 1)
    }
  })
}
const confirm = (qty) => {
  editItem.value.record.qty = qty
}
</script>

<style></style>
