<template>
  <div class="guide-page">
    <div class="guide-container">
      <!-- 采购指南区域（独立卡片） -->
      <div class="guide-card">
        <div class="guide-header">
          <div class="guide-title">
            <span class="title-text">采购指南</span>
            <span class="title-desc">提供智能选品搭配方案，帮助采购人在繁杂品类中快速选品，节省选品时间</span>
          </div>
          <span class="view-more" @click="handleViewMore">了解更多采购信息 &gt;</span>
        </div>
        <div class="guide-content">
          <div class="guide-grid">
            <div
              v-for="item in guideList"
              :key="item.id"
              class="guide-item"
            >
              <el-icon class="delete-icon" @click="handleRemoveGuide(item.id)">
                <Close />
              </el-icon>
              <div class="guide-image">
                <el-image :src="item.imageUrl" fit="cover" lazy class="image">
                  <template #error>
                    <div class="image-slot">
                      <el-icon><Picture /></el-icon>
                    </div>
                  </template>
                </el-image>
              </div>
              <div class="guide-info">
                <p class="guide-name">{{ item.name }}</p>
                <p v-if="item.subTitle" class="guide-subtitle" :style="{ color: item.subTitleColor || '#f56c6c' }">{{ item.subTitle }}</p>
              </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.keyword" placeholder="请输入采购指南编号/名称" clearable style="width: 280px" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleQuery">搜索</el-button>
            </el-form-item>
          </el-form>
        </div>

        <!-- 表格 -->
        <el-table v-loading="loading" :data="searchList" border>
          <el-table-column label="编号" align="center" prop="id" width="120" />
          <el-table-column label="指南图片" align="center" width="120">
            <template #default="scope">
              <el-image :src="scope.row.imageUrl" fit="cover" style="width: 80px; height: 60px; border-radius: 4px" lazy />
            </template>
          </el-table-column>
          <el-table-column label="指南名称" align="center" prop="name" :show-overflow-tooltip="true" min-width="200" />
          <el-table-column label="副标题" align="center" prop="subTitle" :show-overflow-tooltip="true" min-width="150" />
          <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="DecorationGuide" lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Close, Picture } from '@element-plus/icons-vue';

// 采购指南列表
const guideList = ref([
  {
    id: '1',
    name: '全场景无人机 解决方案',
    imageUrl: '/img/品牌广告图片.jpg',
    subTitle: '',
    subTitleColor: ''
  },
  {
    id: '2',
    name: '企业桌面现磨咖啡机',
    imageUrl: '/img/MAXHUB.jpg',
    subTitle: '不止咖啡更是关怀',
    subTitleColor: '#f56c6c'
  },
  {
    id: '3',
    name: '人体工程学椅推荐产品',
    imageUrl: '/img/联想.jpg',
    subTitle: '',
    subTitleColor: ''
  }
]);

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

// 搜索列表数据
const searchList = ref<any[]>([]);
const loading = ref(false);
const total = ref(0);

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

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

// 查看更多
const handleViewMore = () => {
  ElMessage.info('了解更多采购信息功能开发中...');
};

// 移除采购指南
const handleRemoveGuide = (id: string) => {
  ElMessageBox.confirm('是否确认移除该采购指南？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    const index = guideList.value.findIndex(item => item.id === id);
    if (index !== -1) {
      guideList.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">
.guide-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding: 20px;
}

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

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

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

.guide-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;
  }
}

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

.guide-item {
  position: relative;
  cursor: pointer;
  
  &:hover {
    .guide-image .image {
      transform: scale(1.02);
    }
  }
  
  .delete-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 18px;
    color: #fff;
    cursor: pointer;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    padding: 4px;
    
    &:hover {
      background: rgba(245, 108, 108, 0.8);
    }
  }
  
  .guide-image {
    width: 100%;
    height: 180px;
    border-radius: 4px;
    overflow: hidden;
    
    .image {
      width: 100%;
      height: 100%;
      transition: transform 0.3s;
    }
    
    .image-slot {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      background: #f5f7fa;
      color: #909399;
      font-size: 40px;
    }
  }
  
  .guide-info {
    padding: 10px 0;
    
    .guide-name {
      margin: 0 0 5px 0;
      font-size: 14px;
      font-weight: 500;
      color: #303133;
    }
    
    .guide-subtitle {
      margin: 0;
      font-size: 13px;
    }
  }
}

.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;
}

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