<script lang="ts" setup>
import ExpandablePageableTable from "@/components/base/expandable-pageable-table/ExpandablePageableTable.vue";
import DefaultToolButton from "@/components/base/default-tool-button/DefaultToolButton.vue";
import DefaultOperateButtonColumn from "@/components/base/default-column/DefaultOperateButtonColumn.vue";
import DefaultStatusSwitchColumn from "@/components/base/default-column/DefaultStatusSwitchColumn.vue";
import { usePage } from "@/composables/use-page";
import { $t } from "@/common/languages";
import BaseFormWithTable from "@/components/base/base-form-with-table/BaseFormWithTable.vue";
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from "element-plus";
import { formatDate } from "@/common/utils/format-utils";
import BaseItemDialog from "@/components/base/base-item-dialog/BaseItemDialog.vue";
import BaseSelect from "@/components/base/base-select/BaseSelect.vue";
import BaseTableForm from "@/components/base/base-table-form/BaseTableForm.vue";
import { generateDucumentNo } from "@/common/utils/document-no-generator/document-no-generator";
import { get, post } from "@/common/http/request";
import { useStatus } from "@/common/languages/mapping/base-info-mapping";
import { type FieldMappingConfig, type DetailLoadConfig } from "@/components/base/base-form-with-table/type";

/**
 * 必须要的变量
 */

const getPageUrl = "/production/finishedproductreceipt/getFinishedProductReceiptPage";
const addUrl = "/production/finishedproductreceipt/addFinishedProductReceipt";
const editUrl = "/production/finishedproductreceipt/updateFinishedProductReceipt";
const removeUrl = "/production/finishedproductreceipt/deleteFinishedProductReceipt";
const getDetailUrl = "/production/finishedproductreceipt/getFinishedProductReceiptDetail";
const itemUrl = "/production/finishedproductreceipt/getFinishedProductReceiptDetail";
const getWarehouseSelectListUrl = "/warehouse/warehouse/getWarehouseSelectList";
const getOutstockDataUrl = "/production/finishedproductreceipt/getOutstockData";
const saveOutstockUrl = "/production/finishedproductreceipt/saveOutstock";
const getKeyAccountSelectListUrl = "/sys/keyaccount/getKeyAccountSelectList";
const itemArrayName = "deviceItems";
const searchers = [
  { name: "searchCode", type: "text" as const, placeholder: $t("_prop.production.finishedproductreceipt.searchCode") },
];
const rules = reactive<FormRules>({
  formCode: [
    { required: true, message: $t("_message.production.finishedproductreceipt.input_formCode"), trigger: "blur" },
  ],
  formName: [
    { required: true, message: $t("_message.production.finishedproductreceipt.input_formName"), trigger: "blur" },
  ],
  storeNo: [
    { required: true, message: $t("_message.production.finishedproductreceipt.select_storeId"), trigger: "blur" },
  ],
  deviceItems: [
    {
      required: true,
      validator: (rule, value, callback) => {
        if (value === undefined || value.length === 0) {
          callback($t("_message.production.finishedproductreceipt.no_module_sn_items"));
        }
        callback();
      },
      trigger: "change",
    },
  ],
});

const validateDeviceDuplicates = (deviceItems: any[]): string | null => {
  const productSns = new Set<string>();
  const macs = new Set<string>();
  const serialNums = new Set<string>();

  for (const item of deviceItems) {
    if (item.productSn) {
      if (productSns.has(item.productSn)) {
        return $t("_message.production.finishedproductreceipt.duplicate_productSn", { value: item.productSn });
      }
      productSns.add(item.productSn);
    }
    if (item.mac) {
      if (macs.has(item.mac)) {
        return $t("_message.production.finishedproductreceipt.duplicate_mac", { value: item.mac });
      }
      macs.add(item.mac);
    }
    if (item.serialNum) {
      if (serialNums.has(item.serialNum)) {
        return $t("_message.production.finishedproductreceipt.duplicate_serialNum", { value: item.serialNum });
      }
      serialNums.add(item.serialNum);
    }
  }
  return null;
};

const validateDevicesWithBackend = async (deviceItems: any[]): Promise<string | null> => {
  const validateUrl = "/sale/device/validateDevices";
  const devices = deviceItems.map((item: any) => ({
    productSn: item.productSn || "",
    mac: item.mac || "",
    serialNum: item.serialNum || "",
  }));

  try {
    const res = await post(validateUrl, { devices });
    if (res.code === 0 && res.data) {
      if (!res.data.valid) {
        return res.data.message;
      }
    }
    return null;
  } catch (error) {
    console.error("验证设备失败:", error);
    return $t("_message.production.finishedproductreceipt.validate_failed");
  }
};
/**
 * 基本不变通用变量
 */
const tableRef = ref<InstanceType<typeof ExpandablePageableTable> | null>(null);
const { useAdd, useEdit, useRemove, useGeneralPageRef } = usePage(tableRef);
const { title, visible, formType, form, itemVisible, itemParentId } = useGeneralPageRef();
const baseFormWithTableRef = ref<InstanceType<typeof BaseFormWithTable>>();
const warehouseSelectRef = ref<InstanceType<typeof BaseSelect>>();
const outstockDialogRef = ref<InstanceType<typeof BaseTableForm>>();
const keyAccountSelectRef = ref<InstanceType<typeof BaseSelect>>();
const { getFinishedProductReceiptStatusLabel, getActivationStatusLabel, getActivationStatusTxtLabel } = useStatus();

// 出货相关变量
const outstockVisible = ref(false);
const outstockTableData = ref([]);
const currentOutstockId = ref();
const currentOutstockRow = ref<any>({});
const outstockForm = ref({
  keyAccountId: "",
  formMark: "",
});

const selectedOutstockDevices = ref<any[]>([]);

const handleOutstockSelectionChange = (selection: any[]) => {
  selectedOutstockDevices.value = selection;
};

// Excel导入映射配置
const mappingConfig: FieldMappingConfig = {
  productType: {
    sourceKey: ["型号", "productType"],
    header: $t("_prop.production.finishedproductreceipt.productType"),
    width: 15,
    defaultValue: "",
  },
  productSn: {
    sourceKey: ["SN号", "productSn"],
    header: $t("_prop.production.finishedproductreceipt.productSn"),
    width: 20,
    defaultValue: "",
  },
  mac: {
    sourceKey: ["MAC地址", "mac"],
    header: $t("_prop.production.finishedproductreceipt.mac"),
    width: 18,
    defaultValue: "",
  },
  serialNum: {
    sourceKey: ["序列号", "serialNum"],
    header: $t("_prop.production.finishedproductreceipt.serialNum"),
    width: 20,
    defaultValue: "",
  },
  softVersion: {
    sourceKey: ["软件版本", "softVersion"],
    header: $t("_prop.production.finishedproductreceipt.softVersion"),
    width: 15,
    defaultValue: "",
  },
  alVersion: {
    sourceKey: ["算法版本", "alVersion"],
    header: $t("_prop.production.finishedproductreceipt.alVersion"),
    width: 15,
    defaultValue: "",
  },
  alNum: {
    sourceKey: ["算法标志", "alNum"],
    header: $t("_prop.production.finishedproductreceipt.alNum"),
    width: 15,
    defaultValue: "",
  },
  alTxt: {
    sourceKey: ["激活状态", "alTxt"],
    header: $t("_prop.production.finishedproductreceipt.alTxt"),
    width: 12,
    defaultValue: "未激活",
    transform: (val: any) => {
      if (val === "已激活" || val === "Activated" || val === true || val === "1") return "已激活";
      if (val === "未激活" || val === "Not Activated" || val === false || val === "0") return "未激活";
      return "未激活";
    },
  },
  createDate: {
    sourceKey: ["生产日期", "createDate"],
    header: $t("_prop.production.finishedproductreceipt.createDate"),
    width: 15,
    defaultValue: "",
  },
  mark: {
    sourceKey: ["备注", "mark"],
    header: $t("_prop.production.finishedproductreceipt.mark"),
    width: 20,
    defaultValue: "",
  },
};

const detailConfig: DetailLoadConfig = {
  url: getDetailUrl,
  paramName: "id",
  dataPath: "data",
};
/**
 * 可以自定义的变量
 */

const add = () => {
  form.value = {};
  title.value = "_title.production.finishedproductreceipt.add";
  form.value["formCode"] = generateDucumentNo("RK");
  visible.value = true;
  formType.value = false;
};

const edit = (row: any) => {
  title.value = "_title.production.finishedproductreceipt.edit";
  form.value = { ...row };
  visible.value = true;
  formType.value = true;
};
const remove = (row: any) => {
  useRemove(removeUrl, row.id, "_message.production.finishedproductreceipt.delete_message");
};

// 成品入库状态标签类型映射
const getFinishedProductReceiptStatusTagType = (code: number | null): string => {
  const tagTypeMap: Record<number, string> = {
    1: "warning", // 待出货
    3: "primary", // 出货中
    4: "success", // 已完成
  };
  return tagTypeMap[code ?? -1] || "info";
};

const outstock = async (row: any) => {
  // 检查单据状态，只有待出货和出货中状态才能出货
  if (row.formStatus !== 1 && row.formStatus !== 3) {
    ElMessage.warning($t("_message.production.finishedproductreceipt.only_pending_outstocking_can_outstock"));
    return;
  }

  currentOutstockId.value = row.id;
  currentOutstockRow.value = row;

  try {
    const outstockData = await get(getOutstockDataUrl, { id: row.id }).then(res => res.data);
    outstockTableData.value = outstockData.map((item: any) => ({
      ...item,
      selected: false,
    }));

    // 重置出货表单
    outstockForm.value = {
      keyAccountId: "",
      formMark: "",
    };

    outstockVisible.value = true;
  } catch (error) {
    ElMessage.error($t("_message.production.finishedproductreceipt.get_outstock_data_failed"));
    console.error("获取出货数据失败:", error);
  }
};

const saveOutstock = async () => {
  if (!outstockForm.value.keyAccountId) {
    ElMessage.warning($t("_message.production.finishedproductreceipt.select_key_account"));
    return;
  }

  if (selectedOutstockDevices.value.length === 0) {
    ElMessage.warning($t("_message.production.finishedproductreceipt.select_devices"));
    return;
  }

  ElMessageBox.confirm($t("_message.production.finishedproductreceipt.outstock_confirm"), $t("_level.warning"), {
    confirmButtonText: $t("_button.confirm"),
    cancelButtonText: $t("_button.cancel"),
    type: "warning",
  }).then(async () => {
    try {
      const requestData = {
        id: currentOutstockId.value,
        keyAccountId: parseInt(outstockForm.value.keyAccountId),
        outstockList: selectedOutstockDevices.value.map((item: any) => ({
          productSn: item.productSn,
        })),
      };

      const res = await post(saveOutstockUrl, requestData);
      if (res.code === 0) {
        ElMessage.success($t("_message.production.finishedproductreceipt.outstock_success"));
        outstockVisible.value = false;
        tableRef.value?.reload();
      } else {
        ElMessage.error($t("_message.production.finishedproductreceipt.outstock_fail") + res.msg);
      }
    } catch (error) {
      ElMessage.error($t("_message.production.finishedproductreceipt.outstock_fail") + error);
      console.error("出货失败:", error);
    }
  });
};
const showItem = (row: any) => {
  itemParentId.value = row.id;
  itemVisible.value = true;
};
const submit = async (formData: any, formRef: FormInstance | undefined) => {
  setName();
  if (formRef !== undefined) {
    const deviceItems = formData.deviceItems || [];
    const localDuplicateError = validateDeviceDuplicates(deviceItems);
    if (localDuplicateError) {
      ElMessage.error(localDuplicateError);
      return;
    }

    const backendDuplicateError = await validateDevicesWithBackend(deviceItems);
    if (backendDuplicateError) {
      ElMessage.error(backendDuplicateError);
      return;
    }

    formRef.validate(valid => {
      if (valid) {
        if (formType.value) useEdit(editUrl, formData, visible);
        else useAdd(addUrl, formData, visible);
      }
    });
  }
};
const topButtonClick = (eventName: string) => {
  switch (eventName) {
    case "add":
      add();
      break;
  }
};
const operateButtonClick = (eventName: string, row: any) => {
  switch (eventName) {
    case "edit":
      edit(row);
      break;
    case "remove":
      remove(row);
      break;
    case "showItem":
      showItem(row);
      break;
    case "outstock":
      outstock(row);
      break;
  }
};

const authShowFunc = (row: any, button: globalThis.ButtonProp) => {
  // 只有已完成的入库单不能出货（formStatus === 4）
  if (row.formStatus === 4 && button.eventName === "outstock") return false;

  // 其他按钮根据业务需求显示
  return true;
};
const setName = () => {
  form.value["storeName"] = warehouseSelectRef.value?.getLabel();
};
const handleReset = () => {
  form.value["formCode"] = generateDucumentNo("RK");
};
</script>
<template>
  <ExpandablePageableTable
    :url="getPageUrl"
    :searchers="searchers"
    ref="tableRef"
    :item-url="itemUrl"
    item-id-key="id"
    item-id-name="id"
    item-field-name="deviceItems"
  >
    <template #tool-button>
      <DefaultToolButton @top-button-click="topButtonClick" />
    </template>
    <template #columns>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.formCode')" prop="formCode" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.formName')" prop="formName" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.storeName')" prop="storeName" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.formMark')" prop="formMark" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.totalValue')" prop="totalValue" />
      <el-table-column :label="$t('_prop.common.createDate')" prop="createDate" :formatter="formatDate" />
      <DefaultStatusSwitchColumn
        status-param-name="formStatus"
        :status-label-mapping="getFinishedProductReceiptStatusLabel"
        :tag-type-mapping="getFinishedProductReceiptStatusTagType"
      />
      <DefaultOperateButtonColumn @operate-button-click="operateButtonClick" :auth-show-func="authShowFunc" />
    </template>
    <template #item-content="{ itemData }">
      <el-table :data="itemData" size="small" border stripe>
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.productType')" prop="productType" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.productSn')" prop="productSn" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.macAddress')" prop="mac" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.serialNumber')" prop="serialNum" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.softwareVersion')" prop="softVersion" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmVersion')" prop="alVersion" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmFlag')" prop="alNum" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.activationStatus')" prop="alStatus">
          <template #default="{ row }">
            {{ getActivationStatusLabel(row.alStatus) }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.productionDate')" prop="createDate" />
        <el-table-column :label="$t('_prop.production.finishedproductreceipt.remark')" prop="mark" />
      </el-table>
    </template>
  </ExpandablePageableTable>
  <BaseFormWithTable
    ref="baseFormWithTableRef"
    v-model:visible="visible"
    @submit="submit"
    v-model:form="form"
    :title="$t(title)"
    :rules="rules"
    :base-title="$t('_title.production.finishedproductreceipt.baseTitle')"
    :table-title="$t('_title.production.finishedproductreceipt.tableTitle')"
    :item-array-name="itemArrayName"
    :mapping-config="mappingConfig"
    :template-file-name="$t('_title.production.finishedproductreceipt.templateFileName')"
    :detail-config="detailConfig"
    @reset="handleReset"
  >
    <template #form-items>
      <el-form-item prop="id" v-if="false"><el-input v-model="form.id" /></el-form-item>
      <el-form-item prop="storeName" v-if="false"><el-input v-model="form.storeName" /></el-form-item>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item :label="$t('_prop.production.finishedproductreceipt.formCode')" prop="formCode">
            <el-input
              v-model="form.formCode"
              :placeholder="$t('_message.production.finishedproductreceipt.input_formCode')"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('_prop.production.finishedproductreceipt.formName')" prop="formName">
            <el-input
              v-model="form.formName"
              :placeholder="$t('_message.production.finishedproductreceipt.input_formName')"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item :label="$t('_prop.production.finishedproductreceipt.storeNo')" prop="storeNo">
            <BaseSelect v-model="form.storeNo" :url="getWarehouseSelectListUrl" ref="warehouseSelectRef" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item :label="$t('_prop.production.finishedproductreceipt.formMark')" prop="formMark">
        <el-input
          v-model="form.formMark"
          :placeholder="$t('_message.production.finishedproductreceipt.input_formMark')"
          type="textarea"
          autosize
        />
      </el-form-item>
    </template>
    <template #form-table-columns>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.productType')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.productType`">
            <el-input
              v-model="row.productType"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_productType')"
            />
          </el-form-item>
        </template>
      </el-table-column>

      <el-table-column :label="$t('_prop.production.finishedproductreceipt.productSn')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.productSn`">
            <el-input
              v-model="row.productSn"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_productSn')"
            />
          </el-form-item>
        </template>
      </el-table-column>

      <el-table-column :label="$t('_prop.production.finishedproductreceipt.macAddress')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.mac`">
            <el-input
              v-model="row.mac"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_macAddress')"
            />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.serialNumber')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.serialNum`">
            <el-input
              v-model="row.serialNum"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_serialNumber')"
            />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.softwareVersion')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.softVersion`">
            <el-input
              v-model="row.softVersion"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_softwareVersion')"
            />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmVersion')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.alVersion`">
            <el-input
              v-model="row.alVersion"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_algorithmVersion')"
            />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmFlag')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.alNum`">
            <el-input
              v-model="row.alNum"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_algorithmFlag')"
            />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.activationStatus')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.alTxt`">
            <el-select
              v-model="row.alTxt"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_activationStatus')"
            >
              <el-option :label="$t('_base_info.activation_status.activated')" value="已激活" />
              <el-option :label="$t('_base_info.activation_status.not_activated')" value="未激活" />
            </el-select>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.remark')" width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${itemArrayName}.${$index}.mark`">
            <el-input
              v-model="row.mark"
              size="small"
              :placeholder="$t('_message.production.finishedproductreceipt.input_remark')"
            />
          </el-form-item>
        </template>
      </el-table-column>
    </template>
  </BaseFormWithTable>
  <BaseItemDialog
    :title="$t('_title.production.finishedproductreceipt.showItem')"
    v-model:visible="itemVisible"
    :url="getDetailUrl"
    parent-param-name="id"
    v-model:parent-param-value="itemParentId"
    width="80%"
  >
    <template #columns>
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.productType')"
        prop="productType"
        width="120"
      />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.productSn')" prop="productSn" width="150" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.macAddress')" prop="mac" width="150" />
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.serialNumber')"
        prop="serialNum"
        width="150"
      />
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.softwareVersion')"
        prop="softVersion"
        width="120"
      />
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.algorithmVersion')"
        prop="alVersion"
        width="120"
      />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmFlag')" prop="alNum" width="120" />
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.activationStatus')"
        prop="alStatus"
        width="120"
      >
        <template #default="{ row }">
          {{ getActivationStatusLabel(row.alStatus) }}
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.productionDate')"
        prop="createDate"
        width="150"
      />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.remark')" prop="mark" width="150" />
    </template>
  </BaseItemDialog>

  <!-- 出货对话框 -->
  <BaseTableForm
    ref="outstockDialogRef"
    v-model:visible="outstockVisible"
    :title="$t('_title.production.finishedproductreceipt.outstockDialog')"
    :tableData="outstockTableData"
    :selectable="true"
    :useAuth="false"
    @selection-change="handleOutstockSelectionChange"
  >
    <template #filter>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item :label="$t('_prop.production.finishedproductreceipt.formCode')">
            <el-input v-model="currentOutstockRow.formCode" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('_prop.production.finishedproductreceipt.keyAccountId')">
            <BaseSelect
              v-model="outstockForm.keyAccountId"
              :url="getKeyAccountSelectListUrl"
              ref="keyAccountSelectRef"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('_prop.production.finishedproductreceipt.formMark')">
            <el-input
              v-model="outstockForm.formMark"
              :placeholder="$t('_message.production.finishedproductreceipt.input_outstock_mark')"
              type="textarea"
              autosize
            />
          </el-form-item>
        </el-col>
      </el-row>
    </template>

    <template #table-columns>
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.productType')" prop="productType" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.productSn')" prop="productSn" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.macAddress')" prop="mac" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.serialNumber')" prop="serialNum" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.softwareVersion')" prop="softVersion" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmVersion')" prop="alVersion" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.algorithmFlag')" prop="alNum" />
      <el-table-column :label="$t('_prop.production.finishedproductreceipt.activationStatus')" prop="alStatus">
        <template #default="{ row }">
          {{ getActivationStatusLabel(row.alStatus) }}
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('_prop.production.finishedproductreceipt.createDate')"
        prop="createDate"
        :formatter="formatDate"
      />
    </template>

    <template #attachment>
      <el-button type="primary" @click="saveOutstock">
        {{ $t("_button.submit") }}
      </el-button>
    </template>
  </BaseTableForm>
</template>
