<template>
  <div class="enterprise" :style="styleData.goToShopStyle" @click="goShop">
    <div class="shop-logo-box" :style="styleData.logoStyle" v-if="goToshopImg">
      <img
        :src="goToShopList.shopLogoUrl"
        alt=""
        class="shop-logo"
        :style="styleData.shopLogoStyle"
      />
    </div>
    <div v-else class="shop-logo-box" :style="styleData.logoStyle">
      <img
        :src="LogoUrl"
        alt=""
        :style="styleData.shopLogoStyle"
        class="shop-logo"
      />
    </div>
    <p class="shop-name" :style="styleData.shopNameStyle">
      {{ goToShopList.shopName }}
    </p>
    <button
      class="shop-btn"
      :style="styleData.shopBtnStyle"
      @click="goShop"
      v-lz-click="'4'"
      v-if="shopBtn"
    >
      进店逛逛
    </button>
    <button
      class="shop-btn"
      :style="styleData.shopBtnStyle"
      @click="goShop"
      v-lz-click="'4'"
      v-else
    ></button>
  </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"],
  data() {
    return {
      goToShopList: [],
      shareFlag: false,
      shareUserId: "",
      shopBtn: true,
      goToshopImg: true,
      LogoUrl: null,
      shopFlag: false, // true 不需要从新请求API
      shopNameFlag:false,
      isShareClick:false
    };
  },

  created() {
    this.initData();
  },
  mounted() {},
  methods: {
    initData() {
      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 {
        this.shopBtn = this.datas.shopBtn;
        this.shareFlag = this.datas.shareFlag;
        this.isShareClick = this.datas.isShareClick;
        this.shareUserId = store.state.shareUserId;
        this.goToshopImg = this.datas.goToshopImg;
        this.shopFlag = this.datas.shopFlag;
        this.shopNameFlag = this.datas.shopNameFlag;
        console.log(this.isShareClick , 'isShareClick')
        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>
</style>
