<template>
  <div>
    <div v-if="items.length" class="mt-3">
      <div class="positionItem" v-for="(item, index) in items" :key="index" @mouseenter="item.active = true" @mouseleave="item.active = false">
        <div class="position-and-company">
          <div class="position">
            <div class="float-left">
              <v-img :src="getUserAvatar(item?.contact.avatar, item?.contact.sex)" :width="40" style="height: 40px;border-radius: 4px;"/>
            </div>
            <div class="company-info">
              <h3 :class="{'default-active': item.active }" class="title1">{{ item.contact.name }}</h3>
              <p class="mt-2">{{ item?.post?.nameCn }}</p>
            </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">
              <h3 :class="{'default-active': item.active }" class="title1 cursor-pointer">{{ item.enterprise.anotherName }}</h3>
              <p class="mt-2">{{ item.enterprise.financingName }}<span class="mx-2">|</span>{{ item.enterprise.scaleName }}<span class="mx-2">|</span>{{ item.enterprise.industryName }}</p>
            </div>
          </div>
        </div>
        <div class="footer">
          {{ $t('position.viewTime') + timesTampChange(item.updateTime)  }}
        </div>
      </div>
      <CtPagination
        :total="total"
        :page="page.pageNo"
        :limit="page.pageSize"
        @handleChange="handleChangePage"
      ></CtPagination>
    </div>
    <Empty v-else></Empty>
  </div>
</template>

<script setup>
// 看过我
defineOptions({ name: 'position-seen-me' })
import { ref } from 'vue'
import { getInterestedMePage } from '@/api/recruit/personal/personalCenter'
import { dealDictObjData } from '@/utils/position'
import { timesTampChange } from '@/utils/date'
import Empty from '@/components/Empty'
import { getUserAvatar } from '@/utils/avatar'

const total = ref(0)
const items = ref([])
const page = ref({
  pageNo: 1,
  pageSize: 10
})

const getData = async () => {
  const res = await getInterestedMePage(page.value)
  items.value = res.list.map(e => {
    e.enterprise = dealDictObjData({}, e.enterprise)
    e.active = false
    return e
  })
  total.value = res.total
}
getData()

const handleChangePage = (e) => {
  page.value.pageNo = e
  getData()
}

const handleEnterprise = (item) => {
  const id = item.enterprise.id
  if (!id) return
  window.open(`/recruit/personal/company/details/${id}?key=briefIntroduction`)
}

</script>

<style scoped lang="scss">
.title1 {
  color: var(--color-666);
  position: relative;
  max-width: 200px;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  &:hover {
    color: var(--v-primary-base);
  }
}
.company {
  flex: 1;
  display: flex;
  justify-content: end;
}
.company-info {
  float: left;
  margin-left: 16px;
}
.company-info p {
  height: 18px;
  font-size: 13px;
  font-weight: 400;
  color: var(--color-999);
}
.textColor666 { color: var(--color-666); }
.positionItem {
  margin-bottom: 12px;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  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: 484px;
      padding-right: 12px;
    }
  }
}
.footer {
  height: 36px;
  line-height: 36px;
  padding: 0px 20px;
  font-size: 14px;
  color: var(--color-999);
  background: linear-gradient(90deg, #f5fcfc 0, #fcfbfa 100%);
}
</style>
