<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" :class="{'elevation-5': item.active}" @click.stop="jumpToEnterpriseDetail(item.enterprise.id, false)" @mouseenter="item.active = true" @mouseleave="item.active = false">
          <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 v-ellipse-tooltip class="MiSans-Semibold">{{ formatName(item.enterprise.anotherName || item.enterprise.name) }}</h3>
            <p>
              {{ item?.enterprise.scaleName }}
              <span class="septal-line" v-if="item.enterprise.industryName"></span>
              {{ item?.enterprise.industryName }}
            </p>
          </div>
        </div>

        <div class="mx-4 py-2" style="height: 35px;" :style="{'border-bottom': item?.enterprise?.welfareTagStr ? '1px solid #EBEBEB' : 'none'}">
          <div v-ellipse-tooltip class="welfareTag ellipsis-tag">{{ item.enterprise.welfareTagStr }}</div>
        </div>

        <!-- 职位列表 -->
        <ul class="company-job-list pt-3">
          <li v-for="(k, i) in item.jobList" :key="i" @mouseenter="k.active = true" @mouseleave="k.active = false" @click="handleClickPosition(k)">
            <v-card :elevation="k.active ? 5 : 0" class="company-job-item cursor-pointer mb-3">
              <div class="mb-2 d-flex">
                <span v-ellipse-tooltip :class="['name', 'cursor-pointer', {'default-active': k.active }]" :style="{'max-width': !k.payFrom && !k.payTo ? '290px' : '200px'}">{{ formatName(k.name) }}</span>
                <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 class="d-flex font-size-13" style="height: 24px; overflow: hidden; color: #808080; line-height: 24px;">
                <div class="text-truncate mr-3" style="flex: 1">
                  <span v-for="(j, index) in desc" :key="index">
                    <span v-if="k[j] || j === 'areaName'" class="mr-1">
                      {{ j === 'areaName' ? !k.areaId ? '全国' : k.area?.str : k[j] }}
                    </span>
                    <span v-if="index !== desc.length - 1 && (k[j] || j === 'areaName') && k[desc[index + 1]]" class="septal-line ml-1"></span>
                  </span>
                </div>
                <div style="width: 73px;">{{ timesTampChange(k.updateTime, 'Y-M-D') }}</div>
              </div>
            </v-card>
          </li>
        </ul>
        <div class="moreBtn d-flex align-center justify-center" @click.stop="handleMoreEnterprise(item)">
          <span>{{ $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'
import { formatName } from '@/utils/getText'
import { jumpToEnterpriseDetail } from '@/utils/position'
import { useRouter } from 'vue-router'

const props = defineProps({
  items: {
    type: Array,
    default: () => []
  }
})

const router = useRouter()

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

// 职位详情
const handleClickPosition = (k) => {
  router.push(`/recruit/personal/position/details/${k.id}`)
}

// 查看更多职位
const handleMoreEnterprise = (item) => {
  if (!item.enterprise.id) return
  const name = formatName(item.enterprise.anotherName || item.enterprise.name)
  window.open(`/recruit/personal/position?content=${name.includes('&') ? encodeURIComponent(name) : name}`)
}
</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: 373px;
  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;
  }
}
.ellipsis-tag {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #00B760 !important;
}
.company-info {
  float: left;
  margin-left: 16px;
  width: 262px;
}
.company-info-top {
  display: flex;
  height: 90px;
  margin: 12px 12px 0 12px;
  padding: 0 12px;
  overflow: hidden;
  border-bottom: 1px solid #EBEBEB;
  border-radius: 8px;
}
.welfareTag {
  color: #00B760;
  font-size: 13px;
}
.company-info h3 {
  height: 22px;
  font-size: 18px;
  color: #0E100F;
  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 10px 12px;
}
ul li {
  list-style: none
}
.company-job-item {
  display: block;
  height: auto;
  padding: 12px 10px;
  margin: 0;
  border-radius: 8px;
}
.salary {
  font-size: 16px;
  float: right;
  font-family: MiSans-Medium;
  color: #00B760;
  line-height: 22px;
  max-width: none;
  text-align: right;
  flex: 1;
}
.name {
  position: relative;
  line-height: 22px;
  font-weight: 700;
  color: #0E100F;
  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);
  &:hover {
    font-size: 16px;
    span {
      font-weight: 700;
    }
  }
}
</style>
