<template>
  <view class="bigBox">
    <Tabs :list='list' @changeTab="changeTab" :newIndex="current" />
    <view>
      <swiper :current="current" class="swiper" @change="swiperChange">
        <swiper-item>
          <view class="list" v-if="canuse.length!=0">
            <Ticket v-for="(item,index) in canuse" :key="index" :info="item"/>
          </view>
          <view class="emty" v-else>
            <view class="text">暂无可用优惠券</view>
          </view>
        </swiper-item>
        <swiper-item>
          <view class="list"  v-if="cantuse.length!=0">
            <Ticket v-for="(item,index) in cantuse" :key="index" :info="item" />
          </view>
          <view class="emty" v-else>
            <view class="text">暂无可用优惠券</view>
          </view>
        </swiper-item>
      </swiper>
    </view>
  </view>
</template>

<script>
import Ticket from '@/components/Ticket/index.vue'
import Tabs from '@/components/Tabs/index.vue'
import Mine from '@/request/mine'
export default {
  components: {Ticket,Tabs},
  data() {
    return {
      list: [
        {
          name: "HOOLOO券",
        },
        {
          name: "已使用/已失效",
        },
      ],
      nouserList:[],
      current: 0,
      actionIndx:0,
      canuse:[],
      cantuse:[]
    };
  },
  mounted(){
    this.getTickList(true)
    this.getTickList(false)
  },
  methods: {
    async getTickList(val) {
      const {data} = await Mine.getUserList(val)
      const {rows} = data
            const canuse = rows.map(item=>{
                let timeStart = ''
                let timeEnd = ''
                if(item.useStartTime){
                    timeStart = Date.parse(item.useStartTime)<new Date().valueOf()<Date.parse(item.useEndTime)?'':item.useStartTime.slice(0,11).replace(new RegExp('-','g'), '.')
                }
                if(item.useEndTime){
                    timeEnd = item.useEndTime.slice(0,11).replace(new RegExp('-','g'), '.')
                }
                return {
                    id: item.id,
                    status: item.state===0?0:item.state===1?2:3,
                    couponType: item.type,
                    typeDesc: item.categoryName,
                    price: item.priceDiscount===0?'免单':item.priceDiscount,
                    priceDesc: item.ruleDesc,
                    categoryDesc:item.categoryDesc,
                    checkStatus: false,
                    title: item.name,
                    time: [timeStart,timeEnd],
                    shopList: [item.areaLimitDesc],
                    goodList: [item.goodLimitDesc],
                    useScence: ['小程序下单可用'],
                    useDesc: ['*不可与其他优惠券同时使用','*不可与门店优惠共享','*订单完成后选择退款，只退回实际支付金额，优惠券不予退回'],
                    zkRule: item.type===1?'抵扣后实付金额无法小于0':item.type===2?'整单最高抵扣50元':'可享受规定范围内饮品免单',
                    reson: item.notFitableDesc,
                    couponAmount:item.couponAmount,
                    fitItem:item
                }
            })
      if(val){
            this.canuse = canuse
      }else{
            this.cantuse = canuse
      }
    },
    changeTab(current) {
      this.current = current;
    },
    swiperChange(val){
      this.current = val.detail.current;
    }
  },
};
</script>

<style lang="scss" scoped>
.bigBox {
  .swiper {
    background: #F8F8F8;
    height: calc(100vh - 64rpx);
    .list{
      height: 100%;
      padding: 0rpx 32rpx;
      overflow-y: scroll;
    }
    .emty{
        .text{
          text-align: center;
          margin-top: 322rpx;
          font-size: 28rpx;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          line-height: 40rpx;
          letter-spacing: 1rpx;
        }
    }
  }
}
</style>
