<template>
  <div>
    <zhiyuan-list @expand="expand" :tableList="rows" :loading="loading" :cols="cols" readonly></zhiyuan-list>
  </div>
</template>
<script>
import ZhiyuanList from '@/views/career/zhiyuan/components/zhiyuan-list'
import { getRecommendVoluntary, getVoluntaryHeaders, getVoluntaryMarjors } from '@/api/webApi/professlib'

export default {
  components: {
    ZhiyuanList
  },
  data() {
    return {
      cols: [],
      rows: [],
      data: {},
      loading: false
    }
  },
  created() {
    this.data = JSON.parse(this.$route.query.data)
    this.getCols()
    this.getList()
  },
  methods: {
    getCols() {
      getVoluntaryHeaders({
        mode: this.data.mode
        // year: this.batch.year
      }).then(res => {
        this.cols = res.data
      })
    },
    expand(item) {
      console.log(item)
      if (item.isExpand) {
        // 取消
        return
      } else {
        item.isExpand = true
        this.getVoluntaryMarjors(item)
      }
    },
    getVoluntaryMarjors(item) {
      getVoluntaryMarjors(
        {
          batchName: this.data.name,
          collegeCode: item.recruitPlan.collegeCode,
          mode: this.data.mode,
          // // universityId: item.recruitPlan.universityId,
          // // year: item.recruitPlan.year,
          wishResId: this.data.id
        }
      ).then(res => {
        item.majors = res.data.map(item => {
          item.selected = false
          return item
        })
        console.log(res)
      })
    },
    getList() {
      const data = {
        batchName: this.data.batchName,
        mode: this.data.mode,
        score: this.data.score,
        wishResId: this.data.id
      }
      const pageForm = {
        pageSize: 10,
        pageNum: 1
      }
      getRecommendVoluntary({ ...data }, { ...pageForm }).then(res => {
        console.log(res)
        const rows = res.rows.map(item => {
          item.isExpand = false
          item.majors = []
          item.recruitPlan = item.recruitPlan || {}
          return item
        })
        this.rows = rows
      })
    }
  }
}
</script>

<style scoped>

</style>
