label-report.vue 12 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
<template>
  <view class="page">
    <view class="header-hero" :style="{ paddingTop: statusBarHeight + 'px' }">
      <view class="top-bar">
        <view class="top-left" @click="goBack">
          <AppIcon name="chevronLeft" size="sm" color="white" />
        </view>
        <view class="top-center">
          <text class="page-title">Label Report</text>
          <LocationPicker />
        </view>
        <view class="top-right" @click="isMenuOpen = true">
          <AppIcon name="menu" size="sm" color="white" />
        </view>
      </view>
    </view>

    <view class="period-bar">
      <view
        v-for="p in periodOptions"
        :key="p.value"
        class="period-btn"
        :class="{ active: period === p.value }"
        @click="selectPeriod(p.value)"
      >
        <text class="period-text">{{ p.label }}</text>
      </view>
    </view>

    <view v-if="period === 'custom'" class="custom-date-bar">
      <view class="date-field">
        <text class="date-label">Start</text>
        <picker mode="date" :value="customStart" :end="customEnd || '2099-12-31'" @change="onStartChange">
          <view class="date-picker-btn">{{ customStart || 'Select' }}</view>
        </picker>
      </view>
      <view class="date-field">
        <text class="date-label">End</text>
        <picker mode="date" :value="customEnd" :start="customStart || '2000-01-01'" @change="onEndChange">
          <view class="date-picker-btn">{{ customEnd || 'Select' }}</view>
        </picker>
      </view>
    </view>

    <scroll-view class="content" scroll-y>
      <!-- 指标卡 -->
      <view class="metrics-grid">
        <view class="metric-card">
          <text class="metric-label">Total Labels Printed</text>
          <text class="metric-value">2,543</text>
          <text class="metric-trend up">+20.1% from last month</text>
        </view>
        <view class="metric-card">
          <text class="metric-label">Most Printed Category</text>
          <text class="metric-value">Dairy</text>
          <text class="metric-trend">450 labels generated</text>
        </view>
        <view class="metric-card">
          <text class="metric-label">Top Product</text>
          <text class="metric-value">Whole Milk</text>
          <text class="metric-trend">182 labels generated</text>
        </view>
        <view class="metric-card">
          <text class="metric-label">Avg. Daily Prints</text>
          <text class="metric-value">85</text>
          <text class="metric-trend up">+12% from last week</text>
        </view>
      </view>

      <!-- 柱状图 -->
      <view class="section">
        <text class="section-title">Labels by Category</text>
        <text class="section-desc">Distribution of printed labels across product categories.</text>
        <view class="bar-chart">
          <view v-for="item in categoryData" :key="item.name" class="bar-row">
            <text class="bar-label">{{ item.name }}</text>
            <view class="bar-track">
              <view class="bar-fill" :style="{ width: item.percent + '%' }" />
            </view>
            <text class="bar-value">{{ item.value }}</text>
          </view>
        </view>
      </view>

      <!-- 走势图 -->
      <view class="section">
        <text class="section-title">Print Volume Trends</text>
        <text class="section-desc">Daily label printing volume for the last 7 days.</text>
        <view class="line-chart">
          <view class="chart-bars">
            <view v-for="(pct, i) in trendData" :key="i" class="day-bar-wrap">
              <view class="day-bar" :style="{ height: pct + '%' }" />
            </view>
          </view>
          <view class="chart-labels">
            <text v-for="d in dayLabels" :key="d" class="day-label">{{ d }}</text>
          </view>
        </view>
      </view>

      <!-- 最常用产品列表 -->
      <view class="section">
        <text class="section-title">Most Used Products</text>
        <view class="product-table">
          <view class="product-row header">
            <text class="col-name">Product Name</text>
            <text class="col-cat">Category</text>
            <text class="col-total">Total Printed</text>
            <text class="col-pct">Usage %</text>
          </view>
          <view v-for="p in topProducts" :key="p.name" class="product-row">
            <text class="col-name">{{ p.name }}</text>
            <text class="col-cat">{{ p.category }}</text>
            <text class="col-total">{{ p.total }}</text>
            <text class="col-pct">{{ p.usage }}%</text>
          </view>
        </view>
      </view>
    </scroll-view>

    <SideMenu v-model="isMenuOpen" />
  </view>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import AppIcon from '../../components/AppIcon.vue'
import SideMenu from '../../components/SideMenu.vue'
import LocationPicker from '../../components/LocationPicker.vue'
import { getStatusBarHeight } from '../../utils/statusBar'

const statusBarHeight = getStatusBarHeight()
const isMenuOpen = ref(false)
const period = ref('7d')
const customStart = ref('')
const customEnd = ref('')

const periodOptions = [
  { value: '7d', label: 'Last 7 Days' },
  { value: '30d', label: 'Last 30 Days' },
  { value: '90d', label: 'Last 90 Days' },
  { value: 'custom', label: 'Custom' },
]

function selectPeriod(val: string) {
  period.value = val
  if (val === 'custom') {
    const today = formatDate(new Date())
    const weekAgo = new Date()
    weekAgo.setDate(weekAgo.getDate() - 7)
    customStart.value = customStart.value || formatDate(weekAgo)
    customEnd.value = customEnd.value || today
  }
}

function formatDate(d: Date): string {
  const y = d.getFullYear()
  const m = String(d.getMonth() + 1).padStart(2, '0')
  const day = String(d.getDate()).padStart(2, '0')
  return `${y}-${m}-${day}`
}

function onStartChange(e: any) {
  customStart.value = e.detail.value
}

function onEndChange(e: any) {
  customEnd.value = e.detail.value
}

const categoryDataRaw = [
  { name: 'Dairy', value: 450 },
  { name: 'Meat', value: 380 },
  { name: 'Bakery', value: 320 },
  { name: 'Deli', value: 280 },
  { name: 'Produce', value: 220 },
  { name: 'Beverage', value: 180 },
]

const categoryData = computed(() => {
  const max = Math.max(...categoryDataRaw.map(d => d.value))
  return categoryDataRaw.map(d => ({ ...d, percent: (d.value / max) * 100 }))
})

const trendDataRaw = [72, 85, 78, 92, 88, 95, 90]
const trendData = computed(() => {
  const max = Math.max(...trendDataRaw)
  return trendDataRaw.map(v => (v / max) * 100)
})

const dayLabels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

const topProducts = ref([
  { name: 'Whole Milk', category: 'Dairy', total: 182, usage: '7.2' },
  { name: 'Ground Beef 80/20', category: 'Meat', total: 145, usage: '5.7' },
  { name: 'Chicken Breast', category: 'Meat', total: 132, usage: '5.2' },
  { name: 'Sliced Ham', category: 'Deli', total: 98, usage: '3.8' },
])

const goBack = () => {
  const pages = getCurrentPages()
  if (pages.length > 1) {
    uni.navigateBack()
  } else {
    uni.redirectTo({ url: '/pages/index/index' })
  }
}
</script>

<style scoped>
.page {
  min-height: 100vh;
  background: #f3f4f6;
  display: flex;
  flex-direction: column;
}

.header-hero {
  background: linear-gradient(135deg, #1F3A8A, #142a6c);
  padding: 16rpx 32rpx 24rpx;
}

.top-bar {
  height: 96rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-left, .top-right {
  width: 64rpx;
  height: 64rpx;
  border-radius: 999rpx;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.page-title {
  font-size: 34rpx;
  font-weight: 600;
  color: #fff;
}

.period-bar {
  display: flex;
  gap: 12rpx;
  padding: 16rpx 28rpx;
  background: #fff;
  border-bottom: 1rpx solid #e5e7eb;
}

.period-btn {
  flex: 1;
  padding: 16rpx 24rpx;
  border-radius: 12rpx;
  background: #f3f4f6;
  text-align: center;
  transition: all 0.2s;
}

.period-btn.active {
  background: linear-gradient(135deg, #1F3A8A, #1447E6);
}

.period-btn.active .period-text {
  color: #fff;
}

.period-text {
  font-size: 26rpx;
  font-weight: 500;
  color: #6b7280;
}

.custom-date-bar {
  display: flex;
  gap: 24rpx;
  padding: 20rpx 28rpx;
  background: #fff;
  border-bottom: 1rpx solid #e5e7eb;
}

.date-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.date-label {
  font-size: 24rpx;
  color: #6b7280;
  font-weight: 500;
}

.date-picker-btn {
  padding: 20rpx 24rpx;
  background: #f3f4f6;
  border-radius: 12rpx;
  font-size: 28rpx;
  color: #111827;
  border: 2rpx solid #e5e7eb;
}

.content {
  flex: 1;
  padding: 24rpx 28rpx 40rpx;
  box-sizing: border-box;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20rpx;
  margin-bottom: 32rpx;
}

.metric-card {
  background: #fff;
  padding: 28rpx;
  border-radius: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  border: 1rpx solid #e5e7eb;
}

.metric-label {
  font-size: 24rpx;
  color: #6b7280;
  display: block;
  margin-bottom: 12rpx;
  line-height: 1.5;
}

.metric-value {
  font-size: 38rpx;
  font-weight: 700;
  color: #111827;
  display: block;
  margin-bottom: 8rpx;
  letter-spacing: -0.02em;
}

.metric-trend {
  font-size: 24rpx;
  color: #6b7280;
}

.metric-trend.up {
  color: #16a34a;
  font-weight: 500;
}

.section {
  margin-bottom: 32rpx;
}

.section-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #111827;
  display: block;
  margin-bottom: 8rpx;
}

.section-desc {
  font-size: 26rpx;
  color: #6b7280;
  display: block;
  margin-bottom: 24rpx;
  line-height: 1.5;
}

.bar-chart {
  background: #fff;
  padding: 28rpx;
  border-radius: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  border: 1rpx solid #e5e7eb;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 16rpx;
  margin-bottom: 24rpx;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-label {
  width: 120rpx;
  font-size: 26rpx;
  color: #374151;
  flex-shrink: 0;
  font-weight: 500;
}

.bar-track {
  flex: 1;
  height: 36rpx;
  background: #f3f4f6;
  border-radius: 10rpx;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #1F3A8A, #1447E6);
  border-radius: 10rpx;
  transition: width 0.3s ease;
}

.bar-value {
  width: 88rpx;
  text-align: right;
  font-size: 26rpx;
  font-weight: 600;
  color: #111827;
}

.line-chart {
  background: #fff;
  padding: 28rpx;
  border-radius: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  border: 1rpx solid #e5e7eb;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12rpx;
  height: 220rpx;
  margin-bottom: 20rpx;
}

.day-bar-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.day-bar {
  width: 100%;
  max-width: 52rpx;
  min-height: 12rpx;
  background: linear-gradient(180deg, #1F3A8A, #1447E6);
  border-radius: 10rpx 10rpx 0 0;
  transition: height 0.3s ease;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  gap: 12rpx;
}

.day-label {
  flex: 1;
  padding: 0 4rpx;
  font-size: 24rpx;
  color: #6b7280;
  text-align: center;
}

.product-table {
  background: #fff;
  border-radius: 20rpx;
  overflow: hidden;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  border: 1rpx solid #e5e7eb;
}

.product-row {
  display: flex;
  padding: 24rpx 28rpx;
  border-bottom: 1rpx solid #e5e7eb;
  font-size: 28rpx;
}

.product-row:last-child {
  border-bottom: none;
}

.product-row.header {
  background: #fafbfc;
  font-weight: 600;
  color: #6b7280;
  font-size: 24rpx;
}

.col-name { flex: 1; min-width: 0; text-align: left; }
.col-cat { flex: 0 0 140rpx; text-align: left; }
.col-total { flex: 0 0 120rpx; text-align: left; }
.col-pct { flex: 0 0 88rpx; text-align: left; }

.product-row:not(.header) .col-name { color: #111827; font-weight: 500; }
.product-row:not(.header) .col-cat { color: #6b7280; }
.product-row:not(.header) .col-total { color: #111827; }
.product-row:not(.header) .col-pct { color: #1F3A8A; font-weight: 600; }
</style>