<template>
  <div class="item" @click="toDetail(item)">
    <div class="item-header">
      <h4 class="van-ellipsis">
        <div class="van-ellipsis">{{ item.name }}</div>
      </h4>
      <span v-if="item.isFree == 1" class="free">免费</span>
      <template v-if="item.isFree == 2">
        <span v-if="item.supportCode" class="sign">0元签约</span>
        <span v-else-if="item.pricingStrategy" class="unfree">{{
          getFee(item.pricingStrategy)
        }}</span>
      </template>
    </div>
    <p class="text van-multi-ellipsis--l2">
      {{ item.intro }}
    </p>
    <div class="item-footer">
      <div
        class="tg"
        @click.stop="
          item.advisorBasic ? $router.push(`/tg/${item.advisorBasic.id}`) : ''
        "
      >
        <img :src="item.advisorBasic && item.advisorBasic.avatar" alt="" />
        <span>{{ item.advisorBasic && item.advisorBasic.showName }}</span>
        <i>{{ dayjs(item.publishTime).format("MM/DD HH:mm") }}</i>
      </div>
      <div>
        <span>{{ item.subCount || 0 }}订阅</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from "vue";
import dayjs from "dayjs";
defineProps({
  item: {
    required: true,
    type: Object,
    default: () => ({}),
  },
});
const toDetail = (item) => {
  location.href = `${location.origin}/tgh5/viewpackageDetail/${item.id}`;
};

const PRICING_FEE = {
  // 免费永久,单品提拥
  0: "永久",
  1: "周",
  2: "月",
  3: "季度",
  4: "半年",
  5: "年",
};
const getFee = (val) => {
  const res = val.feesList.find((item) => item.defaultDisplay === 1);
  if (res) {
    return `${res.price / 100}元${
      res.period == 99 ? "" : `/${PRICING_FEE[res.period]}`
    }`;
  }
  return "";
};
</script>
<style scoped lang="scss">
.item {
  margin: 0 0 28px;
  background: #fff;
  margin-bottom: 28px;
  padding: 30px;
  border-radius: 20px;

  .item-header {
    display: flex;
    // line-height: 21px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    h4 {
      flex: 1;
      margin: 0;
      font-size: 28px;
      color: #333;
      text-align: left;
      display: flex;
      .circle {
        background: #da000b;
        color: #fff;
        font-style: normal;
        text-align: center;
        padding: 2px 8px;
        font-size: 20px;
        transform: scale(0.83333);
        line-height: 36px;
        margin: 0 10px;
        border-radius: 8px;
        font-weight: 400;
      }
    }
    .free {
      font-size: 24px;
      display: inline-block;
      background: rgba(46, 120, 250, 0.1);
      color: #2e78fa;
      padding: 6px 8px;
      border-radius: 8px;
      font-weight: 400;
      // line-height: 12px;
    }
    .unfree {
      color: #c1272f;
      font-size: 28px;
    }
    .sign {
      color: #c1272f;
      font-size: 28px;
      // border: 1px solid #333;
      // border-radius: 4px;
      // padding: 2px 6px;
    }
  }
  .text {
    text-align: left;
    font-size: 26px;
    line-height: 32px;
  }
  .item-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .tg {
      display: flex;
      align-items: center;
    }
    img {
      width: 30px;
      height: 30px;
      border-radius: 50%;
    }
    span {
      padding-top: 4px;
      font-size: 24px;
      color: #666;
      margin-left: 20px;
      vertical-align: middle;
    }
    i {
      padding-top: 4px;
      margin-left: 20px;
      font-style: normal;
      color: #999;
      font-size: 24px;
      vertical-align: middle;
    }
  }
}
</style>
