<template>
  <el-dialog
    v-if="dialogVisible"
    title="AI分析"
    :visible.sync="dialogVisible"
    :close-on-click-modal ="false"
    width="80%"
  >
    <p class="mb10"><el-button type="primary">整体报告</el-button></p>

    <mx-table :propDefines="propDefines" :rows="formatRows">
      <template #subjects="{row}">
        <el-row>
          <el-col :span="8" v-for="subject in row.subjects">
            <el-tag type="success" class="mr10 mb10">{{ subject[0] }}</el-tag>
          </el-col>
        </el-row>
      </template>
      <template #group="{row}">
        <span :class="{'f-primary': row.allowSelect,'f-red':!row.allowSelect}">{{row.groupName}}</span>
      </template>
      <template #colleges="{row}">
        <el-row>
          <el-col :span="12" v-for="college in row.colleges">
            <el-tag type="success" class="mb10">{{ college.major[0] }}</el-tag>
            :
            <span>{{ college.college }}</span>
          </el-col>
        </el-row>
      </template>
      <template #report="{row}">
        <el-button @click="toReport(row)" >查看</el-button>
      </template>
    </mx-table>
    <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </span>
<!--    <single-subject-report :prevPreferences="prevPreferences"  :reportInfo="tableInfo.rows" :currentGroup="currentReportName" ref="SingleSubjectReport"></single-subject-report>-->
  </el-dialog>
</template>
<script>
import SingleSubjectReport from './single-subject-report'
import BackTrackingAiResolverMixins from './ai-round-select-resolvers/backTracking-ai-resolver-mixins'
export default {
  components:{
    SingleSubjectReport
  },
  props: {
    generation: Object
  },
  mixins: [BackTrackingAiResolverMixins],
  data() {
    return{
      dialogVisible:false,
      formatRows: [],
      tableInfo: {},
      currentReportName: '',
    }
  },
  computed: {
    resolveTablePrefix() {
      return {
        groupName: {
          label: '选科组合'
        },
        scoreSumGroup: {
          label: '组合成绩'
        },
      }
    },
    resolveTableSuffix() {
      return{
        subjects: {
          label: '自选专业',
          slot: 'subjects',
          width: '150'
        },
        colleges: {
          label: '院校',
          slot: 'colleges',
          width: '250'
        },
        signUp: {
          label: '报告',
          slot: 'report',
          width: '100',
          fixed: 'right',
        }
      }
    },
    formatTable() {
      if (!this.formatRows) return {}
      const options = this.generation.options
      console.log(this.generation)
      if (!options || !this.generation.active) return {}
      const optValues = Object.values(options)
      const dynamicColumns = {}
      for (let gen = options.primary.value; gen <= this.generation.active; gen++) {
        const opt = optValues.find(opt => opt.value == gen)
        const resolverKey = opt.key + 'Resolver'
        const resolver = this[resolverKey]
        if (typeof resolver === 'function') {
          const genColumns = resolver(gen, this.generation.active)
          Object.assign(dynamicColumns, genColumns)
        }
      }
      console.log(dynamicColumns)
      return dynamicColumns
    },
    propDefines() {
      return {
        ...this.resolveTablePrefix,
        ...this.formatTable,
        ...this.resolveTableSuffix,
      }
    }
  },
  methods: {
    toReport(row) {
      this.currentReportName = row.groupName
      this.$refs.SingleSubjectReport.dialogVisible = true
    },
    open(rows) {
      this.dialogVisible = true
      this.formatRows = rows
    },
    handleClose() {

    }
  }
}
</script>
<style scoped>
</style>
