<template>
  <div class="d-flex">
    <div class="position-box">
      <div class="sub-li" v-for="(item, index) in props.items" :key="index" :style="{'height': tab === 3 && item.hire ? '180px' : '149px'}">
        <div class="job-info" @click.stop="handlePosition(item)" @mouseenter="item.active = true" @mouseleave="item.active = false">
          <div class="sub-li-top">
            <div class="sub-li-info">
              <p :class="['name', {'default-active': item.active }]">{{ formatName(item.name) }}</p>
              <svg-icon v-if="tab === 3 && item.hire" name="pin" size="30"></svg-icon>
            </div>
          </div>
          <div class="d-flex justify-space-between align-center">
            <div>
              <span v-for="(j, i) in desc" :key="i" class="font-size-13" style="color: #808080;">
                <span
                  v-if="item[j.value] || j.value === 'areaName'"
                  class="mr-1 d-inline-block"
                >
                {{ j.value === 'areaName' ? !item.areaId ? '全国' : item.area?.str : item[j.value] }}
                  <!-- {{ (j.value === 'areaName' && !item.areaId) ? '全国' :  item[j.value] }} -->
                </span>
                <span
                  v-if="i !== desc.length - 1 && (item[j.value] || (j.value === 'areaName' && !item.areaId)) && item[desc[i + 1].value]"
                  class="septal-line ml-1"
                >
                </span>
              </span>
            </div>
            <div>
              <p v-if="!item.payFrom && !item.payTo" class="salary">面议</p>
              <p v-else class="salary">{{ item.payFrom ? item.payFrom + '-' : '' }}{{ item.payTo }}{{ item.payName ? '/' + item.payName : '' }}</p>
            </div>
          </div>
          <div v-ellipse-tooltip.top class="ellipsis" style="height: 24px;overflow: hidden;">
            <span v-for="(j, i) in item.tagList" :key="i" class="mr-3 tags" style="color: #345768;">{{ j }}</span>
          </div>
          <div v-if="tab === 3 && item.hire" class="text-end mt-3">
            <v-chip v-if="item.hirePrice" size="small" label color="primary">赏金：{{ commissionCalculation(item.hirePrice / 100, 1) }}元</v-chip>
            <v-chip v-if="item.hirePoint" size="small" label class="ml-1" color="primary">积分：{{ commissionCalculation(item.hirePoint / 100, 1) }}点</v-chip>
          </div>
          <div v-if="tab === 2" class="font-size-14 mb-3 text-end" style="color: #345768;">发布时间：{{ timesTampChange(item.createTime, 'Y-M-D h:m') }}</div>
        </div>
        <div class="sub-li-bottom" @click.stop="jumpToEnterpriseDetail(item.enterpriseId, isOpenWindow)">
          <div class="user-info">
            <div class="d-flex align-center">
              <v-avatar size="35">
                <v-img :src="item.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" />
              </v-avatar>
              <span v-ellipse-tooltip.top class="names ml-2 font-size-14 ellipsis" style="max-width: 88%;">
                {{ formatName(item.anotherName || item.enterpriseName) }}
                <span class="color-999 font-size-13 ml-3">
                  <span>{{ item.industryName }}</span>
                  <span class="septal-line" v-if="item.industryName && item.scaleName"></span>
                  <span>{{ item.scaleName }}</span>
                </span>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
defineOptions({ name: 'position-card-item' })
import { ref, watch } from 'vue'
import { commissionCalculation, jumpToEnterpriseDetail } from '@/utils/position'
import { timesTampChange } from '@/utils/date'
import { formatName } from '@/utils/getText'

const props = defineProps({
  items: {
    type: Array,
    default: () => []
  },
  tab: {
    type: Number,
    default: 1
  },
  isOpenWindow: {
    type: Boolean,
    default: true
  }
})
// const list = ref([])
// watch(
//   () => props.items, 
//   (newVal) => {
//     console.log(123, 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 emits = defineEmits(['position', 'enterprise'])
const handlePosition = (item) => {
  emits('position', item)
}
</script>

<style lang="scss" scoped>
.position-box {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  height: 100%;
}
.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;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: all .2s linear;
  background-color: #fff;
  &:nth-child(3n) {
    margin-right: 0;
  }
  &:hover {
    box-shadow: 0 2px 12px 0 rgba(153, 153, 153, 1);
  }
}
.job-info {
  position: relative;
  padding: 16px 20px;
}
.recommend {
  position: absolute;
  left: 0;
  top: 0;
}
.sub-li-top {
  display: flex;
  width: 100%;
  align-items: center;
}
.sub-li-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  height: 31%;
  overflow: hidden;
  flex: 1;
}
.salary {
  font-size: 16px;
  font-weight: 700;
  color: #CEC149;
  line-height: 22px;
  flex: none;
}
.tags {
  font-size: 12px;
  color: #666;
  display: inline-block;
}
.job-text {
  white-space: normal;
  padding-right: 0;
  height: 22px;
  line-height: 22px;
  overflow: hidden;
  word-break: break-all;
  max-width: none;
}
.sub-li-info .name {
  position: relative;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: #345768;
  &:hover {
    color: var(--v-primary-base);
  }
}
.sub-li-bottom {
  position: absolute;
  width: 100%;
  height: 54px;
  bottom: 1px;
  left: 0;
  margin-top: 10px;
  padding-top: 0;
  display: block;
  border: none;
}
.user-info {
  // display: flex;
  padding: 10px 20px 12px;
  // align-items: center;
  // justify-content: space-between;
  background-color: #b2dfdb2b;
}
.names {
  font-weight: 500;
  color: #404040;
  &:hover {
    color: var(--v-error-base);
  }
}
</style>