<template>
  <div class="box2">
    <div class="box2-header">
      <div class="icon">
        <img src="./image1.png" alt="" />
      </div>
      <div class="title">
        <div class="text">{{ title }}</div>
        <div class="num">{{ list.length }}</div>
      </div>
    </div>
    <div class="box2-main">

      <div class="box2-main-item" v-for="(item, index) in showRiskSignalList" :key="index" @click="handleItemClick(item, index)">
        <div :class="{
          itemLeftStatus1: item[props.riskLevel] === '特别重大',
          itemLeftStatus2: item[props.riskLevel] === '重大风险',
          itemLeftStatus3: item[props.riskLevel] === '较大风险',
          itemLeftStatus4: item[props.riskLevel] === '一般风险' || !item[props.riskLevel],
          itemLeftStatus5: item[props.riskLevel] === '低风险',
        }">
          {{ item[props.riskLevel] || "暂无数据" }}
        </div>
        <div class="item-right">
          <div class="text"> <span class="text-inner">{{ item[props.name] }}</span></div>
          <div class="time">{{ item[props.postDate] }}</div>
        </div>
      </div>
    </div>
    <div class="box2-footer" @click="handleMoreClick" v-if="showMore">
      <div class="icon">
        <img src="./image2.png" alt="" />
      </div>
      <div class="text">{{ moreText }}</div>
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from "element-plus";
import { computed } from "vue";
// 接收父组件传递的参数
const props = defineProps({
  // 标题（默认“风险信号”）
  title: {
    type: String,
    default: "风险信号"
  },
  // 风险信号列表数据
  list: {
    type: Array,
    default: () => []
  },
  // “查看更多”文本（默认“查看更多”）
  moreText: {
    type: String,
    default: "查看更多"
  },
  //控制“查看更多”是否显示，默认显示
  showMore: {
    type: Boolean,
    default: true
  },
  name: {
    type: String,
    default: "name"
  },
  postDate: {
    type: String,
    default: "postDate"
  },
  riskLevel: {
    type: String,
    default: "riskLevel"
  },

});

const showRiskSignalList = computed(() => {
  return props.list.slice(0,6)
})

// 定义自定义事件，把点击事件传递给父组件
const emit = defineEmits(['item-click', 'more-click']);

// 点击单条风险信号
const handleItemClick = (item, index) => {
  emit('item-click', item, index)
};

// 点击“查看更多”
const handleMoreClick = () => {
  emit('more-click')
};


</script>

<style scoped lang="scss">
.risk-status-base {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 400;
  line-height: 14px;
  box-sizing: border-box;
  padding: 6px 4px;
  text-align: center;
}

.itemLeftStatus1 {
  color: rgb(206, 79, 81) !important;
  background: rgba(255, 241, 240, 1) !important;
  @extend .risk-status-base
}

.itemLeftStatus2 {
  color: rgba(250, 140, 22, 1) !important;
  background: rgba(255, 247, 230, 1) !important;
  @extend .risk-status-base
}

.itemLeftStatus3 {
  color: rgba(212, 177, 6, 1) !important;
  background: rgba(254, 255, 230, 1) !important;
  @extend .risk-status-base
}

.itemLeftStatus4 {
  color: rgba(82, 196, 26, 1) !important;
  background: rgba(246, 255, 237, 1) !important;
  @extend .risk-status-base
}

.itemLeftStatus5 {
  color: rgba(22, 119, 255, 1) !important;
  background: rgba(230, 244, 255, 1) !important;
  @extend .risk-status-base
}


.box2 {
  width: 520px;
  height: 450px;
  border-radius: 10px;
  position: relative;
  background: rgba(255, 255, 255, 1);
  padding: 0;
  box-shadow: 0 0 20px 0 rgba(25, 69, 130, 0.1);
  border: 1px solid rgba(234, 236, 238, 1);
  box-sizing: border-box;
  overflow: hidden;

  .box2-header {
    height: 48px;
    display: flex;
    border-bottom: 1px solid rgba(240, 242, 244, 1);

    .icon {
      width: 24px;
      height: 24px;
      margin-left: 18px;
      margin-top: 14px;
      margin-bottom: 10px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .title {
      display: flex;
      width: 148px;
      background: rgb(206, 79, 81);
      margin-left: 18px;

      .text {
        margin-left: 16px;
        height: 48px;
        color: rgba(255, 255, 255, 1);
        font-family: 'Source Han Sans CN';
        font-size: 20px;
        font-weight: 700;
        line-height: 48px;
      }

      .num {
        width: 24px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: rgba(255, 255, 255, 1);
        font-family: Microsoft YaHei;
        font-size: 12px;
        margin-left: 15px;
        margin-top: 15px;
        border-radius: 100px;
        background: rgba(255, 255, 255, 0.3);
      }
    }
  }

  .box2-main {
    box-sizing: border-box;
    padding-left: 23px;
    padding-right: 30px;
    width: 520px;
    height: 313px;
    border-radius: 4px;
    padding: 15px 30px 10px 23px;
    .box2-main-item {
      width: 463px;
      height: 48px;
      border-radius: 2px;
      position: relative;
      display: flex;
      align-items: center;

      cursor: pointer;

      &:hover {


        .item-right .text {
          color: rgb(5, 95, 194) !important;
          font-weight: 700;
        }

        .item-right .text-inner {
          border-bottom-color: rgb(5, 95, 194) !important;

        }
      }






      .item-right {
        margin-left: 12px;
        height: 46px;
        display: flex;
        align-items: center;
        flex: 1;
        background: transparent;
        padding: 0;
        border-bottom: 1px solid #EAECEE;
        box-sizing: border-box;
        overflow: hidden; // 保证右侧不会溢出

        .text {
          padding-top: 8px;
          padding-bottom: 8px;
          flex: 1 1 auto;
          min-width: 0;
          height: 100%;
          background: transparent;
          font-family: "Source Han Sans CN";
          font-weight: 400;
          font-size: 16px;
          letter-spacing: 0px;
          text-align: left;
          color: rgb(59, 65, 75);
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          box-sizing: border-box;
          flex-shrink: 1;

          .text-inner {
            border-bottom: 1px solid transparent;
          }

        }

        .time {
          flex: 0 0 auto;
          margin-left: 12px;
          padding-top: 11px;
          padding-bottom: 11px;
          height: 100%;
          flex-shrink: 0;
          background: transparent;
          font-family: "Source Han Sans CN", sans-serif;
          font-weight: 400;
          font-size: 16px;
          line-height: 24px;
          letter-spacing: 0px;
          text-align: right;
          box-sizing: border-box;
          color: rgb(132, 136, 142);
          white-space: nowrap;
        }
      }

    }
  }

  .box2-footer {
    position: absolute;
    left: 26px;
    right: 20px;
    bottom: 20px;
    width: 460px;
    height: 42px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    background: var(--color-main-active);
    cursor: pointer;

    .icon {
      width: 16px;
      height: 16px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .text {
      margin-left: 8px;
      color: rgba(255, 255, 255, 1);
      font-family: "Source Han Sans CN";
      font-size: 16px;
      font-weight: 400;
      line-height: 24px;
    }
  }
}
</style>