<template>
  <div ref="collectionTank" class="collectionTank">
    <div class="prizeBox">
      <div v-if="taskCollectionTankResultVo.tankPrizeVoList.length == 1">
        <div v-for="item in taskCollectionTankResultVo.tankPrizeVoList" class="drawDownBox">
          <div class="collectMsg">集满{{item.tankNum}}罐，即可领奖</div>
          <div class="content">
            <!-- 奖品区域 -->
            <div class="skuArea">
              <div class="left">
                <img class="skuImg" :src="item.showImg" alt="">
              </div>
              <div class="right">
                <div class="prizeName">{{item.prizeName}}</div>
                <div class="prizeHasNum">奖品剩余：{{item.prizeHasNum}}</div>
                <div class="userTankNum">您已收集
                  <span style="color:red">{{taskCollectionTankResultVo.userTankNum}}</span>
                  罐
                </div>
              </div>
            </div>
            <!-- 进度条 -->
            <div class="progress">
              <van-progress :percentage='(taskCollectionTankResultVo.userTankNum/item.tankNum)*100 >= 100 ? 100 : (taskCollectionTankResultVo.userTankNum/item.tankNum)*100' pivot-color="#7232dd" stroke-width="13" color="#fbdc4a" track-color="#063bb5" :show-pivot=false />
            </div>
            <!-- 按钮 -->
            <div v-if="item.status == 0" class="btn btn1"></div>
            <div v-if="item.status == 1" class="btn btn2" @click="drawDownFun(item)"></div>
            <div v-if="item.status == 2" class="btn btn3"></div>
            <div v-if="item.status == 3" class="btn btn4"></div>
            <div v-if="item.status == 5" class="btn btn4"></div>
            <div v-if="item.status == 4" class="btn btn4"></div>
          </div>
        </div>
      </div>
      <div class="swipe_box" v-if="taskCollectionTankResultVo.tankPrizeVoList.length > 1 && taskCollectionTankResultVo.tankPrizeVoList">
        <swiper class="swiperAll" ref="mySwiper" :options="swiperOption">
          <swiper-slide v-for="(item,index) in taskCollectionTankResultVo.tankPrizeVoList" :key="index" class="swiperItem">
            <div class="collectMsg">集满{{item.tankNum}}罐，即可领奖</div>
            <div class="content">
              <div class="skuArea">
                <div class="left">
                  <img class="skuImg" :src="item.showImg" alt="">
                </div>
                <div class="right">
                  <div class="prizeName">{{item.prizeName}}</div>
                  <div class="prizeHasNum">奖品剩余：{{item.prizeHasNum}}</div>
                  <div class="userTankNum">您已收集
                    <span style="color:red">{{taskCollectionTankResultVo.userTankNum}}</span>
                    罐
                  </div>
                </div>
              </div>
              <div class="progress">
                <van-progress :percentage='(taskCollectionTankResultVo.userTankNum/item.tankNum)*100 >= 100 ? 100 : (taskCollectionTankResultVo.userTankNum/item.tankNum)*100' pivot-color="#7232dd" stroke-width="13" color="#fbdc4a" track-color="#063bb5" :show-pivot=false />
              </div>
              <div v-if="item.status == 0" class="btn btn1"></div>
              <div v-if="item.status == 1" class="btn btn2" @click="drawDownFun(item)"></div>
              <div v-if="item.status == 2" class="btn btn3"></div>
              <div v-if="item.status == 3" class="btn btn4"></div>
              <div v-if="item.status == 5" class="btn btn4"></div>
              <div v-if="item.status == 4" class="btn btn4"></div>
            </div>
          </swiper-slide>
        </swiper>
      </div>
    </div>
    <div class="goodBox">
      <div class="goodUl">
        <div class="goodLi" v-for="item in taskCollectionTankResultVo.skuInfoList" @click="goToSku(item)" v-lz-click="'5'" v-lz-skuid="item.skuId">
          <div class="imgBox">
            <img :src="item.skuImg" alt="">
          </div>
          <div class="skuName">{{item.skuName}}</div>
          <div class="skuPrice">活动价格：<span>¥{{item.skuPrice}}</span></div>
          <div class="btn"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import Vue from 'vue';
  import { Progress } from 'vant';
  Vue.use(Progress);
  import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
  import 'swiper/swiper.scss'
  import apis1 from '../../../util/apis1.js';
  import { newToSkuPage } from '../../../util/tools.js';
  let { collectionTankActivity, immediatelyDraw, storeGoodsPoint } = apis1;
  import { PrizeResultPopComService, NoPrizeResultPopComService } from '../../../util/hdzxtcomCreate.js';
  export default {
    props: ['datas', 'styleData', 'keyData', 'isTemplate', 'templateData', 'modifyContent', 'isWebClick'],
    components: {
      Swiper,
      SwiperSlide
    },
    data() {
      return {
        taskCollectionTankResultVo: {
          tankPrizeVoList: []
        },
        isPlayType: false,
        swiperOption: {
          slidesPerView: 1.1,
          spaceBetween: 5,
          loop: false,
        }
      };
    },
    computed: {
      swiper() {
        return this.$refs.mySwiper.swiper
      }
    },
    created() {
      this.initData();
    },
    methods: {
      async initData() {
        if (this.isTemplate) {
          if (this.templateData) {
            console.log(this.templateData.collectionTank, 'this.templateData')
            this.taskCollectionTankResultVo.tankPrizeVoList = this.templateData.collectionTank.collectionTankRuleVos[0].prizeList
            this.taskCollectionTankResultVo.tankPrizeVoList.map(item => {
              item.tankNum = item.num
              item.prizeHasNum = item.totalPrizeNum
              item.status = '0'
            })
            this.taskCollectionTankResultVo.userTankNum = 0
            this.taskCollectionTankResultVo.skuInfoList = this.templateData.collectionTank.collectionTankRuleVos[0].exposedGoods
            this.taskCollectionTankResultVo.skuInfoList.map(item => {
              item.skuImg = item.imagePath
              item.skuName = item.name
              item.skuPrice = item.price
            })
          } else {
            this.taskCollectionTankResultVo.tankPrizeVoList = [{
              tankNum: '1',
              prizeHasNum: '1',
              status: '0',
              prizeName:'1积分',
              showImg : "http://img10.360buyimg.com/n0/jfs/t1/173911/37/45363/251881/6656a0a7Faddc445d/079155b23acfb531.jpg"
            }]
            this.taskCollectionTankResultVo.userTankNum = 0
            this.taskCollectionTankResultVo.skuInfoList = [
              {
                skuImg: "http://img10.360buyimg.com/n0/jfs/t1/173911/37/45363/251881/6656a0a7Faddc445d/079155b23acfb531.jpg",
                skuName: "广博(GuangBo)X三丽鸥手提箱手帐套装小学生手帐文具大礼包学习用品咕卡送礼礼盒套装 手帐手提箱套装-玉桂狗",
                skuPrice: "189.00",
              }
            ]
          }
        } else {
          collectionTankActivity(res => {
            this.taskCollectionTankResultVo = res.data.taskCollectionTankResultVoList[0]
          });
        }
      },
      goToSku(item) {
        if (this.isTemplate) {
          this.$toast("活动预览，仅供查看");
          return;
        }
        let actStatus = sessionStorage.getItem("actStatus");
        if (actStatus == 2) {
          this.$toast("活动已结束");
          return;
        }
        if (actStatus == 1) {
          this.$toast("活动未开始");
          return;
        }
        storeGoodsPoint(5)
        newToSkuPage(item);
      },
      drawDownFun(item) {
        if (this.isTemplate) {
          this.$toast('活动预览，仅供参考');
          return;
        }
        let actStatus4 = sessionStorage.getItem('actStatus');
        if (actStatus4 == 1) {
          this.$toast('活动尚未开始');
          return;
        }
        if (actStatus4 == 2) {
          this.$toast("活动已结束");
          return;
        }
        if (this.isPlayType) {
          return;
        }
        this.isPlayType = true;
        if (item.status == 1) {
          immediatelyDraw(item.prizeInfoId, receiveData => {
            if (receiveData.resp_code == 0) {
              this.isPlayType = false;
              if (receiveData.data.result == true) {
                this.initData();
                this.publicData.$emit('isNotyFiceWinnerReorrd', true, this.isTemplate);
                var obj = {
                  datas: {},
                  keyData: {
                    prizeUrl: 'showImg',
                    prizeName: 'prizeName',
                    prizeType: 'prizeType',
                    priceInfo: 'priceInfo',
                    discountType: 'discountType',
                    couponType: 'couponType'
                  }
                };
                obj.datas = receiveData.data;
                PrizeResultPopComService.create(obj, receiveData.data, this.styleData, submit => {
                  PrizeResultPopComService.close();
                });
              } else {
                NoPrizeResultPopComService.create(this.styleData, submit => {
                  NoPrizeResultPopComService.close();
                });
                this.initData();
              }
            } else if (receiveData.resp_code == 60010) {
              this.isPlayType = false;
              this.$toast('抱歉，奖品已发完~');
              setTimeout(() => {
                this.initData();
              }, 1000);
            }
          });
        }
      }
    }
  };
</script>

<style lang="scss" scoped>
  .collectionTank {
    .prizeBox {
      margin-top: 0.3rem;
      .swipe_box {
        width: 100%;
        height: 5.02rem;
        .swiperAll {
          width: 7rem;
          height: 5.02rem;
          display: flex;
          align-items: center;
          justify-content: center;
          margin: auto;
          .swiperItem {
            width: 100%;
            height: 5.02rem;
            background-size: 100%;
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/107440/15/48482/16354/66e110d2Fb5f59024/34d4b16e46b2cdc3.png);
            background-repeat: no-repeat;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            .collectMsg {
              position: absolute;
              font-size: 0.24rem;
              color: #fff;
              width: 3.2rem;
              height: 0.32rem;
              border-radius: 0.16rem;
              background: #fc8343;
              display: flex;
              align-items: center;
              justify-content: center;
              right: 0.3rem;
              top: 0.22rem;
            }
            .content {
              background: #e0f7ff;
              width: 6rem;
              height: 3.5rem;
              border-radius: 0.3rem;
              position: absolute;
              top: 0.9rem;
              .skuArea {
                width: 100%;
                height: 1.7rem;
                margin-top: 0.25rem;
                padding: 0 0.25rem;
                display: flex;
                justify-content: space-between;
                .left {
                  width: 1.7rem;
                  height: 1.7rem;
                  background: #fff;
                  border-radius: 0.2rem;
                  overflow: hidden;
                }
                .right {
                  width: calc(100% - 2rem);
                  text-align: left;
                  .prizeName {
                    font-size: 0.26rem;
                    font-weight: bold;
                    width: 100%;
                    line-height: 0.56rem;
                  }
                  .prizeHasNum {
                    font-size: 0.2rem;
                    width: 100%;
                    margin-top: 0.2rem;
                  }
                  .userTankNum {
                    font-size: 0.26rem;
                    font-weight: bold;
                    width: 100%;
                    margin-top: 0.2rem;
                  }
                }
              }
              .progress {
                width: 5.4rem;
                border: 1px solid #2961ea;
                border-radius: 5px;
                margin: 0.2rem auto 0;
              }
              .btn {
                width: 3.54rem;
                height: 0.85rem;
                background-size: 100%;
                margin: 0.1rem auto 0;
              }
              .btn1 {
                background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/56317/20/26225/20026/66e131adFc6c72300/9a1608ad6a00abe6.png);
              }
              .btn2 {
                background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/1777/23/25013/10792/66e130b1F3a017042/579f4ff39153e571.png);
              }
              .btn3 {
                background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/6618/28/31035/18691/66e134d7Fc6ac9d06/e51a62fbf9af2be4.png);
              }
              .btn4 {
                background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/248794/10/18596/19213/66e13525F2e8d6703/ede654c1e2e32952.png);
              }
              .btn5 {
                background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/187794/28/47232/20318/66ea8ae5F3c142f0e/e1d1fb8e89ba0e1b.png);
              }
            }
          }
        }
      }

      .drawDownBox {
        width: 6.91rem;
        height: 5.02rem;
        background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/107440/15/48482/16354/66e110d2Fb5f59024/34d4b16e46b2cdc3.png);
        background-size: 100%;
        margin-left: calc(50% - 6.91rem / 2);
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        .collectMsg {
          position: absolute;
          font-size: 0.24rem;
          color: #fff;
          width: 3.6rem;
          height: 0.38rem;
          border-radius: 0.19rem;
          background: #fc8343;
          display: flex;
          align-items: center;
          justify-content: center;
          right: 0.3rem;
          top: 0.22rem;
        }
        .content {
          background: #e0f7ff;
          width: 6.65rem;
          height: 3.95rem;
          border-radius: 0.3rem;
          position: absolute;
          bottom: 0.15rem;
          .skuArea {
            width: 100%;
            height: 1.9rem;
            margin-top: 0.25rem;
            padding: 0 0.25rem;
            display: flex;
            justify-content: space-between;
            .left {
              width: 1.9rem;
              height: 1.9rem;
              background: #fff;
              border-radius: 0.2rem;
              overflow: hidden;
            }
            .right {
              width: calc(100% - 2.2rem);
              text-align: left;
              .prizeName {
                font-size: 0.26rem;
                font-weight: bold;
                width: 100%;
                line-height: 0.56rem;
              }
              .prizeHasNum {
                font-size: 0.2rem;
                width: 100%;
                margin-top: 0.2rem;
              }
              .userTankNum {
                font-size: 0.26rem;
                font-weight: bold;
                width: 100%;
                margin-top: 0.2rem;
              }
            }
          }
          .progress {
            width: 6.4rem;
            border: 1px solid #2961ea;
            border-radius: 5px;
            margin: 0.3rem auto 0;
          }
          .btn {
            width: 3.54rem;
            height: 0.85rem;
            background-size: 100%;
            margin: 0.15rem auto 0;
          }
          .btn1 {
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/56317/20/26225/20026/66e131adFc6c72300/9a1608ad6a00abe6.png);
          }
          .btn2 {
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/1777/23/25013/10792/66e130b1F3a017042/579f4ff39153e571.png);
          }
          .btn3 {
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/6618/28/31035/18691/66e134d7Fc6ac9d06/e51a62fbf9af2be4.png);
          }
          .btn4 {
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/248794/10/18596/19213/66e13525F2e8d6703/ede654c1e2e32952.png);
          }
          .btn5 {
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/187794/28/47232/20318/66ea8ae5F3c142f0e/e1d1fb8e89ba0e1b.png);
          }
        }
      }
    }
    .goodBox {
      width: 6.91rem;
      height: 11.8rem;
      background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/240388/25/15462/20251/66e4fc3aFbcb2024b/9fed87a4b2e349d8.png);
      background-size: 100%;
      margin: 0.3rem auto 0;
      padding-top: 1rem;
      .goodUl {
        width: 100%;
        height: 10.5rem;
        overflow: scroll;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-content: flex-start;
        padding: 0 0.15rem;
        .goodLi {
          width: 3.25rem;
          height: 5.14rem;
          background: #c6f4ff;
          margin-bottom: 0.2rem;
          border-radius: 0.3rem;
          overflow: hidden;
          padding: 0.13rem;
          .imgBox {
            width: 3rem;
            height: 3rem;
            background: #fff;
            border-radius: 0.2rem;
            display: flex;
            align-items: center;
            justify-content: center;
            img {
              width: 2.4rem;
              height: 2.4rem;
            }
          }
          .skuName {
            width: 100%;
            margin-top: 0.1rem;
            font-size: 0.22rem;
            display: -webkit-box; /* 设置为WebKit内核的弹性盒子模型 */
            -webkit-box-orient: vertical; /* 垂直排列 */
            -webkit-line-clamp: 2; /* 限制显示两行 */
            overflow: hidden; /* 隐藏超出范围的内容 */
            text-overflow: ellipsis; /* 使用省略号 */
          }
          .skuPrice {
            width: 100%;
            margin-top: 0.1rem;
            color: red;
            font-size: 0.18rem;
            text-align: left;
            span {
              font-size: 0.24rem;
            }
          }
          .btn {
            width: 2.76rem;
            height: 0.66rem;
            background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/1455/38/26933/8763/66e105b6Fd6027a15/0d745e64211b9df4.png);
            background-size: 100%;
            margin-left: calc(50% - 2.76rem / 2);
          }
        }
      }
    }
  }
</style>
