<template>
  <div v-if="show">

    <basicPopNew :pop='pop' @closeClick="backDrawPage">
      <div class="shopPopNew">
        <template v-if="isNewRule">
          <div class="shopPopNewCanYu">
            <div class="tHead">参与条件：</div>
            <div class="tText">
              <span v-if="activityType == '10107'">
                已成功报名且订单的
                <span v-if="data.orderStatus == 0">付款完成时间</span>
                <span v-else>确认收货（订单完成）时间</span>
                在<span class="color-cus" :style="styleData.span">{{ startTime }}~{{ endTime }}</span>期间内，订单商品为
              </span>
              <span v-else>
                在<span class="color-cus" :style="styleData.span">{{ startTime }}~{{ endTime }}</span> 期间，订单商品为
              </span>
                <span class="color-cus" :style="styleData.span">{{ title }}</span>
                <span>，{{timesText}}</span>且订单状态为<span class="color-cus" :style="styleData.span">{{complete}}{{priceTypeText}}</span>
                <span>，虚拟订单没有物流信息，暂不支持参与活动</span>
              </span>
            </div>
          </div>
          <div class="shopPopNewCont">
            <div class="shopPopNewDan" v-for="(item, index) in data.skuInfoVO" :key="index">
              <div @click="goToBuy(item)" v-lz-click="'5'" v-lz-skuid="item.skuId">
                <img :src="item.skuImg" />
                <div class="title">{{ item.skuName }}</div>
              </div>
              <div class="attention">￥{{ item.skuPrice }}</div>
            </div>
          </div>
        </template>
        <template v-else>
          <div class="shopPopNewCanYu">
            <div class="tHead">参与条件：</div>
            <div class="tText">
              <span>在
                <span class="color-cus" :style="styleData.span">{{ startTime }}~{{ endTime }}</span>
                期间，购买
                <span class="color-cus" :style="styleData.span">{{ title }}</span>，且订单状态为<span class="color-cus"
                  :style="styleData.span">已完成</span>
              </span>
            </div>
          </div>
          <div class="shopPopNewCont">
            <div class="shopPopNewDan" v-for="(item, index) in data.skuInfoVO" :key="index">
              <div @click="goToBuy(item.skuId)" v-lz-click="'5'" v-lz-skuid="item.skuId">
                <img :src="item.skuImg" />
                <div class="title">{{ item.skuName }}</div>
              </div>
              <div class="attention">￥{{ item.skuPrice }}</div>
            </div>
          </div>
        </template>
        <div class="haredContent">
          
          <div class="mySharedContent1" :style="styleData.backcolor" v-if="activityType!='10037' && activityType!='10107'">
            通过购物已获得 <span class="num" :style="styleData.span">{{ data.prieCount }}</span>次{{isGame ? '游戏机会' : '抽奖机会'}}
          </div>
          <div v-else-if="activityType=='10107'" class="mySharedContent1" :style="styleData.backcolor">
           通过购物已获得 <span class="num" :style="styleData.span">{{ data.prieCount }}</span>抽奖机会
          </div>
          <div class="mySharedContent1" :style="styleData.backcolor" v-else>
            通过购物已获得 <span class="num" :style="styleData.span">{{ data.prieCount }}</span>分值
          </div>
          <div class="mySharedContent" :style="styleData.babackground" v-lz-click="'4'" @click="enterstore">
            立即进店购物<i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </div>
    </basicPopNew>
  </div>
</template>
<script>
import apis1 from '../../../util/apis1.js';
import basicPopNew from "./hdzxtbasicPop.vue";
import dateUtil from "../../../util/dateUtil.js";
import { newToSkuPage, goToShopPage } from "../../../util/tools.js";
import store from "../../../store/store";
let { storeGoodsPoint } = apis1;
export default {
  props: ["isTemplate", "datas", "keyData", "templateData"],
  components: {
    basicPopNew,
  },
  data() {
    return {
      startTime: "",
      endTime: "",
      title: "",
      baseClassName: "follow",
      skuDiplay: false,
      activityType: 0,
      taskType: '',
      pop: {
        title: '购物获取抽奖机会',
        titlepop: ''
      },
      isGame: false,
      isNewRule: false,
      complete: '',
      timesText: '',
      priceTypeText:''
    };
  },

  created() {
     this.activityType = sessionStorage.getItem("activityType");
    // console.log(this.data, '1234')
    this.taskType = this.data.taskType
    this.pop.titlepop = this.styleData.titlepop ? this.styleData.titlepop : { "backgroundImage": "url(//img10.360buyimg.com/imgzone/jfs/t1/141588/29/18217/44025/5fd571b9Ef55329ec/42dba91b188b9dce.png)" }
    document
      .querySelector("body")
      .setAttribute(
        "style",
        "position:#fixed;top:0;height:100%;overflow:hidden"
      );
    console.log(this.data, "this.data.startTime");
    console.log(this.data.startTime, "this.data.startTime");
    console.log(this.baseClassName);
    if (this.activityType == "10082" || this.activityType == "10059" || this.activityType == "10092" || this.activityType == "10084" ||
      this.activityType == "10086" || this.activityType == "10089" || this.activityType == "10091" || this.activityType == '10093' ||
      this.activityType == "10094" || this.activityType == "10095" || this.activityType == "10035") {
      this.pop.title = '购物获取游戏机会'
      this.isGame = true
    }
    if (this.activityType == "10037") {
      this.pop.title = '购物获取分值'
    }
    if (this.data.category) {
      this.isNewRule = true
      this.startTime = dateUtil.formatTime(
        this.data.orderStartTime,
        "yyyy-MM-dd hh:mm:ss"
      );
      this.endTime = dateUtil.formatTime(
        this.data.orderEndTime,
        "yyyy-MM-dd hh:mm:ss"
      );
      if (this.data.skuInfoVO && this.data.skuInfoVO.length > 0 && this.data.skuType == '1') {
        this.title = "以下任意商品";
        this.baseClassName = "follow1";
        this.skuDiplay = true;
      } else if (this.data.skuInfoVO && this.data.skuInfoVO.length > 0 && this.data.skuType == '2') {
        this.title = "店铺内商品，且下单商品不包含如下商品";
        this.baseClassName = "follow1";
        this.skuDiplay = false;
      } else {
        this.title = "店铺内任意商品";
        this.baseClassName = "follow1";
        this.skuDiplay = false;
      }
      if (this.data.orderStatus == '0') {
        this.complete = '已付款'
      } else if (this.data.orderStatus == '1') {
        this.complete = '已发货'
      } else if (this.data.orderStatus == '2') {
        this.complete = '交易完成'
      }
      if(this.data.category == "1" || this.data.category == "3" || this.data.category == "5"){
        if (this.data.priceType == '0') {
          this.priceTypeText = '，价格类型【京东价】'
        } else if (this.data.priceType == '1') {
          this.priceTypeText = '，价格类型【实付价】'
        }
      }
      let categoryText = ['单笔金额', '单笔件数', '单日金额', '单日件数', '累计金额', '累计件数']
      let isGameText = this.isGame ? '次游戏机会' : '次抽奖机会'
      if(this.activityType == "10037"){
        isGameText = '分值'
      }
      let unit = ''
      if(this.data.category == '1' || this.data.category == '3' || this.data.category == '5'){
        unit = '元'
      }else{
        unit = '件'
      }
      if (this.data.drawType == '0') {
        this.timesText = categoryText[this.data.category - 1] + '，' + '满' + this.data.sendVoList[0].full + unit + '，' + '赠送' + this.data.sendVoList[0].sendTimes +  isGameText + '，'
      } else if (this.data.drawType == '1') {
        this.timesText = categoryText[this.data.category - 1] + '，' + '满' + this.data.sendVoList[0].full + unit + '，' + '赠送' + this.data.sendVoList[0].sendTimes +  isGameText + '，' + categoryText[this.data.category - 1] +'按倍数增加，则多赠送' + this.data.sendVoList[0].sendTimes + isGameText + '，'
      } else if (this.data.drawType == '2') {
        this.data.sendVoList.forEach(ele => {
          this.timesText = this.timesText + categoryText[this.data.category - 1] + '，' + '满' + ele.full + unit + '，' + '赠送' + ele.sendTimes +  isGameText + '，'
        })
      }
    } else {
      this.isNewRule = false
      this.startTime = dateUtil.formatTime(
        this.data.startTime,
        "yyyy-MM-dd hh:mm:ss"
      );
      this.endTime = dateUtil.formatTime(
        this.data.endTime,
        "yyyy-MM-dd hh:mm:ss"
      );
      console.log(this.data.skuInfoVO + "aaaa");
      if (this.data.skuInfoVO && this.data.skuInfoVO.length > 0) {
        this.title = "以下任意商品";
        this.baseClassName = "follow1";
        this.skuDiplay = true;
      } else {
        this.title = "店铺内任意商品";
        this.baseClassName = "follow";
        this.skuDiplay = false;
      }
     
      if (this.activityType == 10031) {
        if (this.data.skuInfoVO && this.data.skuInfoVO.length > 0) {
          this.title =
            "订单中含有" + this.data.skuInfoVO.length + "款中的任意商品";
          this.baseClassName = "follow1";
          this.skuDiplay = true;
        } else {
          this.title = "全店任意商品";
          this.baseClassName = "follow";
          this.skuDiplay = false;
        }
      }
    }

  },
  methods: {
    backDrawPage() {
      document.querySelector("body").removeAttribute("style");
      this.submit(0);
    },
    goToBuy(sku) {
      console.log(sku);
      storeGoodsPoint(5)
      newToSkuPage(sku);
    },
    enterstore() {
      document.querySelector("body").removeAttribute("style");
      console.log("进入商店");
      let shopId = store.state.shopId;
      storeGoodsPoint(4)
      goToShopPage(shopId);
    },
  },
};
</script>
<style lang="scss" scoped="scoped">
.shopPopNew {
  max-height: 11.61rem;
  overflow-y: auto;
  box-sizing: border-box;
  padding-bottom: 3.7rem;
  margin-top: 0.3rem;
  .shopPopNewCanYu {
    padding: 0 0.3rem 0.3rem;
    .tHead {
      font-size: 0.3rem;
      color: #262626;
      font-weight: bold;
    }
    .tText {
      font-size: 0.24rem;
      color: #262626;
      font-weight: 500;
      margin-top: 0.27rem;
      .color-cus {
        color: #f2270c;
      }
    }
  }
  .shopPopNewCont {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin: 0 0.3rem;
    .shopPopNewDan {
      width: 3.4rem;
      border-radius: 0.2rem;
      background: #fff;
      overflow: hidden;
      margin-bottom: 0.1rem;
      img {
        width: 100%;
        display: flex;
      }
      .title {
        overflow: hidden;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        font-size: 0.3rem;
        color: #333333;
        margin: 0.2rem;
      }
      .attention {
        font-size: 0.24rem;
        color: #f2270c;
        margin-left: 0.2rem;
        margin-bottom: 0.2rem;
      }
      .attention1 {
        width: 1.8rem;
        height: 0.5rem;
        font-size: 0.2rem;
        color: #fff;
        background: linear-gradient(90deg, #8c8c8c 0%, #bfbfbf 100%);
        border-radius: 0.25rem;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0 auto 0.3rem;
      }
    }
  }
  .haredContent {
    width: 100%;
    display: flex;
    position: fixed;
    bottom: 0;
    .mySharedContent {
      width: 50%;
      height: 0.88rem;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      background: linear-gradient(90deg, #f2270c 0%, #ff6420 100%);
      font-size: 0.24rem;
    }
    .mySharedContent1 {
      width: 50%;
      height: 0.88rem;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #262626;
      background: #ffe3e3;
      font-size: 0.24rem;
      .num {
        color: #f2270c;
      }
    }
  }
}
</style>
