<template>
  <div class="ticket-detail__container">
    <van-nav-bar title="我的奖票" left-text="返回" @click-left="$route_back" left-arrow/>
    <div class="ticket-detail__content">
      <scroller ref="scroller" :on-refresh="onRefresh" :on-infinite="infinite">
        <div class="ticket-detail__header">
          <YearMonthPicker v-model="month"></YearMonthPicker>
          <StatisticsMonthTotal :data="statisticsData"/>
        </div>
        <div class="ticket-detail__title">
          <span>本月奖票</span>
        </div>
        <div class="ticket-list__wrap" v-if="data && data.length > 0">
          <div class="ticket-list__item" v-for="item in data">
            <!-- 
            <div class="item-content__wrap">
              <div class="text-ellipsis_wrap">
                <div class="item-content">
                  {{ item.remark.customize }}
                </div>
              </div>
              <div class="item-content__divider"></div>
            </div>
            <div class="ticket-item__date">{{ item.create_time }}发放</div>
             -->
              <van-row>
                <van-col span="17" class="ticket_left">{{ item.remark.customize }}</van-col>
                <van-col span="7" class="ticket_right">
                  <div style="font-size: 0.42rem; line-height: 0.6rem;">{{ item.create_time | monthDay}}</div>
                  <div style="font-size: 0.32rem; line-height: 0.6rem;">{{ item.create_time | yearDate}}</div>
                </van-col>
              </van-row>
          </div>
        </div>
        <!-- <van-empty v-else description="暂无数据..."/> -->
         <noData src="static/images/nopicket.png" :list="data" detail_text="没有奖票" />
      </scroller>
     
    </div>
  </div>
</template>

<script>
  import Vue from 'vue'
  import {Empty } from 'vant'
  import moment from 'moment'
  import request from '@/utils/request'
  import StatisticsMonthTotal from './statistics_month_total'
  import YearMonthPicker from '@/components/common/YearMonthPicker'

  Vue.use(Empty)

  export default {
    name: 'ticket_personal_detail',
    data () {
      return {
        data: null,
        month: moment().format('YYYY-MM'),
        statisticsData: [
          {label: '本月奖票', value: 0},
          {label: '累计奖票', value: 0}
        ]
      }
    },
    components: {StatisticsMonthTotal, YearMonthPicker},
    watch: {
      month () {
        this.isFirstLoad = false
        this.searchParams.page = 1
        this.infinite()
      }
    },
    filters:{
      yearDate:function (val){
        return moment(val).format('YYYY')
      },
      monthDay: function (val){
        return moment(val).format('MM-DD')
      }
    },
    created () {
      /** 为了优化性能，在 searchParams 的设值时触发diff 比较. 所以searchParams没有放在data 里定义*/
      this.searchParams = {page: 1, page_size: 10, employee_id: this.$store.getters.user_info.id, month: null}
    },
    methods: {
      onRefresh (doneCallback) {
        this.searchParams.page = 1
        this.getData(doneCallback)
      },
      infinite () {
        if (!this.isFirstLoad) {
          this.isFirstLoad = true
          this.$toast.loading({message: '正在加载'})
          this.getData(() => this.$toast.clear())
        } else {
          this.getData()
        }
      },
      getData (callback = undefined) {
        this.searchParams.month = this.month
        request('get','/api/integral/ticket',this.searchParams).then(res => {
          if (res.data.code === 1) {
            const item = res.data.data
            const list = item.month_list
            if (this.searchParams.page === 1) {
              this.data = list
            } else {
              this.data = this.data.concat(list)
            }
            this.searchParams.page++
            this.statisticsData[0].value = item.month_total
            this.statisticsData[1].value = item.total
            this.$refs.scroller.finishInfinite(list.length < this.searchParams.page_size)
          } else {
            this.$refs.scroller.finishInfinite(true)
          }
        }).finally(callback)
      }
    }
  }
</script>

<style scoped lang="less">
  .ticket-detail__container {
    position: relative;

    & /deep/ .van-nav-bar {
      background-color: #26a2ff;
    }

    & .ticket-detail__content {
      position: relative;
      height: calc(100% - 0.92rem);
      color: #303133;
      font-size: 0.32rem;
    }

    & .ticket-detail__header {
      position: relative;
      height: 2.04rem;
      background: #26a2ff;
      z-index: 1;

      & .bg-fff {
        background: transparent;

        & /deep/ .YMPicker_item_icon,
        /deep/ .date-text {
          color: #fff;
        }
      }
    }

    & .ticket-detail__title {
      position: relative;
      margin: 1rem 0 0.32rem 0;
      padding: 0 0.32rem;
      font-weight: 600;

      &:before {
        content: '';
        position: absolute;
        top: 50%;
        bottom: 0;
        left: 0.32rem;
        margin-top: -0.16rem;
        width: 0.08rem;
        height: 0.34rem;
        background: #26a2ff;
        border-radius: 0.04rem;
      }

      & > span {
        margin-left: 0.16rem;
      }
    }

    & .ticket-list__wrap {
      position: relative;
      padding: 0.32rem;
      color: #303133;

      & .ticket-list__item {
        margin-bottom: 0.24rem;
        background: #fff;
        border-radius: 0.2rem;

        & .item-content__wrap {
          position: relative;
          padding: 0.2rem 0.24rem;
          height: 1rem;

          & .text-ellipsis_wrap {
            display: flex;
            flex: 1;
            overflow: hidden;
          }

          & .item-content {
            height: 1rem;
            line-height: 0.5rem;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }

          & .item-content__divider {
            position: absolute;
            left: 0.3rem;
            right: 0.3rem;
            bottom: 0;
            height: 1px;
            background: linear-gradient(to right, #e2e2e2, #e2e2e2 3px, transparent 3px, transparent);
            background-size: 0.11rem 100%;

            &:before {
              content: ' ';
              position: absolute;
              top: -0.2rem;
              left: -0.5rem;
              height: 0.4rem;
              width: 0.4rem;
              background: #f5f5f5;
              border-radius: 100%;
            }

            &:after {
              content: ' ';
              position: absolute;
              top: -0.2rem;
              right: -0.5rem;
              height: 0.4rem;
              width: 0.4rem;
              background: #f5f5f5;
              border-radius: 100%;
            }
          }
        }

        & .ticket-item__date {
          padding: 0.16rem 0.24rem;
          font-size: 0.28rem;
          color: #C0C4CC;
        }
        & .ticket_left{
          padding: 0 0.24rem;
          margin: 0.24rem 0;
          display: -webkit-box;
          text-overflow: ellipsis;
          overflow: hidden;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          line-height: 0.6rem;
        }

        & .ticket_right{
          padding: 0.24rem; 
          font-size: 0.32rem; 
          text-align: center;
          border-top-right-radius: 0.2rem;
          border-bottom-right-radius: 0.2rem;
          color: #fff;
          background: #c6edff; 
          background: linear-gradient(-160deg,  #26a2ff 0%,#5cb6f9 100%);
        }
      }
    }
  }
</style>
