list.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="db-page db-page--scroll">
  3. <view class="db-header" :style="safeAreaStyle">
  4. <view class="db-header__nav">
  5. <view class="db-header__left">
  6. <text class="db-header__back" @click="goBack">←</text>
  7. <text class="db-header__title">出入库管理</text>
  8. </view>
  9. <view /><!-- 胶囊占位 -->
  10. </view>
  11. </view>
  12. <view class="db-search-wrap">
  13. <db-search
  14. v-model="keyword"
  15. placeholder="搜索往来单位 / 车牌 / 产品"
  16. @change="onKeyword"
  17. @search="onRefresh"
  18. @clear="onClear"
  19. />
  20. </view>
  21. <view class="db-filter-bar">
  22. <view
  23. v-for="item in dateFilters"
  24. :key="item.value"
  25. class="db-filter-chip"
  26. :class="{ 'db-filter-chip--active': dateFilter === item.value }"
  27. @click="setFilter(item.value)"
  28. >
  29. {{ item.label }}
  30. </view>
  31. </view>
  32. <scroll-view
  33. class="db-list db-list-scroll"
  34. scroll-y
  35. :style="{ height: listHeight }"
  36. refresher-enabled
  37. :refresher-triggered="refreshing"
  38. @refresherrefresh="onPullRefresh"
  39. @scrolltolower="onLoadMore"
  40. lower-threshold="80"
  41. >
  42. <view v-if="!loading && !list.length" class="db-empty">暂无数据</view>
  43. <view v-for="item in list" :key="item.id" class="db-card" @click="viewItem(item)">
  44. <view class="db-card__head">
  45. <text class="db-card__title">{{ item.vehicleNo || '未填车牌' }}</text>
  46. <db-tag :type="item.businessType === '入库' ? 'success' : 'warning'">
  47. {{ item.businessType }}
  48. </db-tag>
  49. </view>
  50. <view class="db-card__row">
  51. <text class="db-card__label">日期</text>
  52. <text>{{ item.date || '--' }}</text>
  53. </view>
  54. <view class="db-card__row">
  55. <text class="db-card__label">往来单位</text>
  56. <text>{{ item.partnerCompany || '--' }}</text>
  57. </view>
  58. <view class="db-card__row">
  59. <text class="db-card__label">产品</text>
  60. <text>{{ item.product || '--' }}</text>
  61. </view>
  62. <view class="db-card__row">
  63. <text class="db-card__label">数量</text>
  64. <text>{{ item.quantity ?? '--' }} 吨</text>
  65. </view>
  66. <view class="db-card__row">
  67. <text class="db-card__label">状态</text>
  68. <text>{{ item.status || '待处理' }}</text>
  69. </view>
  70. <view class="db-card__foot" @click.stop>
  71. <db-btn size="small" type="primary" plain @click="viewRelated(item)">关联</db-btn>
  72. <db-btn size="small" type="primary" @click="openPoundQr(item)">磅单二维码</db-btn>
  73. </view>
  74. </view>
  75. <view v-if="list.length" class="db-list-footer">
  76. {{ finished ? '没有更多了' : loading ? '加载中...' : '上拉加载更多' }}
  77. </view>
  78. <view v-else-if="loading" class="db-empty">加载中...</view>
  79. </scroll-view>
  80. <db-popup :show="relatedOpen" height="75vh" @close="relatedOpen = false" @update:show="(v) => (relatedOpen = v)">
  81. <view style="padding: 16px">
  82. <view class="db-header__title" style="margin-bottom: 12px">关联数据</view>
  83. <view v-if="relatedLoading" class="db-empty">加载中...</view>
  84. <template v-else>
  85. <view v-if="related.plan" class="db-card">
  86. <db-tag type="primary">计划</db-tag>
  87. <view class="db-card__row" style="margin-top: 8px">
  88. <text class="db-card__label">计划号</text>
  89. <text>{{ related.plan.planNo || '--' }}</text>
  90. </view>
  91. <view class="db-card__row">
  92. <text class="db-card__label">产品</text>
  93. <text>{{ related.plan.product || '--' }}</text>
  94. </view>
  95. </view>
  96. <view v-if="related.weighing" class="db-card">
  97. <db-tag type="warning">地磅单</db-tag>
  98. <view class="db-card__row" style="margin-top: 8px">
  99. <text class="db-card__label">车牌</text>
  100. <text>{{ related.weighing.vehicleNo || '--' }}</text>
  101. </view>
  102. <view class="db-card__row">
  103. <text class="db-card__label">净重</text>
  104. <text>{{ related.weighing.netWeight ?? '--' }} kg</text>
  105. </view>
  106. </view>
  107. <view v-if="!related.plan && !related.weighing" class="db-empty">暂无关联数据</view>
  108. </template>
  109. </view>
  110. </db-popup>
  111. <db-pound-qrcode-popup
  112. :show="poundQrOpen"
  113. :inventory-id="poundQrId"
  114. :snapshot="poundQrSnapshot"
  115. @close="poundQrOpen = false"
  116. @update:show="(v) => (poundQrOpen = v)"
  117. />
  118. </view>
  119. </template>
  120. <script setup>
  121. import { ref } from 'vue'
  122. import { onShow } from '@dcloudio/uni-app'
  123. import { PAGE_PATHS } from '@/config/api'
  124. import { getSafeAreaStyle } from '@/utils/safeArea'
  125. import { inventoryApi } from '@/pages/db/api/db'
  126. import { formatYmd, addDays, weekRange } from '@/pages/db/utils/dbDate'
  127. import DbSearch from '@/components/db-ui/db-search.vue'
  128. import DbTag from '@/components/db-ui/db-tag.vue'
  129. import DbBtn from '@/components/db-ui/db-btn.vue'
  130. import DbPopup from '@/components/db-ui/db-popup.vue'
  131. import DbPoundQrcodePopup from '@/components/db-ui/db-pound-qrcode-popup.vue'
  132. const safeAreaStyle = getSafeAreaStyle()
  133. const keyword = ref('')
  134. const dateFilter = ref('today')
  135. const loading = ref(false)
  136. const finished = ref(false)
  137. const refreshing = ref(false)
  138. const list = ref([])
  139. const currentPage = ref(1)
  140. const pageSize = 20
  141. const listHeight = ref('60vh')
  142. const relatedOpen = ref(false)
  143. const relatedLoading = ref(false)
  144. const related = ref({ plan: null, weighing: null })
  145. const poundQrOpen = ref(false)
  146. const poundQrId = ref('')
  147. const poundQrSnapshot = ref(null)
  148. let debounce = null
  149. const dateFilters = [
  150. { label: '全部', value: 'all' },
  151. { label: '今日', value: 'today' },
  152. { label: '明日', value: 'tomorrow' },
  153. { label: '昨日', value: 'yesterday' },
  154. { label: '本周', value: 'week' }
  155. ]
  156. function computeListHeight() {
  157. try {
  158. const sys = uni.getSystemInfoSync()
  159. const h = (sys.windowHeight || 600) - 220
  160. listHeight.value = `${Math.max(h, 320)}px`
  161. } catch (e) {
  162. listHeight.value = '60vh'
  163. }
  164. }
  165. function buildParams() {
  166. const params = {
  167. page: currentPage.value,
  168. pageSize,
  169. q: keyword.value || undefined
  170. }
  171. const today = new Date()
  172. if (dateFilter.value === 'today') {
  173. const d = formatYmd(today)
  174. params.dateFrom = d
  175. params.dateTo = d
  176. } else if (dateFilter.value === 'tomorrow') {
  177. const t = formatYmd(addDays(today, 1))
  178. params.dateFrom = t
  179. params.dateTo = t
  180. } else if (dateFilter.value === 'yesterday') {
  181. const y = formatYmd(addDays(today, -1))
  182. params.dateFrom = y
  183. params.dateTo = y
  184. } else if (dateFilter.value === 'week') {
  185. const w = weekRange(today)
  186. params.dateFrom = w.from
  187. params.dateTo = w.to
  188. }
  189. return params
  190. }
  191. async function fetchPage() {
  192. if (loading.value && !refreshing.value) return
  193. loading.value = true
  194. try {
  195. const data = await inventoryApi.list(buildParams())
  196. const items = Array.isArray(data) ? data : data?.items || []
  197. const total = Array.isArray(data) ? data.length : Number(data?.total || 0)
  198. if (currentPage.value === 1) {
  199. list.value = items
  200. } else {
  201. list.value = list.value.concat(items)
  202. }
  203. currentPage.value += 1
  204. finished.value = items.length < pageSize || list.value.length >= total
  205. } catch (e) {
  206. if (currentPage.value === 1) list.value = []
  207. finished.value = true
  208. } finally {
  209. loading.value = false
  210. refreshing.value = false
  211. }
  212. }
  213. function onRefresh() {
  214. currentPage.value = 1
  215. finished.value = false
  216. loading.value = false
  217. list.value = []
  218. fetchPage()
  219. }
  220. function onPullRefresh() {
  221. refreshing.value = true
  222. currentPage.value = 1
  223. finished.value = false
  224. fetchPage()
  225. }
  226. function onLoadMore() {
  227. if (finished.value || loading.value) return
  228. fetchPage()
  229. }
  230. function onKeyword(v) {
  231. keyword.value = typeof v === 'string' ? v : keyword.value
  232. if (debounce) clearTimeout(debounce)
  233. debounce = setTimeout(onRefresh, 300)
  234. }
  235. function onClear() {
  236. keyword.value = ''
  237. onRefresh()
  238. }
  239. function setFilter(v) {
  240. if (dateFilter.value === v) return
  241. dateFilter.value = v
  242. onRefresh()
  243. }
  244. function goBack() {
  245. uni.navigateBack({ fail: () => uni.reLaunch({ url: PAGE_PATHS.workbench }) })
  246. }
  247. function viewItem(item) {
  248. uni.navigateTo({ url: `${PAGE_PATHS.dbInventoryDetail}?id=${item.id}&mode=view` })
  249. }
  250. async function viewRelated(item) {
  251. relatedOpen.value = true
  252. relatedLoading.value = true
  253. try {
  254. related.value = (await inventoryApi.getRelated(item.id)) || { plan: null, weighing: null }
  255. } catch (e) {
  256. relatedOpen.value = false
  257. } finally {
  258. relatedLoading.value = false
  259. }
  260. }
  261. function openPoundQr(item) {
  262. poundQrId.value = item?.id || ''
  263. poundQrSnapshot.value = item || null
  264. poundQrOpen.value = true
  265. }
  266. onShow(() => {
  267. computeListHeight()
  268. onRefresh()
  269. })
  270. </script>
  271. <style lang="scss">
  272. @import '@/styles/db-theme.scss';
  273. .db-page--scroll {
  274. padding-bottom: 0;
  275. }
  276. .db-list-scroll {
  277. box-sizing: border-box;
  278. }
  279. .db-list-footer {
  280. padding: 12px 0 24px;
  281. text-align: center;
  282. font-size: 12px;
  283. color: #9ca3af;
  284. }
  285. </style>