list.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <script setup>
  2. import { ref, computed } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import { listPlans } from '@/api/db'
  5. import { planStatusLabel, dash, formatWeight, filterByKeyword } from '@/utils/dbLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const tabs = [
  8. { key: 'all', label: '全部' },
  9. { key: '入库', label: '入库' },
  10. { key: '出库', label: '出库' }
  11. ]
  12. const activeTab = ref('all')
  13. const keyword = ref('')
  14. const rawList = ref([])
  15. const loading = ref(false)
  16. const list = computed(() => {
  17. let rows = rawList.value
  18. if (activeTab.value !== 'all') {
  19. rows = rows.filter((r) => r.businessType === activeTab.value)
  20. }
  21. return filterByKeyword(rows, keyword.value, [
  22. 'planNo',
  23. 'product',
  24. 'customerName',
  25. 'vehicleNo',
  26. 'executionStatus'
  27. ]).slice(0, 80)
  28. })
  29. const goBack = () => {
  30. uni.navigateBack({
  31. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  32. })
  33. }
  34. const goDetail = (row) =>
  35. uni.navigateTo({ url: `${PAGE_PATHS.dbPlansDetail}?id=${row.id}` })
  36. const load = async () => {
  37. loading.value = true
  38. try {
  39. rawList.value = await listPlans()
  40. } catch (e) {
  41. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  42. } finally {
  43. loading.value = false
  44. }
  45. }
  46. const switchTab = (key) => {
  47. activeTab.value = key
  48. }
  49. onShow(() => load())
  50. </script>
  51. <template>
  52. <view class="mp-page mp-page--sub">
  53. <view class="mp-header mp-header--db">
  54. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  55. <text class="mp-header__title" style="margin-top: 16rpx">地磅计划</text>
  56. <view class="mp-header__search">
  57. <view class="mp-header__search-dot" />
  58. <input
  59. v-model="keyword"
  60. class="mp-header__search-input"
  61. placeholder="计划号 / 产品 / 客户 / 车牌"
  62. />
  63. </view>
  64. </view>
  65. <view class="mp-section" style="padding-bottom: 0">
  66. <scroll-view scroll-x class="mp-tabs">
  67. <view
  68. v-for="t in tabs"
  69. :key="t.key"
  70. class="mp-tab"
  71. :class="{ 'mp-tab--active': activeTab === t.key }"
  72. @click="switchTab(t.key)"
  73. >
  74. {{ t.label }}
  75. </view>
  76. </scroll-view>
  77. </view>
  78. <view class="mp-section">
  79. <mp-empty v-if="!list.length && !loading" title="暂无计划" />
  80. <view v-else class="mp-list">
  81. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  82. <view class="mp-card__head">
  83. <view>
  84. <text class="mp-card__title">{{ dash(row.planNo) }}</text>
  85. <text class="mp-card__sub">{{ dash(row.product) }} · {{ dash(row.businessType) }}</text>
  86. </view>
  87. <text class="mp-tag" :class="'mp-tag--' + planStatusLabel(row.executionStatus).tag">
  88. {{ planStatusLabel(row.executionStatus).text }}
  89. </text>
  90. </view>
  91. <view class="mp-card__row">
  92. <text>计划量</text>
  93. <text class="mp-card__row-val">{{ formatWeight(row.plannedQuantity) }}</text>
  94. </view>
  95. <view class="mp-card__row">
  96. <text>已执行</text>
  97. <text class="mp-card__row-val">{{ formatWeight(row.executedQuantity) }}</text>
  98. </view>
  99. <view class="mp-card__row">
  100. <text>客户</text>
  101. <text class="mp-card__row-val">{{ dash(row.customerName) }}</text>
  102. </view>
  103. </view>
  104. </view>
  105. <view v-if="loading" class="mp-list-loading">加载中…</view>
  106. </view>
  107. </view>
  108. </template>