<template>
  <view class="info-card" @click="onDetailFn(item)">
    <view class="title one-row"> {{ item?.title || '' }}</view>
    <view class="desc two-row">
      {{ formatHtml(item?.content) }}
    </view>
    <view class="bottom">
      <view class="area-time">
        {{ item?.area ? item?.area + '·' : '' }} {{ formatTime(item?.createTime) }}
      </view>
      <!-- 登陆下的分享 -->
      <button class="forward" v-if="isLogin" @click.stop.prevent="shareFn(item)">
        <image src="@/static/images/common/zhuanfa.svg" alt="" />
        <text>转发</text>
      </button>
      <!-- 非登录下分享 -->
      <button
        class="forward"
        :data-title="item?.title"
        :data-id="item?.id"
        @click.stop.prevent="catchtap"
        open-type="share"
        v-else
      >
        <image src="@/static/images/common/zhuanfa.svg" alt="" />
        <text>转发</text>
      </button>
    </view>
  </view>
</template>

<script setup lang="ts">
import formatTime from '@/utils/formatTime'
import { formatRichTxt } from '@/utils/index'
import { defineEmits } from 'vue'

const emit = defineEmits(['onDetail', 'shareFn'])

defineProps({
  item: Object,
  isLogin: Boolean
})

const formatHtml = (str: string) => {
  if (!str) return ''
  return formatRichTxt(str)
}

const catchtap = () => {}

const onDetailFn = (item: any) => {
  emit('onDetail', item)
}
const shareFn = (item: any) => {
  emit('shareFn', {
    id: item.id,
    type: '9',
    shareTitle: item.title
  })
}
</script>

<style lang="scss" scoped>
.info-card {
  padding: 30rpx 0;
  border-bottom: 2rpx solid #d3d3d3;
  width: 690rpx;

  .title {
    width: 95%;
    color: #333;
    font-size: 32rpx;
    line-height: 45rpx;
  }
  .desc {
    width: 95%;
    margin-top: 20rpx;
    color: #666;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 36rpx;
    height: 72rpx;
  }
  .bottom {
    margin-top: 30rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .area-time {
      color: #999;
      font-size: 26rpx;
      font-weight: 400;
    }
    .forward {
      width: 150rpx;
      height: 56rpx;
      background: #f8f8f0;
      border-radius: 200rpx;
      border: none;
      display: flex;
      align-items: center;
      padding: 0 24rpx;
      margin: 0;
      image {
        width: 32rpx;
        height: 32rpx;
        margin-right: 12rpx;
      }
      text {
        color: #6eb657;
        font-size: 28rpx;
      }
    }
  }
}
</style>
