<template>
  <div ref="gwcjlGoToShopNew" @click="styleClick('click', 'gwcjlGoToShopNew')" @mousemove="styleClick('mousemove', 'gwcjlGoToShopNew')"
    @mouseout="styleClick('mouseout')" :style="styleData.shopBtnStyle">
    <div :style="styleData.shopBtnStyleasd" @click="goShop" v-lz-click="'4'" v-if="datas.shopBtn">
      进店逛逛
    </div>
  </div>
</template>
<script>
import apis1 from "../../../util/apis1.js";
import { goToShopPage } from "../../../util/tools.js";
import store from "../../../store/store";
import bus from "../../../util/bus.js";
import { Toast } from "vant";
let {storeGoodsPoint} = apis1
export default {
  props: [
    "isTemplate",
    "datas",
    "keyData",
    "styleData",
    "templateData",
    "isWebClick",
    "modifyContent",
  ],
  data() {
    return {
      goToShopList: [],
      shareFlag: false,
      shareUserId: "",
      shopBtn: true,
      goToshopImg: true,
      LogoUrl: null,
      shopFlag: false, // true 不需要从新请求API
      shopNameFlag: false,
      styleDataOld: {},
      isCustomSwitching: "",
    };
  },

  created() {
    this.initData();
  },
  mounted() { },
  methods: {
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          c_this: this,
          isCustomSwitching: this.isCustomSwitching,
          styleDataOld: this.styleDataOld,
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
    initData() {
      //深拷贝重置需要
      this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
      var datasAll = this.templateData;

      if (this.isTemplate == true) {
        this.shopBtn = this.datas.shopBtn;
        // this.$toast("活动预览，仅供查看");
        if (datasAll) {
          this.goToshopImg = true;
          this.goToShopList.shopLogoUrl = datasAll.activity.shopLogo;
          this.goToShopList.shopName = datasAll.activity.shopName;
        } else {
          //没有模板的数据
          this.goToshopImg = true;
          this.goToShopList = {
            shopLogoUrl: "",
            shopName: "XXX京东自营官方旗舰店",
          };
        }
      } else {
        let actStatus = sessionStorage.getItem("actStatus");
        if (actStatus == 2) {
          Toast("活动已结束");
        }
        if (actStatus == 1) {
          Toast("活动尚未开始");
        }
        this.shopBtn = this.datas.shopBtn;
        this.shareFlag = this.datas.shareFlag;
        this.shareUserId = store.state.shareUserId;
        this.goToshopImg = this.datas.goToshopImg;
        this.shopFlag = this.datas.shopFlag;
        this.shopNameFlag = this.datas.shopNameFlag;
        bus.$on("shopLogo", (content) => {
          console.log(content, "sssssssssssss");
          this.LogoUrl = content;
        });
        if (this.shopNameFlag) {
          console.log("ssssssssssss11111s");
          bus.$on("shopName", (content) => {
            this.goToShopList.shopName = content;
          });
        }
        if (!this.shopFlag) {
          if (this.shareFlag == true) {
            let shopList = apis1[this.datas.shopList];
            shopList(this.shareUserId, (data) => {
              console.log(data.data, "goToshop");
              this.goToShopList = data.data;
              console.log(this.goToShopList, "goToShop");
            });
          } else {
            let shopList = apis1[this.datas.shopList];
            shopList((data) => {
              this.goToShopList = data.data;
              console.log(this.goToShopList, "goToShop");
            });
          }
        }
      }
    },

    goShop() {
      if (this.isTemplate == true) {
        // this.$toast("活动预览，仅供查看");
        return;
      }
      if (this.shopFlag) {
        let shopId = store.state.shopId;
        console.log(shopId, "1");
        // storeGoodsPoint(4)
        goToShopPage(shopId);
      } else {
        let shopId = this.goToShopList.shopId;
        console.log(shopId, "2");
        // storeGoodsPoint(4)
        goToShopPage(shopId);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.enterprise {
  position: relative;
}
.fd-row {
  display: flex;
}
</style>
