<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="120px" class="drawer-form">
            <el-form-item label="伙伴商编号" prop="partnerNo">
              <el-input v-model="queryParams.partnerNo" placeholder="请输入" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="伙伴商名称" prop="partnerName">
              <el-input v-model="queryParams.partnerName" placeholder="请输入" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleQuery">搜索</el-button>
              <el-button @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="hover">
      <template #header>
        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain :disabled="single" icon="Edit" @click="handleUpdate()">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain :disabled="multiple" icon="Delete" @click="handleDelete()">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>
          </el-col>
          <right-toolbar v-model:show-search="showSearch" @query-table="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="merchantList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="伙伴商编号" align="center" prop="partnerNo" min-width="120" />
        <el-table-column label="伙伴商名称" align="center" prop="partnerName" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column label="公司简称" align="center" prop="company" min-width="100" />
        <el-table-column label="合作型态" align="center" prop="partnerCooperateType" min-width="100">
          <template #default="scope">
            <span v-if="scope.row.partnerCooperateType === 0">伙伴商</span>
            <span v-else-if="scope.row.partnerCooperateType === 1">经销商</span>
            <span v-else-if="scope.row.partnerCooperateType === 2">代理商</span>
          </template>
        </el-table-column>
        <el-table-column label="法人代表" align="center" prop="legal" min-width="100" />
        <el-table-column label="固定电话" align="center" prop="telephone" min-width="120" />
        <el-table-column label="传真号码" align="center" prop="fax" min-width="120" />
        <el-table-column label="公司注册地址" align="center" prop="registerAddress" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column label="分司注册地址" align="center" prop="operatingAddress" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" @click="handleUpdate(scope.row)">详情</el-button>
            <el-button link type="primary" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </el-card>

    <el-drawer v-model="dialog.visible" :title="dialog.title" direction="rtl" size="60%" :before-close="handleDrawerClose">
      <div class="drawer-tabs-wrapper">
        <el-tabs v-model="activeTab" class="drawer-tabs">
          <el-tab-pane label="基本信息" name="basic" />
          <el-tab-pane label="资质管理" name="qualification" />
          <el-tab-pane label="银行账户" name="bank" />
          <el-tab-pane label="联系人" name="contact" />
          <el-tab-pane label="合同管理" name="contract" />
          <el-tab-pane label="用户账号" name="user" />
          <el-tab-pane label="仓库管理" name="warehouse" />
        </el-tabs>
      </div>

      <div class="drawer-content">
        <div v-show="activeTab === 'basic'" class="tab-panel">
          <el-form ref="merchantFormRef" :model="form" :rules="rules" label-width="120px" class="drawer-form">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="伙伴商全称" prop="partnerName">
                  <el-input v-model="form.partnerName" placeholder="请输入" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="伙伴商编号" prop="partnerNo">
                  <el-input v-model="form.partnerNo" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="公司简称" prop="company">
                  <el-input v-model="form.company" placeholder="请输入" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="合作型态" prop="partnerCooperateType">
                  <el-select v-model="form.partnerCooperateType" placeholder="请选择">
                    <el-option label="伙伴商" :value="0" />
                    <el-option label="经销商" :value="1" />
                    <el-option label="代理商" :value="2" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="法人代表" prop="legal">
                  <el-input v-model="form.legal" placeholder="请输入" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="固定电话" prop="telephone">
                  <el-input v-model="form.telephone" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="传真号码" prop="fax">
                  <el-input v-model="form.fax" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="公司注册地址" prop="registerAddress">
                  <el-input v-model="form.registerAddress" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="分司注册地址" prop="operatingAddress">
                  <el-input v-model="form.operatingAddress" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>

        <div v-show="activeTab === 'qualification'" class="tab-panel">
          <div class="tab-content">
            <div class="mb-2">
              <el-button type="primary" size="small" @click="handleAddQualification">新增资质</el-button>
            </div>
            <el-table :data="qualificationList" border>
              <el-table-column label="序号" type="index" width="60" />
              <el-table-column label="资质编号" prop="qualificationNo" />
              <el-table-column label="资质类型" prop="qualificationType">
                <template #default="scope">
                  <span v-if="scope.row.qualificationType === 1">营业执照</span>
                  <span v-else-if="scope.row.qualificationType === 2">资质证书</span>
                  <span v-else-if="scope.row.qualificationType === 3">其他</span>
                  <span v-else>{{ scope.row.qualificationType }}</span>
                </template>
              </el-table-column>
              <el-table-column label="签发机构" prop="authority" />
              <el-table-column label="截止日期" prop="deadline" />
              <el-table-column label="操作" width="150">
                <template #default="scope">
                  <el-button link type="primary" @click="handleDeleteQualification(scope.row)">删除</el-button>
                  <el-button link type="primary" @click="handleEditQualification(scope.row)">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <div v-show="activeTab === 'bank'" class="tab-panel">
          <div class="tab-content">
            <div class="mb-2">
              <el-button type="primary" size="small" @click="handleAddBank">新增银行账户</el-button>
            </div>
            <el-table :data="bankList" border>
              <el-table-column label="序号" type="index" width="60" />
              <el-table-column label="开户名称" prop="account" />
              <el-table-column label="财务登记号" prop="registrationNumber" />
              <el-table-column label="开户银行名称" prop="accountBankName" />
              <el-table-column label="银行账号" prop="bankNumber" />
              <el-table-column label="银行联行号" prop="bankInterbankNumber" />
              <el-table-column label="操作" width="150">
                <template #default="scope">
                  <el-button link type="primary" @click="handleDeleteBank(scope.row)">删除</el-button>
                  <el-button link type="primary" @click="handleEditBank(scope.row)">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <div v-show="activeTab === 'user'" class="tab-panel">
          <div class="tab-content">
            <div class="mb-2">
              <el-button type="primary" size="small" @click="handleAddUser">新增用户账号</el-button>
            </div>
            <el-table :data="userList" border>
              <el-table-column label="序号" type="index" width="60" />
              <el-table-column label="登录账号" prop="loginUser" />
              <el-table-column label="用户姓名" prop="name" />
              <el-table-column label="电子邮件" prop="email" />
              <el-table-column label="电话" prop="phone" />
              <el-table-column label="职务" prop="duties" />
              <el-table-column label="操作" width="150">
                <template #default="scope">
                  <el-button link type="primary" @click="handleDeleteUser(scope.row)">删除</el-button>
                  <el-button link type="primary" @click="handleEditUser(scope.row)">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <div v-show="activeTab === 'contact'" class="tab-panel">
          <div class="tab-content">
            <div class="mb-2">
              <el-button type="primary" size="small" @click="handleAddContact">新增联系人</el-button>
            </div>
            <el-table :data="contactList" border>
              <el-table-column label="序号" type="index" width="60" />
              <el-table-column label="姓名" prop="name" />
              <el-table-column label="电话" prop="phone" />
              <el-table-column label="电子邮件" prop="email" />
              <el-table-column label="联系人地址" prop="address" />
              <el-table-column label="操作" width="150">
                <template #default="scope">
                  <el-button link type="primary" @click="handleDeleteContact(scope.row)">删除</el-button>
                  <el-button link type="primary" @click="handleEditContact(scope.row)">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <div v-show="activeTab === 'contract'" class="tab-panel">
          <div class="tab-content">
            <div class="mb-2">
              <el-button type="primary" size="small" @click="handleAddContract">新增合同</el-button>
            </div>
            <el-table :data="contractList" border>
              <el-table-column label="序号" type="index" width="60" />
              <el-table-column label="合同编号" prop="contractNo" />
              <el-table-column label="合作项目名称" prop="cooperativeName" />
              <el-table-column label="合同类型" prop="contractType" />
              <el-table-column label="合同状态" prop="contractStatus" />
              <el-table-column label="合作区域" prop="area" />
              <el-table-column label="操作" width="150">
                <template #default="scope">
                  <el-button link type="primary" @click="handleDeleteContract(scope.row)">删除</el-button>
                  <el-button link type="primary" @click="handleEditContract(scope.row)">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <div v-show="activeTab === 'warehouse'" class="tab-panel">
          <div class="tab-content">
            <div class="mb-2">
              <el-button type="primary" size="small" @click="handleAddWarehouse">新增仓库</el-button>
            </div>
            <el-table :data="warehouseList" border>
              <el-table-column label="序号" type="index" width="60" />
              <el-table-column label="仓库名称" prop="name" />
              <el-table-column label="仓库性质" prop="warehouseNature">
                <template #default="scope">
                  {{ scope.row.warehouseNature === 1 ? '自有仓库' : scope.row.warehouseNature === 2 ? '租赁仓库' : '' }}
                </template>
              </el-table-column>
              <el-table-column label="所在地区" prop="warehouseLocation" />
              <el-table-column label="所在地址" prop="warehouseAddress" />
              <el-table-column label="仓库面积" prop="warehouseArea" />
              <el-table-column label="操作" width="150">
                <template #default="scope">
                  <el-button link type="primary" @click="handleDeleteWarehouse(scope.row)">删除</el-button>
                  <el-button link type="primary" @click="handleEditWarehouse(scope.row)">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>

      <template #footer>
        <div class="drawer-footer">
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" @click="submitForm">保存</el-button>
        </div>
      </template>
    </el-drawer>

    <!-- 资质管理对话框组件 -->
    <QualificationDialog v-model:visible="qualificationDialog.visible" v-model:form-data="qualificationForm" @submit="handleQualificationSubmit" />

    <!-- 银行账户对话框组件 -->
    <BankDialog v-model:visible="financialDialog.visible" v-model:form-data="bankForm" @submit="handleBankSubmit" />

    <!-- 用户账号对话框组件 -->
    <UserDialog v-model:visible="accountDialog.visible" v-model:form-data="userForm" @submit="handleUserSubmit" />

    <!-- 联系人对话框组件 -->
    <ContactDialog v-model:visible="contactDialog.visible" v-model:form-data="contactForm" @submit="handleContactSubmit" />

    <!-- 合同对话框组件 -->
    <ContractDialog v-model:visible="companyDialog.visible" v-model:form-data="contractForm" @submit="handleContractSubmit" />

    <!-- 仓库管理对话框组件 -->
    <WarehouseDialog v-model:visible="financeDialog.visible" v-model:form-data="warehouseForm" @submit="handleWarehouseSubmit" />
  </div>
</template>

<script setup name="PartnerMerchant" lang="ts">
import { PartnerMerchantVO, PartnerMerchantForm, PartnerMerchantQuery } from '@/api/partner/merchant/types';
import {
  listPartnerMerchant,
  getPartnerMerchant,
  addPartnerMerchant,
  updatePartnerMerchant,
  delPartnerMerchant,
  exportPartnerMerchant
} from '@/api/partner/merchant';
import WarehouseDialog from './components/WarehouseDialog.vue';
import QualificationDialog from './components/QualificationDialog.vue';
import BankDialog from './components/BankDialog.vue';
import ContactDialog from './components/ContactDialog.vue';
import UserDialog from './components/UserDialog.vue';
import ContractDialog from './components/ContractDialog.vue';
import { PartnerQualificationVO, PartnerQualificationForm } from '@/api/partner/qualification/types';
import { listPartnerQualification, addPartnerQualification, updatePartnerQualification, delPartnerQualification } from '@/api/partner/qualification';
import { PartnerBankVO, PartnerBankForm } from '@/api/partner/bank/types';
import { listPartnerBank, addPartnerBank, updatePartnerBank, delPartnerBank } from '@/api/partner/bank';
import { PartnerContactsVO, PartnerContactsForm } from '@/api/partner/contacts/types';
import { listPartnerContacts, addPartnerContacts, updatePartnerContacts, delPartnerContacts } from '@/api/partner/contacts';
import { PartnerContractVO, PartnerContractForm } from '@/api/partner/contract/types';
import { listPartnerContract, addPartnerContract, updatePartnerContract, delPartnerContract } from '@/api/partner/contract';
import { PartnerUserVO, PartnerUserForm } from '@/api/partner/user/types';
import { listPartnerUser, addPartnerUser, updatePartnerUser, delPartnerUser } from '@/api/partner/user';
import { PartnerWarehouseVO, PartnerWarehouseForm } from '@/api/partner/warehouse/types';
import { listPartnerWarehouse, addPartnerWarehouse, updatePartnerWarehouse, delPartnerWarehouse } from '@/api/partner/warehouse';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const merchantList = ref<PartnerMerchantVO[]>([]);
const loading = ref(false);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);

const merchantFormRef = ref<ElFormInstance>();
const queryFormRef = ref<ElFormInstance>();
const warehouseFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const activeTab = ref('basic');

// 监听标签页切换，实现懒加载
watch(activeTab, (newTab) => {
  if (!currentPartnerId.value) return;

  switch (newTab) {
    case 'qualification':
      if (qualificationList.value.length === 0) loadQualificationList();
      break;
    case 'bank':
      if (bankList.value.length === 0) loadBankList();
      break;
    case 'contact':
      if (contactList.value.length === 0) loadContactList();
      break;
    case 'contract':
      if (contractList.value.length === 0) loadContractList();
      break;
    case 'user':
      if (userList.value.length === 0) loadUserList();
      break;
    case 'warehouse':
      if (warehouseList.value.length === 0) loadWarehouseList();
      break;
  }
});
const qualificationList = ref<PartnerQualificationVO[]>([]);
const bankList = ref<PartnerBankVO[]>([]);
const contactList = ref<PartnerContactsVO[]>([]);
const contractList = ref<PartnerContractVO[]>([]);
const userList = ref<PartnerUserVO[]>([]);
const warehouseList = ref<PartnerWarehouseVO[]>([]);

const currentPartnerId = ref<number | string>();

// 各个子项弹窗状态
const qualificationDialog = reactive({ visible: false });
const financialDialog = reactive({ visible: false });
const accountDialog = reactive({ visible: false });
const contactDialog = reactive({ visible: false });
const companyDialog = reactive({ visible: false });
const financeDialog = reactive({ visible: false });

// 各个子项表单初始值
const initQualificationForm: PartnerQualificationForm = {
  partnerId: 0,
  qualificationNo: '',
  qualificationType: 1,
  authority: '',
  deadline: '',
  annex: '',
  status: '',
  remark: ''
};

const initBankForm: PartnerBankForm = {
  partnerId: 0,
  account: '',
  registrationNumber: '',
  accountBankName: '',
  bankNumber: '',
  bankLocation: '',
  bankInterbankNumber: '',
  phone: '',
  address: '',
  status: '',
  remark: ''
};

const initUserForm: PartnerUserForm = {
  partnerId: 0,
  loginUser: '',
  name: '',
  email: '',
  phone: '',
  duties: '',
  roleName: '',
  roleId: 0,
  password: '',
  status: '',
  remark: ''
};

const initContactForm: PartnerContactsForm = {
  partnerId: 0,
  name: '',
  phone: '',
  email: '',
  contactType: 1,
  status: '',
  remark: ''
};

const initContractForm: PartnerContractForm = {
  partnerId: 0,
  contractNo: '',
  cooperativeName: '',
  cooperationId: 0,
  startTime: '',
  endTime: '',
  categories: '',
  fee: 0,
  contractType: 1,
  settlementCycle: '',
  salesTarget: 0,
  area: '',
  contacts: '',
  phone: '',
  annex: '',
  importantTerms: '',
  contractStatus: 0,
  rejectInfo: '',
  status: '',
  remark: ''
};

const initWarehouseForm: PartnerWarehouseForm = {
  partnerId: 0,
  name: '',
  warehouseNature: 1,
  warehouseLocation: '',
  warehouseAddress: '',
  warehouseArea: '',
  warehouseContacts: '',
  phone: '',
  annex: '',
  status: '',
  remark: ''
};

// 各个子项表单数据
const qualificationForm = ref<PartnerQualificationForm>({ ...initQualificationForm });

const bankForm = ref<PartnerBankForm>({ ...initBankForm });
const userForm = ref<PartnerUserForm>({ ...initUserForm });
const contactForm = ref<PartnerContactsForm>({ ...initContactForm });
const contractForm = ref<PartnerContractForm>({ ...initContractForm });
const warehouseForm = ref<PartnerWarehouseForm>({ ...initWarehouseForm });

// 保留旧的弹窗变量名以兼容模板
const financialForm = bankForm;
const accountForm = userForm;
const companyForm = contractForm;
const financeForm = warehouseForm;

const initFormData: PartnerMerchantForm = {
  id: undefined,
  partnerNo: '',
  partnerName: '',
  company: '',
  partnerCooperateType: undefined,
  legal: '',
  telephone: '',
  fax: '',
  registerAddress: '',
  operatingAddress: '',
  remark: '',
  status: '0'
};

const data = reactive<PageData<PartnerMerchantForm, PartnerMerchantQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    partnerNo: '',
    partnerName: ''
  },
  rules: {
    partnerName: [{ required: true, message: '伙伴商名称不能为空', trigger: 'blur' }]
  }
});

const { queryParams, form, rules } = toRefs(data);

// 仓库表单验证规则
const warehouseRules = {
  name: [{ required: true, message: '仓库名称不能为空', trigger: 'blur' }]
};

const getList = () => {
  loading.value = true;
  listPartnerMerchant(queryParams.value)
    .then((response: any) => {
      console.log('列表数据返回:', response);
      merchantList.value = response.rows || [];
      total.value = response.total || 0;
      loading.value = false;
    })
    .catch((error) => {
      console.error('获取列表失败:', error);
      loading.value = false;
    });
};

const cancel = () => {
  reset();
  dialog.visible = false;
  activeTab.value = 'basic';
};

const handleDrawerClose = (done: () => void) => {
  proxy?.$modal
    .confirm('确认关闭？')
    .then(() => {
      cancel();
      done();
    })
    .catch(() => {
      // 取消关闭
    });
};

const reset = () => {
  form.value = { ...initFormData };
  merchantFormRef.value?.resetFields();
  // 清空所有子项列表
  qualificationList.value = [];
  bankList.value = [];
  contactList.value = [];
  contractList.value = [];
  userList.value = [];
  warehouseList.value = [];
  // 重置当前伙伴商ID
  currentPartnerId.value = undefined;
};

const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

const resetQuery = () => {
  dateRange.value = ['', ''];
  queryFormRef.value?.resetFields();
  handleQuery();
};

const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = '添加伙伴商';
};

const handleSelectionChange = (selection: PartnerMerchantVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

const handleUpdate = async (row?: PartnerMerchantVO) => {
  const id = row?.id || ids.value[0];

  if (!id) {
    proxy?.$modal.msgError('请选择要修改的数据');
    return;
  }

  try {
    const response: any = await getPartnerMerchant(id);
    const responseData = response.data || response.rows?.[0] || response;

    if (!responseData) {
      throw new Error('未获取到数据');
    }

    // 先设置标签页为基本信息（在打开抽屉之前）
    activeTab.value = 'basic';

    // 设置表单数据
    form.value = {
      id: responseData.id,
      partnerNo: responseData.partnerNo || '',
      partnerName: responseData.partnerName || '',
      company: responseData.company || '',
      partnerCooperateType: responseData.partnerCooperateType,
      legal: responseData.legal || '',
      telephone: responseData.telephone || '',
      fax: responseData.fax || '',
      registerAddress: responseData.registerAddress || '',
      operatingAddress: responseData.operatingAddress || '',
      remark: responseData.remark || '',
      status: responseData.status || '0'
    };

    currentPartnerId.value = responseData.id;

    // 清空所有子项列表，确保数据干净
    qualificationList.value = [];
    bankList.value = [];
    contactList.value = [];
    contractList.value = [];
    userList.value = [];
    warehouseList.value = [];

    // 打开抽屉
    dialog.visible = true;
    dialog.title = '修改伙伴商';

    // 使用nextTick确保DOM更新后再加载基本信息标签页的数据（如果需要）
    await nextTick();

    // 不再一次性加载所有子项数据，改为在切换标签页时按需加载
  } catch (error) {
    console.error('获取详情失败:', error);
    proxy?.$modal.msgError('获取详情失败');
    dialog.visible = false;
  }
};

const submitForm = () => {
  merchantFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      try {
        // 先保存伙伴商基本信息
        if (form.value.id) {
          await updatePartnerMerchant(form.value);
        } else {
          await addPartnerMerchant(form.value);
        }

        // 保存所有子项数据（新增和修改）
        const savePromises = [];

        // 保存资质数据
        for (const item of qualificationList.value) {
          const itemAny = item as any;
          console.log('资质数据:', item, 'id类型:', typeof item.id);

          // 判断是新增还是修改：只有以temp_开头的ID才是新增，其他都是修改
          if (String(item.id).startsWith('temp_')) {
            // 新增数据：删除临时ID
            const data: any = {
              partnerId: currentPartnerId.value,
              qualificationNo: itemAny.qualificationNo,
              qualificationType: itemAny.qualificationType,
              authority: itemAny.authority,
              deadline: itemAny.deadline,
              annex: itemAny.annex,
              status: itemAny.status,
              remark: itemAny.remark
            };
            console.log('调用新增接口:', data);
            savePromises.push(addPartnerQualification(data));
          } else {
            // 修改数据：保留ID
            const data: any = {
              id: item.id,
              partnerId: currentPartnerId.value,
              qualificationNo: itemAny.qualificationNo,
              qualificationType: itemAny.qualificationType,
              authority: itemAny.authority,
              deadline: itemAny.deadline,
              annex: itemAny.annex,
              status: itemAny.status,
              remark: itemAny.remark
            };
            console.log('调用更新接口:', data);
            savePromises.push(updatePartnerQualification(data));
          }
        }

        // 保存银行账户数据
        for (const item of bankList.value) {
          const itemAny = item as any;
          if (String(item.id).startsWith('temp_')) {
            const data: any = {
              partnerId: currentPartnerId.value,
              account: itemAny.account,
              registrationNumber: itemAny.registrationNumber,
              bankId: itemAny.bankId,
              accountBankName: itemAny.accountBankName,
              bankNumber: itemAny.bankNumber,
              bankLocation: itemAny.bankLocation,
              bankInterbankNumber: itemAny.bankInterbankNumber,
              phone: itemAny.phone,
              address: itemAny.address,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(addPartnerBank(data));
          } else {
            const data: any = {
              id: item.id,
              partnerId: currentPartnerId.value,
              account: itemAny.account,
              registrationNumber: itemAny.registrationNumber,
              bankId: itemAny.bankId,
              accountBankName: itemAny.accountBankName,
              bankNumber: itemAny.bankNumber,
              bankLocation: itemAny.bankLocation,
              bankInterbankNumber: itemAny.bankInterbankNumber,
              phone: itemAny.phone,
              address: itemAny.address,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(updatePartnerBank(data));
          }
        }

        // 保存联系人数据
        for (const item of contactList.value) {
          const itemAny = item as any;
          if (String(item.id).startsWith('temp_')) {
            const data: any = {
              partnerId: currentPartnerId.value,
              name: itemAny.name,
              phone: itemAny.phone,
              email: itemAny.email,
              contactType: itemAny.contactType,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(addPartnerContacts(data));
          } else {
            const data: any = {
              id: item.id,
              partnerId: currentPartnerId.value,
              name: itemAny.name,
              phone: itemAny.phone,
              email: itemAny.email,
              contactType: itemAny.contactType,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(updatePartnerContacts(data));
          }
        }

        // 保存合同数据
        for (const item of contractList.value) {
          const itemAny = item as any;
          if (String(item.id).startsWith('temp_')) {
            const data: any = {
              partnerId: currentPartnerId.value,
              contractNo: itemAny.contractNo,
              cooperativeName: itemAny.cooperativeName,
              cooperationId: itemAny.cooperationId,
              startTime: itemAny.startTime,
              endTime: itemAny.endTime,
              categories: itemAny.categories,
              fee: itemAny.fee,
              contractType: itemAny.contractType,
              settlementCycle: itemAny.settlementCycle,
              salesTarget: itemAny.salesTarget,
              area: itemAny.area,
              contacts: itemAny.contacts,
              phone: itemAny.phone,
              annex: itemAny.annex,
              importantTerms: itemAny.importantTerms,
              contractStatus: itemAny.contractStatus,
              rejectInfo: itemAny.rejectInfo,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(addPartnerContract(data));
          } else {
            const data: any = {
              id: item.id,
              partnerId: currentPartnerId.value,
              contractNo: itemAny.contractNo,
              cooperativeName: itemAny.cooperativeName,
              cooperationId: itemAny.cooperationId,
              startTime: itemAny.startTime,
              endTime: itemAny.endTime,
              categories: itemAny.categories,
              fee: itemAny.fee,
              contractType: itemAny.contractType,
              settlementCycle: itemAny.settlementCycle,
              salesTarget: itemAny.salesTarget,
              area: itemAny.area,
              contacts: itemAny.contacts,
              phone: itemAny.phone,
              annex: itemAny.annex,
              importantTerms: itemAny.importantTerms,
              contractStatus: itemAny.contractStatus,
              rejectInfo: itemAny.rejectInfo,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(updatePartnerContract(data));
          }
        }

        // 保存用户账号数据
        for (const item of userList.value) {
          const itemAny = item as any;
          if (String(item.id).startsWith('temp_')) {
            const data: any = {
              partnerId: currentPartnerId.value,
              loginUser: itemAny.loginUser,
              name: itemAny.name,
              email: itemAny.email,
              phone: itemAny.phone,
              duties: itemAny.duties,
              roleName: itemAny.roleName,
              roleId: itemAny.roleId,
              password: itemAny.password,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(addPartnerUser(data));
          } else {
            const data: any = {
              id: item.id,
              partnerId: currentPartnerId.value,
              loginUser: itemAny.loginUser,
              name: itemAny.name,
              email: itemAny.email,
              phone: itemAny.phone,
              duties: itemAny.duties,
              roleName: itemAny.roleName,
              roleId: itemAny.roleId,
              password: itemAny.password,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(updatePartnerUser(data));
          }
        }

        // 保存仓库数据
        for (const item of warehouseList.value) {
          const itemAny = item as any;
          if (String(item.id).startsWith('temp_')) {
            const data: any = {
              partnerId: currentPartnerId.value,
              name: itemAny.name,
              warehouseNature: itemAny.warehouseNature,
              warehouseLocation: itemAny.warehouseLocation,
              warehouseAddress: itemAny.warehouseAddress,
              warehouseArea: itemAny.warehouseArea,
              warehouseContacts: itemAny.warehouseContacts,
              phone: itemAny.phone,
              annex: itemAny.annex,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(addPartnerWarehouse(data));
          } else {
            const data: any = {
              id: item.id,
              partnerId: currentPartnerId.value,
              name: itemAny.name,
              warehouseNature: itemAny.warehouseNature,
              warehouseLocation: itemAny.warehouseLocation,
              warehouseAddress: itemAny.warehouseAddress,
              warehouseArea: itemAny.warehouseArea,
              warehouseContacts: itemAny.warehouseContacts,
              phone: itemAny.phone,
              annex: itemAny.annex,
              status: itemAny.status,
              remark: itemAny.remark
            };
            savePromises.push(updatePartnerWarehouse(data));
          }
        }

        // 等待所有子项保存完成
        if (savePromises.length > 0) {
          await Promise.all(savePromises);
          proxy?.$modal.msgSuccess(`保存成功，共保存${savePromises.length}条子项数据`);
        } else {
          proxy?.$modal.msgSuccess(form.value.id ? '修改成功' : '新增成功');
        }

        cancel();
        if (!form.value.id) {
          queryParams.value.pageNum = 1;
        }
        getList();
      } catch (error) {
        console.error('保存失败:', error);
        proxy?.$modal.msgError('保存失败，请重试');
      }
    }
  });
};

const handleDelete = async (row?: PartnerMerchantVO) => {
  const deleteIds = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除选中的伙伴商数据？');
  delPartnerMerchant(deleteIds).then(() => {
    proxy?.$modal.msgSuccess('删除成功');
    getList();
  });
};

const handleExport = () => {
  proxy?.$modal
    .confirm('是否确认导出所有伙伴商数据？')
    .then(() => {
      return exportPartnerMerchant(queryParams.value);
    })
    .then(() => {
      proxy?.$modal.msgSuccess('导出成功');
    });
};

// 通用子项提交函数
const submitSubItem = <T extends { id?: string | number; partnerId?: string | number }>(
  list: Ref<T[]>,
  form: Ref<T>,
  dialog: { visible: boolean },
  formReset: T,
  itemName: string = '数据',
  formRef?: Ref<any>
) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }

  // 如果提供了formRef，先进行表单验证
  const doSubmit = () => {
    const existingIndex = list.value.findIndex((item) => item.id === form.value.id);

    if (existingIndex !== -1) {
      // 编辑模式
      const updatedItem: any = { ...form.value };
      updatedItem.partnerId = currentPartnerId.value;
      if (typeof updatedItem.id === 'number') {
        updatedItem._isModified = true;
      }
      list.value.splice(existingIndex, 1, updatedItem);
      proxy?.$modal.msgSuccess(`修改成功，请点击保存按钮保存到数据库`);
    } else {
      // 新增模式
      const newItem: any = { ...form.value };
      newItem.partnerId = currentPartnerId.value;
      newItem.id = 'temp_' + Date.now();
      newItem._isNew = true;
      list.value.push(newItem);
      proxy?.$modal.msgSuccess(`添加成功，请点击保存按钮保存到数据库`);
    }

    dialog.visible = false;
    form.value = { ...formReset };
  };

  if (formRef?.value) {
    formRef.value.validate((valid: boolean) => {
      if (valid) {
        doSubmit();
      }
    });
  } else {
    doSubmit();
  }
};

// 加载子项数据（带错误处理）
const loadQualificationList = () => {
  if (!currentPartnerId.value) return;
  listPartnerQualification({ partnerId: currentPartnerId.value })
    .then((res: any) => {
      qualificationList.value = res.rows || [];
    })
    .catch((error) => {
      console.error('加载资质列表失败:', error);
      proxy?.$modal.msgError('加载资质列表失败');
    });
};

const loadBankList = () => {
  if (!currentPartnerId.value) return;
  listPartnerBank({ partnerId: currentPartnerId.value })
    .then((res: any) => {
      bankList.value = res.rows || [];
    })
    .catch((error) => {
      console.error('加载银行账户列表失败:', error);
      proxy?.$modal.msgError('加载银行账户列表失败');
    });
};

const loadContactList = () => {
  if (!currentPartnerId.value) return;
  listPartnerContacts({ partnerId: currentPartnerId.value })
    .then((res: any) => {
      contactList.value = res.rows || [];
    })
    .catch((error) => {
      console.error('加载联系人列表失败:', error);
      proxy?.$modal.msgError('加载联系人列表失败');
    });
};

const loadContractList = () => {
  if (!currentPartnerId.value) return;
  listPartnerContract({ partnerId: currentPartnerId.value })
    .then((res: any) => {
      contractList.value = res.rows || [];
    })
    .catch((error) => {
      console.error('加载合同列表失败:', error);
      proxy?.$modal.msgError('加载合同列表失败');
    });
};

const loadUserList = () => {
  if (!currentPartnerId.value) return;
  listPartnerUser({ partnerId: currentPartnerId.value })
    .then((res: any) => {
      userList.value = res.rows || [];
    })
    .catch((error) => {
      console.error('加载用户列表失败:', error);
      proxy?.$modal.msgError('加载用户列表失败');
    });
};

const loadWarehouseList = () => {
  if (!currentPartnerId.value) return;
  listPartnerWarehouse({ partnerId: currentPartnerId.value })
    .then((res: any) => {
      warehouseList.value = res.rows || [];
    })
    .catch((error) => {
      console.error('加载仓库列表失败:', error);
      proxy?.$modal.msgError('加载仓库列表失败');
    });
};

const handleAddQualification = () => {
  qualificationForm.value = {
    partnerId: 0,
    qualificationNo: '',
    qualificationType: 1,
    authority: '',
    deadline: '',
    annex: '',
    status: '',
    remark: ''
  };
  qualificationDialog.visible = true;
};

const handleAddBank = () => {
  bankForm.value = {
    partnerId: 0,
    account: '',
    registrationNumber: '',
    bankId: null,
    accountBankName: '',
    bankNumber: '',
    bankLocation: '',
    bankInterbankNumber: '',
    phone: '',
    address: '',
    status: '',
    remark: ''
  };
  financialDialog.visible = true;
};

const handleAddUser = () => {
  userForm.value = {
    partnerId: 0,
    loginUser: '',
    name: '',
    email: '',
    phone: '',
    duties: '',
    roleName: '',
    roleId: 0,
    password: '',
    status: '',
    remark: ''
  };
  accountDialog.visible = true;
};

const handleAddContact = () => {
  contactForm.value = {
    partnerId: 0,
    name: '',
    phone: '',
    email: '',
    contactType: 1,
    status: '',
    remark: ''
  };
  contactDialog.visible = true;
};

const handleAddContract = () => {
  contractForm.value = {
    partnerId: 0,
    contractNo: '',
    cooperativeName: '',
    cooperationId: 0,
    startTime: '',
    endTime: '',
    categories: '',
    fee: 0,
    contractType: 1,
    settlementCycle: '',
    salesTarget: 0,
    area: '',
    contacts: '',
    phone: '',
    annex: '',
    importantTerms: '',
    contractStatus: 0,
    rejectInfo: '',
    status: '',
    remark: ''
  };
  companyDialog.visible = true;
};

const handleAddWarehouse = () => {
  warehouseForm.value = {
    partnerId: 0,
    name: '',
    warehouseNature: 1,
    warehouseLocation: '',
    warehouseAddress: '',
    warehouseArea: '',
    warehouseContacts: '',
    phone: '',
    annex: '',
    status: '',
    remark: ''
  };
  financeDialog.visible = true;
};

// 编辑和删除处理函数
const handleEditQualification = (row: PartnerQualificationVO) => {
  qualificationForm.value = { ...row } as any;
  qualificationDialog.visible = true;
};

const handleDeleteQualification = async (row: PartnerQualificationVO) => {
  const index = qualificationList.value.findIndex((item) => item.id === row.id);
  if (index !== -1) {
    // 如果是新增的数据（临时ID），直接从列表中删除
    if ((row as any)._isNew) {
      qualificationList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    } else {
      // 如果是已存在的数据，调用后端删除接口
      await proxy?.$modal.confirm('是否确认删除该资质数据？');
      await delPartnerQualification(row.id);
      qualificationList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    }
  }
};

const handleEditBank = (row: PartnerBankVO) => {
  bankForm.value = { ...row } as any;
  financialDialog.visible = true;
};

const handleDeleteBank = async (row: PartnerBankVO) => {
  const index = bankList.value.findIndex((item) => item.id === row.id);
  if (index !== -1) {
    if ((row as any)._isNew) {
      bankList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    } else {
      await proxy?.$modal.confirm('是否确认删除该银行账户数据？');
      await delPartnerBank(row.id);
      bankList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    }
  }
};

const handleEditUser = (row: PartnerUserVO) => {
  userForm.value = { ...row } as any;
  accountDialog.visible = true;
};

const handleDeleteUser = async (row: PartnerUserVO) => {
  const index = userList.value.findIndex((item) => item.id === row.id);
  if (index !== -1) {
    if ((row as any)._isNew) {
      userList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    } else {
      await proxy?.$modal.confirm('是否确认删除该用户账号数据？');
      await delPartnerUser(row.id);
      userList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    }
  }
};

const handleEditContact = (row: PartnerContactsVO) => {
  contactForm.value = { ...row } as any;
  contactDialog.visible = true;
};

const handleDeleteContact = async (row: PartnerContactsVO) => {
  const index = contactList.value.findIndex((item) => item.id === row.id);
  if (index !== -1) {
    if ((row as any)._isNew) {
      contactList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    } else {
      await proxy?.$modal.confirm('是否确认删除该联系人数据？');
      await delPartnerContacts(row.id);
      contactList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    }
  }
};

const handleEditContract = (row: PartnerContractVO) => {
  contractForm.value = { ...row } as any;
  companyDialog.visible = true;
};

const handleDeleteContract = async (row: PartnerContractVO) => {
  const index = contractList.value.findIndex((item) => item.id === row.id);
  if (index !== -1) {
    if ((row as any)._isNew) {
      contractList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    } else {
      await proxy?.$modal.confirm('是否确认删除该合同数据？');
      await delPartnerContract(row.id);
      contractList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    }
  }
};

const handleEditWarehouse = (row: PartnerWarehouseVO) => {
  warehouseForm.value = { ...row } as any;
  financeDialog.visible = true;
};

const handleDeleteWarehouse = async (row: PartnerWarehouseVO) => {
  const index = warehouseList.value.findIndex((item) => item.id === row.id);
  if (index !== -1) {
    if ((row as any)._isNew) {
      warehouseList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    } else {
      await proxy?.$modal.confirm('是否确认删除该仓库数据？');
      await delPartnerWarehouse(row.id);
      warehouseList.value.splice(index, 1);
      proxy?.$modal.msgSuccess('删除成功');
    }
  }
};

const handleQualificationSubmit = (formData: PartnerQualificationForm) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }
  const existingIndex = qualificationList.value.findIndex((item) => item.id === formData.id);
  if (existingIndex !== -1) {
    const updatedItem: any = { ...formData };
    updatedItem.partnerId = currentPartnerId.value;
    if (typeof updatedItem.id === 'number') {
      updatedItem._isModified = true;
    }
    qualificationList.value.splice(existingIndex, 1, updatedItem);
    proxy?.$modal.msgSuccess('修改成功，请点击保存按钮保存到数据库');
  } else {
    const newItem: any = { ...formData };
    newItem.partnerId = currentPartnerId.value;
    newItem.id = 'temp_' + Date.now();
    newItem._isNew = true;
    qualificationList.value.push(newItem);
    proxy?.$modal.msgSuccess('添加成功，请点击保存按钮保存到数据库');
  }
  qualificationDialog.visible = false;
  qualificationForm.value = { ...initQualificationForm };
};

const handleBankSubmit = (formData: PartnerBankForm) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }
  const existingIndex = bankList.value.findIndex((item) => item.id === formData.id);
  if (existingIndex !== -1) {
    const updatedItem: any = { ...formData };
    updatedItem.partnerId = currentPartnerId.value;
    if (typeof updatedItem.id === 'number') {
      updatedItem._isModified = true;
    }
    bankList.value.splice(existingIndex, 1, updatedItem);
    proxy?.$modal.msgSuccess('修改成功，请点击保存按钮保存到数据库');
  } else {
    const newItem: any = { ...formData };
    newItem.partnerId = currentPartnerId.value;
    newItem.id = 'temp_' + Date.now();
    newItem._isNew = true;
    bankList.value.push(newItem);
    proxy?.$modal.msgSuccess('添加成功，请点击保存按钮保存到数据库');
  }
  financialDialog.visible = false;
  bankForm.value = { ...initBankForm };
};

const handleUserSubmit = (formData: PartnerUserForm) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }
  const existingIndex = userList.value.findIndex((item) => item.id === formData.id);
  if (existingIndex !== -1) {
    const updatedItem: any = { ...formData };
    updatedItem.partnerId = currentPartnerId.value;
    if (typeof updatedItem.id === 'number') {
      updatedItem._isModified = true;
    }
    userList.value.splice(existingIndex, 1, updatedItem);
    proxy?.$modal.msgSuccess('修改成功，请点击保存按钮保存到数据库');
  } else {
    const newItem: any = { ...formData };
    newItem.partnerId = currentPartnerId.value;
    newItem.id = 'temp_' + Date.now();
    newItem._isNew = true;
    userList.value.push(newItem);
    proxy?.$modal.msgSuccess('添加成功，请点击保存按钮保存到数据库');
  }
  accountDialog.visible = false;
  userForm.value = { ...initUserForm };
};

const handleContactSubmit = (formData: PartnerContactsForm) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }
  const existingIndex = contactList.value.findIndex((item) => item.id === formData.id);
  if (existingIndex !== -1) {
    const updatedItem: any = { ...formData };
    updatedItem.partnerId = currentPartnerId.value;
    if (typeof updatedItem.id === 'number') {
      updatedItem._isModified = true;
    }
    contactList.value.splice(existingIndex, 1, updatedItem);
    proxy?.$modal.msgSuccess('修改成功，请点击保存按钮保存到数据库');
  } else {
    const newItem: any = { ...formData };
    newItem.partnerId = currentPartnerId.value;
    newItem.id = 'temp_' + Date.now();
    newItem._isNew = true;
    contactList.value.push(newItem);
    proxy?.$modal.msgSuccess('添加成功，请点击保存按钮保存到数据库');
  }
  contactDialog.visible = false;
  contactForm.value = { ...initContactForm };
};

const handleContractSubmit = (formData: PartnerContractForm) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }
  const existingIndex = contractList.value.findIndex((item) => item.id === formData.id);
  if (existingIndex !== -1) {
    const updatedItem: any = { ...formData };
    updatedItem.partnerId = currentPartnerId.value;
    if (typeof updatedItem.id === 'number') {
      updatedItem._isModified = true;
    }
    contractList.value.splice(existingIndex, 1, updatedItem);
    proxy?.$modal.msgSuccess('修改成功，请点击保存按钮保存到数据库');
  } else {
    const newItem: any = { ...formData };
    newItem.partnerId = currentPartnerId.value;
    newItem.id = 'temp_' + Date.now();
    newItem._isNew = true;
    contractList.value.push(newItem);
    proxy?.$modal.msgSuccess('添加成功，请点击保存按钮保存到数据库');
  }
  companyDialog.visible = false;
  contractForm.value = { ...initContractForm };
};

// 仓库提交处理（组件方式）
const handleWarehouseSubmit = (formData: PartnerWarehouseForm) => {
  if (!currentPartnerId.value) {
    proxy?.$modal.msgError('请先选择伙伴商');
    return;
  }

  const existingIndex = warehouseList.value.findIndex((item) => item.id === formData.id);

  if (existingIndex !== -1) {
    // 编辑模式
    const updatedItem: any = { ...formData };
    updatedItem.partnerId = currentPartnerId.value;
    if (typeof updatedItem.id === 'number') {
      updatedItem._isModified = true;
    }
    warehouseList.value.splice(existingIndex, 1, updatedItem);
    proxy?.$modal.msgSuccess('修改成功，请点击保存按钮保存到数据库');
  } else {
    // 新增模式
    const newItem: any = { ...formData };
    newItem.partnerId = currentPartnerId.value;
    newItem.id = 'temp_' + Date.now();
    newItem._isNew = true;
    warehouseList.value.push(newItem);
    proxy?.$modal.msgSuccess('添加成功，请点击保存按钮保存到数据库');
  }

  // 关闭对话框
  financeDialog.visible = false;
  // 重置表单
  warehouseForm.value = { ...initWarehouseForm };
};

onMounted(() => {
  getList();
});
</script>

<style scoped lang="scss">
.drawer-tabs-wrapper {
  border-bottom: 1px solid var(--el-border-color);
  background-color: #fff;
}

.drawer-tabs {
  :deep(.el-tabs__header) {
    margin: 0;
    padding: 0 20px;
    background-color: #f5f7fa;
  }

  :deep(.el-tabs__nav-wrap) {
    padding: 0;
  }

  :deep(.el-tabs__content) {
    display: none;
  }
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.tab-panel {
  min-height: 100%;
}

.drawer-form {
  padding: 0;
}

.tab-content {
  padding: 0;
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 20px;
  border-top: 1px solid var(--el-border-color);
  background-color: #fff;
}

:deep(.el-drawer__header) {
  margin-bottom: 0;
  padding: 20px;
  border-bottom: 1px solid var(--el-border-color);
}

:deep(.el-drawer__body) {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mb-2 {
  margin-bottom: 10px;
}
</style>
