<template>
  <div>
    <van-sticky class="sticky" v-if="!appFlag">
      <div class="header">
        <div class="back">
          <backIcon/>
        </div>
        <!-- 卡券中心 -->
        {{ $t('share.l10') }}
        <div class="right flex" @click="$router.push('/statement/coupon')">
          <img class="img" src="/img/share/icon11.png" alt="极度证券">
          <!-- 声明 -->
          {{ $t('share.l11') }}
        </div>
      </div>
    </van-sticky>
    <div class="page">
      <div class="section">
        <div class="tabs flex">
          <div class="tab" :class="{active: type == '1'}" @click="changeType('1')">
            <!-- 可用券 -->
            {{ $t('share.l12') }}
          </div>
          <div class="tab" :class="{active: type == '2'}" @click="changeType('2')">
            <!-- 历史记录 -->
            {{ $t('share.l13') }}
          </div>
        </div>
      </div>
      <usableList v-if="type == '1'"/>
      <historyList v-if="type == '2'"/>
    </div>
  </div>
</template>
<script>
import backBar from '@/components/backBar'
import usableList from "./components/usableList.vue";
import historyList from "./components/historyList.vue";
export default {
  components: {
    backBar,
    usableList,
    historyList
  },
  data () {
    return {
      type: '1'
    }
  },
  created () {
    if (this.$route.params.type) {
      this.type = this.$route.params.type
    }
  },
  methods: {
    changeType(val) {
      if (this.type == val) {
        return
      }
      this.type = val
      this.$router.replace('/coupon-center/' + val)
    }
  }
}
</script>
<style lang="less" scoped>
.sticky {
  background-color: var(--bg-);
}
.header {
  position: relative;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  background-color: var(--bg-);
  height: 50px;
  padding: 0 84px 2px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  .back {
    position: absolute;
    left: 9px;
    top: 11px;
  }
  .right {
    position: absolute;
    top: 16px;
    right: 17px;
    font-size: 16px;
    font-weight: 400;
    color: #444444;
    cursor: pointer;
    .img {
      width: 14px;
      margin-right: 4px;
    }
  }
}
.page {
  padding: 0px 17px 10px;
}
.section {
  padding-top: 6px;
  position: sticky;
  top: 50px;
  z-index: 2;
  background-color: #fff;
}
.tabs {
  background: #F3F7F8;
  border-radius: 8px;
  .tab {
    text-align: center;
    cursor: pointer;
    font-size: 16px;
    line-height: 42px;
    color: #676767;
    flex: 1;
    &.active {
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0px 2px 5px 0px rgba(188,192,193,0.31);
      color: #000000;
    }
  }
}
</style>