<template>
  <view class="container">
    <view class="tabs">
      <view :class="['tab', tabActive == 1 ? 'active' : '']" @click="tabClick(1)">可使用</view>
      <view :class="['tab', tabActive == 2 ? 'active' : '']" style="margin-left: 20rpx" @click="tabClick(2)">
        已使用
      </view>
      <view :class="['tab', tabActive == 3 ? 'active' : '']" style="margin-left: 20rpx" @click="tabClick(3)">
        已过期
      </view>
    </view>
    <view :class="['card', item.status != 0 ? 'grey' : '']" v-for="(item, index) in list">
      <view class="leftIcon"></view>
      <view class="left">
        ￥
        <span style="font-size: 36rpx">{{ item.discount }}</span>
      </view>
      <view class="right">
        <view class="row title">
          {{ item.name }}
        </view>
        <view class="row endTime">{{ item.endTime }}到期</view>
        <view class="row desc">
          {{ item.desc }}
        </view>
      </view>
    </view>
    <noData v-if="list.length == 0" />
  </view>
</template>

<script>
import noData from '@/component/noData.vue'
import { couponListApi } from '@/api/coupon.js'
export default {
  components: {
    noData,
  },
  onLoad() {
    this.$nextTick(() => {
      this.getList()
    })
  },
  data() {
    return {
      tabActive: 1,
      list: [],
      params: {
        limit: 999,
        page: 1,
        status: 0,
      },
    }
  },
  methods: {
    tabClick(index) {
      this.tabActive = index
      if (index == 1) {
        this.params.status = 0
      } else if (index == 2) {
        this.params.status = 1
      } else {
        this.params.status = 2
      }
      this.getList()
    },
    getList() {
      // wx.showLoading()
      couponListApi(this.params).then(res => {
        console.log(res, '我的优惠券')
        this.list = res.data.list
        // wx.hideLoading()
      })
    },
  },
}
</script>

<style scoped lang="scss">
.tabs {
  display: flex;
  margin-bottom: 20rpx;
  .tab {
    width: 136rpx;
    height: 48rpx;
    font-size: 28rpx;
    background: #fff;
    border-radius: 8rpx;
    line-height: 48rpx;
    text-align: center;
  }
  .active {
    background: #fea200;
    color: #fff;
  }
}
.container {
  background: #eaeaea;
  padding: 20rpx;

  .card {
    background: #fff;
    border-radius: 16rpx;
    overflow: hidden;
    display: flex;
    margin-bottom: 20rpx;

    .leftIcon {
      height: auto;
      width: 16rpx;
      background: #ff2c43;
    }
    .left {
      width: 160rpx;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      color: #ff2c43;
      font-weight: 600;
    }
    .right {
      padding: 20rpx;
      .row {
        margin-bottom: 8rpx;
        font-size: 24rpx;
      }
      .title {
        font-size: 28rpx;
        font-weight: 600;
      }
      .endTime {
        color: #ff2c43;
      }
      .desc {
        margin-top: 10rpx;
        color: #8c8c8c;
      }
    }
  }
}
</style>
