<template>
  <div class="rate-container">
    <cr-sticky class="rate-head">
      <cr-radio-btn v-model="titleIndex" :radio-data="titleOptions" />
      <cr-tabbar v-model="amountIndex" active-color="#333" inactive-color="#666">
        <cr-tabbar-item v-for="(item, index) in amountOptions" :key="index">
          {{ item }}
        </cr-tabbar-item>
      </cr-tabbar>
    </cr-sticky>
    <div class="rate-body">
      <table class="table rate-table">
        <thead>
          <tr>
            <th style="width: 40%">投保年龄</th>
            <th style="width: 30%">男</th>
            <th style="width: 30%">女</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in listOptions.age" :key="index">
            <th>{{ item }}</th>
            <td>{{ listOptions.list[0][index] || "-" }}</td>
            <td>{{ listOptions.list[1][index] || "-" }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import crRadioBtn from "@/components/CrRadioBtn";
import detail from "@/api/detail.huatai.zhongjixian";
const { rateInfo } = detail;
export default {
  name: "GoodsDetail",
  components: {
    crRadioBtn
  },
  data() {
    return {
      rateInfo,
      titleIndex: 0,
      amountIndex: 0
    };
  },
  computed: {
    titleOptions() {
      return this.rateInfo.map((item, index) => {
        return {
          label: item.title,
          value: index
        };
      });
    },
    amountOptions() {
      const { rateInfo, titleIndex } = this;
      const _length = rateInfo[titleIndex].list.length;
      return rateInfo[titleIndex].list.map((item, index) => `${_length - index}0万保额`);
    },
    listOptions() {
      const { rateInfo, titleIndex, amountIndex } = this;
      return {
        age: rateInfo[titleIndex].age,
        list: rateInfo[titleIndex].list[amountIndex]
      };
    }
  },
  methods: {}
};
</script>
<style lang="less" scoped>
@import "../../../../style/var.less";

.rate-container {
  background-color: @white;
}
.rate-head {
  width: 100% !important;
  @{deep} & > div {
    width: 100% !important;
    z-index: 100;
  }
  @{deep} .cr-tabbar {
    font-size: @font-size-16;
    padding: @padding-lg+1 0;
    &-item {
      position: relative;
      &::after {
        position: absolute;
        left: 0;
        right: 0;
        margin: auto;
        top: 26px;
        // transition: width .2s linear;
        content: " ";
        display: block;
        width: 0;
        height: 4px;
        background: @orange-light;
        border-radius: @border-radius-lx;
      }
      &--active {
        font-weight: 600;
        &::after {
          width: 32px;
        }
      }
    }
  }
  .cr-radio-group {
    margin-top: 10px;
  }
}

.rate-body {
  padding: 15px 0;
}
.rate-table {
  margin: 0;
  width: 100%;
  thead {
    th {
      &:first-child {
        padding-left: 30px;
      }
    }
  }
  tbody {
    th {
      padding-left: 30px;
    }
  }
}
</style>
