<template>
  <view class="bigBox">
    <Tabs :list='list1' @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 {
      list1: [
        {
          name: "HOOLOO券",
        },
        {
          name: "已使用/已失效",
        },
      ],
      nouserList:[],
      current: 0,
      actionIndx:0,
      canuse:[],
      cantuse:[]
    };
  },
  watch:{
    current(val) {
      console.log(val,'val')
      if(val===1&&this.cantuse.length===0){
        this.getTickList(false)
      }
    }
  },
  mounted(){
    for(let i=0;i<2;i++){
      this.nouserList.push({
          status:2, // 0可使用 1不可使用/已过期/已失效
          couponType:0, // 0满减 1折扣 2抵扣
          typeDesc:'最大字数最大字', // 左上角文案描述
          mjPrice:'30', // 满减金额
          zkPrice:'7', // 折扣金额
          dkPrice:'免单', // 抵扣金额
          priceDesc:'满130可用', // 条件描述
          checkStatus:false, // 优惠券选中状态
          title:'最大字数最大字数最大', // 优惠券标题
          time:['2022.07.24.17:20'], // 过期时间
          shopList:['全门店可用'], // 可用门店
          goodList:['全品类可用'], // 可用品类 
          useScence:['小程序下单可用'], // 使用场景
          useDesc:['*不可与其他优惠券同时使用','*不可与门店优惠共享','*订单完成后选择退款，只退回实际支付金额，优惠券不予退回'], // 使用说明
          zkRule:'整单最高抵扣50元', // 折扣规则
          reson:'不可与已勾选券叠加使用' // 不可使用原因
      })
    }
    this.getTickList(true)
  },
  methods: {
    async getTickList(val) {
      const {data} = await Mine.getUserList(val)
      const {rows} = data
      console.log(data)
            const canuse = rows.map(item=>{
                let timeStart = ''
                let timeEnd = ''
                if(item.useStartTime){
                    timeStart = item.useStartTime.slice(0,11).replace('-', '.')
                }
                if(item.useEndTime){
                    timeEnd = item.useEndTime.slice(0,11).replace('-', '.')
                }
                return {
                    id: item.id,
                    status: item.state===0?0:item.state===1?2:3,
                    couponType: item.type,
                    typeDesc: item.categoryName,
                    price: item.priceDiscount,
                    priceDesc: item.ruleDesc,
                    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>
