<template>
  <!-- 打印 -->
  <el-dialog v-model="dialogVisiblePoint" :title="dialogTitle" width="60%">
    <ContentWrap>
      <Table :columns="detailListTableColumns" :data="tableObject.tableList" :loading="tableObject.loading" :pagination="{
      total: tableObject.total
    }" v-model:pageSize="tableObject.pageSize" v-model:currentPage="tableObject.currentPage"
      v-model:sort="tableObject.sort">
      <template #batch="{ row }">
        <el-input v-model="row.batch">{{ row.batch }}</el-input>
      </template>
    </Table>
    </ContentWrap>
    <ButtonBase :Butttondata="Butttondata" @button-base-click="buttonTableClick($event)"/>
  </el-dialog>
</template>

<script setup lang="ts">
import * as SupplierdeliverRequestMainApi from '@/api/wms/supplierdeliverRequestMain'
import * as SupplierdeliverRequestDetailApi from '@/api/wms/supplierdeliverRequestDetail'
import * as defaultButtons from '@/utils/disposition/defaultButtons'

const props = defineProps({
  // 表頭
  detailListTableColumns: {
    type: Array,
    required: true,
    default: null
  },
})

// 供应商发货申请
defineOptions({ name: 'SupplierdeliverRequestMain' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const Butttondata = [
  {
    label: '生成标签',
    name: 'ssbq',
    hide: false,
    type: 'primary',
    icon: 'ep:select',
    color: '',
    hasPermi: '',
    link: false, // 文本展现按钮
  },
  defaultButtons.formCloseBtn(null) // 关闭
]

const dialogVisiblePoint = ref(false)
const { tableObject, tableMethods } = useTable({
  getListApi: SupplierdeliverRequestDetailApi.getSupplierdeliverRequestDetailPage // 分页接口
})
const dialogVisible = ref(false)
const isShow = ref(false)
const dialogTitle = ref('')
const closeDialog = () => {
  dialogVisiblePoint.value = false
  isShow.value = false
}

/** 生成标签按钮操作 */
const genLabel = async () => {
  try {
    // 生成标签的二次确认
    await message.confirm('是否为此数据生成标签？')
    tableObject.loading = true
    // 发起生成标签
    await SupplierdeliverRequestMainApi.genLabel(genLabelId.value)
    dialogVisible.value = false
    isShow.value = false
    message.success(t('生成标签成功!'))
    dialogVisiblePoint.value = false
    isShow.value = false
    tableObject.loading = false
    // 刷新列表
    await getList()
  } catch { }
}

// 获得表格的各种操作
const { getList } = tableMethods
const genLabelId = ref();
const  openPoint = async (masterId)=>{
  tableObject.params = {
    masterId:masterId,
  }
  dialogVisiblePoint.value = true
   genLabelId.value = masterId
   getList()
}
defineExpose({ openPoint }) // 提供 open 方法，用于打开弹窗

  // 列表-操作按钮事件
  const buttonTableClick = async (val) => {
    if (val == 'ssbq') { // 生成标签
      genLabel()
    } else if (val == 'close') {// 关闭
      closeDialog()
    }
  }

/** 初始化 **/
onMounted(async () => {
 
})
</script>
