<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 { 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 {};
      }
    }
  },
  mounted() {
    this.getLinkResourceStatus(this.item.pagePath);
  },
  methods: {
    getLinkResourceStatus(v) {
      let result = JSON.parse(v);
      const params = {
        id: result.type,
        params: ''
      };
      switch (result.type) {
        case 'product_category_link':
        case 'mall_costomize_page':
        case '28':
        case 28:
        case '17':
        case 17:
        case 'coup':
        case 'gift':
          result.params && (params.params = JSON.stringify(result.params));
          break;
        case 'yueshi_integral_mall':
          params.params = '';
          break;
        case '35':
        case 35:
          params.params = result.appid;
          break;
        case 'GAME_LINK_DZP':
        case 'GAME_LINK_GGK':
        case 'GAME_LINK_PTYX':
        case 'GAME_LINK_KLFL':
        case 'GAME_LINK_ZNM':
          params.params = result.tagid;
          break;
        default:
          return;
      }
      const statusMap = { 1: '已删除', 2: '已失效' };
      getLinkResourceStatus(params).then(res => {
        this.statusText = statusMap[res.result] || '';
      });
    }
  }
};
</script>

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