reportComponent.vue 9.08 KB
<template>
  <div
    class="report-component "
    :class="{ 'is-card': isCard }"
  >
    <template v-if="reportIndex == 1">
      <div class="date">统计周期:{{dayjs(reportItem.reportStartDate).format('YYYY年M月')}} ({{ reportItem.reportStartDate }}至{{ reportItem.reportEndDate }})</div>
    </template>
    <div class="business-title">{{reportIndex}}、{{ businessTitle }}业务线</div>

    <!-- 1.1 门店数据汇总 -->
    <div class="sub-title">{{ reportIndex }}.1 门店数据汇总</div>
    <template v-for="(m,mindex) in reportItem.metchantListData">
      <div
        class="merchant-list"
        :key="mindex"
      >
        <div class="merchant-item">
          <div class="label">展业新店</div>
          <div class="value">{{ m['展业新店'] || 0 }}<span class="unit">家</span></div>
        </div>
        <div class="merchant-divider"></div>
        <div class="merchant-item">
          <div class="label">展业老店</div>
          <div class="value">{{ m['展业老店'] || 0 }}<span class="unit">家</span></div>
        </div>
        <div class="merchant-divider"></div>
        <div class="merchant-item">
          <div class="label">流失预警门店</div>
          <div class="value">{{ m['流失预警门店'] || 0 }}<span class="unit">家</span></div>
        </div>
      </div>
    </template>

    <!-- 1.2 业务数据汇总 -->
    <div class="sub-title">{{ reportIndex }}.2 业务数据汇总</div>
    <template v-for="(b,bindex) in reportItem.brandList">

      <div
        :key="'b'+ bindex"
        class="business-data"
      >
        <div class="brand-title">🚗 {{ b.brandName }}</div>
        <div class="data-table">
          <table>
            <thead>
              <tr>
                <th>指标</th>
                <th>{{reportItem.reportType == 2 ? '本月' : '本周'}}数据</th>
                <th>{{reportItem.reportType == 2 ? '上月' : '上周'}}数据</th>
                <th>环比变化</th>
              </tr>
            </thead>
            <tbody>
              <tr
                v-for="(row, index) in b.businessListData"
                :key="index"
              >
                <td class="indicator-name">{{ row.name }}</td>
                <td :class="getValueClass(row.currentValue)">{{ row.currentValue }}{{ row.unit || '' }}</td>
                <td>{{ row.lastValue }}{{ row.unit || '' }}</td>
                <td :class="getChangeClass(row.change)">
                  <div class="pre flex">
                    {{ formatChange(row.change) }}
                    <template v-if="row.change != null">
                      <div
                        class="sprite-icon icon-up"
                        v-if="row.change > 0"
                      ></div>
                      <div
                        class="sprite-icon icon-down"
                        v-else-if="row.change < 0"
                      ></div>
                      <div
                        class="sprite-icon icon-stable"
                        v-else
                      ></div>
                    </template>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>

        <!-- 整体结论 -->
        <div class="section-title">
          <span class="dot">●</span>
          整体结论
        </div>
        <div
          class="content-text"
          v-html="formatText(b.overallConclusion)"
        >
        </div>

        <!-- 行动建议 -->
        <div class="section-title">
          <span class="dot">●</span>
          行动建议
        </div>
        <div
          class="content-text"
          v-html="formatText(b.actionSuggestion)"
        >
        </div>
      </div>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
import dayjs from 'dayjs'
export default {
  name: 'report-component',
  props: {
    reportItem: {
      type: Object,
      default: () => { }
    },
    reportIndex: {
      type: Number,
      default: 1
    },
    isCard: {
      type: Boolean,
      default: false
    },
  },
  data () {
    return {
      dayjs
    }
  },
  computed: {
    businessTitle () {
      return {
        1: '延保',
        2: '轻改',
        3: '权益'
      }[this.reportItem.businessType] || '其他'
    },
    tableData () {
      // 从 reportItem 中提取表格数据
      const data = this.reportItem.metrics || []
      return data.length > 0 ? data : this.defaultMetrics
    },
    defaultMetrics () {
      // 默认指标数据(如果没有传入)
      return [
      ]
    }
  },
  methods: {
    // 格式化文本,将 \n 转换为 <br>
    formatText (text) {
      if (!text) return '暂无内容'
      // 将换行符转换为 <br> 标签
      return text.replace(/\n/g, '<br>')
    },
    // 格式化变化值
    formatChange (value) {
      if (value === null || value === undefined) return '-'
      return Math.abs(value || 0) + '%'
    },
    // 获取数值样式类
    getValueClass (value) {
      // 可以根据数值返回不同的类
      return 'value-cell'
    },
    // 获取变化样式类
    getChangeClass (change) {
      if (change > 0) return 'change-up'
      if (change < 0) return 'change-down'
      return 'change-stable'
    }
  }
}
</script>

<style scoped lang='scss'>
.report-component {
  .date {
    font-size: 13px;
    color: rgba(19, 51, 104, 0.8);
  }

  .business-title {
    color: #133368;
    font-size: 14px;
    font-weight: 500;
    margin: 8px 0;
  }

  .sub-title {
    color: #133368;
    font-size: 14px;
    margin-bottom: 8px;
  }
  .brand-title{
    height: 20px;
    color: #133368;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
  }
  // 门店数据汇总
  .merchant-list {
    display: flex;
    justify-content: space-between;
    border-radius: 8px;
    border: 1px solid #d8e6f0;
    background: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 6px 0 rgba(0, 136, 255, 0.1);
    backdrop-filter: blur(2px);
    padding: 8px 10px;
    margin-bottom: 8px;

    .merchant-item {
      flex: 1;
      .label {
        font-size: 14px;
        color: #133368;
        line-height: 20px;
      }

      .value {
        color: #133368;
        font-size: 18px;
        font-weight: 500;
        line-height: 25px;
        display: flex;
        align-items: baseline;
        gap: 2px;
        .unit {
          font-size: 14px;
          font-weight: normal;
        }
      }
    }

    .merchant-divider {
      width: 1px;
      background: #d8e6f0;
      margin: 0 10px;
    }
  }

  // 数据表格
  .data-table {
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: auto;
    border: 1px solid #d8e6f0;

    table {
      width: 100%;
      border-collapse: collapse;
      font-size: 13px;
      color: #133368;
      thead {
        tr {
          font-weight: 500;
          background: #f6fbff;
          th {
            padding: 8px;
            text-align: left;
            font-weight: 600;
            color: #333;
            border: 1px solid #d8e6f0;
            border-top: none;

            &:first-child {
              border-left: none;
            }

            &:last-child {
              border-right: none;
            }
          }
        }
      }

      tbody {
        tr {
          background: #fff;
          td {
            border-left: none !important;
            &:last-child {
              border-right: none !important;
            }
          }
          &:last-child {
            td {
              border-bottom: none;
              &:last-child {
                border-right: none;
              }
            }
          }

          td {
            padding: 6px 8px;
            text-align: left;
            border: 1px solid #d8e6f0;

            &.change-up {
              color: #ff2d55;
            }

            &.change-down {
              color: #34c759;
            }

            &.change-stable {
              color: #ff8d28;
            }
          }
        }
      }
    }
  }

  // 结论文字部分
  .section-title {
    color: #133368;
    font-size: 14px;
    font-weight: 500;
    margin: 8px 0;
    display: flex;
    align-items: center;

    .dot {
      color: #133368;
      margin-right: 8px;
      font-size: 12px;
    }
  }

  .content-text {
    color: #133368;
    font-size: 14px;
    text-align: justify;
    margin-bottom: 8px;
  }
}

.is-card {
  .date {
    font-size: 14.31px !important;
  }
  .content-text,
  .section-title,
  .business-title,
  .sub-title {
    font-size: 15.31px !important;
  }
  .merchant-list .merchant-item {
    .value{
      font-size: 19.68px !important;
    }
    .label,
    .unit {
      font-size: 15.31px !important;
    }
  }
  .data-table table{
    font-size: 14.31px !important;
  }
  .brand-title{
    font-size: 15.31px !important;
  }
}
</style>