<template>
  <div class="view-box">
    <el-empty v-if="!props.surveyList?.length" description="暂无数据" :image-size="100" />
    <div class="timeline-item" v-for="(item, index) in props.surveyList" :key="item.searchid" @click="onNavigateToDetail(item)">
      <div class="timeline-date">
        <div class="date-text">{{ item.searchdatezh.slice(0,4) }}</div>
        <div class="date-text">{{ item.searchdatezh.slice(5) }}</div>
      </div>
      <div class="timeline-line-box">
        <div class="timeline-icon">
          <img v-if="item.sortimageurl" :src="item.sortimageurl" alt="" />
          <div v-else class="default-dot"></div>
        </div>
        <div class="timeline-line" v-if="index !== props.surveyList.length - 1"></div>
      </div>
      <div class="timeline-content-card">
        <div class="item-head">
          <div :class="`item-tag tag-${item.sortcode}`">{{ item.sortcode }}</div>
          <div class="item-name one-line-ellipsis">{{ item.searchname }}</div>
          <div class="item-state">
            <span class="dot">•</span> {{ item.casestatus }}
          </div>
        </div>
        <div class="card-body">{{ item.content }}</div>
        <div class="card-footer">
          <div class="footer-left-tags">
            <AreaTag v-for="(name, num) in item.searchArea" :key="num" :tagName="name"></AreaTag>
          </div>
          <div class="footer-right-flags">
            <div class="flag-icon" v-for="(name, num) in item.countryImage" :key="num">
              <img :src="name" alt="" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="SurveyHistory">
import router from "@/router";

const props = defineProps({
  surveyList: {
    type: Array,
    default: () => ([]),
  },
})

const onNavigateToDetail = item => {
	const curRoute = router.resolve({
		path: "/marketSingleCaseLayout/overview",
		query: { id: item.sortcode, searchId: item.searchid }
	});
	window.open(curRoute.href, "_blank");
};

</script>

<style scoped lang="scss">
.view-box {
  min-height: 600px;
  width: 100%;
  padding: 18px 27px 0 24px;
  border-top: 1px solid rgba(234, 236, 238, 1);
  border-bottom: 1px solid rgba(234, 236, 238, 1);
}

.timeline-item {
	display: flex;
  cursor: pointer;

  .timeline-date {
    width: 80px;
    text-align: right;
    margin-right: 16px;

    .date-text {
      height: 24px;
      font-size: 16px;
      font-weight: 700;
      color: var(--color-main-active);
      line-height: 24px;
      letter-spacing: 1px;
    }
  }

  .timeline-line-box {
    width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;

    .timeline-icon {
      width: 32px;
      height: 32px;
      z-index: 2;
      background: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0;

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

      .default-dot {
        width: 12px;
        height: 12px;
        border-radius: 50%;
        background: orange;
      }
    }

    .timeline-line {
      width: 2px;
      flex: 1;
      background: #eaeeef;
      margin: 4px 0;
    }
  }

  .timeline-content-card {
    width: 20px;
    flex: auto;
    padding: 4px 16px 0;
    margin-bottom: 30px;

    &:hover .item-head .item-name {
      color: var(--color-main-active);
      text-decoration: underline;
    }

    .item-head {
      display: flex;
      align-items: center;
      margin-bottom: 10px;

      .item-tag {
        width: 48px;
        height: 24px;
        line-height: 24px;
        text-align: center;
        border-radius: 4px;
        font-weight: bold;
        font-size: 16px;
        margin-right: 12px;
      }
      .tag-337 {
        border: 1px solid #91caff;
        background: #e6f4ff;
        color: #055fc2;
      }
      .tag-232 {
        border: 1px solid #b37feb;
        background: #f9f0ff;
        color: #722ed1;
      }
      .tag-301 {
        border: 1px solid #ffd591;
        background: #fff7e6;
        color: #fa8c16;
      }

      .item-name {
        font-size: 18px;
        line-height: 18px;
        font-weight: bold;
        color: #3b414b;
        width: 20px;
        flex: auto;
      }

      .item-state {
        font-size: 16px;
        color: #84888e;
        color: var(--color-main-active);
        margin-left: 100px;
      }
    }

    .card-body {
      font-size: 16px;
      color: #5f656c;
      line-height: 30px;
      margin-bottom: 8px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      overflow: hidden;
    }

    .card-footer {
      display: flex;
      gap: 8px;
      align-items: center;

      .footer-left-tags {
        display: flex;
        gap: 8px;

        .area-tag {
          padding: 2px 12px;
          background: #e6f7ff;
          border: 1px solid #91d5ff;
          color: #1890ff;
          border-radius: 4px;
          font-size: 14px;
        }
      }

      .footer-right-flags {
        display: flex;
        gap: 4px;

        .flag-icon {
          width: 12px;
          height: 24px;

          img {
            border-radius: 50%;
            border: 1px solid #eee;
            width: 24px;
            height: 100%;
            object-fit: cover;
          }
        }
      }
    }
  }
}
</style>