<template>
  <div class="special-page">
    <div class="special-container">
      <!-- 行家精选区域（独立卡片） -->
      <div class="expert-card">
        <div class="expert-header">
          <div class="expert-title">
            <span class="title-text">行家精选</span>
            <span class="title-desc">品质保证，厂家直供，性价比首选</span>
          </div>
          <span class="view-more" @click="handleViewMore">查看更多 &gt;</span>
        </div>
        <div class="expert-content">
          <div class="product-grid">
            <div
              v-for="product in expertProducts"
              :key="product.id"
              class="product-card"
            >
              <el-icon class="delete-icon" @click="handleRemoveExpert(product.id)">
                <Close />
              </el-icon>
              <div class="product-image">
                <el-image :src="product.imageUrl" fit="contain" lazy class="image">
                  <template #error>
                    <div class="image-slot">
                      <el-icon><Picture /></el-icon>
                    </div>
                  </template>
                </el-image>
              </div>
              <div class="product-info">
                <p class="product-name">{{ product.name }}</p>
                <div class="product-price">
                  <span class="current-price">¥{{ product.price }}</span>
                  <span class="original-price">¥{{ product.originalPrice }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 特价信息列表区域（独立卡片） -->
      <div class="list-card">
        <div class="list-title">特价信息列表</div>
        
        <!-- 搜索区域 -->
        <div class="search-area">
          <el-form :model="queryParams" :inline="true">
            <el-form-item>
              <el-input v-model="queryParams.productId" placeholder="请输入商品编号" clearable style="width: 200px" />
            </el-form-item>
            <el-form-item>
              <el-input v-model="queryParams.productName" placeholder="请输入商品名称" clearable style="width: 200px" />
            </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>
        </div>

        <!-- 表格 -->
        <el-table v-loading="loading" :data="specialList" border>
          <el-table-column label="商品编号" align="center" prop="productId" width="120" />
          <el-table-column label="商品图片" align="center" width="100">
            <template #default="scope">
              <el-image
                :src="scope.row.imageUrl"
                fit="cover"
                style="width: 60px; height: 60px; border-radius: 4px"
                lazy
              />
            </template>
          </el-table-column>
          <el-table-column label="商品名称" align="center" prop="productName" :show-overflow-tooltip="true" min-width="200" />
          <el-table-column label="特价" align="center" prop="specialPrice" width="120">
            <template #default="scope">
              <span class="price-text">¥{{ scope.row.specialPrice }}</span>
            </template>
          </el-table-column>
          <el-table-column label="原价" align="center" prop="originalPrice" width="120">
            <template #default="scope">
              <span class="original-text">¥{{ scope.row.originalPrice }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="120">
            <template #default="scope">
              <span class="action-link primary" @click="handleEdit(scope.row)">编辑</span>
              <span class="action-link danger" @click="handleDelete(scope.row)">删除</span>
            </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"
        />
      </div>
    </div>
  </div>
</template>

<script setup name="DecorationSpecial" lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Close, Picture } from '@element-plus/icons-vue';

// 行家精选商品列表
const expertProducts = ref([
  {
    id: '1',
    name: 'TCL-75Q60E超高清4K电视75寸',
    imageUrl: '/img/创维100V5-HG1会议平板触控一体机.png',
    price: '5599.00',
    originalPrice: '6890.00'
  },
  {
    id: '2',
    name: '格力KFR-72LW(72532)NhAa-3空...',
    imageUrl: '/img/格力.jpg',
    price: '7519.22',
    originalPrice: '8238.76'
  },
  {
    id: '3',
    name: '先锋DYT-Z9Pro电热油汀取暖器',
    imageUrl: '/img/江润实验台.png',
    price: '469',
    originalPrice: '799.00'
  },
  {
    id: '4',
    name: '美菱MF-LC4009A砂电脑电饭煲4L',
    imageUrl: '/img/电饭煲.png',
    price: '399',
    originalPrice: '499.00'
  },
  {
    id: '5',
    name: '富得P1106打印机',
    imageUrl: '/img/奔图.jpg',
    price: '1465.27',
    originalPrice: '1798.80'
  }
]);

// 查询参数
const queryParams = reactive({
  productId: '',
  productName: '',
  pageNum: 1,
  pageSize: 10
});

// 特价列表数据
const specialList = ref<any[]>([]);
const loading = ref(false);
const total = ref(0);

// 查询列表
const getList = () => {
  loading.value = true;
  // 模拟数据
  setTimeout(() => {
    specialList.value = [];
    total.value = 0;
    loading.value = false;
  }, 300);
};

// 搜索
const handleQuery = () => {
  queryParams.pageNum = 1;
  getList();
};

// 重置
const resetQuery = () => {
  queryParams.productId = '';
  queryParams.productName = '';
  handleQuery();
};

// 查看更多
const handleViewMore = () => {
  ElMessage.info('查看更多功能开发中...');
};

// 移除行家精选商品
const handleRemoveExpert = (id: string) => {
  ElMessageBox.confirm('是否确认移除该商品？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    const index = expertProducts.value.findIndex(item => item.id === id);
    if (index !== -1) {
      expertProducts.value.splice(index, 1);
      ElMessage.success('移除成功');
    }
  }).catch(() => {});
};

// 编辑
const handleEdit = (row: any) => {
  ElMessage.info('编辑功能开发中...');
};

// 删除
const handleDelete = (row: any) => {
  ElMessageBox.confirm('是否确认删除该特价商品？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('删除成功');
    getList();
  }).catch(() => {});
};

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

<style scoped lang="scss">
.special-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding: 20px;
}

.special-container {
  max-width: 1200px;
  margin: 0 auto;
}

.expert-card {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 12px;
}

.expert-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.expert-title {
  .title-text {
    font-size: 20px;
    font-weight: 600;
    color: #303133;
    margin-right: 15px;
  }
  
  .title-desc {
    font-size: 14px;
    color: #909399;
  }
}

.view-more {
  font-size: 14px;
  color: #409eff;
  cursor: pointer;
  
  &:hover {
    color: #66b1ff;
  }
}

.expert-content {
  .product-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
  }
}

.product-card {
  position: relative;
  background: #fff;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  padding: 10px;
  cursor: pointer;
  
  &:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  }
  
  .delete-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 16px;
    color: #909399;
    cursor: pointer;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    padding: 2px;
    
    &:hover {
      color: #f56c6c;
    }
  }
  
  .product-image {
    width: 100%;
    height: 150px;
    margin-bottom: 10px;
    
    .image {
      width: 100%;
      height: 100%;
    }
    
    .image-slot {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      background: #f5f7fa;
      color: #909399;
      font-size: 30px;
    }
  }
  
  .product-info {
    .product-name {
      margin: 0 0 8px 0;
      font-size: 13px;
      color: #303133;
      line-height: 1.4;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      min-height: 36px;
    }
    
    .product-price {
      .current-price {
        font-size: 16px;
        font-weight: 600;
        color: #f56c6c;
        margin-right: 8px;
      }
      
      .original-price {
        font-size: 12px;
        color: #909399;
        text-decoration: line-through;
      }
    }
  }
}

.list-card {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
}

.list-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 15px;
}

.search-area {
  margin-bottom: 15px;
}

.price-text {
  color: #f56c6c;
  font-weight: 600;
}

.original-text {
  color: #909399;
  text-decoration: line-through;
}

.action-link {
  cursor: pointer;
  margin: 0 8px;
  
  &.primary {
    color: #409eff;
    &:hover { color: #66b1ff; }
  }
  
  &.danger {
    color: #f56c6c;
    &:hover { color: #f78989; }
  }
}
</style>
