<template>
  <div class="ruleMaskDiv" v-if="show">
    <basicPop :title="title" @closeClick="closeClick">
      <div class="goodList">
        <div class="goodsItem" v-for="(item, index) in commodityList" :key="index">
          <div class="goodImg" @click="goToBuy(item)" v-lz-click="'5'" v-lz-skuid="item.skuId">
            <img class="Img1" :src="item.skuImg"/>
          </div>
          <div class="goodBottom">
            <p class="goodName">{{item.skuName}}</p>
            <p class="goodPrice" v-if="item.skuPrice > 0">￥{{item.skuPrice}}</p>
            <div class="purchaseBtn" :class="{gray100:item.status == 1}" @click="toPurchase(item)" v-lz-click="'5'" v-lz-skuid="item.skuId">
              <template v-if="item.status == 0">{{ title }}</template>
              <template v-else>{{ title1 }}</template>
            </div>
          </div>
        </div>
      </div>
    </basicPop>
  </div>
</template>

<script>
import apis1 from "../../../util/apis1.js";
import { newToSkuPage } from '../../../util/tools.js';
import basicPop from "./basicPop.vue";
let { pinshousuTaskRequest,storeGoodsPoint } = apis1;
export default {
  props: [],
  components: {
    basicPop,
  },
  data() {
    return {
      title: '',
      title1:'',
      sendNum:0,
      commodityList:[],
      intNum:0,
    };
  },
  created() {
    document
      .querySelector("body")
      .setAttribute(
        "style",
        "position:#fixed;top:0;height:100%;overflow:hidden"
      );

    this.initData();
  },
  methods: {
    initData() {
      if (this.type == '1') {
        this.commodityList = this.data.skuInfoVO;
        this.title = "加购商品";
        this.title1 = "已加购过";
        this.sendNum = this.data.sendNum;
      } else if (this.type == '2'){
        this.commodityList = this.data.skuInfoVO;
        this.title = "浏览商品";
        this.title1 = "已浏览过";
        this.sendNum = this.data.sendNum;
      } else if (this.type == '3'){
        this.commodityList = this.data.skuInfoVO;
        this.title = "关注商品";
        this.title1 = "已关注过";
        this.sendNum = this.data.sendNum;
      }
    },
    toPurchase(item){
      //type 1加购 不需要调接口  2浏览 3领取优惠券 调接口toDo
      if(this.type == 2){
        if (item.status == '0') {
          if (this.data.completeCount < this.data.maxNum) {
            pinshousuTaskRequest(this.data.taskId, item.skuId, data => {
              if (data.data == false){
                this.$toast("活动期间该任务完成次数已达上限！");
                return;
              }
              item.status = 1;
              this.data.completeCount = this.data.completeCount + 1;
              this.intNum = this.data.completeCount / this.data.finishNum;
              if (/(^[1-9]\d*$)/.test(this.intNum)){
                this.publicData.$emit('readSeconds', this.sendNum);
              }
              storeGoodsPoint(5)
              newToSkuPage(item);
            });
          }else {
            this.$toast("今日您已完成浏览商品任务，明天再来哦~");
          }
        } else {
          this.$toast("此商品今天已浏览过，明天再来哦~");
        }
      }
      if (this.type == 1) {
        if (item.status == '0') {
          if (this.data.completeCount < this.data.maxNum) {
            pinshousuTaskRequest(this.data.taskId, item.skuId, data => {
              if (data.data == false){
                this.$toast("活动期间该任务完成次数已达上限！");
                return;
              }
              item.status = 1;
              this.data.completeCount = this.data.completeCount + 1;
              this.intNum = this.data.completeCount / this.data.finishNum;
              if (/(^[1-9]\d*$)/.test(this.intNum)) {
                this.publicData.$emit('readSeconds', this.sendNum);
              }
            });
          }else {
            this.$toast("今日您已完成加购商品任务，明天再来哦~");
          }
        } else {
          this.$toast("此商品今天已加购过，明天再来哦~");
        }
      }
      if (this.type == 3) {
        if (item.status == '0') {
          if (this.data.completeCount < this.data.maxNum) {
            pinshousuTaskRequest(this.data.taskId, item.skuId, data => {
              item.status = 1;
              this.data.completeCount = this.data.completeCount + 1;
              this.intNum = this.data.completeCount / this.data.finishNum;
              if (/(^[1-9]\d*$)/.test(this.intNum)) {
                this.publicData.$emit('readSeconds', this.sendNum);
              }
            });
          }else {
            this.$toast("您已完成关注商品任务");
          }
        } else {
          this.$toast("此商品今天已关注过，明天再来哦~");
        }
      }
    },
    goToBuy(sku) {
      storeGoodsPoint(5)
      newToSkuPage(sku);
    },
    closeClick() {
      document.querySelector("body").removeAttribute("style");
      this.submit(this.data.completeCount);
    },
  },
};
</script>

<style lang="scss" scoped>
.ruleMaskDiv {
  .basicPopDiv {
    height: 9.13rem;
    .context1 {
      margin-top: 0.2rem;
      height: 100%;
      display: flex;
      // align-items: center;
      justify-content: center;
      font-size: 0.24rem;
      color: #333333;
    }
    .context {
      height: 7.5rem;
      overflow-y: scroll;
      padding-right: 0.15rem;
      padding-left: 0.15rem;
    }
  }
}
.goodList{
  overflow-y: scroll;
  width: 6.9rem;
  max-height: 7rem;
  margin: .9rem auto 0 auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0 .25rem;
}
.goodsItem{
  width: 3.15rem;
  height: 4.8rem;
  background-color: white;
  margin-bottom: .1rem;
  overflow-y: scroll;
}
.goodImg{
  width: 100%;
  height: 3.4rem;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.4rem
}
.Img1{
  max-height: 100%;
  max-width: 100%;
}
.goodBottom{
  width: 100%;
  height: 1.2rem;
}
.goodName{
  max-width: 3.4rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: .24rem;
  padding: 0 .38rem;
}
.goodPrice{
  width: 100%;
  padding: 0 .38rem;
  color: #e2231a;
  font-size: .24rem;
}
.purchaseBtn{
  width: 1.2rem;
  height: 0.4rem;
  font-size: 0.22rem;
  color: rgb(255, 255, 255);
  background: rgb(252, 60, 44);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 40px;
  margin-left: 1.8rem;
}
.gray100{
  filter: grayscale(100);
}
</style>
