<template>
  <div v-loading="loading">
    <div class="filter">
      <el-row class="radioInput">
        <div>
          <span class="radiaTitle">排名类型:</span>
        </div>
        <el-radio-group v-model="filter_form.type">
          <el-radio-button
            v-for="item in filter_list.types"
            :key="item"
            :label="item"
            style="margin-bottom:10px"
          />
        </el-radio-group>
      </el-row>
      <el-row class="radioInput">
        <div>
          <span class="radiaTitle">排名年份:</span>
        </div>
        <el-radio-group v-model="filter_form.year">
          <el-radio-button
            v-for="item in filter_list.years"
            :key="item"
            :label="item"
            style="margin-bottom:10px"
          />
        </el-radio-group>
      </el-row>
      <mx-search-group v-model="collegeName" justify="end" @search="clickSuffix">
        <p>共 <span class="f-primary">{{ pageForm.total }}</span> 条</p>
      </mx-search-group>
    </div>
    <el-row class="mt10 ">
      <div v-if="pageForm.total > 0">
        <div class="list-wrap pl30">
          <div v-for="(item, idx) in collegeList" :key="idx" class="list-item fx-row mb30">
            <div class="index">{{ item.ranking }}</div>
            <div class="img pointer" @click="toDetail(item)">
              <img style="width: 100%;height: 100%" :src="item.universities.logo" alt="">
            </div>
            <div class="info ml20">
              <div class="college_name pointer f-333 f20 mb5" @click="toDetail(item)">{{ item.collegeName }}</div>
              <div v-if="item.universities.features" class="tags">
                <span
                  v-for="feature in item.universities.features.split(',')"
                  :key="feature"
                  class="mr5 el-tag el-tag--info el-tag--plain"
                >{{ feature }}</span>
              </div>
              <div class="college-desc mt5 f14 f-666">
                <p>{{
                  `${item.universities.location} ${item.universities.cityName} ${item.universities.type} / ${item.universities.natureTypeCN} / ${item.universities.managerType} `
                }}</p>
              </div>
            </div>
            <div class="heat f12 f-666">
              <p>综合指数</p>
              <p class="mt3">{{ item.universities.comScore }}</p>
            </div>
            <div class="heat f12  f-666">
              <p>热度</p>
              <p class="mt3">{{ (item.universities.hits / 10000).toFixed(1) }}万</p>
            </div>
          </div>
        </div>
        <pagination
          class="mt10"
          :total="pageForm.total"
          :auto-scroll="false"
          :page.sync="pageForm.pageNum"
          :limit.sync="pageForm.pageSize"
          @pagination="onChangePage"
        />
      </div>

      <evaluation-empty v-else title="暂无数据" />
    </el-row>
  </div>
</template>

<script>
import { rankingFilter, universitiesRanking } from '@/api/webApi/career-course'
import MxSearchGroup from '@/components/MxSearch/mx-search-group'
import transferMixin from '@/components/mx-transfer-mixin'

export default {
  components: { MxSearchGroup },
  mixins: [transferMixin],
  data() {
    return {
      filter_form: {
        type: '',
        year: '',
        collegeName: ''
      },
      loading: false,
      pageForm: {
        pageSize: 10,
        pageNum: 1,
        total: 0
      },
      collegeName: '',
      filter_list: {},
      collegeList: []
    }
  },
  watch: {
    filter_form: {
      immediate: false,
      deep: true,
      handler(val) {
        this.getUniversitiesRanking()
      }
    }
  },
  created() {
    this.getRankingFilter()
  },
  methods: {
    clickSuffix() {
      this.filter_form.collegeName = this.collegeName
    },
    getRankingFilter() {
      rankingFilter().then(res => {
        this.filter_list = res.data
        this.filter_form.type = res.data.types[0]
        this.filter_form.year = res.data.years[0]
      })
    },
    getUniversitiesRanking() {
      this.loading = true
      universitiesRanking({
        ...this.filter_form, pageNum: this.pageForm.pageNum,
        pageSize: this.pageForm.pageSize
      }).then(res => {
        res.rows.forEach(i => i.universities = i.universities || {})
        this.collegeList = res.rows
        this.pageForm.total = res.total
      }).finally(_ => {
        this.loading = false
      })
    },
    toDetail(item) {
      this.transferTo('/career/plan/UniversityDetail', { code: item.collegeCode })
    },
    onChangePage(page) {
      this.pageForm.pageSize = page.limit
      this.pageForm.pageNum = page.page
      this.getUniversitiesRanking()
    }
  }
}
</script>

<style lang="scss" scoped>
.heat {
  width: 200px;
  height: 72px;
  padding-top: 22px;
  color: #666;
}

.info {
  width: 400px;
}

.index {
  width: 50px;
  flex-shrink: 0;
  text-align: center;
  align-self: center;
}

.img {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  align-self: center;
}

.tags {
  .el-tag {
    height: 16px;
    line-height: 16px;
    font-size: 12px;
    color: #909399;
  }
}

.radioInput ::v-deep {
  display: flex;

  .el-radio-button .el-radio-button__inner {
    border-radius: 4px !important;
    border: none;
    padding: 5px 10px !important;
    font-weight: 400;
    font-family: PingFangSC-Regular, PingFang SC;
  }

  .el-radio-button__orig-radio:checked + .el-radio-button__inner {
    box-shadow: none;
  }

  .radiaTitle {
    display: inline-block;
    width: 80px;
    font-size: 14px;
    text-align: right;
    margin-top: 2px;
    margin-right: 10px;
  }
}

.radioInput ::v-deep {
  display: flex;

  .el-radio-button .el-radio-button__inner {
    border-radius: 4px !important;
    border: none;
    padding: 5px 10px !important;
    font-weight: 400;
    font-family: PingFangSC-Regular, PingFang SC;
  }

  .el-radio-button__orig-radio:checked + .el-radio-button__inner {
    box-shadow: none;
  }

  .radiaTitle {
    display: inline-block;
    width: 80px;
    font-size: 14px;
    text-align: right;
    margin-top: 2px;
    margin-right: 10px;
  }
}

.radioInput ::v-deep {
  background-color: #ffffff;
  font-size: 14px;
  padding: 5px;
}

</style>
