<template>
  <view class="album-card" @click="onDetailFn(item)">
    <view class="img">
      <uv-image :src="getImgUrl(item?.scfm)" width="210rpx" height="180rpx" />
    </view>
    <view class="info">
      <view class="title one-row">{{ item?.xcmc }}</view>
      <view class="desc two-row">{{ formatHtml(item?.wb) }}</view>
      <view class="bottom">
        <view class="time">{{ 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?.xcmc"
          :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>
  </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 getImgUrl = (path: string) => import.meta.env.VITE_APP_URL + path

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

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

  display: flex;
  .img {
    margin-right: 30rpx;
  }

  .info {
    width: 450rpx;
  }
  .title {
    color: #333;
    line-height: 45rpx;
    font-size: 32rpx;
  }
  .desc {
    margin-top: 20rpx;
    height: 68rpx;
    color: #666;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 34rpx;
  }
  .bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56rpx;
    .time {
      color: #999;
      font-size: 26rpx;
      font-weight: 400;
      line-height: 36rpx;
    }
    .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>
