<template>
  <div class="app-container">
    <!-- 返回按钮 -->
    <div class="back-container">
      <el-button type="default" size="small" @click="handleBack" class="back-btn">
        返回
      </el-button>
    </div>

    <!-- 知识库卡片网格 -->
    <div class="knowledge-grid">
      <div
        class="knowledge-card"
        v-for="(card, index) in knowledgeCards"
        :key="index"
        @click="handleCardClick(card)"
      >
        <div class="card-icon">
          <img :src="card.icon" :alt="card.title" />
        </div>
        <div class="card-content">
          <h3 class="card-title">{{ card.title }}</h3>
          <p class="card-description">{{ card.description }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import enterpriseKnowledgeIcon from '@/assets/enterpriseLibrary/enterpriseKnowledgeIcon.png';
import { encryptWithSM4,decryptWithSM4 } from '@/utils/sm'

export default {
  name: 'EnterpriseKnowledge',
  data() {
    return {
      enterpriseId: decryptWithSM4(this.$route.query.enterpriseId),
      enterpriseKnowledgeIcon,
      knowledgeCards: [
        {
          type: 'performance',
          title: '业绩库',
          description: '业绩库主要管理企业的项目业绩信息, 包括合同、验收报告、中标通知书等',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/performance',
          name: 'Performance'
        },
        {
          type: 'personnel',
          title: '人员库',
          description: '人员库主要管理企业的人员资质信息, 包括岗位、工作经验、员工证书等',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/personnel',
          name: 'Personnel'
        },
        {
          type: 'qualification',
          title: '资质库',
          description: '资质库主要管理企业的资质证书信息, 包括软著、专利、荣誉等',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/qualification',
          name: 'Qualification'
        },
        {
          type: 'technical',
          title: '技术方案库',
          description: '解决方案库主要用于管理企业内部技术方案、产品方案、项目方案等',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/technical',
          name: 'Technical'
        },
        {
          type: 'tools',
          title: '工器具库',
          description: '工器具库主要用于登记工器具资料信息, 统一管理工器具清单等',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/tool',
          name: 'Tools'
        },
        {
          type: 'financial',
          title: '财务库',
          description: '财务库主要管理企业的财务报告文档, 包括审计报告、年报等',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/financial',
          name: 'Financial'
        },
        {
          type: 'rejection',
          title: '废标项库',
          description: '废标项库主要用于协助标书解析、标书生成、标书审查',
          icon: enterpriseKnowledgeIcon,
          path: '/enterpriseLibrary/enterprise/rejection',
          name: 'Rejection'
        }
      ]
    }
  },
  methods: {
    // 返回上一页
    handleBack() {
      const obj = { path: "/enterpriseLibrary/enterprise" }
      this.$tab.closeOpenPage(obj)
    },

    // 卡片点击事件
    handleCardClick(card) {
      // 查找对应的卡片数据
      if (card && card.path) {
        // 如果有路径，则跳转到对应页面
        this.$router.push({
          name: card.name,
          query: {
            enterpriseId: encryptWithSM4(this.enterpriseId || '0'),
          }
        })
      } else {
        // 否则显示提示信息
        this.$message.info(`点击了${this.getCardTitle(type)}`)
      }
    },

    // 获取卡片标题
    getCardTitle(type) {
      const card = this.knowledgeCards.find(item => item.type === type)
      return card ? card.title : '未知'
    },

  },

}
</script>

<style scoped lang="scss">
.app-container {
  padding: 20px;
  background: linear-gradient(180deg, #F1F6FF 20%, #E5EFFF 100%);
  min-height: calc(100vh - 84px);
}

.back-container {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 30px;
  padding: 0 20px;

  .back-btn {
    width: 98px;
    height: 36px;
    background: #FFFFFF;
    box-shadow: 0px 4px 8px 0px rgba(76, 76, 76, 0.2);
    border-radius: 4px;
    border: none;
    color: #666;
    font-size: 14px;
    transition: all 0.3s ease;

    &:hover {
      background: #f5f5f5;
      color: #409EFF;
      box-shadow: 0px 6px 12px 0px rgba(76, 76, 76, 0.3);
    }
  }
}

.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  max-width: 100%;
  margin: 0;
  padding: 0 10px;
}

.knowledge-card {
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  text-align: left;
  min-height: 120px;

  &:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
    // border-color: #409EFF;
  }

  .card-icon {
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    flex-shrink: 0;

    img {
      width: auto;
      height: auto;
      max-width: 100%;
      max-height: 100%;
      object-fit: contain;
    }
  }

  .card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .card-title {
      font-size: 18px;
      font-weight: 600;
      color: #333;
      margin: 0 0 8px 0;
      line-height: 1.4;
    }

    .card-description {
      font-size: 14px;
      color: #666;
      line-height: 1.6;
      margin: 0;
    }
  }
}
</style>
