<template>
  <div class="hot-box">
    <div class="sub-li" v-for="(item, index) in list" :key="index">
      <div v-if="item">
        <!-- 公司信息 -->
        <div class="company-info-top align-center" @click="handleClickEnterprise(item)">
          <div class="float-left">
            <v-img :src="item?.enterprise.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" alt="" width="77" height="77" style="border-radius: 4px;"/>
          </div>
          <div class="company-info cursor-pointer">
            <h3>{{ item.enterprise.anotherName }}</h3>
            <p>
              {{ item?.enterprise.financingName }}
              <span class="septal-line" v-if="item.enterprise.financingName && item.enterprise.scaleName"></span>
              {{ item?.enterprise.scaleName }}
              <span class="septal-line" v-if="item.enterprise.industryName"></span>
              {{ item?.enterprise.industryName }}
            </p>
          </div>
        </div>
        <div class="px-5 py-1 ellipsis" :style="{'height': '33px', 'border-bottom': item.enterprise.welfareList && item.enterprise.welfareList.length ? '1px solid #EBEBEB;' : 'none'}">
          <span class="welfareTag mr-5" v-for="(k, i) in item.enterprise.welfareList" :key="i">{{ k }}</span>
        </div>
        <!-- 职位列表 -->
        <ul class="company-job-list">
          <li class="company-job-item" v-for="(k, i) in item.jobList" :key="i" :class="{'company-job-item-hover': k.active}" @mouseenter="k.active = true" @mouseleave="k.active = false" @click="handleClickPosition(k)">
            <div class="job-info" @mouseenter="k.active = true" @mouseleave="k.active = false" @click="handleClickPosition(k)">
              <div class="mb-2 d-flex">
                <p :class="['name', 'cursor-pointer', {'default-active': k.active }]">{{ k.name }}</p>
                <span v-if="!k.payFrom && !k.payTo" class="salary">面议</span>
                <span v-else class="salary">{{ k.payFrom ? k.payFrom + '-' : '' }}{{ k.payTo }}{{ k.payName ? '/' + k.payName : '' }}</span>
              </div>
              <div style="height: 24px; overflow: hidden; color: #808080;">
                <span v-for="(j, index) in desc" :key="index">
                  <span v-if="k[j.value]" class="mr-1 font-size-13">{{ k[j.value] }}</span>
                  <span v-if="k[j.value] && index !== desc.length - 1 && k[desc[index + 1].value]" class="septal-line ml-1"></span>
                </span>
                <span class="font-size-13 float-right">{{ timesTampChange(k.updateTime, 'Y-M-D') }}</span>
              </div>
            </div>
          </li>
        </ul>
        <div class="moreBtn d-flex align-center justify-center" @click="handleMoreEnterprise(item)" @mouseenter="item.active = true" @mouseleave="item.active = false">
          <span :style="{'text-decoration': item.active ? 'underline' : 'none'}">{{ $t('position.moreBtn') }}</span>
          <v-icon>mdi-menu-right</v-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="hotPromoted">
import { ref, watch } from 'vue'
import { timesTampChange } from '@/utils/date'

const props = defineProps({
  items: {
    type: Array,
    default: () => []
  }
})
const list = ref([])
watch(
  () => props.items, 
  (newVal) => {
    list.value = newVal
  },
  { immediate: true },
  { deep: true }
)
const desc = [
  { value: 'areaName' },
  { value: 'eduName' },
  { value: 'expName' }
]

// 职位详情
const handleClickPosition = (k) => {
  window.open(`/recruit/personal/position/details/${k.id}`)
}
// 企业详情
const handleClickEnterprise = (item) => {
  window.open(`/recruit/personal/company/details/${item.enterprise.id}?key=briefIntroduction`)
}

// 查看更多职位
const handleMoreEnterprise = (item) => {
  if (!item.enterprise.id) return
  window.open(`/recruit/personal/company/details/${item.enterprise.id}?key=recruitmentPositions`)
}
</script>

<style lang="scss" scoped>
.hot-box {
  display: flex;
  flex-wrap: wrap;
}
.sub-li {
  position: relative;
  width: calc((100% - 24px) / 3);
  min-width: calc((100% - 24px) / 3);
  max-width: calc((100% - 24px) / 3);
  margin: 0 12px 12px 0;
  height: 360px;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  transition: all .2s linear;
  background-color: #fff;
  box-shadow: 0 2px 20px 0 rgba(37, 39, 48, .2);
  &:nth-child(3n) {
    margin-right: 0;
  }
}
.company-info {
  float: left;
  margin-left: 16px;
  width: 282px;
}
.company-info-top {
  display: flex;
  height: 110px;
  padding: 16px 20px;
  overflow: hidden;
  border-bottom: 1px solid #EBEBEB;
  &:hover {
    background-color: #f2f4f7;
  }
}
.welfareTag {
  color: #CEC149;
  font-size: 13px;
}
.company-info h3 {
  height: 22px;
  font-size: 18px;
  font-weight: 700;
  color: #404040;
  line-height: 22px;
  margin: 0 0 4px 0;
  padding: 0;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  &:hover {
    color: var(--v-primary-base);
  }
}
.company-info p {
  height: 18px;
  font-size: 13px;
  font-weight: 400;
  color: var(--color-999);
  line-height: 18px;
}
.company-job-list {
  padding: 4px 20px 12px;
}
ul li {
  list-style: none
}
.company-job-item {
  display: block;
  height: auto;
  padding: 12px 0;
  margin: 0;
  &-hover {
    background-color: #f2f4f7;
  }
}
.salary {
  font-size: 16px;
  float: right;
  font-weight: 700;
  color: #CEC149;
  line-height: 22px;
  max-width: none;
  text-align: right;
  flex: 1;
}
.name {
  position: relative;
  max-width: 200px;
  line-height: 22px;
  font-weight: 700;
  color: #404040;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all linear .2s;
}
.moreBtn {
  position: absolute;
  width: 100%;
  bottom: 0;
  height: 47px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  background: linear-gradient(to right, #12ebb0, #427daa);
}
</style>