<template>
  <div class="help">
    <x-header></x-header>
    <div class="item"
         v-for="(val,i) in QA"
         :key="i"
         @click="expand(val.index)">
      <div class="question">
        <span class="QA-title"
              v-if="val.title">{{val.Q}}</span>
        <span class="question-title"
              v-if="!val.title">{{val.Q}}</span>
      </div>
      <div class="answer"
           v-if="!val.title">
        <p ref="answer">{{val.A}}</p>
      </div>
    </div>
  </div>
</template>
<script>
import QA from "@/analog-data/QA.json";
import { Help } from "./namespace.js";
export default {
  name: Help.name,
  data() {
    return {
      QA: QA,
      expandNumber: 0
    };
  },
  methods: {
    expand(i) {
      const before = this.$refs.answer[this.expandNumber];
      const after = this.$refs.answer[i];
      if (before) {
        before.parentNode.style.height = 0;
      }
      this.expandNumber = i === this.expandNumber ? -1 : i;
      if (this.expandNumber >= 0)
        after.parentNode.style.height = after.offsetHeight + 20 + "px";
    }
  },
  mounted() {
    this.$nextTick().then(() => {
      this.$refs.answer[this.expandNumber].parentNode.style.height =
        this.$refs.answer[this.expandNumber].offsetHeight + 20 + "px";
    });
  }
};
</script>
<style scoped lang="scss">
.help {
  background-color: #fff;
}

.item {
  line-height: 1.5em;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  .QA-title {
    color: #ff6060;
    font-size: 0.35rem;
    margin-left: 0.3rem;
  }
  .QA-title:before {
    margin-left: -0.3rem;
    content: "";
    background-color: #ff6060;
    display: inline-block;
    width: 0.08rem;
    height: 0.3rem;
    border-radius: 0.1em;
    vertical-align: -0.1em;
    margin-right: 0.2em;
  }
  .question {
    font-size: 1.2em;
    margin: 0.3rem 0.2rem 0.3rem 0.3rem;
  }
  .question-title {
    font-size: 0.31rem;
    line-height: normal;
    color: #333;
  }
  .number,
  .hot {
    color: #fff;
    background-color: red;
    display: inline-block;
    height: 1.2em;
    width: 1.2em;
    text-align: center;
    border-radius: 2px;
    line-height: 1.2em;
    font-family: arial;
    vertical-align: 1px;
    margin-right: 4px;
    font-size: 1em;
  }
  .hot {
    width: auto;
    padding: 0 0.4em;
  }
  .answer {
    color: #666666;
    background-color: #f7f7f7;
    font-size: 1.2em;
    white-space: pre-wrap;
    overflow: hidden;
    transition: 0.5s height;
    margin: 0.2rem;
    height: 0;
    p {
      margin: 10px;
      line-height: 1.8em;
    }
    .link {
      color: white;
      width: 15em;
      padding: 0.2em;
      border-radius: 2px;
      margin-left: 0;
      margin-top: 0;
    }
  }
}
</style>
