<template>
  <van-popup v-model="visible" class="winners-popup" closeable position="left">
    <div class="winners-popup__container">
      <div class="winners-popup__container__head">中奖名单</div>
      <div class="winners-popup__container__content">
        <div class="winners-popup__container__content__list">
          <div v-for="(item, index) in winnersList" :key="index" class="item">
            <span class="item__prize">{{ item.userNick }}获得{{ item.prizeName }}</span>
          </div>
          <div v-if="winnersList.length === 0" class="winners-popup__container__content__list__no-data">暂无数据</div>
        </div>
      </div>
    </div>
  </van-popup>
</template>

<script>
import { getWinnersList } from '@/api/modules/lottery'

export default {
  name: 'WinnersPopup',
  props: {
    value: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      winnersList: []
    }
  },
  computed: {
    visible: {
      get () {
        return this.value
      },
      set (val) {
        this.$emit('input', val)
      }
    }
  },
  watch: {
    visible(nVal) {
      if (nVal) {
        this.dataInit()
      }
    }
  },
  methods: {
    dataInit() {
      getWinnersList({
        id: this.$route.query.id,
        uin: this.$route.query.uin
      }).then(res => {
        const { code, errorCode, errorMessage, data } = res
        if (code === 200 && errorCode === 0) {
          this.winnersList = data
        } else {
          this.$toast(errorMessage)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
@titleHeight: 46px;
.winners-popup {
  height: 100%;
  width: 300px;
  box-shadow: 0 -1px 1px 0px #fff;
  /deep/ .van-popup__close-icon {
    color: #fc5147;
  }
  &__container {
    background-color: #ff8e5e;
    width: 100%;
    height: 100%;
    padding: 6px;
    &__head {
      height: @titleHeight;
      line-height: @titleHeight;
      text-align: center;
      font-size: 16px;
      font-weight: 600;
      color: #fc5147;
      background-color: #fcf7d5;
      border-radius: 6px 6px 0 0;
    }
    &__content {
      height: calc(100% - @titleHeight);
      overflow: auto;
      background-color: #fcf7d5;
      border-radius: 0 0 6px 6px;
      &__list {
        font-size: 14px;
        color: #f76b5f;
        width: 90%;
        margin: 0 auto;
        padding: 10px 0;
        line-height: 18px;
        .item {
          display: flex;
          justify-content: center;
          margin-top: 6px;
          &:first-child {
            margin-top: 0;
          }
        }
        &__no-data {
          color: #aaa;
          text-align: center;
        }
      }
    }
  }
}
</style>
