<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="showAddCustomerModal = true" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700">
              添加客户
            </button>
            <button @click="showAddFollowupModal = 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">{{ totalCustomers }}</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">{{ activeCustomers }}</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">{{ averageSatisfaction }}%</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">{{ pendingFollowups }}</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.type" 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="type in customerTypes" :key="type.id" :value="type.id">{{ type.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.level" 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="level in customerLevels" :key="level.id" :value="level.id">{{ level.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.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 statusTypes" :key="status.id" :value="status.id">{{ status.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="customer in filteredCustomers" :key="customer.id">
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="text-sm font-medium text-gray-900 dark:text-white">{{ customer.name }}</div>
                <div class="text-sm text-gray-500 dark:text-gray-400">{{ customer.contact }}</div>
                <div class="text-xs text-gray-500 dark:text-gray-400">{{ customer.phone }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white">
                {{ getCustomerTypeName(customer.type) }}
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <span :class="getCustomerLevelClass(customer.level)" class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full">
                  {{ getCustomerLevelName(customer.level) }}
                </span>
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <span :class="getCustomerStatusClass(customer.status)" class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full">
                  {{ getCustomerStatusName(customer.status) }}
                </span>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                <button @click="viewCustomer(customer)" class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300 mr-3">查看</button>
                <button @click="editCustomer(customer)" class="text-yellow-600 hover:text-yellow-900 dark:text-yellow-400 dark:hover:text-yellow-300 mr-3">编辑</button>
                <button @click="deleteCustomer(customer)" 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>
              <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="followup in filteredFollowups" :key="followup.id">
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="text-sm font-medium text-gray-900 dark:text-white">{{ followup.customerName }}</div>
                <div class="text-sm text-gray-500 dark:text-gray-400">{{ followup.contact }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white">
                {{ getFollowupTypeName(followup.type) }}
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-900 dark:text-white">{{ followup.content }}</div>
                <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">{{ followup.nextFollowupDate }}</div>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white">
                {{ followup.follower }}
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white">
                {{ formatDate(followup.date) }}
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                <button @click="viewFollowup(followup)" class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300 mr-3">查看</button>
                <button @click="editFollowup(followup)" class="text-yellow-600 hover:text-yellow-900 dark:text-yellow-400 dark:hover:text-yellow-300 mr-3">编辑</button>
                <button @click="deleteFollowup(followup)" 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="showAddCustomerModal" 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="addCustomer">
          <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="newCustomer.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="newCustomer.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="newCustomer.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="newCustomer.type" 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="type in customerTypes" :key="type.id" :value="type.id">{{ type.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>
            <select v-model="newCustomer.level" 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="level in customerLevels" :key="level.id" :value="level.id">{{ level.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="newCustomer.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="showAddCustomerModal = 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="showAddFollowupModal" 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="addFollowup">
          <div class="mb-4">
            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">客户</label>
            <select v-model="newFollowup.customerId" 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="customer in customers" :key="customer.id" :value="customer.id">{{ customer.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>
            <select v-model="newFollowup.type" 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="type in followupTypes" :key="type.id" :value="type.id">{{ type.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="newFollowup.content" 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"></textarea>
          </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="newFollowup.nextFollowupDate" 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>
            <textarea v-model="newFollowup.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="showAddFollowupModal = 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-green-600 text-white rounded-md hover:bg-green-700">
              添加
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

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

// 客户数据
const customers = ref([
  {
    id: 1,
    name: 'ABC科技有限公司',
    contact: '张三',
    phone: '13800138000',
    type: 1,
    level: 2,
    status: 1,
    remark: '重要客户'
  },
  {
    id: 2,
    name: 'XYZ贸易有限公司',
    contact: '李四',
    phone: '13900139000',
    type: 2,
    level: 1,
    status: 2,
    remark: '潜在客户'
  }
])

// 跟进记录数据
const followups = ref([
  {
    id: 1,
    customerId: 1,
    customerName: 'ABC科技有限公司',
    contact: '张三',
    type: 1,
    content: '讨论新项目需求',
    follower: '王五',
    date: '2024-03-15',
    nextFollowupDate: '2024-03-22',
    remark: '需要准备详细方案'
  },
  {
    id: 2,
    customerId: 2,
    customerName: 'XYZ贸易有限公司',
    contact: '李四',
    type: 2,
    content: '产品演示',
    follower: '赵六',
    date: '2024-03-16',
    nextFollowupDate: '2024-03-23',
    remark: '客户对产品很感兴趣'
  }
])

// 客户类型
const customerTypes = ref([
  { id: 1, name: '企业客户' },
  { id: 2, name: '个人客户' },
  { id: 3, name: '政府机构' },
  { id: 4, name: '教育机构' }
])

// 客户等级
const customerLevels = ref([
  { id: 1, name: '普通客户' },
  { id: 2, name: '重要客户' },
  { id: 3, name: 'VIP客户' }
])

// 客户状态
const statusTypes = ref([
  { id: 1, name: '活跃' },
  { id: 2, name: '潜在' },
  { id: 3, name: '流失' }
])

// 跟进方式
const followupTypes = ref([
  { id: 1, name: '电话' },
  { id: 2, name: '拜访' },
  { id: 3, name: '邮件' },
  { id: 4, name: '会议' }
])

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

// 模态框状态
const showAddCustomerModal = ref(false)
const showAddFollowupModal = ref(false)

// 新客户表单
const newCustomer = ref({
  name: '',
  contact: '',
  phone: '',
  type: '',
  level: '',
  remark: ''
})

// 新跟进记录表单
const newFollowup = ref({
  customerId: '',
  type: '',
  content: '',
  nextFollowupDate: '',
  remark: ''
})

// 计算属性
const filteredCustomers = computed(() => {
  return customers.value.filter(item => {
    const matchesSearch = !searchText.value || 
      item.name.toLowerCase().includes(searchText.value.toLowerCase()) ||
      item.contact.toLowerCase().includes(searchText.value.toLowerCase())
    const matchesType = !filters.value.type || item.type === filters.value.type
    const matchesLevel = !filters.value.level || item.level === filters.value.level
    const matchesStatus = !filters.value.status || item.status === filters.value.status
    return matchesSearch && matchesType && matchesLevel && matchesStatus
  })
})

const filteredFollowups = computed(() => {
  return followups.value.filter(item => {
    const matchesSearch = !searchText.value || 
      item.customerName.toLowerCase().includes(searchText.value.toLowerCase()) ||
      item.contact.toLowerCase().includes(searchText.value.toLowerCase())
    return matchesSearch
  })
})

const totalCustomers = computed(() => customers.value.length)

const activeCustomers = computed(() => {
  return customers.value.filter(item => item.status === 1).length
})

const averageSatisfaction = computed(() => {
  // 这里假设有一个满意度评分系统
  return 85
})

const pendingFollowups = computed(() => {
  const today = new Date().toISOString().split('T')[0]
  return followups.value.filter(item => item.nextFollowupDate <= today).length
})

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

// 获取客户类型名称
const getCustomerTypeName = (typeId) => {
  const type = customerTypes.value.find(t => t.id === typeId)
  return type ? type.name : '未知类型'
}

// 获取客户等级名称
const getCustomerLevelName = (levelId) => {
  const level = customerLevels.value.find(l => l.id === levelId)
  return level ? level.name : '未知等级'
}

// 获取客户状态名称
const getCustomerStatusName = (statusId) => {
  const status = statusTypes.value.find(s => s.id === statusId)
  return status ? status.name : '未知状态'
}

// 获取跟进方式名称
const getFollowupTypeName = (typeId) => {
  const type = followupTypes.value.find(t => t.id === typeId)
  return type ? type.name : '未知方式'
}

// 获取客户等级样式
const getCustomerLevelClass = (levelId) => {
  const classes = {
    1: 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300',
    2: 'bg-blue-100 text-blue-800 dark:bg-blue-700 dark:text-blue-300',
    3: 'bg-purple-100 text-purple-800 dark:bg-purple-700 dark:text-purple-300'
  }
  return classes[levelId] || 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300'
}

// 获取客户状态样式
const getCustomerStatusClass = (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 addCustomer = () => {
  const item = {
    id: customers.value.length + 1,
    ...newCustomer.value,
    status: 1 // 默认为活跃状态
  }
  customers.value.push(item)
  showAddCustomerModal.value = false
  resetNewCustomer()
}

// 重置新客户表单
const resetNewCustomer = () => {
  newCustomer.value = {
    name: '',
    contact: '',
    phone: '',
    type: '',
    level: '',
    remark: ''
  }
}

// 添加跟进记录
const addFollowup = () => {
  const customer = customers.value.find(c => c.id === newFollowup.value.customerId)
  const item = {
    id: followups.value.length + 1,
    ...newFollowup.value,
    customerName: customer.name,
    contact: customer.contact,
    follower: '当前用户', // 这里应该获取当前登录用户
    date: new Date().toISOString().split('T')[0]
  }
  followups.value.push(item)
  showAddFollowupModal.value = false
  resetNewFollowup()
}

// 重置新跟进记录表单
const resetNewFollowup = () => {
  newFollowup.value = {
    customerId: '',
    type: '',
    content: '',
    nextFollowupDate: '',
    remark: ''
  }
}

// 查看客户
const viewCustomer = (item) => {
  // 实现查看客户逻辑
  console.log('查看客户:', item)
}

// 编辑客户
const editCustomer = (item) => {
  // 实现编辑客户逻辑
  console.log('编辑客户:', item)
}

// 删除客户
const deleteCustomer = (item) => {
  if (confirm(`确定要删除客户"${item.name}"吗？`)) {
    const index = customers.value.findIndex(c => c.id === item.id)
    if (index !== -1) {
      customers.value.splice(index, 1)
    }
  }
}

// 查看跟进记录
const viewFollowup = (item) => {
  // 实现查看跟进记录逻辑
  console.log('查看跟进记录:', item)
}

// 编辑跟进记录
const editFollowup = (item) => {
  // 实现编辑跟进记录逻辑
  console.log('编辑跟进记录:', item)
}

// 删除跟进记录
const deleteFollowup = (item) => {
  if (confirm(`确定要删除"${item.customerName}"的跟进记录吗？`)) {
    const index = followups.value.findIndex(f => f.id === item.id)
    if (index !== -1) {
      followups.value.splice(index, 1)
    }
  }
}
</script> 