<template>
  <div class="d-flex">
    <div class="position-box">
      <div class="sub-li" v-for="(item, index) in list" :key="index">
        <div class="job-info" @click="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 }]">{{ item.name }}</p>
              <svg-icon v-if="tab === 3 && item.hire" name="pin" size="30"></svg-icon>
            </div>
            <p class="salary">{{ item.payFrom }}-{{ item.payTo }}/{{ item.payName }}</p>
          </div>
          <div style="height: 24px;overflow: hidden;">
            <v-chip size="x-small" label v-for="(k, i) in item.tagList" :key="i" class="mr-1" color="var(--color-666)">{{ k }}</v-chip>
          </div>
          <div class="d-flex justify-space-between align-center">
            <div>
              <span v-for="(j, i) in desc" :key="i">
                <v-chip v-if="item[j.value]" size="x-small" label class="mr-1" color="var(--color-666)" :prepend-icon="j.mdi">{{ item[j.value] }}</v-chip>
              </span>
            </div>
          </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, 1) }}元</v-chip>
            <v-chip v-if="item.hirePoint" size="small" label class="ml-1" color="primary">积分：{{ commissionCalculation(item.hirePoint, 1) }}点</v-chip>
          </div>
        </div>
        <div class="sub-li-bottom" @click="handleEnterprise(item)">
          <div class="user-info">
            <div class="d-flex align-center">
              <v-img :src="item.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" width="40" style="height: 40px;" />
              <span class="names ml-2" style="font-size: 14px">{{ item.anotherName }}</span>
            </div>
            <p class="names float-right">
              <span>{{ item.industryName }}</span>
              <span class="septal-line" v-if="item.industryName && item.scaleName"></span>
              <span>{{ item.scaleName }}</span>
            </p>
          </div>
        </div>
      </div>
    </div>
    <!-- 滚动提现数据 -->
    <div class="pa-3 white-bgc" :style="{height:height}" style="flex: 1; border-radius: 5px; margin: 0 12px 12px 0;">
      <bountyDisplay></bountyDisplay>
    </div>
  </div>
</template>

<script setup>
import bountyDisplay from '@/views/publicRecruitment/components/bountyDisplay.vue'

defineOptions({ name: 'position-card-item' })
import { ref, watch } from 'vue'
import { commissionCalculation } from '@/utils/position'

const props = defineProps({
  items: {
    type: Array,
    default: () => []
  },
  tab: {
    type: Number,
    default: 1
  }
})
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 emits = defineEmits(['position', 'enterprise'])
const handlePosition = (item) => {
  emits('position', item)
}
const handleEnterprise = (item) => {
  emits('enterprise', item)
}

const height = ((210 * 2) + 12) + 'px'
</script>

<style lang="scss" scoped>
.position-box {
  display: flex;
  flex-wrap: wrap;
  width: 66.66%;
  
}
.sub-li {
  position: relative;
  // width: calc((100% - 24px) / 3);
  width: calc((100% - 24px) / 2);
  min-width: calc((100% - 24px) / 2);
  max-width: calc((100% - 24px) / 2);
  margin: 0 12px 12px 0;
  height: 210px;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: all .2s linear;
  background-color: #fff;
  &:nth-child(2n) { // 3n
    margin-right: 0;
  }
  &:hover {
    box-shadow: 0 16px 40px 0 rgba(153, 153, 153, .3);
  }
}
.job-info {
  position: relative;
  padding: 16px 20px;
}
.recommend {
  position: absolute;
  left: 0;
  top: 0;
}
.sub-li-top {
  display: flex;
  width: 100%;
  align-items: center;
  margin-bottom: 12px;
}
.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: var(--v-error-base);
  line-height: 22px;
  flex: none;
}
.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;
  max-width: 140px;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  &:hover {
    color: var(--v-primary-base);
  }
}
.sub-li-bottom {
  position: absolute;
  width: 100%;
  bottom: -6px;
  left: 0;
  background: linear-gradient(90deg, #f5fcfc 0, #fcfbfa 100%);
  margin-top: 10px;
  padding-top: 0;
  display: block;
  border: none;
}
.user-info {
  display: flex;
  padding: 12px 20px;
  align-items: center;
  justify-content: space-between;
}
.names {
  color: var(--color-666);
  font-size: 13px;
  &:hover {
    color: var(--v-primary-base);
  }
}
</style>