<template>
  <div class="min-h-screen bg-gray-100 dark:bg-gray-900">
    <!-- 顶部导航 -->
    <div class="bg-white dark:bg-gray-800 shadow">
      <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
        <div class="flex justify-between items-center">
          <h1 class="text-2xl font-bold text-gray-900 dark:text-white">采购管理</h1>
          <div class="flex space-x-4">
            <button @click="showAddOrderModal = true" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700">
              新增订单
            </button>
            <button @click="showAddSupplierModal = true" class="bg-green-600 text-white px-4 py-2 rounded-md hover:bg-green-700">
              新增供应商
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
      <!-- 采购统计卡片 -->
      <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
          <div class="text-sm font-medium text-gray-500 dark:text-gray-400">本月采购</div>
          <div class="mt-2 text-3xl font-bold text-blue-600 dark:text-blue-400">¥{{ formatNumber(currentMonthPurchases) }}</div>
          <div class="mt-2 text-sm text-gray-500 dark:text-gray-400">
            环比增长 <span :class="purchaseGrowth >= 0 ? 'text-green-600' : 'text-red-600'">{{ purchaseGrowth }}%</span>
          </div>
        </div>
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
          <div class="text-sm font-medium text-gray-500 dark:text-gray-400">总订单数</div>
          <div class="mt-2 text-3xl font-bold text-purple-600 dark:text-purple-400">{{ formatNumber(totalOrders) }}</div>
          <div class="mt-2 text-sm text-gray-500 dark:text-gray-400">
            完成率 <span class="text-green-600">{{ completionRate }}%</span>
          </div>
        </div>
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
          <div class="text-sm font-medium text-gray-500 dark:text-gray-400">总供应商</div>
          <div class="mt-2 text-3xl font-bold text-green-600 dark:text-green-400">{{ formatNumber(totalSuppliers) }}</div>
          <div class="mt-2 text-sm text-gray-500 dark:text-gray-400">
            活跃供应商 <span class="text-blue-600">{{ formatNumber(activeSuppliers) }}</span>
          </div>
        </div>
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
          <div class="text-sm font-medium text-gray-500 dark:text-gray-400">平均采购周期</div>
          <div class="mt-2 text-3xl font-bold text-yellow-600 dark:text-yellow-400">{{ averageCycle }}天</div>
          <div class="mt-2 text-sm text-gray-500 dark:text-gray-400">
            环比变化 <span :class="cycleChange >= 0 ? 'text-green-600' : 'text-red-600'">{{ cycleChange }}%</span>
          </div>
        </div>
      </div>

      <!-- 搜索和筛选 -->
      <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6 mb-6">
        <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
          <div>
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">搜索</label>
            <input type="text" v-model="searchText" placeholder="订单号/供应商名称" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div>
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">订单状态</label>
            <select v-model="filters.status" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
              <option value="">所有状态</option>
              <option v-for="status in orderStatuses" :key="status.id" :value="status.id">{{ status.name }}</option>
            </select>
          </div>
          <div>
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">时间范围</label>
            <select v-model="filters.timeRange" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
              <option v-for="range in timeRanges" :key="range.id" :value="range.id">{{ range.name }}</option>
            </select>
          </div>
          <div>
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">采购员</label>
            <select v-model="filters.purchaser" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
              <option value="">所有采购员</option>
              <option v-for="purchaser in purchasers" :key="purchaser.id" :value="purchaser.id">{{ purchaser.name }}</option>
            </select>
          </div>
        </div>
      </div>

      <!-- 采购订单列表 -->
      <div class="bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden mb-6">
        <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700">
          <h2 class="text-lg font-medium text-gray-900 dark:text-white">采购订单</h2>
        </div>
        <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
          <thead class="bg-gray-50 dark:bg-gray-700">
            <tr>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">订单信息</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">供应商信息</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">金额</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">状态</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">操作</th>
            </tr>
          </thead>
          <tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
            <tr v-for="order in filteredOrders" :key="order.id">
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="text-sm font-medium text-gray-900 dark:text-white">{{ order.orderNo }}</div>
                <div class="text-sm text-gray-500 dark:text-gray-400">{{ formatDate(order.orderDate) }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="text-sm text-gray-900 dark:text-white">{{ order.supplierName }}</div>
                <div class="text-sm text-gray-500 dark:text-gray-400">{{ order.supplierContact }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white">
                ¥{{ formatNumber(order.amount) }}
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <span :class="getOrderStatusClass(order.status)" class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full">
                  {{ getOrderStatusName(order.status) }}
                </span>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                <button @click="viewOrder(order)" class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300 mr-3">查看</button>
                <button @click="editOrder(order)" class="text-yellow-600 hover:text-yellow-900 dark:text-yellow-400 dark:hover:text-yellow-300 mr-3">编辑</button>
                <button @click="deleteOrder(order)" class="text-red-600 hover:text-red-900 dark:text-red-400 dark:hover:text-red-300">删除</button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <!-- 供应商列表 -->
      <div class="bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700">
          <h2 class="text-lg font-medium text-gray-900 dark:text-white">供应商列表</h2>
        </div>
        <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
          <thead class="bg-gray-50 dark:bg-gray-700">
            <tr>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">供应商信息</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">联系方式</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">合作状态</th>
              <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">操作</th>
            </tr>
          </thead>
          <tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
            <tr v-for="supplier in suppliers" :key="supplier.id">
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="text-sm font-medium text-gray-900 dark:text-white">{{ supplier.name }}</div>
                <div class="text-sm text-gray-500 dark:text-gray-400">{{ supplier.code }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="text-sm text-gray-900 dark:text-white">{{ supplier.contact }}</div>
                <div class="text-sm text-gray-500 dark:text-gray-400">{{ supplier.phone }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <span :class="getSupplierStatusClass(supplier.status)" class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full">
                  {{ getSupplierStatusName(supplier.status) }}
                </span>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                <button @click="viewSupplier(supplier)" class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300 mr-3">查看</button>
                <button @click="editSupplier(supplier)" class="text-yellow-600 hover:text-yellow-900 dark:text-yellow-400 dark:hover:text-yellow-300 mr-3">编辑</button>
                <button @click="deleteSupplier(supplier)" class="text-red-600 hover:text-red-900 dark:text-red-400 dark:hover:text-red-300">删除</button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

    <!-- 新增订单模态框 -->
    <div v-if="showAddOrderModal" class="fixed inset-0 bg-gray-500 bg-opacity-75 flex items-center justify-center">
      <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full p-6">
        <h2 class="text-xl font-bold mb-4 text-gray-900 dark:text-white">新增采购订单</h2>
        <form @submit.prevent="addOrder">
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">供应商</label>
            <select v-model="newOrder.supplierId" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
              <option v-for="supplier in suppliers" :key="supplier.id" :value="supplier.id">{{ supplier.name }}</option>
            </select>
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">订单金额</label>
            <input type="number" v-model="newOrder.amount" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">订单日期</label>
            <input type="date" v-model="newOrder.orderDate" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">订单状态</label>
            <select v-model="newOrder.status" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
              <option v-for="status in orderStatuses" :key="status.id" :value="status.id">{{ status.name }}</option>
            </select>
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">备注</label>
            <textarea v-model="newOrder.remark" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"></textarea>
          </div>
          <div class="flex justify-end space-x-3">
            <button type="button" @click="showAddOrderModal = false" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700">
              取消
            </button>
            <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">
              添加
            </button>
          </div>
        </form>
      </div>
    </div>

    <!-- 新增供应商模态框 -->
    <div v-if="showAddSupplierModal" class="fixed inset-0 bg-gray-500 bg-opacity-75 flex items-center justify-center">
      <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full p-6">
        <h2 class="text-xl font-bold mb-4 text-gray-900 dark:text-white">新增供应商</h2>
        <form @submit.prevent="addSupplier">
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">供应商名称</label>
            <input type="text" v-model="newSupplier.name" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">供应商编码</label>
            <input type="text" v-model="newSupplier.code" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">联系人</label>
            <input type="text" v-model="newSupplier.contact" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">联系电话</label>
            <input type="tel" v-model="newSupplier.phone" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">合作状态</label>
            <select v-model="newSupplier.status" required class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white">
              <option v-for="status in supplierStatuses" :key="status.id" :value="status.id">{{ status.name }}</option>
            </select>
          </div>
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">备注</label>
            <textarea v-model="newSupplier.remark" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"></textarea>
          </div>
          <div class="flex justify-end space-x-3">
            <button type="button" @click="showAddSupplierModal = false" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700">
              取消
            </button>
            <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">
              添加
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'

// 采购订单数据
const orders = ref([
  {
    id: 1,
    orderNo: 'PO2024001',
    supplierId: 1,
    supplierName: '供应商A',
    supplierContact: '张三',
    amount: 10000,
    orderDate: '2024-01-15',
    status: 1
  },
  {
    id: 2,
    orderNo: 'PO2024002',
    supplierId: 2,
    supplierName: '供应商B',
    supplierContact: '李四',
    amount: 20000,
    orderDate: '2024-01-16',
    status: 2
  }
])

// 供应商数据
const suppliers = ref([
  {
    id: 1,
    name: '供应商A',
    code: 'SUP001',
    contact: '张三',
    phone: '13800138000',
    status: 1
  },
  {
    id: 2,
    name: '供应商B',
    code: 'SUP002',
    contact: '李四',
    phone: '13800138001',
    status: 2
  }
])

// 订单状态
const orderStatuses = ref([
  { id: 1, name: '待处理' },
  { id: 2, name: '已确认' },
  { id: 3, name: '已完成' },
  { id: 4, name: '已取消' }
])

// 供应商状态
const supplierStatuses = ref([
  { id: 1, name: '合作中' },
  { id: 2, name: '暂停合作' },
  { id: 3, name: '终止合作' }
])

// 时间范围
const timeRanges = ref([
  { id: 1, name: '今天' },
  { id: 2, name: '本周' },
  { id: 3, name: '本月' },
  { id: 4, name: '本季度' },
  { id: 5, name: '本年' }
])

// 采购员
const purchasers = ref([
  { id: 1, name: '王五' },
  { id: 2, name: '赵六' }
])

// 筛选条件
const searchText = ref('')
const filters = ref({
  status: '',
  timeRange: '',
  purchaser: ''
})

// 模态框状态
const showAddOrderModal = ref(false)
const showAddSupplierModal = ref(false)

// 新订单表单
const newOrder = ref({
  supplierId: '',
  amount: '',
  orderDate: '',
  status: '',
  remark: ''
})

// 新供应商表单
const newSupplier = ref({
  name: '',
  code: '',
  contact: '',
  phone: '',
  status: '',
  remark: ''
})

// 计算属性
const filteredOrders = computed(() => {
  return orders.value.filter(order => {
    const matchesSearch = !searchText.value || 
      order.orderNo.toLowerCase().includes(searchText.value.toLowerCase()) ||
      order.supplierName.toLowerCase().includes(searchText.value.toLowerCase())
    const matchesStatus = !filters.value.status || order.status === filters.value.status
    const matchesTimeRange = !filters.value.timeRange || true // 这里需要根据实际时间范围进行过滤
    const matchesPurchaser = !filters.value.purchaser || true // 这里需要根据实际采购员进行过滤
    return matchesSearch && matchesStatus && matchesTimeRange && matchesPurchaser
  })
})

const currentMonthPurchases = computed(() => {
  // 这里假设有一个计算本月采购金额的逻辑
  return 300000
})

const purchaseGrowth = computed(() => {
  // 这里假设有一个计算环比增长的逻辑
  return 5
})

const totalOrders = computed(() => {
  return orders.value.length
})

const completionRate = computed(() => {
  const completedOrders = orders.value.filter(order => order.status === 3).length
  return Math.round((completedOrders / totalOrders.value) * 100)
})

const totalSuppliers = computed(() => {
  return suppliers.value.length
})

const activeSuppliers = computed(() => {
  return suppliers.value.filter(supplier => supplier.status === 1).length
})

const averageCycle = computed(() => {
  // 这里假设有一个计算平均采购周期的逻辑
  return 7
})

const cycleChange = computed(() => {
  // 这里假设有一个计算环比变化的逻辑
  return -2
})

// 格式化数字
const formatNumber = (num) => {
  return num.toLocaleString('zh-CN')
}

// 格式化日期
const formatDate = (date) => {
  return new Date(date).toLocaleDateString('zh-CN')
}

// 获取订单状态名称
const getOrderStatusName = (statusId) => {
  const status = orderStatuses.value.find(s => s.id === statusId)
  return status ? status.name : '未知状态'
}

// 获取订单状态样式
const getOrderStatusClass = (statusId) => {
  const classes = {
    1: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-700 dark:text-yellow-300',
    2: 'bg-blue-100 text-blue-800 dark:bg-blue-700 dark:text-blue-300',
    3: 'bg-green-100 text-green-800 dark:bg-green-700 dark:text-green-300',
    4: 'bg-red-100 text-red-800 dark:bg-red-700 dark:text-red-300'
  }
  return classes[statusId] || 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300'
}

// 获取供应商状态名称
const getSupplierStatusName = (statusId) => {
  const status = supplierStatuses.value.find(s => s.id === statusId)
  return status ? status.name : '未知状态'
}

// 获取供应商状态样式
const getSupplierStatusClass = (statusId) => {
  const classes = {
    1: 'bg-green-100 text-green-800 dark:bg-green-700 dark:text-green-300',
    2: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-700 dark:text-yellow-300',
    3: 'bg-red-100 text-red-800 dark:bg-red-700 dark:text-red-300'
  }
  return classes[statusId] || 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300'
}

// 添加订单
const addOrder = () => {
  const supplier = suppliers.value.find(s => s.id === newOrder.value.supplierId)
  const order = {
    id: orders.value.length + 1,
    orderNo: `PO${new Date().getFullYear()}${String(orders.value.length + 1).padStart(3, '0')}`,
    supplierId: newOrder.value.supplierId,
    supplierName: supplier.name,
    supplierContact: supplier.contact,
    amount: newOrder.value.amount,
    orderDate: newOrder.value.orderDate,
    status: newOrder.value.status
  }
  orders.value.push(order)
  showAddOrderModal.value = false
  resetNewOrder()
}

// 重置新订单表单
const resetNewOrder = () => {
  newOrder.value = {
    supplierId: '',
    amount: '',
    orderDate: '',
    status: '',
    remark: ''
  }
}

// 添加供应商
const addSupplier = () => {
  const supplier = {
    id: suppliers.value.length + 1,
    ...newSupplier.value
  }
  suppliers.value.push(supplier)
  showAddSupplierModal.value = false
  resetNewSupplier()
}

// 重置新供应商表单
const resetNewSupplier = () => {
  newSupplier.value = {
    name: '',
    code: '',
    contact: '',
    phone: '',
    status: '',
    remark: ''
  }
}

// 查看订单
const viewOrder = (order) => {
  // 实现查看订单逻辑
  console.log('查看订单:', order)
}

// 编辑订单
const editOrder = (order) => {
  // 实现编辑订单逻辑
  console.log('编辑订单:', order)
}

// 删除订单
const deleteOrder = (order) => {
  if (confirm(`确定要删除订单"${order.orderNo}"吗？`)) {
    const index = orders.value.findIndex(o => o.id === order.id)
    if (index !== -1) {
      orders.value.splice(index, 1)
    }
  }
}

// 查看供应商
const viewSupplier = (supplier) => {
  // 实现查看供应商逻辑
  console.log('查看供应商:', supplier)
}

// 编辑供应商
const editSupplier = (supplier) => {
  // 实现编辑供应商逻辑
  console.log('编辑供应商:', supplier)
}

// 删除供应商
const deleteSupplier = (supplier) => {
  if (confirm(`确定要删除供应商"${supplier.name}"吗？`)) {
    const index = suppliers.value.findIndex(s => s.id === supplier.id)
    if (index !== -1) {
      suppliers.value.splice(index, 1)
    }
  }
}
</script> 