<template>
  <div class="common-adert-wrapper">
    <img
      :class="{'margin-top-20': needPadTop}"
      v-if="showInfo.imageUrl"
      @click="jumpPage"
      :src="showInfo.imageUrl"
      alt
    />
  </div>
</template>
<script>
import { EMLINK } from "constants";
export default {
  name: "common-title",
  data() {
    return {
      isWeb: window.__isWeb,
      showInfo: {
        imageUrl: "",
        jumpUrl: ""
      }
    };
  },
  props: {
    advertInfoList: {
      type: Array,
      default: () => []
    },
    position: {
      type: String | Number,
      default: 0
    },
    needPadTop: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    advertInfoList: {
      handler(list) {
        list.forEach(element => {
          if (element.position == this.position) {
            this.showInfo = element;
          }
        });
      },
      deep: true
    }
  },
  created() {},
  mounted() {},
  computed: {},
  methods: {
    // 广告位跳转
    jumpPage() {
      // if (this.isWeb) {
      //   window.location.href = this.showInfo.jumpUrl;
      //   return;
      // }
      let paramList = [
        {
          key: "pageUrl",
          value: this.showInfo.jumpUrl,
          type: 4,
          seqNo: 1
        }
      ];
      rocNative.dispatchEventByModuleCode({
        modeCode: "M300",
        jsonString: paramList
      });
    }
  }
};
</script>
<style lang="less" scoped>
.common-adert-wrapper {
  img {
    width: 100%;
    // padding: 10px 0;
    // height: 60px;
  }
  .margin-top-20 {
    margin-top: 20px;
  }
}
</style>
