index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import {
  5. getDashboardStats,
  6. listWeighing,
  7. getInboundByCargo,
  8. getOutboundByCargo
  9. } from '@/api/db'
  10. import { weighingPhase, todayYmd, dash, formatWeight } from '@/utils/dbLabels'
  11. import { PAGE_PATHS } from '@/config/api'
  12. const stats = ref({
  13. todayInbound: 0,
  14. todayOutbound: 0,
  15. todayWeighing: 0,
  16. needSecond: 0
  17. })
  18. const topCargo = ref([])
  19. const loading = ref(false)
  20. const goBack = () => {
  21. uni.navigateBack({
  22. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  23. })
  24. }
  25. const goWeighing = () => uni.navigateTo({ url: PAGE_PATHS.dbWeighingList })
  26. const goPlans = () => uni.navigateTo({ url: PAGE_PATHS.dbPlansList })
  27. const goInventory = () => uni.navigateTo({ url: PAGE_PATHS.dbInventoryList })
  28. const load = async () => {
  29. loading.value = true
  30. try {
  31. const [s, weighings, inCargo, outCargo] = await Promise.all([
  32. getDashboardStats(),
  33. listWeighing({ dateFrom: todayYmd(), dateTo: todayYmd() }),
  34. getInboundByCargo(),
  35. getOutboundByCargo()
  36. ])
  37. const todayList = weighings || []
  38. const needSecond = todayList.filter((w) => {
  39. const p = weighingPhase(w)
  40. return p.text === '一次过磅'
  41. }).length
  42. stats.value = {
  43. todayInbound: s.todayInbound ?? s.today_inbound ?? 0,
  44. todayOutbound: s.todayOutbound ?? s.today_outbound ?? 0,
  45. todayWeighing: todayList.filter((w) => Number(w.isVoided) !== 1).length,
  46. needSecond
  47. }
  48. const merged = []
  49. .concat(inCargo || [])
  50. .concat(outCargo || [])
  51. .slice(0, 6)
  52. topCargo.value = merged
  53. } catch (e) {
  54. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  55. } finally {
  56. loading.value = false
  57. }
  58. }
  59. onShow(() => load())
  60. </script>
  61. <template>
  62. <view class="mp-page mp-page--sub">
  63. <view class="mp-header mp-header--db">
  64. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  65. <text class="mp-header__title" style="margin-top: 16rpx">地磅仪表盘</text>
  66. <text class="mp-header__meta">今日出入库与过磅概况</text>
  67. </view>
  68. <view class="mp-stats mp-stats--4">
  69. <view class="mp-stat">
  70. <text class="mp-stat__num">{{ stats.todayWeighing }}</text>
  71. <text class="mp-stat__label">今日过磅</text>
  72. </view>
  73. <view class="mp-stat">
  74. <text class="mp-stat__num">{{ stats.needSecond }}</text>
  75. <text class="mp-stat__label">待二次过磅</text>
  76. </view>
  77. <view class="mp-stat">
  78. <text class="mp-stat__num">{{ Number(stats.todayInbound).toFixed(0) }}</text>
  79. <text class="mp-stat__label">今日入库</text>
  80. </view>
  81. <view class="mp-stat">
  82. <text class="mp-stat__num">{{ Number(stats.todayOutbound).toFixed(0) }}</text>
  83. <text class="mp-stat__label">今日出库</text>
  84. </view>
  85. </view>
  86. <view class="mp-section">
  87. <view class="mp-list">
  88. <view class="mp-card" @click="goWeighing">
  89. <view class="mp-card__head">
  90. <text class="mp-card__title">地磅单管理</text>
  91. <text class="mp-tag mp-tag--warning">现场</text>
  92. </view>
  93. <text class="mp-card__sub">查看过磅记录,办理二次过磅</text>
  94. </view>
  95. <view class="mp-card" @click="goPlans">
  96. <view class="mp-card__head">
  97. <text class="mp-card__title">地磅计划</text>
  98. <text class="mp-tag mp-tag--info">计划</text>
  99. </view>
  100. <text class="mp-card__sub">查看入/出库计划执行进度</text>
  101. </view>
  102. <view class="mp-card" @click="goInventory">
  103. <view class="mp-card__head">
  104. <text class="mp-card__title">出入库单</text>
  105. <text class="mp-tag mp-tag--success">单据</text>
  106. </view>
  107. <text class="mp-card__sub">查看出入库及关联过磅</text>
  108. </view>
  109. </view>
  110. </view>
  111. <view v-if="topCargo.length" class="mp-block">
  112. <text class="mp-block__title">货品计划 vs 实绩(节选)</text>
  113. <view class="mp-block__panel">
  114. <view v-for="(c, i) in topCargo" :key="i" class="mp-kv">
  115. <text class="mp-kv__label">{{ dash(c.label) }}</text>
  116. <text class="mp-kv__value">
  117. 计划 {{ formatWeight(c.planned, '') }} / 实绩 {{ formatWeight(c.actual, '') }}
  118. </text>
  119. </view>
  120. </view>
  121. </view>
  122. <view v-if="loading" class="mp-list-loading">加载中…</view>
  123. </view>
  124. </template>