list.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <script setup>
  2. import { ref, computed } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import { listInventory } from '@/api/db'
  5. import {
  6. inventoryStatusLabel,
  7. dash,
  8. formatWeight,
  9. filterByKeyword,
  10. todayYmd
  11. } from '@/utils/dbLabels'
  12. import { PAGE_PATHS } from '@/config/api'
  13. const tabs = [
  14. { key: 'all', label: '全部' },
  15. { key: '入库', label: '入库' },
  16. { key: '出库', label: '出库' },
  17. { key: 'pending', label: '待处理' }
  18. ]
  19. const activeTab = ref('all')
  20. const keyword = ref('')
  21. const rawList = ref([])
  22. const loading = ref(false)
  23. const list = computed(() => {
  24. let rows = rawList.value
  25. if (activeTab.value === '入库' || activeTab.value === '出库') {
  26. rows = rows.filter((r) => r.businessType === activeTab.value)
  27. } else if (activeTab.value === 'pending') {
  28. rows = rows.filter((r) => String(r.status || '').includes('待'))
  29. }
  30. return filterByKeyword(rows, keyword.value, [
  31. 'batchNo',
  32. 'planNo',
  33. 'vehicleNo',
  34. 'product',
  35. 'partnerCompany',
  36. 'status'
  37. ]).slice(0, 80)
  38. })
  39. const goBack = () => {
  40. uni.navigateBack({
  41. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  42. })
  43. }
  44. const goDetail = (row) =>
  45. uni.navigateTo({ url: `${PAGE_PATHS.dbInventoryDetail}?id=${row.id}` })
  46. const load = async () => {
  47. loading.value = true
  48. try {
  49. // 默认拉今日,减轻全量压力;切「全部」再无日期
  50. if (activeTab.value === 'all' && !keyword.value) {
  51. const today = todayYmd()
  52. rawList.value = await listInventory({ dateFrom: today, dateTo: today })
  53. if (rawList.value.length < 5) {
  54. rawList.value = await listInventory()
  55. }
  56. } else {
  57. rawList.value = await listInventory()
  58. }
  59. } catch (e) {
  60. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  61. } finally {
  62. loading.value = false
  63. }
  64. }
  65. const switchTab = (key) => {
  66. activeTab.value = key
  67. load()
  68. }
  69. onShow(() => load())
  70. </script>
  71. <template>
  72. <view class="mp-page mp-page--sub">
  73. <view class="mp-header mp-header--db">
  74. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  75. <text class="mp-header__title" style="margin-top: 16rpx">地磅出入库</text>
  76. <view class="mp-header__search">
  77. <view class="mp-header__search-dot" />
  78. <input
  79. v-model="keyword"
  80. class="mp-header__search-input"
  81. placeholder="单号 / 车牌 / 产品 / 往来单位"
  82. />
  83. </view>
  84. </view>
  85. <view class="mp-section" style="padding-bottom: 0">
  86. <scroll-view scroll-x class="mp-tabs">
  87. <view
  88. v-for="t in tabs"
  89. :key="t.key"
  90. class="mp-tab"
  91. :class="{ 'mp-tab--active': activeTab === t.key }"
  92. @click="switchTab(t.key)"
  93. >
  94. {{ t.label }}
  95. </view>
  96. </scroll-view>
  97. </view>
  98. <view class="mp-section">
  99. <mp-empty v-if="!list.length && !loading" title="暂无出入库单" />
  100. <view v-else class="mp-list">
  101. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  102. <view class="mp-card__head">
  103. <view>
  104. <text class="mp-card__title">{{ dash(row.batchNo || row.id) }}</text>
  105. <text class="mp-card__sub">
  106. {{ dash(row.vehicleNo) }} · {{ dash(row.product) }} · {{ dash(row.businessType) }}
  107. </text>
  108. </view>
  109. <text class="mp-tag" :class="'mp-tag--' + inventoryStatusLabel(row.status).tag">
  110. {{ inventoryStatusLabel(row.status).text }}
  111. </text>
  112. </view>
  113. <view class="mp-card__row">
  114. <text>数量</text>
  115. <text class="mp-card__row-val">{{ formatWeight(row.quantity) }}</text>
  116. </view>
  117. <view class="mp-card__row">
  118. <text>往来单位</text>
  119. <text class="mp-card__row-val">{{ dash(row.partnerCompany) }}</text>
  120. </view>
  121. <view class="mp-card__row">
  122. <text>日期</text>
  123. <text class="mp-card__row-val">{{ dash(row.date) }}</text>
  124. </view>
  125. </view>
  126. </view>
  127. <view v-if="loading" class="mp-list-loading">加载中…</view>
  128. </view>
  129. </view>
  130. </template>