index.uvue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <uni-navbar-lite :show-right=false title="库存查询"></uni-navbar-lite>
  3. <view class="list-page">
  4. <view class="search-block">
  5. <view class="search-bar">
  6. <view class="search-box">
  7. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  8. <input class="search-input" type="text" placeholder="请输入物料名称查询" v-model="keyword" @input="handleSearch" />
  9. <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
  10. <text class="clear-btn-text">×</text>
  11. </view>
  12. <view class="search-btn" @tap="handleSearch">
  13. <text class="search-btn-text">搜索</text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="status-tabs">
  19. <view
  20. class="status-tab"
  21. :class="{ 'active': currentStatus === '' }"
  22. @tap="handleStatusChange('')"
  23. >
  24. <text class="status-tab-text" :class="{ 'active-text': currentStatus === '' }">全部</text>
  25. </view>
  26. <view
  27. class="status-tab"
  28. :class="{ 'active': currentStatus === '1' }"
  29. @tap="handleStatusChange('1')"
  30. >
  31. <text class="status-tab-text" :class="{ 'active-text': currentStatus === '1' }">有库存</text>
  32. </view>
  33. <view
  34. class="status-tab"
  35. :class="{ 'active': currentStatus === '0' }"
  36. @tap="handleStatusChange('0')"
  37. >
  38. <text class="status-tab-text" :class="{ 'active-text': currentStatus === '0' }">无库存</text>
  39. </view>
  40. </view>
  41. <common-list
  42. :dataList="dataList"
  43. :loading="loading"
  44. :refreshing="refreshing"
  45. :hasMore="hasMore"
  46. @refresh="handleRefresh"
  47. @loadMore="loadMore"
  48. >
  49. <template #default="{ item, index }">
  50. <view class="list-item">
  51. <view class="item-container">
  52. <view class="item-header">
  53. <view class="item-main-info">
  54. <view class="item-name-row">
  55. <text class="item-name">{{ getItemName(item) }}</text>
  56. <text class="item-measure">{{ getMeasureName(item) }}</text>
  57. </view>
  58. <view class="item-details">
  59. <text class="item-code">编码: {{ getItemCode(item) }}</text>
  60. </view>
  61. </view>
  62. <view class="item-qty-row">
  63. <text class="item-qty-label">在库</text>
  64. <text class="item-qty-value">{{ getQuantityOnhand(item) }}</text>
  65. </view>
  66. </view>
  67. <view class="item-info">
  68. <view class="info-row">
  69. <text class="info-label">规格型号</text>
  70. <text class="info-value">{{ getSpecification(item) }}</text>
  71. </view>
  72. <view class="info-row">
  73. <text class="info-label">入库批次</text>
  74. <text class="info-value">{{ getBatchCode(item) }}</text>
  75. </view>
  76. <view class="info-row">
  77. <text class="info-label">仓库位置</text>
  78. <text class="info-value">{{ getWarehouseFull(item) }}</text>
  79. </view>
  80. <view class="info-row">
  81. <text class="info-label">供应商</text>
  82. <text class="info-value">{{ getVendorName(item) }}</text>
  83. </view>
  84. <view class="info-row">
  85. <text class="info-label">入库日期</text>
  86. <text class="info-value">{{ getRecptDate(item) }}</text>
  87. </view>
  88. <view class="info-row" v-if="getExpireDate(item).length > 0">
  89. <text class="info-label">有效期至</text>
  90. <text class="info-value">{{ getExpireDate(item) }}</text>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. </common-list>
  97. </view>
  98. </template>
  99. <script setup lang="uts">
  100. import { ref, onMounted } from 'vue'
  101. import { onShow } from '@dcloudio/uni-app';
  102. import { listWmstock } from '../../api/wmstock/index'
  103. let searchTimer: number | null = null
  104. const dataList = ref<any[]>([])
  105. const keyword = ref<string>("")
  106. const currentStatus = ref<string>('1')
  107. const page = ref<number>(1)
  108. const pageSize: number = 10
  109. const hasMore = ref<boolean>(true)
  110. const loading = ref<boolean>(false)
  111. const refreshing = ref<boolean>(false)
  112. const getItemName = (item: any | null): string => {
  113. if (item == null) return ''
  114. const jsonItem = item as UTSJSONObject
  115. const val = jsonItem['itemName']
  116. return val != null ? val.toString() : ''
  117. }
  118. const getItemCode = (item: any | null): string => {
  119. if (item == null) return ''
  120. const jsonItem = item as UTSJSONObject
  121. const val = jsonItem['itemCode']
  122. return val != null ? val.toString() : ''
  123. }
  124. const getMeasureName = (item: any | null): string => {
  125. if (item == null) return ''
  126. const jsonItem = item as UTSJSONObject
  127. const val = jsonItem['measureName']
  128. return val != null ? val.toString() : ''
  129. }
  130. const getSpecification = (item: any | null): string => {
  131. if (item == null) return ''
  132. const jsonItem = item as UTSJSONObject
  133. const val = jsonItem['specification']
  134. return val != null ? val.toString() : ''
  135. }
  136. const getQuantityOnhand = (item: any | null): string => {
  137. if (item == null) return '0'
  138. const jsonItem = item as UTSJSONObject
  139. const val = jsonItem['quantityOnhand']
  140. return val != null ? val.toString() : '0'
  141. }
  142. const getBatchCode = (item: any | null): string => {
  143. if (item == null) return ''
  144. const jsonItem = item as UTSJSONObject
  145. const val = jsonItem['batchCode']
  146. return val != null ? val.toString() : ''
  147. }
  148. const getWarehouseFull = (item: any | null): string => {
  149. if (item == null) return ''
  150. const jsonItem = item as UTSJSONObject
  151. const wh = jsonItem['warehouseName']
  152. const loc = jsonItem['locationName']
  153. const area = jsonItem['areaCode']
  154. let result = wh != null ? wh.toString() : ''
  155. if (loc != null && loc.toString().length > 0) result += '->' + loc.toString()
  156. if (area != null && area.toString().length > 0) result += '->' + area.toString()
  157. return result
  158. }
  159. const getVendorName = (item: any | null): string => {
  160. if (item == null) return ''
  161. const jsonItem = item as UTSJSONObject
  162. const val = jsonItem['vendorName']
  163. return val != null ? val.toString() : ''
  164. }
  165. const getRecptDate = (item: any | null): string => {
  166. if (item == null) return ''
  167. const jsonItem = item as UTSJSONObject
  168. const val = jsonItem['recptDate']
  169. if (val == null) return ''
  170. const dateStr = val.toString()
  171. return dateStr.length >= 10 ? dateStr.substring(0, 10) : dateStr
  172. }
  173. const getExpireDate = (item: any | null): string => {
  174. if (item == null) return ''
  175. const jsonItem = item as UTSJSONObject
  176. const val = jsonItem['expireDate']
  177. if (val == null) return ''
  178. const dateStr = val.toString()
  179. return dateStr.length >= 10 ? dateStr.substring(0, 10) : dateStr
  180. }
  181. const loadData = async (isRefresh: boolean): Promise<void> => {
  182. if (loading.value) return
  183. try {
  184. loading.value = true
  185. if (isRefresh) {
  186. page.value = 1
  187. }
  188. const result = await listWmstock(page.value, pageSize, keyword.value, currentStatus.value)
  189. const resultObj = result as UTSJSONObject
  190. const rows = resultObj['rows']
  191. const total = resultObj['total'] as number
  192. if (rows != null) {
  193. const newData = rows as any[]
  194. if (isRefresh) {
  195. dataList.value = newData
  196. } else {
  197. dataList.value = [...dataList.value, ...newData]
  198. }
  199. hasMore.value = dataList.value.length < total
  200. } else {
  201. if (isRefresh) {
  202. dataList.value = []
  203. }
  204. hasMore.value = false
  205. }
  206. } catch (e) {
  207. console.error('加载失败:', e)
  208. } finally {
  209. loading.value = false
  210. refreshing.value = false
  211. }
  212. }
  213. const handleSearch = (): void => {
  214. const timer = searchTimer
  215. if (timer != null) {
  216. clearTimeout(timer)
  217. }
  218. searchTimer = setTimeout(() => {
  219. loadData(true)
  220. }, 300)
  221. }
  222. const handleStatusChange = (status: string): void => {
  223. currentStatus.value = status
  224. page.value = 1
  225. loadData(true)
  226. }
  227. const clearKeyword = (): void => {
  228. keyword.value = ''
  229. loadData(true)
  230. }
  231. const handleRefresh = (): void => {
  232. refreshing.value = true
  233. loadData(true)
  234. }
  235. const loadMore = (): void => {
  236. if (!hasMore.value || loading.value) return
  237. page.value++
  238. loadData(false)
  239. }
  240. onMounted(() => {
  241. loadData(true)
  242. })
  243. onShow(() => {
  244. loadData(true)
  245. })
  246. </script>
  247. <style lang="scss">
  248. .list-page {
  249. flex: 1;
  250. background-color: #e8f0f9;
  251. }
  252. .search-block {
  253. background-color: #ffffff;
  254. border-radius: 15rpx;
  255. }
  256. .search-bar {
  257. padding: 20rpx 30rpx;
  258. }
  259. .search-box {
  260. flex-direction: row;
  261. align-items: center;
  262. height: 72rpx;
  263. padding: 0 24rpx;
  264. background-color: #f5f5f5;
  265. border-radius: 36rpx;
  266. .search-icon {
  267. width: 32rpx;
  268. height: 32rpx;
  269. margin-right: 12rpx;
  270. }
  271. .search-input {
  272. flex: 1;
  273. font-size: 28rpx;
  274. color: #333333;
  275. }
  276. .search-btn {
  277. padding: 10rpx 20rpx;
  278. background-color: #007aff;
  279. border-radius: 8rpx;
  280. margin-left: 10rpx;
  281. }
  282. .search-btn-text {
  283. color: #ffffff;
  284. font-size: 24rpx;
  285. }
  286. .clear-btn {
  287. width: 36rpx;
  288. height: 36rpx;
  289. border-radius: 18rpx;
  290. background-color: #cccccc;
  291. align-items: center;
  292. justify-content: center;
  293. margin-left: 10rpx;
  294. }
  295. .clear-btn-text {
  296. color: #ffffff;
  297. font-size: 24rpx;
  298. font-weight: bold;
  299. }
  300. }
  301. .status-tabs {
  302. display: flex;
  303. flex-direction: row;
  304. padding: 0rpx 30rpx 20rpx;
  305. background-color: #ffffff;
  306. }
  307. .status-tab {
  308. flex: 1;
  309. padding: 16rpx 0;
  310. text-align: center;
  311. margin-right: 16rpx;
  312. border-radius: 8rpx;
  313. background-color: #f5f5f5;
  314. justify-content: center;
  315. align-items: center;
  316. &:last-child {
  317. margin-right: 0;
  318. }
  319. &.active {
  320. background-color: #007aff;
  321. }
  322. .status-tab-text {
  323. font-size: 26rpx;
  324. color: #666666;
  325. &.active-text {
  326. color: #ffffff;
  327. font-weight: bold;
  328. }
  329. }
  330. }
  331. .list-item {
  332. margin: 8rpx 10rpx;
  333. background-color: #ffffff;
  334. border-radius: 12rpx;
  335. }
  336. .item-container {
  337. padding: 20rpx;
  338. }
  339. .item-header {
  340. flex-direction: row;
  341. align-items: flex-start;
  342. justify-content: space-between;
  343. margin-bottom: 12rpx;
  344. width: 100%;
  345. .item-main-info {
  346. flex: 1;
  347. margin-right: 20rpx;
  348. }
  349. .item-name-row {
  350. flex-direction: row;
  351. align-items: center;
  352. margin-bottom: 8rpx;
  353. }
  354. .item-name {
  355. font-size: 28rpx;
  356. color: #1d2129;
  357. font-weight: bold;
  358. }
  359. .item-measure {
  360. font-size: 24rpx;
  361. color: #86909c;
  362. margin-left: 10rpx;
  363. }
  364. .item-details {
  365. flex-direction: row;
  366. width: 100%;
  367. }
  368. .item-code {
  369. font-size: 23rpx;
  370. color: #797979;
  371. flex: 1;
  372. }
  373. .item-qty-row {
  374. flex-direction: column;
  375. align-items: center;
  376. justify-content: center;
  377. background-color: #f0f5ff;
  378. padding: 10rpx 16rpx;
  379. border-radius: 8rpx;
  380. min-width: 100rpx;
  381. }
  382. .item-qty-label {
  383. font-size: 20rpx;
  384. color: #165dff;
  385. }
  386. .item-qty-value {
  387. font-size: 32rpx;
  388. color: #165dff;
  389. font-weight: 700;
  390. }
  391. }
  392. .item-info {
  393. .info-row {
  394. flex-direction: row;
  395. padding: 4rpx 0;
  396. }
  397. .info-label {
  398. font-size: 24rpx;
  399. color: #86909c;
  400. width: 120rpx;
  401. flex-shrink: 0;
  402. }
  403. .info-value {
  404. font-size: 24rpx;
  405. color: #1d2129;
  406. flex: 1;
  407. }
  408. }
  409. </style>