<template>
  <div class="back" :style="styleData.backStyle" v-if="skuFlag">
    <div class="imgTitle" :style="styleData.imgTitleStyle">{{ title }}</div>
    <div class="goodClass" :style="styleData.goodClassStyle">
      <div class="goodList" :style="styleData.goodListStyle">
        <div class="goodsItem" v-for="(item, index) in exposureList" :key="index" :style="styleData.goodsItemStyle">
          <div class="goodImg" @click="goToBuy(item.skuId)" v-lz-click="'5'" :style="styleData.goodImgStyle">
            <img class="Img1" :src="item.skuImg" :style="styleData.Img1Style"/>
          </div>
          <div class="goodBottom" :style="styleData.goodBottomStyle">
            <p class="goodName" :style="styleData.goodNameStyle">{{item.skuName}}</p>
            <p class="goodPrice" :style="styleData.goodPriceStyle" v-if="item.skuPrice > 0">￥{{item.skuPrice}}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {goToSkuPage } from '../../../util/tools.js';
import apis1 from '../../../util/apis1.js';
import store from "../../../store/store";
let { taskBargaining,taskYuanTrial} = apis1;

export default {
  props:["isTemplate", "datas", "keyData", "styleData", "templateData"],
  data() {
    return {
      exposureList:[],
      exposureInfoList:[],
      shareFlag:false,
      shareUserId:'',
      title:'',
      skuFlag:false,
      helpStatus:4,
    };
  },
  created() {
    this.publicData.$on('bargainTeamJoin', res => {
      this.skuFlag = false;
    });
    this.initData();
  },
  methods: {
    initData() {
      var datasAll = this.templateData;

      if (this.isTemplate == true) {
        this.$toast("活动预览，仅供查看");
        if (datasAll) {
          this.exposureList = datasAll.exposedData.exposedGoods;
          this.exposureInfoList.skuFlag = true;
          for (var i = 0; i < this.exposureList.length; i++){
            this.exposureList[i].skuImg = datasAll.exposedData.exposedGoods[i].imagePath;
            this.exposureList[i].skuName = datasAll.exposedData.exposedGoods[i].name;
            this.exposureList[i].skuPrice = datasAll.exposedData.exposedGoods[i].price;
            this.exposureList[i].skuId = datasAll.exposedData.exposedGoods[i].skuId;
          }
        }
      }else{
        this.shareFlag = this.datas.shareFlag;
        this.shareUserId = store.state.shareUserId;
        this.title = this.datas.title;

        if (this.shareFlag == true) {
          let goodsList = apis1[this.datas.goodsList];
          goodsList(this.shareUserId, data => {
            this.exposureList = data.data.skuInfoList;
            this.helpStatus = data.data.helpStatus;
            if (this.helpStatus == 0 || this.helpStatus == 1 || this.helpStatus == 3) {
              if (this.exposureList.length > 0){
                this.skuFlag = true;
              }
            }
          });
        } else {
          let goodsList = apis1[this.datas.goodsList];
          goodsList(data => {
            this.exposureList = data.data.skuInfoList;
            this.helpStatus = data.data.helpStatus;
            if (this.helpStatus == 0 || this.helpStatus == 1 || this.helpStatus == 3) {
              if (this.exposureList.length > 0){
                this.skuFlag = true;
              }
            }
          });
        }
      }
    },
    goToBuy(sku) {
      if (this.isTemplate == true) {
        this.$toast("活动预览，仅供查看");
        return;
      }
      goToSkuPage(sku);
    }
  }
};
</script>

<style lang="scss" scoped="scoped">

</style>
