index.uvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <uni-navbar-lite :showRight=false title="物料清单"></uni-navbar-lite>
  3. <view class="page-container">
  4. <view class="list-page">
  5. <!-- 搜索栏和类型标签 -->
  6. <view class="search-block">
  7. <view class="search-bar">
  8. <view class="search-box">
  9. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  10. <input class="search-input" type="text" placeholder="请输入关键字查询" v-model="keyword" @input="handleSearch" />
  11. <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
  12. <text class="clear-btn-text">×</text>
  13. </view>
  14. <view class="search-btn" @tap="handleSearch">
  15. <text class="search-btn-text">搜索</text>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 类型标签 -->
  20. <view class="status-tabs">
  21. <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false">
  22. <view
  23. v-for="(cat, idx) in categories"
  24. :key="idx"
  25. class="status-tab"
  26. :class="{ 'active': currentStatus === cat.id }"
  27. @click="switchStatus(cat.id)"
  28. >
  29. <text class="status-tab-text" :class="{ 'active-text': currentStatus === cat.id }">{{ cat.name }}</text>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </view>
  34. <!-- 列表内容 -->
  35. <common-list
  36. :dataList="dataList"
  37. :loading="loading"
  38. :refreshing="refreshing"
  39. :hasMore="hasMore"
  40. @refresh="handleRefresh"
  41. @loadMore="loadMore"
  42. >
  43. <template #default="{ item, index }">
  44. <view class="list-item" @click="handleItemClick(item)">
  45. <view class="item-container">
  46. <view class="item-header">
  47. <view class="item-main-info">
  48. <view class="item-name-row">
  49. <text class="item-name">{{ getItemName(item) }}</text>
  50. <text class="item-measure">{{ getMeasureName(item) }}</text>
  51. </view>
  52. <view class="item-details">
  53. <text class="item-code">编码: {{ getItemCode(item) }}</text>
  54. <text class="item-warehouse">仓库: {{ getWarehouseName(item) }}</text>
  55. </view>
  56. </view>
  57. <text class="item-type">{{ getItemTypeName(item) }}</text>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. </common-list>
  63. </view>
  64. </view>
  65. </template>
  66. <script setup lang="uts">
  67. import { ref, onMounted } from 'vue'
  68. import { onLoad, onShow } from '@dcloudio/uni-app';
  69. import { getItemList, getItemTypeListByParentId } from '../../api/apply/index'
  70. type CategoryItem = { id: string; name: string; code: string }
  71. // 列表数据
  72. const dataList = ref<any[]>([])
  73. const keyword = ref<string>("")
  74. let searchTimer: number | null = null
  75. const page = ref<number>(1)
  76. const pageSize: number = 10
  77. const hasMore = ref<boolean>(true)
  78. const loading = ref<boolean>(false)
  79. const refreshing = ref<boolean>(false)
  80. // 分类数据
  81. const categories = ref<CategoryItem[]>([])
  82. const currentStatus = ref<string>('')
  83. const isSearching = ref<boolean>(false)
  84. // 获取物料名称
  85. const getItemName = (item: any | null): string => {
  86. if (item == null) return ''
  87. const jsonItem = item as UTSJSONObject
  88. const val = jsonItem['itemName']
  89. return val != null ? val.toString() : ''
  90. }
  91. // 获取物料类型
  92. const getItemTypeName = (item: any | null): string => {
  93. if (item == null) return ''
  94. const jsonItem = item as UTSJSONObject
  95. const val = jsonItem['itemTypeName']
  96. return val != null ? val.toString() : ''
  97. }
  98. // 获取计量单位
  99. const getMeasureName = (item: any | null): string => {
  100. if (item == null) return ''
  101. const jsonItem = item as UTSJSONObject
  102. const val = jsonItem['measureName']
  103. return val != null ? val.toString() : ''
  104. }
  105. // 获取物料编码
  106. const getItemCode = (item: any | null): string => {
  107. if (item == null) return ''
  108. const jsonItem = item as UTSJSONObject
  109. const val = jsonItem['itemCode']
  110. return val != null ? val.toString() : ''
  111. }
  112. // 获取仓库名称
  113. const getWarehouseName = (item: any | null): string => {
  114. if (item == null) return ''
  115. const jsonItem = item as UTSJSONObject
  116. const val = jsonItem['warehouseName']
  117. return val != null ? val.toString() : ''
  118. }
  119. // 点击列表项跳转到详情页
  120. const handleItemClick = (item: any | null): void => {
  121. if (item == null) return
  122. const jsonItem = item as UTSJSONObject
  123. const itemId = jsonItem['itemId']
  124. if (itemId != null) {
  125. uni.navigateTo({
  126. url: '/pages/item/detail?id=' + itemId.toString()
  127. })
  128. }
  129. }
  130. // 获取当前选中的分类code
  131. const getCurrentCategoryCode = (): string => {
  132. const currentCat = categories.value.find((c: CategoryItem) => c.id === currentStatus.value)
  133. return currentCat != null ? currentCat.code : ''
  134. }
  135. // 加载列表数据
  136. const loadData = async (isRefresh: boolean): Promise<void> => {
  137. if (loading.value) return
  138. try {
  139. loading.value = true
  140. if (isRefresh) {
  141. page.value = 1
  142. }
  143. const searchKeyword = keyword.value != null ? keyword.value : ''
  144. const itemTypeCode = getCurrentCategoryCode()
  145. const result = await getItemList(itemTypeCode, page.value, pageSize, searchKeyword)
  146. const resultObj = result as UTSJSONObject
  147. const rows = resultObj['rows']
  148. const total = resultObj['total'] as number
  149. if (rows != null) {
  150. const newData = rows as any[]
  151. if (isRefresh) {
  152. dataList.value = newData
  153. } else {
  154. dataList.value = [...dataList.value, ...newData]
  155. }
  156. hasMore.value = dataList.value.length < total
  157. } else {
  158. if (isRefresh) {
  159. dataList.value = []
  160. }
  161. hasMore.value = false
  162. }
  163. } catch (e) {
  164. console.error('加载失败:', e)
  165. } finally {
  166. loading.value = false
  167. refreshing.value = false
  168. }
  169. }
  170. // 加载分类数据
  171. const loadCategories = (): void => {
  172. getItemTypeListByParentId(200).then((res: any) => {
  173. const data = res as UTSJSONObject
  174. const list = data['data']
  175. if (list != null) {
  176. const listData = list as UTSJSONObject[]
  177. if (listData.length > 0) {
  178. const arr: CategoryItem[] = []
  179. listData.forEach((item: UTSJSONObject) => {
  180. const idVal = item['itemTypeId']
  181. const nameVal = item['itemTypeName']
  182. const codeVal = item['itemTypeCode']
  183. const cat: CategoryItem = {
  184. id: idVal != null ? idVal.toString() : '',
  185. name: nameVal != null ? nameVal.toString() : '',
  186. code: codeVal != null ? codeVal.toString() : ''
  187. }
  188. arr.push(cat)
  189. })
  190. const allItem: CategoryItem = {id: '', name: '全部', code: ''}
  191. arr.unshift(allItem)
  192. categories.value = arr
  193. // 加载第一个分类的物料
  194. if (arr.length > 0) {
  195. currentStatus.value = arr[0].id
  196. loadData(true)
  197. }
  198. return
  199. }
  200. }
  201. const defaultArr: CategoryItem[] = []
  202. const defaultItem: CategoryItem = {id: '', name: '全部', code: ''}
  203. defaultArr.push(defaultItem)
  204. categories.value = defaultArr
  205. }).catch(() => {
  206. const defaultArr: CategoryItem[] = []
  207. const defaultItem: CategoryItem = {id: '', name: '全部', code: ''}
  208. defaultArr.push(defaultItem)
  209. categories.value = defaultArr
  210. })
  211. }
  212. // 切换分类
  213. const switchStatus = (status: string): void => {
  214. if (loading.value) {
  215. return;
  216. }
  217. if (isSearching.value) {
  218. return
  219. }
  220. isSearching.value = true
  221. currentStatus.value = status
  222. page.value = 1
  223. loadData(true)
  224. setTimeout(() => {
  225. isSearching.value = false
  226. }, 100)
  227. }
  228. // 下拉刷新
  229. const handleRefresh = (): void => {
  230. refreshing.value = true
  231. loadData(true)
  232. }
  233. // 加载更多
  234. const loadMore = (): void => {
  235. if (!hasMore.value || loading.value) return
  236. page.value++
  237. loadData(false)
  238. }
  239. // 搜索
  240. const handleSearch = (): void => {
  241. const timer = searchTimer
  242. if (timer != null) {
  243. clearTimeout(timer)
  244. }
  245. searchTimer = setTimeout(() => {
  246. page.value = 1
  247. loadData(true)
  248. }, 300)
  249. }
  250. // 清空搜索关键字
  251. const clearKeyword = (): void => {
  252. keyword.value = ''
  253. page.value = 1
  254. loadData(true)
  255. }
  256. // 初始化
  257. onMounted(() => {
  258. loadCategories()
  259. })
  260. // 页面显示时刷新列表
  261. onShow(() => {
  262. loadData(true)
  263. })
  264. </script>
  265. <style lang="scss">
  266. .page-container {
  267. flex: 1;
  268. background-color: #f5f8fe;
  269. padding-top: env(safe-area-inset-top);
  270. background-color: #e8f0f9;
  271. padding: 20rpx 10rpx 20rpx 10rpx;
  272. }
  273. .page-header{
  274. font-size: 32rpx;
  275. color: #333333;
  276. font-weight: bold;
  277. padding-top:20px;
  278. padding-bottom: 10px;
  279. }
  280. .list-page {
  281. flex: 1;
  282. background-color: #e8f0f9;
  283. }
  284. .search-block {
  285. background-color: #ffffff;
  286. border-radius: 15rpx;
  287. }
  288. .search-bar {
  289. padding: 20rpx 30rpx;
  290. }
  291. .search-box {
  292. flex-direction: row;
  293. align-items: center;
  294. height: 72rpx;
  295. padding: 0 24rpx;
  296. background-color: #f5f5f5;
  297. border-radius: 36rpx;
  298. .search-icon {
  299. width: 32rpx;
  300. height: 32rpx;
  301. margin-right: 12rpx;
  302. }
  303. .search-input {
  304. flex: 1;
  305. font-size: 28rpx;
  306. color: #333333;
  307. }
  308. .search-btn {
  309. padding: 10rpx 20rpx;
  310. background-color: #007aff;
  311. border-radius: 8rpx;
  312. margin-left: 10rpx;
  313. }
  314. .search-btn-text {
  315. color: #ffffff;
  316. font-size: 24rpx;
  317. }
  318. .clear-btn {
  319. width: 36rpx;
  320. height: 36rpx;
  321. border-radius: 18rpx;
  322. background-color: #cccccc;
  323. align-items: center;
  324. justify-content: center;
  325. margin-left: 10rpx;
  326. }
  327. .clear-btn-text {
  328. color: #ffffff;
  329. font-size: 24rpx;
  330. font-weight: bold;
  331. }
  332. }
  333. .status-tabs {
  334. padding: 20rpx 30rpx;
  335. background-color: #ffffff;
  336. border-bottom: 1rpx solid #eeeeee;
  337. }
  338. .scroll-view_H {
  339. width: 100%;
  340. flex-direction: row;
  341. }
  342. .status-tab {
  343. padding: 16rpx 24rpx;
  344. text-align: center;
  345. margin-right: 16rpx;
  346. border-radius: 8rpx;
  347. background-color: #f5f5f5;
  348. flex-shrink: 0;
  349. &:last-child {
  350. margin-right: 0;
  351. }
  352. &.active {
  353. background-color: #007aff;
  354. }
  355. .status-tab-text {
  356. font-size: 26rpx;
  357. color: #666666;
  358. &.active-text {
  359. color: #ffffff;
  360. font-weight: bold;
  361. }
  362. }
  363. }
  364. .list-item {
  365. margin: 10rpx 10rpx;
  366. background-color: #ffffff;
  367. border-radius: 16rpx;
  368. }
  369. .item-container {
  370. padding: 30rpx;
  371. }
  372. .item-header {
  373. flex-direction: row;
  374. align-items: flex-start;
  375. justify-content: space-between;
  376. margin-bottom: 10rpx;
  377. width: 100%;
  378. .item-main-info {
  379. flex: 1;
  380. margin-right: 20rpx;
  381. }
  382. .item-name-row {
  383. flex-direction: row;
  384. align-items: center;
  385. margin-bottom: 8rpx;
  386. }
  387. .item-name {
  388. font-size: 28rpx;
  389. color: #333333;
  390. font-weight: bold;
  391. }
  392. .item-measure {
  393. font-size: 24rpx;
  394. color: #999999;
  395. margin-left: 10rpx;
  396. }
  397. .item-details {
  398. flex-direction: row;
  399. justify-content: space-between;
  400. width: 100%;
  401. }
  402. .item-code {
  403. font-size: 23rpx;
  404. color: #797979;
  405. flex: 1;
  406. }
  407. .item-warehouse {
  408. font-size: 23rpx;
  409. color: #797979;
  410. flex: 1;
  411. text-align: right;
  412. }
  413. .item-type {
  414. font-size: 24rpx;
  415. color: #007aff;
  416. background-color: #e6f7ff;
  417. padding: 8rpx 16rpx;
  418. border-radius: 8rpx;
  419. white-space: nowrap;
  420. }
  421. }
  422. </style>