<template>
  <view>
    <view v-for="(item,index) in dataContent.subList">
      <u-swipe-action ref="swipeAction"
                      :class="item.scaned? 'scan_view':''"
                      :options="(item.scaned&&isEdit)?editAndRemoveOptions : item.scaned? removeOptions:options"
                      @click="(...event)=>swipeClick(event,item,index)">
        <item-qty :dataContent="item" :handleQty="item.handleQty" :isShowBalanceQty="false"></item-qty>
        <location :locationCode="item.fromLocationCode"></location>
        <recommendBalanceBatch style='margin-left: 20px;' :detail="item" :isShowLocation="false"
                               :isShowPack="item.packingNumber"></recommendBalanceBatch>
      </u-swipe-action>
    </view>
  </view>
  <qtyEdit ref="balanceQtyEdit" @confirm="confirm" :isShowStatus="true"></qtyEdit>
  <detail-info-popup ref="detailInfoPopup"></detail-info-popup>
  <comMessage ref="message"></comMessage>
</template>

<script setup lang="ts">
import itemQty from '@/mycomponents/item/itemQty.vue'
import recommend from '@/mycomponents/recommend/recommend.vue'
import recommendBalance from '@/mycomponents/balance/recommendBalance.vue'
import recommendBalanceBatch from '@/mycomponents/balance/recommendBalanceBatch.vue'
import handleBalance from '@/mycomponents/balance/handleBalance.vue'
import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
import requiredLocation from '@/mycomponents/location/requiredLocation.vue'
import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
import qtyEdit from '@/mycomponents/qty/qtyEdit.vue'
import location from '@/mycomponents/balance/location.vue'
import detailInfoPopup from '@/pages/productionReceipt/coms/detailInfoPopup.vue'
import {
  getDetailOption,
  getPurchaseReceiptOption,
  getRemoveOption,
  getEditRemoveOption
} from '@/common/array.js';
import {ref, watch, onMounted} from 'vue';

const props = defineProps({
  dataContent: {
    type: Object,
    default: () => ({})
  },
  settingParam: {
    type: Object,
    default: () => ({})
  },
  isEdit: {
    type: Boolean,
    default: true
  }
});

const emit = defineEmits(['updateData']);

const option = ref([]);
const showItem = ref({});
const editItem = ref({});
const batchItem = ref({});
const detailOptions = ref([]);
const scanOptions = ref([]);
const options = ref([]);
const removeOptions = ref([]);
const editAndRemoveOptions = ref([]);

const balanceQtyEdit = ref(null);
const receiptHint = ref(null);
const message = ref(null);
onMounted(() => {
  removeOptions.value = getRemoveOption();
  editAndRemoveOptions.value = getEditRemoveOption();
});

// 方法
const resizeCollapse = () => {
  // 实现 resizeCollapse 的逻辑
};

const swipeClick = (e, item, index) => {
  if (e.content.text === "编辑") {
    edit(item);
  } else if (e.content.text === "移除") {
    remove(item, index);
  }
};

const edit = (item) => {
  console.log(item);
  editItem.value = item;
  // that.batchItem = batch;
  // record.balance.balanceQty = record.balance.qty;
  balanceQtyEdit.value?.openEditPopup(item);
};

const detail = (item) => {
  showItem.value = item;
  receiptHint.value?.openScanPopup();
};

const remove = (item) => {
  message.value?.showQuestionMessage("确定移除扫描信息?", (res) => {
    if (res) {
      item.handleQty = 0;
      item.scaned = false;
      // this.$emit('updateData', record)
    }
  });
};

const confirm = (val) => {
  console.log(val);
  editItem.value.handleQty = val;
  emit('updateData', editItem.value);
  // let qty = 0;
  // this.batchItem.Records.forEach(r => {
  // 	qty += Number(r.qty);
  // })
  // this.batchItem.handleQty = qty;
};

</script>

<style>
</style>