genderCompare.vue 5.04 KB
<template>
  <div class="gender-compare">
    <ul class="gender-box-top">
      <li class="gender-top-item">
        <div class="bar-num">{{ headerData.maleTraffic || '--' }}</div>
        <div>
          <img src="~@/assets/img/man.png" alt="" class="gender-man-img">
          <span class="bar-title">{{ $t('head.man') }}</span>
        </div>
        <div class="gender-progress-bars">
          <span class="feature-progress male-feature-progress" :style="{ width: computedProgress(true, headerData.maleTraffic, headerData.femaleTraffic, 'width') }"></span>
        </div>
      </li>
      <li class="gender-top-item">
        <div class="bar-num">{{ headerData.femaleTraffic || '--' }}</div>
        <div>
          <img src="~@/assets/img/woman.png" alt="" class="gender-woman-img">
          <span class="bar-title woman-bar-title">{{ $t('head.woman') }}</span>
        </div>
        <div class="gender-progress-bars">
          <span class="feature-progress female-feature-progress" :style="{ width: computedProgress(false, headerData.maleTraffic, headerData.femaleTraffic, 'width') }"></span>
        </div>
      </li>
      <li class="gender-top-item">
        <div class="bar-num">{{ computedProgress(true, headerData.maleTraffic, headerData.femaleTraffic, 'ratio') }}</div>
        <div>
          <img src="~@/assets/img/huiyuan.png" alt="" class="gender-huiyuan-img">
          <span class="bar-title huiyuan-bar-title">{{ $t('head.man') }}</span>
        </div>
        <div class="gender-progress-bars">
          <span class="feature-progress huiyuan-feature-progress" :style="{ width: computedProgress(true, headerData.maleTraffic, headerData.femaleTraffic, 'width') }"></span>
        </div>
      </li>
      <li class="gender-top-item">
        <div class="bar-num">{{ computedProgress(false, headerData.maleTraffic, headerData.femaleTraffic, 'ratio') }}</div>
        <div>
          <img src="~@/assets/img/feihuiyuan.png" alt="" class="gender-feihuiyuan-img">
          <span class="bar-title feihuiyuan-bar-title">{{ $t('head.woman') }}</span>
        </div>
        <div class="gender-progress-bars">
          <span class="feature-progress feihuiyuan-feature-progress" :style="{ width: computedProgress(false, headerData.maleTraffic, headerData.femaleTraffic, 'width') }"></span>
        </div>
      </li>
    </ul>
    <ul class="gender-box-bottom">
      <li class="gender-bottom-item">
        <div>
          <img src="~@/assets/img/dianyuan.png" alt="">
          <span class="gender-bottom-title">{{ $t('head.clerkNum') }}</span>
        </div>
        <div class="bottom-text">{{ headerData.staffManTime || 0 }}</div>
      </li>
      <li class="gender-bottom-item">
        <div>
          <img src="~@/assets/img/chongfu.png" alt="">
          <span class="gender-bottom-title">{{ $t('head.repeatTraff') }}</span>
        </div>
        <div class="bottom-text">{{ computedRepeat(headerData) }}</div>
      </li>
      <li class="gender-bottom-item">
        <div>
          <img src="~@/assets/img/youxiao.png" alt="">
          <span class="gender-bottom-title">{{ $t('head.effectiveTraff') }}</span>
        </div>
        <div class="bottom-text">{{ headerData.effectiveTraffic || '--' }}</div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'genderCompare',
  props: {
    headerData: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
     headerData: {
       handler(newVal) {
         if(newVal) {}
       },
       deep: true
     },
  },
  data() {
    return {}
  },
  methods: {
    /**
     * 计算进度
     * @param {boolean} isMan
     * @param {number|string} maleNum
     * @param {number|string} femaleNum
     * @param {string} computeType
     * @param {number|string} effecticeNum
     * @returns {string|number}
     */
    computedProgress(isMan, maleNum, femaleNum, computeType, effecticeNum) {
      let resultNum = '', totalNum = null, nums = null
      if (typeof(maleNum) === 'number' && typeof(femaleNum) === 'number') {
        totalNum = maleNum + femaleNum
        if (isMan) {
          nums = (maleNum / totalNum) * 100
          if (effecticeNum) {
            resultNum = Math.floor(effecticeNum * nums / 100);
          } else { 
            resultNum = computeType == 'width' ? nums + '%' : nums.toFixed(2) + '%'
          }
        } else {
          nums = (femaleNum / totalNum) * 100
          if (effecticeNum) {
            resultNum = Math.ceil(effecticeNum * nums / 100);
          } else {
            resultNum = computeType == 'width' ? nums + '%' : nums.toFixed(2) + '%'
          }
        }
        return resultNum
      } else {
        return '--'
      }
    },
    computedRepeat(headerData) {
      let repeatNum = null
      repeatNum = (headerData.dayInnum || headerData.accumulativeTraffic)
        && headerData.effectiveTraffic
        && (headerData.staffManTime || headerData.staffManTime >= 0)
          ? (headerData.dayInnum || headerData.accumulativeTraffic) - headerData.effectiveTraffic - headerData.staffManTime
          : '--'
      return repeatNum < 0 ? 0 : repeatNum
    },
  }
}
</script>