<template style="background-color: red">
  <div
    style="
      background-image: url(https://file.rongcyl.cn/festatic/bkm/bg_i.png);
      background-repeat: no-repeat;
      background-position: center center;
      background-size: contain;
      background-color: #000;
    "
  >
    <img src="https://file.rongcyl.cn/festatic/bkm/banner.png" class="w-full" style="height: 400rpx" />
    <div
      style="
        background: rgba(0, 0, 0, 0.85);
        background-image: url(https://file.rongcyl.cn/festatic/bkm/box.png);
        background-size: cover;
      "
    >
      <div class="flex justify-between">
        <img src="https://file.rongcyl.cn/festatic/bkm/activity.png" class="area" @click="activity" />
        <img
          src="https://file.rongcyl.cn/festatic/bkm/task.png"
          class="area"
          @click="$navigateTo('/pages/task/index')"
        />
        <img
          src="https://file.rongcyl.cn/festatic/bkm/invite.png"
          class="area"
          @click="$navigateTo('/pages/invite/invite')"
        />
      </div>

      <div class="flex justify-between m-2 co">
        <img src="https://file.rongcyl.cn/festatic/bkm/center.png" class="center" />
        <div class="clicks flex-1 overflow-scroll flex flex-nowrap">
          <div class="ml-2 mt-2 inline-block relative" v-for="c in couponList" :key="c.id" @click="receive(c)">
            <img src="https://file.rongcyl.cn/festatic/bkm/clicked.png" v-if="c.status == 1" />
            <img src="https://file.rongcyl.cn/festatic/bkm/click.png" v-if="c.status == 0" />
            <div class="absolute top-4 left-0 text-center right-0">
              <div class="bold fs12">{{ c.name }}</div>
              <div class="fs11 text-zinc-600">{{ c.desc }}</div>
            </div>
          </div>
        </div>
        <!-- <img src="https://file.rongcyl.cn/festatic/bkm/more.png" class="more" /> -->
      </div>

      <div class="flex justify-between m-2">
        <img src="https://file.rongcyl.cn/festatic/bkm/c1.png" class="c" />
        <img src="https://file.rongcyl.cn/festatic/bkm/c2.png" @click="$navigateTo('/pages/vip/vip')" class="c" />
        <img src="https://file.rongcyl.cn/festatic/bkm/c3.png" class="c" />
        <img src="https://file.rongcyl.cn/festatic/bkm/c4.png" class="c" />
      </div>

      <div class="tabs">
        <div class="tab" :class="{ active: type == 0 }" @click="type = 0">热门</div>
        <div class="tab" :class="{ active: type == 5 }" @click="type = 5">FIRST赏</div>
        <div class="tab" :class="{ active: type == 2 }" @click="type = 2">LAST赏</div>

        <div class="tab" :class="{ active: type == 3 }" @click="type = 3">全套赏</div>
        <div class="tab" :class="{ active: type == 1 }" @click="type = 1">无限赏</div>
        <!-- <div class="tab" :class="{ active: type == 4 }" @click="type = 4">抽盒机</div> -->
      </div>

      <div class="cards">
        <div class="card relative" v-for="(item, i) in list" @click="$navigateTo('/pages/first2/index')" :key="i">
          <img
            :src="`https://file.rongcyl.cn/festatic/bkm/tags/${item.type}.png`"
            class="absolute top-0 left-0"
            style="width: 62px; height: 24px"
          />
          <img
            :src="`https://file.rongcyl.cn/festatic/bkm/tags/tag1.png`"
            class="absolute top-0 right-0"
            style="width: 88rpx; height: 88rpx"
            v-if="item.subType && item.subType.includes('110')"
          />
          <img
            :src="`https://file.rongcyl.cn/festatic/bkm/tags/tag2.png`"
            class="absolute top-0 right-0"
            style="width: 88rpx; height: 88rpx"
            v-if="item.subType && item.subType.includes('120')"
          />
          <img
            :src="`https://file.rongcyl.cn/festatic/bkm/tags/tag3.png`"
            class="absolute top-0 right-0"
            style="width: 88rpx; height: 88rpx"
            v-if="item.subType && item.subType.includes('112')"
          />
          <img :src="item.icon" />
          <div class="mt-1">{{ item.name }}</div>
          <!-- <div class="flex justify-between" style="font-size: 13px; margin-top: 12rpx">
            
            <img src="https://file.rongcyl.cn/festatic/bkm/imgv2/raffle/tag2.png" style="height: 35rpx; width: 80rpx" />
            <div>
              <span style="font-size: 14px; margin-right: 4px; color: #fc5b20" class="bold">{{ item.totalNum }}</span>
              <span style="color: #666666">销量</span>
            </div>
          </div> -->
          <div class="flex justify-between">
            <div style="color: #fc5b20; margin-top: 12rpx">
              <span class="fs14">￥</span>
              <span class="bold fs16">{{ item.price }}</span>
            </div>
            <!-- <div v-if="item.subType">
              <div class="tag" v-if="item.subType.includes('110')">欧王</div>
              <div class="tag" v-if="item.subType.includes('120')">连击</div>
              <div class="tag" v-if="item.subType.includes('112')">免单</div>
            </div> -->
            <div
              style="margin-top: 12rpx; color: #a79e9e; font-size: 12px"
              v-if="!item.subType && (item.type == 5 || item.type == 2)"
            >
              剩余 {{ item.balaceNum }}/ {{ item.totalNum }}
            </div>
          </div>
        </div>
      </div>
      <div class="p" @click="$navigateTo('/pages/integralRecord/integralRecord')">
        <img src="https://file.rongcyl.cn/festatic/bkm/p.png" />
        <div class="absolute text-white bottom-2 fs11 text-center left-0 right-0">{{ userInfo.integral }}</div>
      </div>
    </div>
    <!-- <div
      class="fixed left-0 right-0 bottom-0 pb-1 bg-black flex justify-around items-center fs13"
      style="color: #b4c9da; height: 80px"
    >
      <div class="text-center">
        <img src="https://file.rongcyl.cn/festatic/bkm/index2tabs/home_a.png" class="w-7 h-7" />
        <div style="color: #fc5b20">首页</div>
      </div>
      <div class="text-center">
        <img src="https://file.rongcyl.cn/festatic/bkm/index2tabs/shop.png" class="w-7 h-7" />
        <div>商城</div>
      </div>
      <div class="text-center">
        <img src="https://file.rongcyl.cn/festatic/bkm/index2tabs/cc.png" class="w-8 h-8" />
        <div>抽卡机</div>
      </div>
      <div class="text-center">
        <img src="https://file.rongcyl.cn/festatic/bkm/index2tabs/bag.png" class="w-7 h-7" />
        <div>背包</div>
      </div>
      <div class="text-center">
        <img src="https://file.rongcyl.cn/festatic/bkm/index2tabs/mine.png" class="w-7 h-7" />
        <div>我的</div>
      </div>
    </div> -->
  </div>
</template>

<script>
import { raffleListApi } from '@/api/drawCard'
import { couponCenter, couponReceive } from '@/api/coupon'
import { userInfoApi } from '@/api/user.js'
export default {
  data() {
    return {
      list: [],
      type: 0,
      couponList: [],
      userInfo: {},
    }
  },
  created() {
    this.getList()
    this.getCouponList()
    if (wx.getStorageSync('token')) {
      userInfoApi().then(res => {
        this.userInfo = res.data
      })
    }
  },
  watch: {
    type() {
      this.getList()
    },
  },

  methods: {
    activity() {
      wx.showToast({
        title: '敬请期待',
        icon: 'none',
      })
    },
    receive(item) {
      if (item.status == 1) return
      couponReceive({ couponId: item.id }).then(res => {
        wx.showToast({
          title: '领取成功',
          icon: 'none',
        })
        this.getCouponList()
      })
    },
    getCouponList() {
      couponCenter().then(res => {
        this.couponList = res.data
      })
    },
    getList() {
      let params = {
        limit: 999,
        page: 1,
        type: this.type || '',
        isHot: this.type == 0,
      }
      raffleListApi(params).then(res => {
        let list = res.data.list
        for (var i = 0; i < list.length; i++) {
          if (list[i].subType) {
            list[i].subType = list[i].subType.split(',')
          }
        }
        this.list = list
      })
    },
  },
}
</script>

<style scoped lang="scss">
.area {
  width: 168px;
  height: 88px;
}

.c {
  width: 82px;
  height: 47px;
}

.center {
  width: 38px;
  height: 98px;
}

.clicks {
  height: 98px;
  background-image: linear-gradient(to bottom, #ffaea6, #ff654c);

  img {
    height: 82px;
    width: 82px;
  }
}
.tag {
  border-radius: 3px;
  margin-top: 12rpx;
  height: 20px;
  line-height: 20px;
  text-align: center;
  background: #fc5b20;
  color: #fff;
  padding: 0 8rpx;
  font-size: 13px;
  display: inline-block;
  margin-left: 10px;
}
.more {
  width: 28px;
  height: 98px;
}

.p {
  position: fixed;
  bottom: 120px;
  right: 20px;

  img {
    width: 50px;
    height: 50px;
  }
}

.tabs {
  display: flex;
  justify-content: space-around;

  .tab {
    font-size: 16px;
    font-weight: 400;
    color: #fff;
    padding: 10px 0;

    &.active {
      font-weight: 600;
      border-bottom: 2px solid #fc5b20;
      color: #fc5b20;
    }
  }
}

.cards {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  padding: 0 20rpx;
  flex-wrap: wrap;

  .card {
    box-sizing: border-box;
    width: 344rpx;
    // height: 500rpx;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 20rpx;
    padding: 20rpx;
    padding-bottom: 12rpx;

    img {
      width: 308rpx;
      height: 308rpx;
      border-radius: 8px;
    }
  }
}
</style>
