<template>
  <zj-page-layout :hasFooter="true"
    :isScroll="true"
    :refresherTriggered="refresherTriggered"
    @refresherrefresh="refresherrefresh">
    <template slot="header">
      <view class="tab-container">
      	<u-tabs
      		:scrollable="false"
      		:list="tabList"
      		:current="tabCurrent"
      		@click="changeTab"
      		lineColor="#3D8FFD"
      		:activeStyle="{
      			color: '#3D8FFD'
      		}"
      		:inactiveStyle="{
      			color: '#666666'
      		}"
      		itemStyle="padding-left: 0; padding-right: 0; height: 88rpx;">
      	</u-tabs>
      </view>
    </template>

    <view class="list-container">
      <view class="item" v-for="(item, index) in dataList" :key="index" @tap="toForm(item)">
        <image v-if="item.detailImgs" :src="(item.detailImgs.split(','))[0]" mode="aspectFill"></image>
        <view class="main">
          <view class="title">{{item.name}}</view>
          <view class="text" v-if="item.startTime && item.endTime">{{item.startTime.slice(0, 10)}} 至 {{item.endTime.slice(0, 10)}}</view>
        </view>
        <text class="iconfont icon-jinru"></text>
      </view>
    </view>
	<template slot="footer">
		<view class="footer-btn-group">
		  <u-button text="报名记录" @tap="toList"></u-button>
		</view>
	</template>
    <Loading :type="2" :loadStatus="loadStatus" :dataList="dataList" />

  </zj-page-layout>
</template>

<script>
  export default {
    data() {
      return {
		dataList: [],
		pageNum: 1,
		loadStatus: 0,
        refresherTriggered: false,
        tabList: [
          {name: '进行中', value: 1},
          {name: '已过期', value: 2},
          // {name: '我参与的', value: 9},
        ],
        tabCurrent: 0,
        status: '',
      }
    },

    onLoad({tab = 1}) {
      this.status = tab;
      this.tabCurrent = this.tabList.map(o => o.value).indexOf(tab);

      this.getList();
    },

    methods: {
      getList() {
      	this.loadStatus = 1;
      	this.$api.post('/promotion/questionnaire/list', {
          status: this.status,
      	}).then(res => {
      		this.loadStatus = 0;
      		let list = res.data;
      		if (list.length < 1) {
      		  this.loadStatus = 2;
      		}
      		this.dataList = res.data;
      	}).catch(() => {
      		this.loadStatus = 2;
      	}).finally(res => {
      		this.refresherTriggered = false;
      	})
      },

      changeTab(e) {
      	this.tabCurrent = e.index;
      	this.status = e.value;
        this.refreshList();
      },

      refreshList() {
      	this.dataList = [];
      	this.pageNum = 1;
      	this.getList();
      },

      // 触发下拉刷新
      refresherrefresh(e) {
      	this.refresherTriggered = true;
      	this.refreshList();
      },

      toForm(item) {
        this.$navToPage({
          url: `/packageHome/pages/codeActivity/activityForm?id=${item.id}`
        })
      },
	  
	  toList() {
	    this.$navToPage({
	      url: `/packageHome/pages/codeActivity/applyList?id=`
	    })
	  },
    },
  }
</script>

<style lang="scss" scoped>
.tab-container {
  background: #FFFFFF;
}

.list-container {
  padding: 0 20rpx;
  box-sizing: border-box;
  .item {
    @include zj-card;
    margin-top: 20rpx;
    padding: 30rpx;
    display: flex;
    align-items: center;
	box-sizing: border-box;
    image {
      width: 160rpx;
      height: 120rpx;
      margin-right: 20rpx;
    }
    .main {
      flex: 1;
      .title {
        font-size: 32rpx;
        font-weight: 600;
      }
      .text {
        font-size: 24rpx;
        color: $sec-font;
        margin-top: 12rpx;
      }
    }
    .iconfont {
      color: $sec-font;
    }
  }
}
</style>
