index.uvue 13 KB

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