<template>
  <div class="home">
    <div class="wrapper">
      <image class="banner" src="https://cdn.cunwuyun.cn/wxmp/tianfuxing/banner.png" />

      <div class="activity-wrapper">
        <h2>线下活动</h2>
        <div class="activity-list">
          <div class="activity-item" @click="$linkTo('./Activity?id=' + item.id)" hover-class="bg-hover" v-for="(item, index) in list" :key="index">
            <div class="top">
              <h2>{{ item.title }}</h2>
              <p>{{ item.detail }}</p>
            </div>
            <div class="bottom">
              <div class="item">
                <h3>进场时间：</h3>
                <div class="right">
                  <p>{{ item.intoBegintime }}  至</p>
                  <p>{{ item.intoEndtime }}</p>
                </div>
              </div>
              <div class="item">
                <h3>离场时间：</h3>
                <div class="right">
                  <p>{{ item.exitBegintime }}  至</p>
                  <p>{{ item.exitEndtime }}</p>
                </div>
              </div>
            </div>
          </div>
          <AiEmpty v-if="!list.length"></AiEmpty>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { mapActions, mapState } from 'vuex'

  export default {
    appName: '活动签到',
    navigationBarTitleText: '活动签到',
    name: 'ActivityList',

    data () {
      return {
        current: 1,
        list: [],
        isMore: false,
        isFixed: false,
        statusBarHeight: 20,
      }
    },

    computed: {
      ...mapState(['user', 'token'])
    },

    onLoad () {
      this.getList()

      if (!this.token) {
        this.autoLogin()
      } else {
        this.getUserInfo()
      }
    },

    methods: {
      ...mapActions(['autoLogin', 'getUserInfo']),

      getList () {
        if (this.isMore) return

        this.$loading()
        this.$instance.post(`/api/appactivityinfo/list`, null, {
          withoutToken: true,
          params: {
            current: this.current,
            size: 10
          }
        }).then(res => {
          if (res.code === 0) {
            this.$hideLoading()
            if (this.current > 1) {
              this.list = [...this.list, ...res.data.records]
            } else {
              this.list = res.data.records
            }

            if (res.data.records.length < 10) {
              this.isMore = true

              return false
            }

            this.current = this.current + 1
          } else {
            this.isMore = true
          }
        }).catch(() => {
          this.$hideLoading()
        })
      }
    },

    onReachBottom () {
      this.getList()
    }
  }
</script>

<style lang="scss" scoped>
  .home {
    position: relative;
    padding: 32px 0 40px;

    .bg-img {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 512px;
    }

    .wrapper {
      position: relative;
      z-index: 11;
    }

    .back-wrapper {
      position: fixed;
      z-index: 11;
      left: 20px;
      top: 24px;
      width: 40px;
      height: 40px;

      image {
        width: 40px;
        height: 40px;
      }
    }

    .banner {
      display: block;
      width: 686px;
      height: 240px;
      margin: 0 auto 32rpx;
      border-radius: 10px;
    }

    .activity-wrapper {
      padding: 0 32px;

      & > h2 {
        margin-bottom: 26px;
        color: #1D2229;
        font-size: 34px;
        font-weight: 600;
      }

      .activity-item {
        margin-bottom: 24px;
        padding: 24px;
        background: #FCFCFC;
        box-shadow: 0 0 8px 0 rgba(0,0,0,0.02);
        border-radius: 16px;

        .bottom {
          padding-top: 24px;

          .item {
            display: flex;
            line-height: 1.3;
            margin-bottom: 8px;

            h3 {
              font-size: 28px;
              color: #999999;
            }

            div {
              flex: 1;

              p {
                font-size: 28px;
                color: #333333;
              }
            }
          }
        }

        .top {
          padding-bottom: 24px;
          border-bottom: 1px solid #eee;

          h2 {
            margin-bottom: 14px;
            font-weight: 500;
            font-size: 34px;
            color: #333333;
          }

          p {
            display: -webkit-box;
            overflow: hidden;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            line-height: 1.3;
            font-size: 30px;
            color: #999999;
            text-align: justify;
          }
        }
      }
    }
  }
</style>
