<template>
    <div :style="styleData[keyData.acStartTimeC]"   ref="activityStartTime"
    @click="styleClick('click', 'activityStartTime')"
    @mousemove="styleClick('mousemove', 'activityStartTime')"
    @mouseout="styleClick('mouseout')"> 
        <div :style="styleData[keyData.bannerContainer]">
            <div :style="styleData[keyData.bannerContainerShowTime]">{{priceDate1}}</div>
            <div :style="styleData[keyData.bannerContainerActivityTime]">活动时间：{{activityStart}}-{{activityEnd}}</div>
        </div>
        <div :style="styleData[keyData.countDownShopContainer]">
            <div :style="styleData[keyData.joinPeople]">
                <div>{{userCount}}</div>
                <div>人参与</div>
            </div>
            <div :style="styleData[keyData.shopInfoGoToShop]">
                <div :style="styleData[keyData.shopInfoGoToShopDiv]">
                    <img :src="shopLogoUrl" alt="" style="width:1.1rem;">
                    <div :style="styleData[keyData.shopInfoGoToShopName]">{{shopName}}</div>
                </div>
                <div :style="styleData[keyData.goShopBtn]" @click="goShop"  v-lz-click="'4'">进店逛逛</div>
            </div>
        </div>
    </div>
</template>

<script>
import { goToShopPage } from "../../../util/tools.js";
import {ShoppingCartfriendPopComService ,addSkuHelpFriendComService } from '../../../util/comCreate.js';
import apis1 from '../../../util/apis1.js';
import store from "../../../store/store";
import dateUtil from "../../../util/dateUtil";
export default {
    components: {
        store,
    },
    props:['datas','keyData','styleData','isTemplate', "templateData","isWebClick",
    "modifyContent"],
    data() {
        return {
            shoppingCard:[],
            shareFlag: false,
            shopLogoUrl:'',
            shopName:'',
            userCount:0,
            priceDate1:'',
            activityStart:'',
            activityEnd:'',
            shareUserId:'',//用户id取得
            shareNum: 0,
            shareNumName:'',
            shopId:'',
            followStoreFlag: true,
            addSkuStartTime: "",
            addSkuEndTime: "",
             styleDataOld: {},
        };
    },
    mounted() {},
    created() {
        this.initData();
         //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    },
    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);
      }
    },
    initData() {
            var datasAll = this.templateData;
        if (this.isTemplate == true) {
        this.$toast("活动预览，仅供查看");
        if (datasAll) {
            this.priceDate1 = dateUtil.formatTime(datasAll.addSku.priceTime, 'MM.dd');
            this.activityStart = dateUtil.formatTime(datasAll.activity.startTime, 'MM.dd');
            this.activityEnd = dateUtil.formatTime(datasAll.activity.endTime, 'MM.dd');
            this.userCount = 1;
            this.shopName = datasAll.activity.shopName,
            this.shopLogoUrl = "http://img30.360buyimg.com/popshop/jfs/t12040/167/1277706166/88856/87939c85/5a1e9842N3d659b8f.jpg"
        } else {
            this.priceDate1 = "02.02";
            this.activityStart = "02.02";
            this.activityEnd = "02.20";
            this.userCount = 1;
            this.shopName = "XXX京东自营官方旗舰店";
            this.shopLogoUrl = "http://img30.360buyimg.com/popshop/jfs/t12040/167/1277706166/88856/87939c85/5a1e9842N3d659b8f.jpg"
        }
        }else {
        this.shareUserId = store.state.shareUserId;
        this.getShoppingCard()
        }
    },
    getShoppingCard() {
        this.shareUserId = store.state.shareUserId;
        let shoppingCard = apis1[this.datas.shoppingCard];
        var shareUserId = this.shareUserId;
        shoppingCard(shareUserId,data => {
            var that = this;
            that.shoppingCard = data.data;
            that.shareFlag = data.data.shareFlag;
            that.shopLogoUrl = data.data.shopLogoUrl;
            that.shopName = data.data.shopName;
            that.userCount = data.data.userCount;
            that.priceDate1 = data.data.priceDate1;
            that.activityStart = data.data.activityStart;
            that.activityEnd = data.data.activityEnd;
            that.shareNum = data.data.shareNum;
            that.shopId= data.data.shopId;
            that.followStoreFlag = data.data.followStoreFlag;
            that.addSkuStartTime = data.data.addSkuStartTime;
            that.addSkuEndTime = data.data.addSkuEndTime;

            if(that.shareNum == 1 || that.shareNum == 2 || that.shareNum == 3||that.shareNum == 4 || that.followStoreFlag == 1){
                ShoppingCartfriendPopComService.create(
                    that.shareFlag,
                    that.shareNumName,
                    that.followStoreFlag,
                    that.shareNum,
                    that.shopName,
                    that.shopId,
                    (submit) => {
                        this.shareNumName = submit;
                    ShoppingCartfriendPopComService.close();
                    }
                );
            }
        });
    },

    goShop() {
      goToShopPage(this.shopId);
    },

    addSkuHelpFriend(){
        if (this.isTemplate == true) {
            this.$toast("活动预览，仅供查看");
            return;
        }
        if(new Date().getTime()<new Date(this.addSkuStartTime).getTime() || new Date().getTime()>new Date(this.addSkuEndTime).getTime()){
            this.$toast('活动未开始');
            return;
        }
        addSkuHelpFriendComService.create(
            (submit) => {
            addSkuHelpFriendComService.close();
            }
        );
    }
  }
};
</script>

