<template>
  <div :class="{ active: isScroll }" class="xb-header-container">
    <div :class="{ active: isScroll }" class="top-header">
      <div class="content left-icon" @click="goBack">
        <img :src="headerLeftIcon" />
      </div>
      <div :class="{ active: isScroll }" class="content title">
        <span>{{ shareTitle1 }}</span>
      </div>
      <div 
      v-show="isShowRightIcon" 
      class="content right-icon" 
      @click="share"
      v-bp="{ component_tag: '360#360001'}">
        <img :src="headerRightIcon" />
      </div>
    </div>
  </div>
</template>

<script>
import { getShareUrl } from '@/utils';
import { ENV_CONFIG } from '@/utils/enumerate';

import './index.less';

export default {
  name: 'Header',
  props: {
    prePage: {
      type: Boolean,
      default: false
    },
    isWeb: {
      type: Boolean,
      default: false
    },
    isScroll: {
      type: Boolean,
      default: false
    },
    shareTitle1: {
      type: String,
      default: ''
    },
    shareTitle2: {
      type: String,
      default: ''
    },
    token: {
      type: String,
      default: ''
    },
    shareIconUrl: {
      type: String
    },
    isShowRightIcon: {
      type: Boolean,
      default: false
    },
    tempId: {
      type: String | Number,
      default: ''
    },
    userId: {
      type: String | Number,
      default: ''
    },
    userName: {
      type: String,
      default: ''
    },
    avatarl: {
      type: String,
      default: ''
    },
    taskId: {
      type: String | Number,
      default: 7
    }
  },
  computed: {
    headerLeftIcon() {
      return !!this.isScroll ? 
        'https://file.yunqueyi.com/gpranking/left-icon.png' :
        'https://file.yunqueyi.com/2019/04/template/left-array.png'
    },
    headerRightIcon() {
      return !!this.isScroll ?
        'https://file.yunqueyi.com/gpranking/right-icon.png' :
        'https://file.yunqueyi.com/2019/04/template/share-icon.png'
    }
  },
  methods: {
    goBack() {
      if(this.prePage) {
        this.$router.go(-1);
      } else {
        this.$rocNative.goBack();
      }
    },
    share() {
      let shareUrl = '';
      const { NUXT_ENV_APP } = process.env;
      const { tempId, taskId, userName, userId, avatarl, token, shareTitle1, shareTitle2, shareIconUrl } = this;
      //shareUrl = ENV_CONFIG[NUXT_ENV_APP]['shareUrl'] + '/compaign_ssr/?id=' + tempId + '&token=' + token;
      shareUrl = `http://10.177.10.217:3000/compaign_ssr/login-point?activityId=${tempId}&taskId=${taskId}&id=${userId}&name=${userName}&avatar=${avatarl}`;

      // const { id } = this.$route.query;
      // this.$sendBuriedData({
      //   class_name: '',
      //   component_tag: `200#400089#${id}#${shareTitle1}`  
      // });
      this.$rocNative.shareWechat({
        type: 6,
        shareId: 0,
        shareUrl: shareUrl,
        title1: shareTitle1,
        title2: shareTitle2,
        shareImageUrl: shareIconUrl || 'https://file.yunqueyi.com/logo.png?version=' + new Date().getTime()
      });
    }
  },
}
</script>

