<template>
  <view class="pest-archive" v-if="pest_info.name">
    <view class="pest-archive__header">
      <view class="pest-archive__title">虫害档案</view>
    </view>

      <view
        class="pest-card"
        @tap="handleCardClick()"
      >
        <view class="pest-card__image">
          <image :src="pest_info.img_urls" mode="aspectFill" class="pest-img"></image>
        </view>
        <view class="pest-card__info">
          <view class="pest-card__top">
            <view class="pest-card__name">
              名称
            </view>
            <view class="pest-card__status">
              {{ pest_info.name || '未知' }}
            </view>
          </view>
          <view class="pest-card__top">
            <view class="pest-card__name">
              害虫信息
            </view>
            <view class="pest-card__status" style="height:200rpx;overflow: auto;">
              {{ pest_info.prevention || '未知' }}
            </view>
          </view>
        </view>
      </view>
      <u-popup v-model="showDetail" mode="bottom" border-radius="32">
        <view class="pest-card__detail">
          <view class="pest-card__image">
            <image :src="pest_info.img_urls" mode="aspectFill" class="pest-img"></image>
          </view>
          <view>
            {{ pest_info.name || '未知' }}
          </view>
          <view>
            {{ pest_info.prevention || '未知' }}
          </view>
        </view>
      </u-popup>
  </view>
</template>

<script>
export default {
  props: {
    scrollHeight: {
      type: String,
      default: '500rpx'
    },
    pest_info: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      showDetail: false,
    }
  },
  methods: {
    showPestDetail(){
      this.showDetail = true;
    },
    handleCardClick() {
      this.showPestDetail()
      this.$emit('click', this.pest_info)
    }
  }
}
</script>

<style lang="scss" scoped>
.pest-archive {
  width: 100%;
  padding: 32rpx;
  margin-top: 24rpx;
  box-sizing: border-box;
  background: #fff;
  border-radius: 16rpx;
}

.pest-archive__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24rpx;
}

.pest-archive__title {
  font-size: 32rpx;
  color: #042118;
  font-family: 'Source Han Sans CN VF';
  font-weight: 500;
}

.pest-archive__add {
  width: 56rpx;
  height: 56rpx;
  border-radius: 50%;
  background: linear-gradient(135deg, #00D26A 0%, #00B55A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4rpx 12rpx rgba(0, 210, 106, 0.3);

  .add-icon {
    font-size: 40rpx;
    color: #fff;
    line-height: 1;
    font-weight: 300;
  }
}

.pest-card__detail{
  height: 70vh;
  padding: 40rpx;
}
.pest-archive__list {
  width: 100%;
}

.pest-card {
  display: flex;
  padding: 24rpx;
  margin-bottom: 16rpx;
  background: #F7F8F9;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);

  &:last-child {
    margin-bottom: 0;
  }

  &:active {
    opacity: 0.8;
  }
}

.pest-card__image {
  width: 200rpx;
  height: 200rpx;
  border-radius: 12rpx;
  overflow: hidden;
  flex-shrink: 0;
  margin-right: 20rpx;
  background: #e0e0e0;

  .pest-img {
    width: 100%;
    height: 100%;
  }
}

.pest-card__info {
  padding: 4rpx 0;
}

.pest-card__top {
  display: flex;
}

.pest-card__name {
  font-size: 26rpx;
  color: #999999;
  font-family: "Source Han Sans CN VF";
  font-weight: 400;
  width: 110rpx;
}

.pest-card__status {
  width: 270rpx;
  color: #303133;
  font-size: 26srpx;
  font-weight: 500;

  &.status--handled {
    background: rgba(0, 210, 106, 0.15);
    color: #00B55A;
  }

  &.status--handling {
    background: rgba(255, 149, 0, 0.15);
    color: #FF9500;
  }

  &.status--pending {
    background: rgba(255, 53, 70, 0.15);
    color: #FF3546;
  }
}

.pest-card__time {
  font-size: 24rpx;
  color: #86909C;
  margin-top: 8rpx;
}

.pest-card__desc {
  font-size: 26rpx;
  color: #4E5969;
  margin-top: 12rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.5;
}
</style>
