<template>
  <box title="产品概括" :isErrorBtn="isErrorBtn()" @errorResolution="errorResolution">
    <ul>
      <li v-for="(item, index) in data.completions" :key="index" :id="item.id" :class="`${item.tag} isDomActive ${isClass(item)}`">
        <img :src="iconUrl(item)" class="icon" />
        <div class="tag">{{ item.subject }}</div>
        <div class="text" v-if="$route.path === '/product-analysis/result'">{{ item.commit_answer }}</div>
        <textarea v-else placeholder="请输入" v-model="item.commit_answer"></textarea>
      </li>
    </ul>
  </box>
</template>

<script>
import Box from './Box.vue'
export default {
  components: { Box },
  props: {
    data: { type: Object }
  },
  methods: {
    isErrorBtn() {
      const findErr = this.data.completions.findIndex(item => !item.is_correct)
      return findErr + 1
    },
    iconUrl(item) {
      const map = {
        product_overview_completion: 'https://webapp-pub.ezijing.com/x-training-new/products1.png',
        operation_mode_completion: 'https://webapp-pub.ezijing.com/x-training-new/products2.png',
        open_frequency_completion: 'https://webapp-pub.ezijing.com/x-training-new/products3.png',
        transaction_currency_completion: 'https://webapp-pub.ezijing.com/x-training-new/products4.png',
        fund_manager_completion: 'https://webapp-pub.ezijing.com/x-training-new/products5.png',
        fund_principal_completion: 'https://webapp-pub.ezijing.com/x-training-new/products6.png'
      }
      return map[item.tag]
    },
    isClass(item) {
      if (this.$route.path === '/product-analysis/result') {
        return item.is_correct ? '' : 'active'
      }
      return ''
    },
    errorResolution() {
      this.$emit('errorResolution', this.data)
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
ul {
  padding-top: 27px;
  display: flex;
  flex-wrap: wrap;
  margin-right: -24px;
  li {
    margin-right: 18px;
    margin-bottom: 13px;
    width: 198px;
    padding-bottom: 27px;
    background: #f1fcf9;
    border: 1px solid #b8ebde;
    border-radius: 12px;
    &.active{
      background: #FFFFFF !important;
      border: 1px solid #C11818 !important;
      box-shadow: 5px 6px 13px rgba(4, 0, 0, 0.18);
      textarea{
        border-bottom: 1px solid #C11818 !important;
      }
    }
    .text {
      width: 151px;
      font-size: 22px;
      text-align: center;
      margin: 20px auto 0;
      padding-bottom: 10px;
    }
    &.product_overview_completion{
      background: #f1fcf9;
      border: 1px solid #b8ebde;
      .text{
        border-bottom: 1px solid #7bc1af;
        color: #68b8a4;
      }
      textarea {
        border-bottom: 1px solid #7bc1af;
        color: #68b8a4;
      }
    }
    &.operation_mode_completion {
      background: #ecfafc;
      border: 1px solid #b5ebeb;
      textarea {
        border-bottom: 1px solid #a5e1e9;
        color: #62c2d0;
      }
      .text{
        border-bottom: 1px solid #a5e1e9;
        color: #62c2d0;
      }
    }
    &.open_frequency_completion {
      background: #fffdf0;
      border: 1px solid #f0eccb;
      margin-right: 0;
      textarea {
        border-bottom: 1px solid #dad396;
        color: #d9d292;
      }
      .text{
        border-bottom: 1px solid #dad396;
        color: #d9d292;
      }
    }
    &.transaction_currency_completion {
      background: #fdf8ee;
      border: 1px solid #ecd7aa;
      textarea {
        border-bottom: 1px solid #e2c485;
        color: #e2c485;
      }
      .text{
        border-bottom: 1px solid #e2c485;
        color: #e2c485;
      }
    }
    &.fund_manager_completion {
      background: #fcede9;
      border: 1px solid #f2c1b6;
      textarea {
        border-bottom: 1px solid #de9888;
        color: #de9888;
      }
      .text{
        border-bottom: 1px solid #de9888;
        color: #de9888;
      }
    }
    &.fund_principal_completion {
      background: #f1fcf9;
      border: 1px solid #b8ebde;
      // margin-right: 0;
      textarea {
        border-bottom: 1px solid #7bc1af;
        color: #7bc1af;
      }
      .text{
        border-bottom: 1px solid #7bc1af;
        color: #7bc1af;
      }
    }
    .icon {
      width: 82px;
      display: block;
      margin: 36px auto 18px;
    }
    .tag {
      text-align: center;
      font-size: 16px;
      color: #8e8e8e;
      line-height: 100%;
    }
    textarea {
      width: 150px;
      height: 43px;
      outline: none;
      resize: none;
      margin: 15px auto 0;
      display: block;
      background: none;
      text-align: center;
      padding-top: 10px;
      &::-webkit-input-placeholder {
        font-size: 18px;
        color: #cacaca;
      }
    }
  }
}
</style>
