<template>
  <view class="ad-container">
    <block v-for="(ad, index) in ads" :key="index">
      <image 
        :src="ad.imageUrl" 
        mode="widthFix"
        @click="handleAdClick(ad)"
      />
      <text v-if="ad.title" class="ad-title">{{ ad.title }}</text>
    </block>
  </view>
</template>

<script>
export default {
  props: {
    ads: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    handleAdClick(ad) {
      // 广告点击统计
      this.$http.post('/ad/click', { adId: ad.id });
      
      // 处理跳转
      if (ad.linkType === 'NOVEL') {
        uni.navigateTo({ url: `/pages/novel/detail?id=${ad.linkTarget}` });
      } else if (ad.linkType === 'URL') {
        uni.navigateTo({ url: `/pages/webview?url=${encodeURIComponent(ad.linkTarget)}` });
      }
    }
  }
}
</script>

<style>
.ad-container {
  padding: 10px;
  background: #f5f5f5;
  margin: 15px 0;
  border-radius: 8px;
}
.ad-title {
  display: block;
  text-align: center;
  font-size: 14px;
  color: #666;
}
</style>