index.uvue 13 KB

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