<template>
  <view class="" style="background-color: #fff">
    <u-collapse ref="collapse1" @change="">
      <u-collapse-item :open="true">
        <template v-slot:title>
          <!-- <uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="removeData($event,dataContent)" :right-options="removeOptions">
							<item-qty :dataContent="dataContent" :isShowBalanceQty="false"
								:isShowBalance="true"></item-qty>
						</uni-swipe-action-item>
					</uni-swipe-action> -->
          <u-swipe-action :show="false" style="width: 90%" :options="removeOptions" bg-color="rgba(255,255,255,0)" class="u-m-b-20" @click="(...event) => removeData(event, dataContent)">
            <item-qty :dataContent="dataContent" :isShowBalanceQty="false" :isShowBalance="true"></item-qty>
          </u-swipe-action>
        </template>
        <!-- <view class='split_line'></view>
				<view class="" v-for="(item,index) in dataContent.subList">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="swipeClick($event,item,index)"
							:right-options="item.scaned?scanOptions:detailOptions">
							<balance :dataContent="item" :isShowStdPack="false" :isShowStatus="true" :isShowPack="true"
								:isShowFromLocation="false" :isShowToLocation="false"></balance>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view> -->
        <u-swipe-action :show="detail.show" :index="index" v-for="(detail, index) in dataContent.subList" :key="index" :options="detail.scaned ? scanOptions : detailOptions" bg-color="rgba(255,255,255,0)" class="u-m-b-20" @click="(...event) => swipeClick(event, detail)">
          <balance :dataContent="item" :isShowStdPack="false" :isShowStatus="false" :isShowPack="true" :isShowFromLocation="false" :isShowToLocation="false"></balance>
        </u-swipe-action>
      </u-collapse-item>
    </u-collapse>
    <recommend-qty-edit ref="qtyEdit" :dataContent="editItem" :settingParam="settingParam" :handleQty="editItem.qty" @confirm="confirm"> </recommend-qty-edit>
    <package-detail-popup ref="packageDetailPopupRef"> </package-detail-popup>
    <com-message ref="comMessageRef" />
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted, nextTick, watch } from 'vue'
import itemQty from '@/mycomponents/item/itemQty.vue'
import recommend from '@/mycomponents/recommend/recommend.vue'
import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
import balance from '@/mycomponents/balance/balance.vue'
import balanceMove from '@/mycomponents/balance/balanceMove.vue'
import purchaseLabel from '@/mycomponents/balance/purchaseLabel.vue'
import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
import packageDetailPopup from '@/mycomponents/package/packageDetailPopup.vue'
import { getDetailOption, getDetailEditRemoveOption, getClearOption } from '@/common/array.js'

const props = defineProps({
  dataContent: {
    type: Object,
    default: {}
  },
  settingParam: {
    type: Object,
    default: {}
  },
  fromInventoryStatus: {
    type: String,
    default: ''
  },
  toInventoryStatus: {
    type: String,
    default: ''
  },
  isShowStatus: {
    type: Boolean,
    default: false
  },
  isShowLocation: {
    type: Boolean,
    default: false
  }
})
const collapse1 = ref()
// 监视属性
watch(
  () => props.dataContent,
  (val) => {
    if (val.subList.length > 0) {
      if (collapse1.value != undefined && collapse1.value != null) {
        nextTick((res) => {
          collapse1.value.init()
        })
      }
    }
  },
  { immediate: true, deep: true }
)
const option = ref([])
const title = ref('推荐详情')
const showItem = ref({})
const editItem = ref({})
const detailOptions = ref([])
const scanOptions = ref([])
const removeOptions = ref([])
const dataList = ref([])
const comMessageRef = ref('')
const qtyEdit = ref('')
const packageDetailPopupRef = ref('')
const dataContent = ref(props.dataContent)
dataContent.value.subList.forEach((item) => {
  item.show = false
})
onMounted(() => {
  detailOptions.value = getDetailOption()
  scanOptions.value = getDetailEditRemoveOption()
  removeOptions.value = getClearOption()
})
const removeData = (params, dataContent) => {
  const { text } = removeOptions.value[params[1]]
  if (text == '清空') {
    comMessageRef.value.showQuestionMessage('确定清空物料及箱码信息', (res) => {
      if (res) {
        emit('removeItem')
      }
    })
  }
}
const swipeClick = (params, item) => {
  let text = ''
  if (item.scaned) {
    text = scanOptions.value[params[1]].text
  } else {
    text = detailOptions.value[params[1]].text
  }
  if (text == '详情') {
    detail(itemm.package)
  } else if (text == '编辑') {
    edit(item)
  } else if (text == '移除') {
    remove(item, params[0])
  }
}
const edit = (item) => {
  editItem.value = item
  qtyEdit.value.openRecordEditPopup(item.handleQty, item)
}
const detail = (packageInfo) => {
  showItem.value = packageInfo
  packageDetailPopupRef.value.openPopup(packageInfo)
}
const remove = (item, index) => {
  comMessageRef.value.showQuestionMessage('确定移除扫描信息?', (res) => {
    if (res) {
      dataContent.value.subList.splice(index, 1)
      emit('removePack')
    }
  })
}
const confirm = (qty) => {
  editItem.value.handleQty = qty
  emit('updateData')
}
// 传递给父类
const emit = defineEmits(['updateData', 'removePack', 'removeItem'])
</script>

<style></style>
