<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="top-tab">
      <u-tabs class="tab" :list="list" @click="handlerChangeTab1"
      :activeStyle="{
            color: '#fff',
            fontWeight: 'bold',
            transform: 'scale(1.05)'
        }"
        :inactiveStyle="{
            color: '#fff',
            transform: 'scale(1)'
        }"
        itemStyle="height: 34px; width:27%;" lineColor="#D89A4C"></u-tabs>
    </view>

    <!-- 优惠券的可用和失效 -->
    <view class="use">
      <u-tabs :list="list2" lineWidth="100" lineColor="#347caf" :scrollable="false" :activeStyle="{
          color: '#347caf',
          fontWeight: 'bold',
          transform: 'scale(1.05)',
        }" :inactiveStyle="{
          color: '#b7b6b8',
          transform: 'scale(1)',
        }" itemStyle="padding-left: 90rpx; padding-right: 80rpx; height: 120rpx;"
        @change='handlerSelectTab'
        />
    </view>

    <!-- 优惠券可用 -->
    <view class="couponUse" v-show="lable_type == 0" v-for="(item,index) of init_list">
      <view class="useLeft">
        <view>{{ item.name }}</view>
        <text>2320-07-02 ~ {{ item.expiration	}}</text>
      </view>
      <view class="useRight">
        <view class="text">{{ item.discount * 10 }}<text>折</text></view>
        <view>折扣</view>
        <view class="gouUse">去使用</view>
      </view>
    </view>

    <u-empty v-if="total == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"> </u-empty>
    <!-- 优惠券失效 -->
    <!-- <view class="couponDisUse couponUse" v-show="lable_type == 1" v-for="item of 3">
      <view class="useLeft">
        <view>满500减100元</view>
        <text>2320-07-02 ~ 202-08-03</text>
      </view>
      <view class="useRight">
        <view class="text">2<text>折</text></view>
        <view>折扣</view>
        <view class="gouUse">去使用</view>
      </view>
    </view> -->
  </view>
</template>

<script>
  import { maintainCouponPaging } from "@/api/mine.js"
  import { mapState } from "vuex"
  export default {
    data() {
      return {
        list: [
          {
            id: 1,
            name: '满减',
            type:'REDUCE'
          },
          {
            id: 2,
            name: '折扣',
            type:'DISCOUNT'
          },
          {
            id: 3,
            name: '赠送',
            type:'GIVE'
          },
        ],
        list2: [{
            name: '可用',
            type:'UNUSED'
          },
          {
            name: '失效',
            type:'CLOSED'
          },
        ],
        lable_type: 0, // 是否可用
        queryParams:{
          size:10,//分页信息  取值范围: 页码,分页大小
          type:'GIVE',//优惠券类型 允许值: GIVE(赠送), REDUCE(满减), DISCOUNT(折扣)
          status:'UNUSED',// 用户优惠券状态 UNUSED(未使用), USED(已使用), EXPIRED(已过期), CLOSED(作废)
        },

        init_list:[],//初始化列表
        total:0
      };
    },
    mounted() {
      this.handlerInitCouponList()
    },
    methods: {
      // 初始化优惠卷列表
      handlerInitCouponList(){
        maintainCouponPaging(this.queryParams).then(res=>{
          this.init_list = res.data.records
          this.total = res.data.total
        })
      },
      // 选择顶部导航栏
      handlerChangeTab1(e){
        this.queryParams.type = e.type
        this.handlerInitCouponList()
      },
      // 点击选择下层tab栏 选择是否可用
      handlerSelectTab(e){
        this.lable_type = e.index
        this.queryParams.status = e.type
        this.handlerInitCouponList()
      }
    },
  };
</script>

<style lang="scss" scoped>
  .container {
    height: 100vh;
    background-color: #efefef;

    .top-tab {
      width: 100%;
      background-color: #347CAF;
      padding: 20rpx 0;
    }

    .use {
      padding: 0 140rpx;
    }

    /* 优惠券可用 */
    .couponUse {
      margin: 20rpx 30rpx;
      height: 200rpx;
      display: flex;
      background-color: #fff;
      box-sizing: border-box;

      .useLeft {
        width: 380rpx;
        padding: 20rpx;

        >view {
          font-size: 40rpx;
          margin: 20rpx;
          color: #333;
        }

        >text {
          font-size: 28rpx;
          color: #5f5f5f;
        }
      }

      .useRight {
        height: 100%;
        padding: 10rpx;
        color: #fff;
        text-align: center;
        box-sizing: border-box;
        width: calc(100% - 380rpx);
        background-color: #347caf;

        .text {
          font-size: 50rpx;

          >text {
            margin-left: 5rpx;
            font-size: 24rpx;
          }
        }

        .gouUse {
          width: 180rpx;
          height: 60rpx;
          line-height: 60rpx;
          color: #347caf;
          margin: 16rpx 0 0 60rpx;
          background-color: #fff;
        }
      }
    }

    .couponDisUse {
      .useRight {
        background-color: #cecece;

        .gouUse {
          color: #cecece;
        }
      }
    }
  }

</style>
