<template>
  <div>
    <div
      ref="addShopBtn"
      @click="styleClick('click', 'addShopBtn')"
      @mousemove="styleClick('mousemove', 'addShopBtn')"
      @mouseout="styleClick('mouseout')"
      class="btnStatus"
    >
      <img
        :style="styleData.btnStatusImg"
        :src="styleData.btnStatusImg.imageUrl"
        @click="getDraw()"
      />
    </div>
  </div>
</template>

<script>
import apis1 from "../../../util/apis1.js";
let { getUserFollowInfo, saveFollowInfo } = apis1;
import {
  PrizeResultPopComService,
  NoPrizeResultPopComService,
  AddBuyErrDialogService
} from "../../../util/comCreate.js";
export default {
  props: [
    "isTemplate",
    "datas",
    "isWebClick",
    "keyData",
    "templateData",
    "styleData",
    "modifyContent"
  ],
  data() {
    return {
      prizeResultData: {
        styleData: {},
        datas: {},
        keyData: {
          prizeUrl: "showImg",
          prizeName: "prizeName",
          prizeType: "prizeType",
          priceInfo: "priceInfo",
          discountType: "discountType",
          couponType: "couponType"
        }
      }
    };
  },
  created() {
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
  },
  mounted() {
    this.publicData.$on("getUserFollowInfoData", goodsNum => {
      this.goodsNum = goodsNum;
    });
  },
  methods: {
    //点击可修改位置的方法
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          isCustomSwitching: this.isCustomSwitching, //有tab切换时
          c_this: this,
          styleDataOld: this.styleDataOld
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
    //领奖
    getDraw() {
      let actStatus = sessionStorage.getItem("actStatus");
      if (this.isTemplate) {
        // this.$toast('活动预览，仅供查看');
        return;
      }
      if (actStatus == "1") {
        this.$toast("活动未开始");
        return;
      }
      if (actStatus == "2") {
        this.$toast("活动已结束");
        return;
      }
      if (this.goodsNum > 0) {
        getUserFollowInfo(shopData => {
          if (shopData.data.goodsNum > 0) {
            if (shopData.data.followShop) {
              //有参加资格
              //可以正常关注店铺领奖
              this.doFrontBuryPoint({
                code: "ljq-gzdp",
                value: "",
                event: "click"
              });
              saveFollowInfo(data111 => {
                if (data111.resp_code == 0) {
                  let prizeData = data111.data;
                  let initDatas = data111.data;
                  //重新刷新接口显示奖品剩余数量
                  this.publicData.$emit("reShowPrize", true);

                  // if (data111.resp_msg == "发放奖品成功") {
                  if (prizeData.status == 1) {
                    //中奖
                    this.prizeResultData.datas = prizeData;
                    PrizeResultPopComService.create(
                      this.prizeResultData,
                      initDatas,
                      submit => {
                        PrizeResultPopComService.close();
                      }
                    );
                  } else {
                    // NoPrizeResultPopComService.create(
                    //   "非常遗憾，您与大奖擦肩而过~",
                    //   "//img10.360buyimg.com/imgzone/jfs/t1/136745/32/20121/48059/5fd996feE56314a28/b952f0e6f3fe811f.png",
                    //   submit => {
                    //     NoPrizeResultPopComService.close();
                    //   }
                    // );
                    AddBuyErrDialogService.create({}, initDatas, submit => {
                      AddBuyErrDialogService.close();
                    });
                  }
                }
              });
            } else {
              //没有参加资格
              this.$toast("此活动只针对新关注店铺用户~");
            }
          } else {
            // this.$toast("奖品已发完哦~");
            let obj = {
              canSend: 5
            };
            AddBuyErrDialogService.create({}, obj, submit => {
              AddBuyErrDialogService.close();
            });
          }
        });
      } else {
        // this.$toast("奖品已发完哦~");
        let obj = {
          canSend: 5
        };
        AddBuyErrDialogService.create({}, obj, submit => {
          AddBuyErrDialogService.close();
        });
      }
    }
  }
};
</script>

<style lang="scss">
.btnStatus {
  height: 1rem;
  margin-top: 0.3rem;
  img {
    width: 6.9rem;
    height: 1rem;
  }
}
</style>
