<template>
  <div class="enterprise-cert">
    <div class="cert-bg"></div>
    <div class="cert-content">
      <div class="cert-header">
        <div class="cert-title">
          <h3>企业认证</h3>
          <span class="cert-status" v-show="certData.qymc">{{ statusText }}</span>
        </div>
      </div>
      <div class="cert-body">
        <template v-if="certData.qymc">
          <div class="cert-info">
            <div class="info-row">
              <span class="name-icon"></span>
              <!-- <span class="info-label">企业名称</span> -->
              <span class="info-value">{{ certData.qymc }}</span>
            </div>
            <div class="info-row">
              <span class="eid-icon"></span>
              <!-- <span class="info-label">统一社会信用代码</span> -->
              <span class="info-value">{{ certData.nsrsbh }}</span>
            </div>
            <div class="info-row">
              <span class="cert-icon"></span>
              <span class="info-label">认证时间</span>
              <span class="info-value">{{ formatDate(certData.lrrq) }}</span>
            </div>
          </div>
        </template>
        <template v-else>
          <div class="cert-empty">
            <span>暂未认证企业信息</span>
          </div>
        </template>
        <!-- <div class="cert-actions">
          <button class="cert-btn" @click="handleClick">
            <span>{{ certData.qymc ? '查看详情' : '立即认证' }}</span>
            <ArrowRightIcon />
          </button>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
import api from '@/pages/index/api/gxzx/index.js';
import { ArrowRightIcon } from 'tdesign-icons-vue';

export default {
  name: 'EnterpriseCert',
  components: {
    ArrowRightIcon,
  },
  data() {
    return {
      certData: {
        qymc: '',
      },
    };
  },
  mounted() {
    this.fetchCertData();
  },
  methods: {
    async fetchCertData() {
      try {
        const { data } = await api.init();
        this.certData = data || {};
      } catch (error) {
        console.error('获取企业认证信息失败', error);
        this.certData = {};
      }
    },
    formatDate(dateStr) {
      if (!dateStr) return '-';
      const date = new Date(dateStr);
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    handleClick() {
      this.$router.push('/yhzx/qyrenzheng');
    },
  },
};
</script>

<style lang="less" scoped>
@green-primary: #00B42A;
@green-dark: #008530;
@green-light: #E8FFEA;
@text-dark: #1D2129;
@text-muted: #4E5969;
@text-light: #86909C;
@bg-card: #FFFFFF;

.enterprise-cert {
  position: relative;
  width: 280px;
  height: 170px;
  overflow: hidden;
  background: @bg-card;
  border-radius: 4px;
  box-shadow: 0 4px 8px 0 rgba(0, 185, 107, 0.2);
}

.cert-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('./cert-bg.png');
  background-size: cover;
  background-position: center;
  opacity: 0.6;
  pointer-events: none;
}

.cert-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px;
}

.cert-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;

  .cert-title {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;

    h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 600;
      color: @text-dark;
    }

    .cert-status {
      width: 70px;
      height: 22px;
      background-image: url('./cert-label.png');
      background-size: 100% 100%;
      background-position: center;
    }
  }
}

.cert-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.cert-info {
  display: flex;
  flex-direction: column;
  gap: 12px;

  .info-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .info-label {
      font-size: 14px;
      color: #344F3D;
      margin: 0 4px;
    }

    .info-value {
      font-size: 14px;
      // font-weight: 500;
      color: #344F3D;
    }
  }
  .name-icon {
    display: flex;
    width: 20px;
    height: 20px;
    background-image: url('./cert-icon.png');
    background-size: 100% 100%;
    background-position: center;
    margin-right: 4px;
  }
  .eid-icon {
    display: flex;
    width: 20px;
    height: 20px;
    background-image: url('./eid-icon.png');
    background-size: 100% 100%;
    background-position: center;
    margin-right: 4px;
  }
  .cert-icon {
    display: flex;
    width: 20px;
    height: 20px;
    background-image: url('./cert-icon.png');
    background-size: 100% 100%;
    background-position: center;
  }
}

.cert-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  font-size: 12px;
  color: @text-muted;
}

.cert-actions {
  margin-top: auto;

  .cert-btn {
    display: flex;
    width: 100%;
    padding: 8px;
    font-size: 12px;
    font-weight: 600;
    color: @green-primary;
    cursor: pointer;
    background: @green-light;
    border: 1px solid rgba(0, 180, 42, 0.2);
    border-radius: 4px;
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
    gap: 4px;

    &:hover {
      color: #fff;
      background: @green-primary;
      border-color: @green-primary;
    }

    .t-icon {
      font-size: 12px;
      transition: transform 0.3s ease;
    }

    &:hover .t-icon {
      transform: translateX(3px);
    }
  }
}
</style>
