<template>
  <div v-loading="loading">
    <filter-form :filter="filter_form" multiple></filter-form>
    <mx-search-group justify="end" v-model="collegeName" @search="clickSuffix">
      <p>共 <span class="f-primary">{{ pageForm.total }}</span> 条</p>
    </mx-search-group>
    <el-row class="mt10 ">
      <div v-if="pageForm.total > 0">
        <div class="list-wrap pl30">
          <div class="fx-row ai-cen mb30" v-for="item in collegeList">
            <div class="img">
              <img style="width: 100%;height: 100%" :src="item.logo" alt="">
            </div>
            <div class="info ml20">
              <div class="college_name pointer f-333 f20 mb5" @click="toDetail(item)">{{ item.name }}</div>
              <div class="tags" v-if="item.features">
                <span class="mr5 el-tag el-tag--info el-tag--plain"
                      v-for="feature in item.features.split(',')">{{ feature }}</span>
              </div>
              <div class="college-desc mt5 f14 f-666">
                <p>
                  {{ `${item.location} ${item.cityName} ${item.type} / ${item.natureTypeCN} / ${item.managerType} ` }}</p>
              </div>
            </div>
            <div class="heat f12 f-666">
              <p>排名</p>
              <p class="mt3">{{ `第${item.ranking}名 / 综合指数${item.comScore}` }}</p>
            </div>
            <div class="heat f12  f-666">
              <p>热度</p>
              <p class="mt3">{{ (item.hits / 10000).toFixed(1) }}万</p>
            </div>
          </div>
        </div>
        <pagination class="mt10" :total="pageForm.total" :autoScroll="false" @pagination="onChangePage"
                    :page.sync="pageForm.pageNum"
                    :limit.sync="pageForm.pageSize"
        ></pagination>
      </div>
      <evaluation-empty v-else shadow title="暂无数据"></evaluation-empty>
    </el-row>
  </div>
</template>

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

export default {
  mixins: [transferMixin],
  components: { MxSearchGroup, FilterForm },
  data() {
    return {
      filter_form: {
        location: [],
        natureTypeCN: [],
        type: [],
        level: [],
        features: [],
        name: ''
      },
      loading: false,
      collegeName: '',
      pageForm: {
        pageSize: 10,
        pageNum: 1,
        total: 0
      },
      filter_list: {},
      collegeList: []
    }
  },
  watch: {
    filter_form: {
      immediate: true,
      deep: true,
      handler(val) {
        this.getUniversityList()
      }
    }
  },
  methods: {
    toDetail(item) {
      this.transferTo('/career/plan/UniversityDetail', { code: item.code })
    },
    onChangePage(page) {
      this.pageForm.pageSize = page.limit
      this.pageForm.pageNum = page.page
      this.getUniversityList()
    },
    clickSuffix() {
      this.filter_form.name = this.collegeName
    },
    formatFilterForm() {
      const result = {}
      Object.keys(this.filter_form).forEach(key => result[key] = this.filter_form[key].toString())
      return result
    },
    getUniversityList() {
      this.loading = true
      // console.log(params)
      selectUniversityList({
        ...this.formatFilterForm(),
        pageNum: this.pageForm.pageNum,
        pageSize: this.pageForm.pageSize
      }).then(res => {
        this.pageForm.total = res.total
        this.collegeList = res.rows
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

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

.info {
  width: 400px;
}

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

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


</style>
