<!-- 搜索页面的职位详情-长条 -->
<template>
  <div class="positionItem" v-for="(item, index) in list" :key="index" @mouseenter="item.active = true" @mouseleave="item.active = false">
    <div class="position-and-company">
      <!-- 职位 -->
      
      <div class="position" @mouseenter="item.positionActive = true" @mouseleave="item.positionActive = false" @click="handlePosition(item)">
        <div class="d-flex">
          <div v-if="item?.job?.hire" class="mr-3">
            <svg-icon name="pin" size="45"></svg-icon>
          </div>
          <div>
            <div class="d-flex">
              <p v-if="item.job.name.indexOf('style')" v-html="item.job.name" :class="['title1', {'default-active': item.positionActive }]"></p>
              <p v-else :class="['title1', {'default-active': item.positionActive }]">{{ item.job.name }}{{ item.job.pos ? ' [' + item.job.pos + '] ' : '' }}</p>
              <p class="salary ml-1">{{ item.job.payFrom }}-{{ item.job.payTo }}/{{ item.job.payName }}</p>
              <div v-if="item?.job?.hire">
                <v-chip v-if="item?.job?.hirePrice && item?.job?.hirePrice > 0" class="ml-3" label color="primary" size="small">赏金：{{ commissionCalculation(item.job.hirePrice, 1) }}元</v-chip>
                <v-chip v-if="item?.job?.hirePoint && item?.job?.hirePoint > 0" class="ml-3" label color="primary" size="small">积分：{{ commissionCalculation(item.job.hirePoint, 1) }}点</v-chip>
              </div>
            </div>
            <div class="mt-2">
              <span v-for="(j, i) in desc" :key="i">
                <v-chip v-if="item.job[j.value]" size="x-small" label class="mr-1" color="var(--color-666)" :prepend-icon="j.mdi">{{ item.job[j.value] }}</v-chip>
              </span>
            </div>
          </div>
        </div>
      </div>
      <!-- 公司 -->
      <div class="company" @click="handleEnterprise(item)">
        <div class="float-left">
          <v-img :src="item?.enterprise.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" :alt="item.enterprise.anotherName" :width="40" style="height: 40px;border-radius: 4px;"/>
        </div>
        <div class="company-info">
          <v-hover>
            <template v-slot:default="{ isHovering, props }">
              <h3 v-bind="props" :class="{'default-active': isHovering }" class="title1">{{ item.enterprise.anotherName }}</h3>
            </template>
          </v-hover>
          <p class="mt-2">
            {{ item.enterprise.financingName }}
            <span class="mx-2" v-if="item.enterprise.financingName && item.enterprise.industryName">|</span>
            {{ item.enterprise.scaleName }}
            <span class="mx-2" v-if="item.enterprise.scaleName && item.enterprise.industryName">|</span>
            {{ item.enterprise.industryName }}
          </p>
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="footer">
      <div class="footer-left">
        <template v-for="(jobTag, jobTagsIndex) in item.job.tagList" :key="jobTagsIndex">
          <span class="textColor666 mx-1" v-if="jobTagsIndex">|</span>
          <span class="textColor666 dis">{{ jobTag }}</span>
        </template>
      </div>
      <div class="footer-right">
        <v-avatar size="x-small" :image="getUserAvatar(item.contact.avatar, item.contact.sex)"></v-avatar>
        <span class="mx-2 textColor666">
          {{ item.contact.name }}
          <span v-if="item?.contact?.postNameCn">|</span>
          {{ item.contact.postNameCn }}
        </span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { commissionCalculation } from '@/utils/position'
defineOptions({ name: 'long-strip-position-card-item' })
import { ref, watch } from 'vue'
import { getUserAvatar } from '@/utils/avatar'
const props = defineProps({
  items: {
    type: Object,
    default: () => ({ data: [], total: 0 })
  }
})
const list = ref([])
watch(
  () => props.items, 
  (newVal) => {
    list.value = newVal
  },
  { immediate: true },
  { deep: true }
)

const desc = [
  { mdi: 'mdi-map-marker-outline', value: 'areaName' },
  { mdi: 'mdi-school-outline', value: 'eduName' },
  { mdi: 'mdi-clock-time-ten-outline', value: 'expName' }
]

const handlePosition = (item) => {
  const id = item.job.id // item.job.positionId
  if (!id) return
  window.open(`/recruit/personal/position/details/${id}`)
}
const handleEnterprise = (item) => {
  const id = item.enterprise.id // item.enterprise.enterpriseId
  if (!id) return
  window.open(`/recruit/personal/company/details/${id}?key=briefIntroduction`)
}
</script>

<style lang="scss" scoped>
.title1 {
  position: relative;
  max-width: 200px;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 600;
  &:hover {
    color: var(--v-primary-base);
  }
}
.company {
  flex: 1;
  display: flex;
  justify-content: start;
}
.company-info {
  float: left;
  margin-left: 16px;
  // width: 282px;
}
.company-info p {
  height: 18px;
  font-size: 13px;
  font-weight: 400;
  color: var(--color-999);
}
.textColor666 { color: var(--color-666); }
.positionItem {
  width: 850px;
  margin-bottom: 12px;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: all .2s linear;
  background-color: #fff;
  &:hover {
    box-shadow: 0 16px 40px 0 rgba(153, 153, 153, .3);
  }
  .position-and-company {
    display: flex;
    padding: 16px 20px;
    width: 100%;
    .position {
      width: 500px;
      padding-right: 30px;
    }
  }
  .footer {
    height: 48px;
    line-height: 48px;
    padding: 0px 20px;
    font-size: 14px;
    background: linear-gradient(90deg, #f5fcfc 0, #fcfbfa 100%);
    display: flex;
    .footer-left {
      width: 440px;
      padding-right: 12px;
    }
    .footer-right {
      flex: 1;
      text-align: right;
    }
    div {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .ellipsisStyle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.salary {
  font-size: 16px;
  font-weight: 700;
  color: var(--v-error-base);
  line-height: 22px;
  flex: none;
}
</style>