<template>
  <div class="dm__is-delete" v-if="item.status == 0">小程序链接-已删除</div>
  <div v-else class="dm-wxa__item__wrap" @mouseover="maskShow = true" @mouseout="maskShow = false">
    <div class="dm-wxa__item">
      <div class="dm-wxa__avatar">
        <img :src="item.brandLogo || loadErrorImg" alt="" />
        <span>{{ item.brandName }}</span>
      </div>
      <p class="ellipsis-l2">{{ item.title }}</p>
      <img :src="item.imageUrl || loadErrorImg" alt="" srcset="" />
      <p class="dm-wxa__item--bottom">
        <img src="../assets/img/wxa-circle.svg" alt="" srcset="" /><span> 小程序</span><span class="wxa-status">{{ statusText }}</span>
      </p>
    </div>
  </div>
</template>

<script>
import { getLinkResourceStatusECM, getLinkResourceStatus } from '@/service/api/ecmApi.js';
export default {
  name: 'item-wxa',
  data() {
    return {
      maskShow: false,
      // eslint-disable-next-line
      loadErrorImg: require('../assets/img/loaderror.png'),
      statusText: ''
    };
  },
  props: {
    item: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  watch: {
    item: {
      handler() {
        this.statusText = '';
      },
      immediate: true
    }
  },
  mounted() {
    this.getLinkResourceStatus(this.item.pagePath);
  },
  methods: {
    getLinkResourceStatus(v) {
      let params = {};
      const statusMap = { 1: '已删除', 2: '已失效' };
      const result = JSON.parse(v);
      console.log(v);
      if (result.pageType == 4 && result.type && result.type.startsWith('GAME_LINK')) {
        params = {
          id: result.type,
          params: result.tagid
        };
        getLinkResourceStatus(params).then(res => {
          this.statusText = statusMap[res.result] || '';
          this.$emit('set-status', res.result);
        });
      } else {
        params = {
          pagePath: v
        };
        getLinkResourceStatusECM(params).then(res => {
          this.statusText = statusMap[res.result] || '';
          this.$emit('set-status', res.result);
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.wxa-status {
  margin-left: 20px;
  color: #f5222d;
}
</style>
