AccountBasicData.nvue 3.57 KB
<template>
  <view class="c-list">
    <view class="c-l-item" v-for="(item,index) in cardData" :key="item.key">
      <view class="c-list_item_title">
        <text class="c-list_item_title_text">{{ item.name }}</text>
      </view>
      <view class="c-list_item_value">
        <text class="c-list_item_value_text">{{formatValue(item)}}</text>
      </view>
      <view class="c-list_item_other" v-if="average_key.includes(item.key)">
        <text class="c-list_item_other_text">{{ t('navData.averexposure') }}: {{item.average}}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
  import {
    formatSeconds,
    getStageObj
  } from '@/utils'
  import {
    t
  } from '@/plugins/index.js'
  const props = defineProps({
    cardData: {
      type: Array,
      default: () => []
    }
  })

  // 需要展示店均的key列表
  // 依次: 集团总客流人数、集团总客流、过店人次、批次客流
  const average_key = ['account_passenger_number', 'account_passenger_flow', 'mall_customer_group',
    'mall_outside_number'
  ]

  // 需要格式化时间key列表
  // 依次:顾客停留时间 顾客滞留时间
  const time_key = ['custom_residence_time', 'custom_residence_time']

  // 需要合并展示的值
  // 依次:成人&儿童
  const conbine_key = {
    'mall_customer_adult_child': ['adult', 'child']
  }



  const formatValue = (item) => {

    // 格式化时间
    if (time_key.includes(item.key)) {
      return formatSeconds(item.value)
    }
    // 格式化合并项
    if (conbine_key[item.key]) {
      return conbine_key[item.key].map(elKey => item[elKey]).join('/')
    }
    if (item.unit === '%') {
      return `${item.value}%`
    }

    if (item.value > 1000000) {
      return (item.value / 10000).toFixed(2) + 'w'
    }

    return item.value

  }
</script>

<style lang="scss">
  .c-list {
    padding: 28rpx;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;

    .c-l-item {
      width: 320rpx;
      height: 194rpx;
      padding: 24rpx 0 0 24rpx;
      border-radius: 8rpx;
      border: 2rpx solid #EDEFF3;
      margin-bottom: 14rpx;
      display: flex;
      flex-direction: column;

      .c-list_item_title {
        .c-list_item_title_text {
          font-size: 26rpx;
          color: #656A72;

        }
      }

      .c-list_item_value {
        margin: 14rpx 0;

        &_text {
          color: #202328;
          font-family: D-DIN-PRO-700-Bold;
          font-size: 44rpx;
        }
      }

      .c-list_item_other {
        &_text {
          font-size: 24rpx;
          color: #90949D;
        }
      }
    }

    // 	&_item {
    // 		/* 三列布局核心计算 */
    // 		height: 160rpx;

    // 		/* 以下保持原有样式 */
    // 		align-items: center;

    // 		&_title {
    // 			flex-direction: row;

    // 			&_text {
    // 				font-size: 26rpx;
    // 				color: #202328;
    // 			}

    // 			&_icon {}
    // 		}

    // 		&_value {
    // 			width: 100%;
    // 			margin: 8rpx 0;

    // 			&_text {
    // 				/* #ifdef APP */
    // 				lines: 1;
    // 				/* #endif */
    // 				/* #ifdef H5 || MP-WEIXIN */
    // 				overflow: hidden;
    // 				text-overflow: ellipsis;
    // 				white-space: nowrap;
    // 				/* #endif */
    // 				font-weight: bold;
    // 				text-align: center;
    // 				font-size: 36rpx;
    // 				color: #202328;
    // 			}
    // 		}

    // 		&_other {
    // 			&_text {
    // 				font-size: 20rpx;
    // 				color: #6d778f;
    // 				flex-direction: row;
    // 			}
    // 		}
    // 	}

  }
</style>