<template>
  <div class="product-analysis-case-select">
    <div class="inner">
      <div class="left">
        <div class="case">
          <el-radio-group v-model="caseSelect">
            <el-radio :label="item.id" v-for="(item, index) in caseList" :key="index">{{item.name}}</el-radio>
          </el-radio-group>
        </div>
      </div>
      <div class="right">
        <ul>
          <li :class="{ active: index === selected }" v-for="(item, index) in list" :key="index" @click="handleClick(item, index)">{{item.name}}</li>
        </ul>
        <el-button type="primary" size="medium" plain style="margin-left:20px;" @click="handleGo">选好了</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { getCategories, getCasesList, selectCase } from '../api'
export default {
  data() {
    return {
      caseList: [
        { label: '股票型基金案例：广发银行优选股票A', id: '111' },
        { label: '股票型基金案例：广发银行优选股票B', id: '222' },
        { label: '股票型基金案例：广发银行优选股票C', id: '333' },
        { label: '股票型基金案例：广发银行优选股票D', id: '444' }
      ],
      caseSelect: '',
      list: [],
      selected: 0
    }
  },
  mounted() {
    this.getCategories()
  },
  methods: {
    getCategories() {
      getCategories(1).then(res => {
        this.getCasesList(res.data.items[0].id)
        this.list = res.data.items
      })
    },
    handleClick(item, index) {
      this.selected = index
      this.getCasesList(item.id)
    },
    handleGo() {
      const data = this.caseList.find(item => { return item.id === this.caseSelect })
      this.$store.commit('setCase', data)
      this.selectCase(data.id)
      // console.log(this.$store.state.case, '1231')
    },
    getCasesList(id) {
      getCasesList(id).then(res => {
        this.caseList = res.data.items
        this.caseSelect = res.data.items[0].id
      })
    },
    selectCase(id) {
      selectCase(id).then(res => {
        this.$router.push({ path: '/product-analysis/report' })
      })
    }
  }
}
</script>
<style scoped>
.product-analysis-case-select{
  background:#eaf0f0;
  height:548px;
  margin:24px 30px 60px 30px;
  padding-top:32px;
  position:relative;
}
.inner{
  display: flex;
  height:500px;
  width:1080px;
  margin:0 auto;
  background:url('@/assets/images/product_analysis_case.png') no-repeat left center;
}
.left{
  width:810px;
  padding:35px 20px 80px 225px;
}
.case{
  height:100%;
  width:100%;
  position:relative;
}
.case .el-radio-group{
  position:absolute;
  left:50%;
  top:50%;
  transform: translate(-50%, -50%);
}
.case ::v-deep.el-radio{
  display:block;
  margin-bottom:20px;
}
.case ::v-deep.el-radio.all .el-radio__input.is-checked .el-radio__inner{
  border-color:#636363;
  background:#636363;
}
.right{
  width:280px;
  margin-top:32px;
  flex-wrap:wrap;
  flex-direction: column;
}
ul{
  display:flex;
  flex-wrap:wrap;
  flex-direction: row;
  align-content: flex-start;
  height:380px;
}
li{
  width:122px;
  height:40px;
  font-size:16px;
  line-height:40px;
  text-align:center;
  color:#666;
  margin:0 0 10px 10px;
  cursor:pointer;
  background:#f8f8f8;
}
li.active{
  background:#68B8A4;
  color:#fff;
}
</style>
