index.vue 9.22 KB
<template>
  <div @wheel="handleWheel" ref="fleetContentBox" :class="{ scrolling: isScrolling }" class="fleet-content-box">
    <!-- 线路信息 -->
    <div v-for="(childItem, childIndex) in item.fleetInfos" :key="childItem.lineName" ref="fleetLineInfoContainer"
      class="fleet-line-info-container">
      <div :id="childItem.lineName" class="fleet-line-title">
        {{ childItem.lineName }}
      </div>
      <div class="line-box" style="height: 2px; margin: 10px 0; background: #d9e0e2;"></div>
      <div ref="fleetNbbmInfoContainer" class="fleet-nbbm-info-container">
        <div v-for="(sunItem, sunIndex) in childItem.lineInfos" :key="sunItem.nbbm" class="fleet-nbbm-info-item">
          <div v-if="sunItem.saleInfoVo != null" class="fleet-nbbm-info-have-sale">
            <el-popover popper-class="fleet-popover-style" placement="top-start" :title="childItem.lineName" :width="320"
              :open-delay="500" :popper-options="{ boundariesElement: 'viewport', removeOnDestroy: true }"
              :show-after="200" @after-enter="alterEnterHandler(sunItem.driverInfoVo.jobCode)">
              <ConstForm :showFlag="personSignInfo.jobCode == sunItem.driverInfoVo.jobCode"
                :currentDateKey="currentDateKey" :jobCode="sunItem.driverInfoVo.jobCode" />
              <template #reference>
                <div class="fleet-nbbm-have-sale-driver" :style="signStyleColor[sunItem.driverInfoVo.signStatus]">
                </div>
              </template>
            </el-popover>
            <div class="fleet-nbbm-have-sale-txt-box">
              <span class="fleet-nbbm-have-sale-txt">
                <span :style="{ color: sunItem.driverInfoVo.signStatus != 1 ? 'white' : 'black' }">
                  {{ sunItem.nbbm.substring(0, Math.floor(sunItem.nbbm.length / 2)) }}</span>
                <span :style="{ color: sunItem.saleInfoVo.signStatus != 1 ? 'white' : 'black' }">
                  {{ sunItem.nbbm.substring(Math.floor(sunItem.nbbm.length / 2), sunItem.nbbm.length) }}
                </span>
              </span>
            </div>
            <el-popover popper-class="fleet-popover-style" placement="top-start" :title="childItem.lineName" :width="320"
              :open-delay="500" :popper-options="{ boundariesElement: 'viewport', removeOnDestroy: true }"
              :show-after="200" @after-enter="alterEnterHandler(sunItem.saleInfoVo.jobCode)">
              <ConstForm :showFlag="personSignInfo.jobCode == sunItem.saleInfoVo.jobCode" :currentDateKey="currentDateKey"
                :jobCode="sunItem.saleInfoVo.jobCode" />
              <template #reference>
                <div class="fleet-nbbm-have-sale-sale" :style="signStyleColor[sunItem.saleInfoVo.signStatus]">
                </div>
              </template>
            </el-popover>
          </div>
          <el-popover v-else :show-after="200" @after-enter="alterEnterHandler(sunItem.driverInfoVo.jobCode)"
            :open-delay="500" :popper-options="{ boundariesElement: 'viewport', removeOnDestroy: true }"
            placement="top-start" :title="childItem.lineName" popper-class="fleet-popover-style" :width="320">
            <ConstForm :showFlag="personSignInfo.jobCode == sunItem.driverInfoVo.jobCode" :currentDateKey="currentDateKey"
              :jobCode="sunItem.driverInfoVo.jobCode" />
            <template #reference>
              <div class="fleet-nbbm-info-no-sale" :style="signStyleColor[sunItem.driverInfoVo.signStatus]">
                <span class="fleet-nbbm-info-no-sale-text">
                  {{ sunItem.nbbm }}
                </span>
              </div>
            </template>
          </el-popover>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import ConstForm from '@/components/ConstForm/index.vue';
import { nextTick, onMounted, reactive, ref } from 'vue';
const popoverRef = ref({});
const props = defineProps({
  item: {
    type: Object,
    required: true
  },
  currentDateKey: {
    type: String,
    required: true
  },
  handleLoadSuccess: {
    type: Function,
    required: true
  },
  signStyleColor: {
    type: Object,
    required: true
  }
})

/** 签到信息 */
const personSignInfo = reactive(
  {
    jobCode: null,
    date: null
  }
);
// 控制滚动
const isScrolling = ref(false);
// 元素信息
const fleetNbbmInfoContainer = ref();
const fleetContentBox = ref();
const fleetLineInfoContainer = ref();
/**
 * 显示弹窗
 * @param {*} val 工号
 */
const alterEnterHandler = (val) => {
  personSignInfo.jobCode = val;
}

/**
 * 处理容器滚动回调函数
 * @param container HTML parent element
 * @param boxContainerElement HTML parent element
 */
const handleContainerScrollCallBack = (container, boxContainerElement) => {
  let element = container[0];
  let parentLength = element.offsetWidth - 1;
  let styles = window.getComputedStyle(element.firstElementChild);
  let margin = Number(styles.marginRight.substring(0, styles.marginRight.length - 2));
  let childLength = element.firstElementChild.offsetWidth - 1 + margin;
  let elementCount = Math.floor(parentLength / childLength);
  let containerLength = elementCount * childLength;
  let surplus = Math.floor((parentLength - containerLength) / 2) - 1;
  boxContainerElement.forEach(boxElement => {
    boxElement.style.paddingLeft = surplus + "px";
    boxElement.style.paddingRight = surplus + "px";
  });
}

/**
 * 鼠标滚轮触发了
 * @param {*} el
 */
const handleWheel = (el) => {
  const containerElement = fleetContentBox.value;
  // 内容溢出
  if (containerElement.scrollHeight > containerElement.clientHeight) {
    // el.preventDefault();
    // 根据滚轮滚动的距离来计算滚动量
    const scrollAmount = el.deltaY > 0 ? 100 : -100;
    // 修改盒子的滚动位置
    containerElement.scrollTop += scrollAmount;
  }
}

onMounted(() => {
  nextTick(() => {
    const containerElement = fleetNbbmInfoContainer.value;
    const boxContainerElement = fleetLineInfoContainer.value;
    try {
      handleContainerScrollCallBack(containerElement, boxContainerElement);
    } catch (error) {
      console.log("元素为空");
    }
    props.handleLoadSuccess(false);
  })
})


</script>

<style lang="scss" scoped>
.fleet-content-box {
  height: calc(100% - clamp(0.8rem, -0.907rem + 5.71vw, 1.3rem));
  width: auto;
  overflow: hidden;

  .scrolling {
    animation: scroll 5s linear infinite;
  }

  @keyframes scroll {
    0% {
      transform: translateY(0);
    }

    100% {
      transform: translateY(-100%);
    }
  }

  // 线路信息
  .fleet-line-info-container {
    width: 100%;
    height: auto;

    .fleet-line-title {
      margin-top: clamp(0.8rem, -0.549rem + 4.09vw, 1.2rem);
      margin-bottom: calc(clamp(0.8rem, -0.549rem + 4.09vw, 1.2rem) - 0.4vw);
      box-sizing: border-box;
      font-weight: bold;
    }

    .fleet-nbbm-info-container {
      width: 100%;
      height: auto;
      box-sizing: border-box;
      display: flex;
      flex-wrap: wrap;
      font-size: 0.8vw;

      .fleet-nbbm-info-item {
        width: 6vw;
        height: 2.4vh;
        box-sizing: border-box;
        margin-top: 0.4vw;
        margin-right: 0.4vw;
        color: black;

        .fleet-nbbm-info-have-sale {
          width: 100%;
          height: 100%;
          display: flex;

          .fleet-nbbm-have-sale-driver {
            border-radius: 1 solid #0761ba;
            border-radius: 5px 0 0 5px;
            height: 100%;
            width: 100%;
            margin-right: 0.2vw;
            position: relative;
            display: flex;
            align-items: center;
          }

          .fleet-nbbm-have-sale-sale {
            width: 100%;
            height: 100%;
            border-radius: 0 5px 5px 0;
            display: flex;
            justify-content: center;
            align-items: center;
          }

          .fleet-nbbm-have-sale-txt-box {
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;

            .fleet-nbbm-have-sale-txt {
              position: absolute;
              width: auto;
              /* 防止文字换行 */
              white-space: nowrap;

              padding-left: 0.5vw;
              padding-right: 0.5vw;
              /** 防止元素遮挡 */
              pointer-events: none;
            }
          }
        }

        .fleet-nbbm-info-no-sale {
          width: 100%;
          height: 100%;
          position: relative;
          display: flex;
          justify-content: center;
          align-items: center;
          box-sizing: border-box;
          border-radius: 5px;

          /* 防止文字换行 */
          .fleet-nbbm-info-no-sale-text {
            position: absolute;
            width: auto;
            white-space: nowrap;
            padding-left: 0.5vw;
            padding-right: 0.5vw;
            /* 防止文字换行 */
          }
        }
      }
    }
  }
}
</style>
<style>
.fleet-popover-style {
  color: black !important;
  margin: 10px 0 10px 0;
  min-width: 100px;
}

.el-popover.fleet-popover-style {
  border-color: #f4f4f5;
}

.fleet-popover-style .el-popover__title {
  color: black;
  font-weight: bold;
}

.el-popper[data-popper-placement^=top]>.el-popper__arrow::before {
  border-top-color: rgba(244, 244, 245, 0.735) !important;
  background-color: rgba(244, 244, 245, 0.735) !important;
}
</style>