<template>
  <div :key="timer" class="sigPrizeNew" :style="styleDataNew[keyData.signPrizeDiv]" ref="sigPrizeNew"
    @click.stop="styleClick('click', 'sigPrizeNew')" @mousemove.stop="styleClick('mousemove', 'sigPrizeNew')"
    @mouseout.stop="styleClick('mouseout')">
    <div>
      <!-- 活动规则 -->
      <div v-lz-click="'18'" @click="operClick(1)" v-if="datas.isSign && styleDataNew.imageSignStyle">
        <img :style="styleDataNew.imageSignStyle" :src="styleDataNew.imageSignStyle.imageUrl" />
      </div>
      <!-- 我的奖品 -->
      <div @click="operClick(2)" v-lz-click="'19'" v-if="datas.isPrize && styleDataNew.imagePrizeStyle">
        <img :style="styleDataNew.imagePrizeStyle" :src="styleDataNew.imagePrizeStyle.imageUrl" />
      </div>
      <!-- 邀请好友 -->
      <div @click="operClick(4)" v-if="datas.shareBtn && styleDataNew.shareFriendStyle">
        <img :style="styleDataNew.shareFriendStyle" :src="styleDataNew.shareFriendStyle.imageUrl" />
      </div>
      <!-- 下单类活动商品 先定义为30 -->
      <div @click="operClick(30)" v-if="datas.goodsBtn && styleDataNew.imageGoodsStyle && assignGoodsFlag">
        <img :style="styleDataNew.imageGoodsStyle" :src="styleDataNew.imageGoodsStyle.imageUrl" />
      </div>
      <!-- 我的好友 -->
      <div @click="operClick(5)" v-if="styleDataNew.imageMyFriendsStyle"><img :style="styleDataNew.imageMyFriendsStyle"
          :src="styleDataNew.imageMyFriendsStyle.imageUrl" /></div>
      <div @click="operClick(9)" :style="styleData.imageBtnStyle" v-if="styleData.imageBtnStyle && isShowCheckOrder">订单查询
      </div>
      <div @click="operClick(10)" :style="styleData.drawRecord" v-if="datas.isShowDrawRecord">
        <img  v-if="datas.isShowDrawRecordImg" :style="styleDataNew.prizeHistoryInfo" :src="styleDataNew.prizeHistoryInfo.imageUrl" />
        <span v-else>抽奖记录</span>
      </div>
      <div @click="goShop" v-lz-click="'4'" v-if="datas.shopBtn && styleDataNew.imageShopStyle">
        <img :style="styleDataNew.imageShopStyle" :src="styleDataNew.imageShopStyle.imageUrl" />
      </div>
    </div>
  </div>
</template>

<script>
import { ShareFriendPopComService, LuckDrawRecordPopComService, GiftPopComService } from '../../../util/comCreate.js';
import { AcRulePopComService, MyPrizePopComService, HdzxtMyFriendPopComServiceNew2, MyOrderPrizePopComService, OrderCheckPopNewService, orderActivityGoodsService, drawRecordPopNewService } from '../../../util/hdzxtcomCreate.js';
import { goToShopPage } from '../../../util/tools.js';
import store from '../../../store/store';
import { Toast } from 'vant';
import apis1 from '../../../util/apis1.js'
let { storeGoodsPoint, checkOrderByActType } = apis1
import bus from '../../../util/bus.js';
export default {
  props: ['datas', 'styleData', 'keyData', 'isTemplate', 'templateData', 'modifyContent', 'isWebClick'],
  data() {
    return {
      timer: new Date().getTime(),
      isShowImg: true, // 活动规则是 按钮图片 false 不显示图片
      isShow: true,
      isShowImg2: false,
      isEditAddress: true, //是否可以编辑地址 默认可以编辑地址
      isAlLookAddress: false, //是否可以一直查看地址 默认不可以一直查看
      isShowLuckDrawRecord: false, // 积分猜大小 游戏记录
      styleDataNew: {},
      styleDataOld: {},
      myPrizePopComData: {
        styleData: {},
        datas: {},
        keyData: {
          prizeType: 'prizeType',
          prizeUrl: 'showImg',
          prizeName: 'prizeName',
          prizeDate: 'dayTime',
          prizeStatus: 'activityType',
          realName: 'realName',
          recevierPhone: 'mobile',
          logisticsJson: 'logisticsJson',
          nickName: 'nickName'
        }
      },
      acRulePopComData: {
        styleData: {},
        datas: {},
        keyData: {}
      },
      goToShopList: [],
      shareFlag: false,
      shareUserId: '',
      goToshopImg: true,
      LogoUrl: null,
      shopFlag: false, // true 不需要从新请求API
      shopNameFlag: false,
      isShowCheckOrder: false,//是否显示同步订单
      assignGoodsFlag: false
    };
  },

  created() {
    console.log(this.styleData, "llllllllllll");
    console.log(this.datas, "llllllllllllaaaaaaaaa");
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    //如果父组件传递过来的样式数据则使用样式数据否则使用默认数据
    this.styleDataNew = this.styleData; //父组件传递过来的样式数据
    this.isShow = this.datas.isShowPrize;
    this.isShowImg = this.datas.isShowImg == false ? false : true;
    this.isShowImg2 = this.datas.isShowImg2 == false ? false : true;
    this.isEditAddress = this.datas.isEditAddress == false ? false : true;
    this.isAlLookAddress = this.datas.isAlLookAddress == true ? true : false;
    this.isShowLuckDrawRecord = this.datas.isShowLuckDrawRecord == true ? true : false;
    this.publicData.$on('showMyPrize', datas => {
      if (datas == true) {
        //显示我的奖品组件
        this.isShow = true;
        if (this.isTemplate == true) {
          this.initData(this.templateData);
        } else {
          this.initData();
        }
      } else {
        this.isShow = false;
      }
    });
    this.initData();
    this.checkOrderByActType();
  },
  mounted() {
    bus.$on('assignGoodsFlag', (data) => {
      if (data == '1') {
        this.assignGoodsFlag = true
      } else {
        this.assignGoodsFlag = false
      }
    })
  },
  methods: {
    //判断是否显示同步订单
    checkOrderByActType() {
      // checkOrderByActType(sessionStorage.getItem('activityType'),(initdatas)=>{
      //   console.log(initdatas,'initdatasinitdatas');
      //   if(initdatas.data === true){
      //    this.isShowCheckOrder = true;
      //    this.timer = new Date().getTime();
      //   }
      // })
    },
    //点击可修改位置的方法
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleDataNew,
          styleDataOld: this.styleDataOld,
          c_this: this
        };
        this.$emit('opertaionCom', type, byValue);
      }
    },
    initData() {
      var datas = this.templateData;
      if (this.isTemplate == true) {
        this.templateData = datas;
      }
      this.isShow = this.datas.isShowPrize;
      this.timer = new Date().getTime();
      // this.publicData.$emit("isNotyFiceWinnerReorrd",true,this.isTemplate)
    },

    goShop() {
      if (this.isTemplate == true) {
        this.$toast('活动预览，仅供查看');
        return;
      }
      let shopId = store.state.shopId;
      storeGoodsPoint(4)
      goToShopPage(shopId);
    },

    //type 1 签到规则 2 我的奖品 3、积分抽奖记录
    operClick(type) {
      console.log(123333, type);
      if (this.isWebClick) {
        return;
      }
      if (this.isTemplate) {
        this.$toast('活动预览，仅供查看');
        return;
      }
      switch (type) {
        case 1:
          // this.$emit('operClick', 1);
          this.doFrontBuryPoint({ code: 'banner-hdge', value: '', event: 'pop' })
          console.log('签到规则1', this.acRulePopComData);
          console.log('签到规则2', this.templateData);
          AcRulePopComService.create(this.acRulePopComData, this.isTemplate, this.templateData, this.styleDataNew, prizeRecordDetilClick => {
            AcRulePopComService.close();
          });
          break;
        case 2:
          let actStatus = sessionStorage.getItem('actStatus');
          let activityType = sessionStorage.getItem('activityType');

          if (actStatus == 1) {
            // Toast('活动尚未开始');
            Toast({
              message: '活动尚未开始',
              onClose: () => {
                Toast.clear();
              }
            });
            return;
          }
          // this.$emit('operClick', 2);
          this.doFrontBuryPoint({ code: 'banner-wdjp', value: '', event: 'pop' })
          this.myPrizePopComData.datas.isEditAddress = this.isEditAddress;
          this.myPrizePopComData.datas.isAlLookAddress = this.isAlLookAddress;
          console.log('我的奖品', this.myPrizePopComData);
          if (activityType == 10030) {
            MyOrderPrizePopComService.create(this.myPrizePopComData, this.isTemplate, this.styleData, prizeRecordDetilClick => {
              MyOrderPrizePopComService.close();
            });
          } else {
            MyPrizePopComService.create(this.myPrizePopComData, this.isTemplate, this.styleDataNew, prizeRecordDetilClick => {
              MyPrizePopComService.close();
            });
          }
          break;
        case 3:
          let actStatus1 = sessionStorage.getItem('actStatus');
          if (actStatus1 == 1) {
            this.$toast('活动尚未开始');
            return;
          }
          LuckDrawRecordPopComService.create(this.myPrizePopComData, this.isTemplate, prizeRecordDetilClick => {
            LuckDrawRecordPopComService.close();
          });
          break;
        case 4:
          // ShareFriendPopComService
          ShareFriendPopComService.create(prizeRecordDetilClick => {
            ShareFriendPopComService.close();
          });
          break;
        case 5:
          let actStatus2 = sessionStorage.getItem('actStatus');
          if (actStatus2 == 1) {
            this.$toast('活动尚未开始');
            return;
          }
          HdzxtMyFriendPopComServiceNew2.create(this.styleDataNew, this.datas, submit => {
            HdzxtMyFriendPopComServiceNew2.close();
          });
          break;
        case 10:
          drawRecordPopNewService.create(this.isTemplate, this.styleData, submit => {
            drawRecordPopNewService.close();
          });
          break;
        case 30:
          if (sessionStorage.getItem("actStatus") == 1) {
            this.$toast("活动尚未开始");
            return;
          }
          
          orderActivityGoodsService.create(1, this.styleData, submit => {
            orderActivityGoodsService.close();
          });
          break;
      }
    }
  }
};
</script>

<style lang="scss"></style>
