<template>
  <div
    class="sharebuttonC"
    :style="styleData.sharebutton"
    ref="shareButton"
    @click="styleClick('click', 'shareButton')"
    @mousemove="styleClick('mousemove', 'shareButton')"
    @mouseout="styleClick('mouseout')"
  >
    <div id="shareTips" :style="styleData.shareTips">
      分享给好友后，需要好友点击进入才算分享成功哦~
    </div>
    <div
      class="btn1"
      :style="styleData.btn1div"
      v-lz-click="'2'"
      @click="handleshare"
      v-if="btnimg"
    ></div>
    <div
      class="btn2"
      :style="styleData.btn2div"
      v-lz-click="'2'"
      @click="handleshare"
      v-else
    ></div>
  </div>
</template>
<script>
import apis1 from "../../../util/apis1.js";
let { followShop } = apis1;
import { allShare } from "../../../js/share.js";
import { Toast } from "vant";
import bus from "../../../util/bus.js";
export default {
  props: [
    "isTemplate",
    "datas",
    "keyData",
    "styleData",
    "templateData",
    "modifyContent",
    "isWebClick",
  ],
  components: {},
  data() {
    return {
      nowdatas: null,
      btnimg: false,
      styleDataOld: {},
    };
  },
  mounted() {
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    this.initdatas();
  },
  methods: {
    //点击可修改位置的方法
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          styleDataOld: this.styleDataOld,
          c_this: this,
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
    initdatas() {
      if (this.isTemplate == true) {
        Toast("活动预览，仅供查看");
        var datasAll = this.templateData;
        if (datasAll) {
          if (datasAll.sharePolite) {
            if (datasAll.sharePolite.isFollow == 1) {
              this.btnimg = true;
            }
          }
        }

        return;
      } else {
        bus.$on("data", (content) => {
          this.nowdatas = content; //接收总数据
          if (this.nowdatas.involvementFlag == 1) {
            this.btnimg = true;
          } else {
            this.btnimg = false;
          }
        });
      }
    },
    handleshare() {
      //点击按钮
      if (this.isTemplate == true) {
        Toast("活动预览，仅供查看");
        return;
      } else {
        let actStatus = sessionStorage.getItem("actStatus");
        if (actStatus == 2) {
          this.$toast("活动已结束");
          return;
        }
        if (actStatus == 1) {
          this.$toast("活动尚未开始");
          return;
        }
        if (this.nowdatas.involvementFlag == 1) {
          //如果需要关注
          followShop((initdatas) => {}); //调用关注店铺接口
          var url = "";
          url = location.href; //获取本地地址
          console.log(url + "url");
          allShare(this.isTemplate, this, (callBackData) => {
            //调用分享接口
            console.log(callBackData, "callBackData" + url);
          });
        } else {
          var url = "";
          url = location.href; //获取本地地址
          console.log(url + "url");
          allShare( this.isTemplate, this, (callBackData) => {
            //调用分享接口
            console.log(callBackData, "callBackData" + url);
          });
        }
        this.nowdatas.shareSuccessTimesList.forEach((v) => {
          if (v.status == 0) {
            Toast(
              "抱歉哦~部分奖品已发放完毕，继续召唤小伙伴可能无法获得奖品哦~"
            );
          }
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.sharebuttonC {
  position: relative;
}
</style>