index.uvue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <uni-navbar-lite @rightClick="handleRight" :show-right="showRight" title="物料申请"></uni-navbar-lite>
  3. <view class="list-page">
  4. <!-- 搜索栏和状态标签 -->
  5. <view class="search-block">
  6. <view class="search-bar">
  7. <view class="search-box">
  8. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  9. <input class="search-input" type="text" placeholder="请输入申请单号查询" v-model="keyword" @input="handleSearch" />
  10. <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
  11. <text class="clear-btn-text">×</text>
  12. </view>
  13. <view class="search-btn" @tap="handleSearch">
  14. <text class="search-btn-text">搜索</text>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- 状态标签 -->
  19. <scroll-view class="status-tabs" scroll-x="true">
  20. <view
  21. class="status-tab"
  22. :class="{ 'active': currentStatus === '' }"
  23. @tap="handleStatusChange('')"
  24. >
  25. <text class="status-tab-text" :class="{ 'active-text': currentStatus === '' }">全部</text>
  26. </view>
  27. <view
  28. class="status-tab"
  29. :class="{ 'active': currentStatus === 'PREPARE' }"
  30. @tap="handleStatusChange('PREPARE')"
  31. >
  32. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'PREPARE' }">待确认</text>
  33. </view>
  34. <view
  35. class="status-tab"
  36. :class="{ 'active': currentStatus === 'CONFIRMED' }"
  37. @tap="handleStatusChange('CONFIRMED')"
  38. >
  39. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'CONFIRMED' }">已确认</text>
  40. </view>
  41. <view
  42. class="status-tab"
  43. :class="{ 'active': currentStatus === 'WAITOUT' }"
  44. @tap="handleStatusChange('WAITOUT')"
  45. >
  46. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'WAITOUT' }">待出库</text>
  47. </view>
  48. <view
  49. class="status-tab"
  50. :class="{ 'active': currentStatus === 'FINISHED' }"
  51. @tap="handleStatusChange('FINISHED')"
  52. >
  53. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'FINISHED' }">已完成</text>
  54. </view>
  55. </scroll-view>
  56. </view>
  57. <!-- 列表内容 -->
  58. <common-list
  59. :dataList="dataList"
  60. :loading="loading"
  61. :refreshing="refreshing"
  62. :hasMore="hasMore"
  63. @refresh="handleRefresh"
  64. @loadMore="loadMore"
  65. @itemClick="handleItemClick"
  66. >
  67. <template #default="{ item, index }">
  68. <view class="list-item">
  69. <view class="item-container">
  70. <view class="item-header">
  71. <text class="item-title">{{ getApplyCode(item) }}</text>
  72. <text class="item-status" :class="'status-' + getStatus(item)">{{ getStatusText(item) }}</text>
  73. </view>
  74. <view class="item-info">
  75. <view class="info-row">
  76. <view class="info-item">
  77. <text class="info-label">申请时间</text>
  78. <text class="info-value">{{ getCreateTime(item) }}</text>
  79. </view>
  80. <view class="info-item">
  81. <text class="info-label">申请人</text>
  82. <text class="info-value">{{ getNickName(item) }}</text>
  83. </view>
  84. </view>
  85. <view class="info-row">
  86. <view class="info-item">
  87. <text class="info-label">申请数</text>
  88. <text class="info-value warning">{{ getApplyCount(item) }}</text>
  89. </view>
  90. <view class="info-item">
  91. <text class="info-label">已出库</text>
  92. <text class="info-value primary">{{ getOutCount(item) }}</text>
  93. </view>
  94. </view>
  95. <view class="info-row">
  96. <view class="info-item">
  97. <text class="info-label">申购状态</text>
  98. <text class="info-value" :class="'purchase-status-' + getPurchaseStatus(item)">{{ getPurchaseStatusText(item) }}</text>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </template>
  105. </common-list>
  106. </view>
  107. </template>
  108. <script setup lang="uts">
  109. import { ref } from 'vue'
  110. import { onLoad, onShow } from '@dcloudio/uni-app';
  111. import { getPurchaseApplyList, getPendingReceiveApplyCount } from '../../api/apply/index'
  112. import { getUserInfo } from '../../utils/storage'
  113. let currentUserId: string = ''
  114. // 列表数据
  115. const dataList = ref<any[]>([])
  116. const keyword = ref<string>("")
  117. let searchTimer: number | null = null
  118. const currentStatus = ref<string>("")
  119. const page = ref<number>(1)
  120. const pageSize: number = 10
  121. const hasMore = ref<boolean>(true)
  122. const loading = ref<boolean>(false)
  123. const refreshing = ref<boolean>(false)
  124. const showRight = ref<boolean>(false)
  125. const pendingReceiveCount = ref<number>(0)
  126. // 加载待领取数量
  127. const loadPendingReceiveCount = (): void => {
  128. if (currentUserId.length === 0) return
  129. getPendingReceiveApplyCount(currentUserId).then((res: any) => {
  130. const result = res as UTSJSONObject
  131. const count = result['data']
  132. pendingReceiveCount.value = count != null ? parseInt(count.toString()) : 0
  133. }).catch((e) => {
  134. console.error('加载待领取数量失败:', e)
  135. })
  136. }
  137. // 获取申请单号
  138. const getApplyCode = (item: any | null): string => {
  139. if (item == null) return ''
  140. const jsonItem = item as UTSJSONObject
  141. const val = jsonItem['applyCode']
  142. return val != null ? val.toString() : ''
  143. }
  144. // 获取状态
  145. const getStatus = (item: any | null): string => {
  146. if (item == null) return ''
  147. const jsonItem = item as UTSJSONObject
  148. const val = jsonItem['status']
  149. return val != null ? val.toString() : ''
  150. }
  151. // 获取状态文本
  152. const getStatusText = (item: any | null): string => {
  153. if (item == null) return ''
  154. const jsonItem = item as UTSJSONObject
  155. const val = jsonItem['status']
  156. const status = val != null ? val.toString() : ''
  157. switch (status) {
  158. case 'PREPARE': return '草稿'
  159. case 'CONFIRMED': return '已确认'
  160. case 'FINISHED': return '已完成'
  161. case 'CANCEL': return '已取消'
  162. case 'APPROVED': return '已审批'
  163. case 'APPROVING': return '审批中'
  164. case 'WAITOUT': return '待出库'
  165. default: return status
  166. }
  167. }
  168. // 获取申购状态
  169. const getPurchaseStatus = (item: any | null): string => {
  170. if (item == null) return ''
  171. const jsonItem = item as UTSJSONObject
  172. const val = jsonItem['applyStatus']
  173. return val != null ? val.toString() : ''
  174. }
  175. // 获取申购状态文本
  176. const getPurchaseStatusText = (item: any | null): string => {
  177. if (item == null) return ''
  178. const jsonItem = item as UTSJSONObject
  179. const val = jsonItem['applyStatus']
  180. const status = val != null ? val.toString() : ''
  181. switch (status) {
  182. case '0': return '未申购'
  183. case '1': return '已申购'
  184. default: return ''
  185. }
  186. }
  187. // 获取创建时间
  188. const getCreateTime = (item: any | null): string => {
  189. if (item == null) return ''
  190. const jsonItem = item as UTSJSONObject
  191. const val = jsonItem['createTime']
  192. return val != null ? val.toString() : ''
  193. }
  194. // 获取申请人
  195. const getNickName = (item: any | null): string => {
  196. if (item == null) return ''
  197. const jsonItem = item as UTSJSONObject
  198. const val = jsonItem['nickName']
  199. return val != null ? val.toString() : ''
  200. }
  201. // 获取申请数量
  202. const getApplyCount = (item: any | null): string => {
  203. if (item == null) return '0'
  204. const jsonItem = item as UTSJSONObject
  205. const val = jsonItem['applyQuantity']
  206. return val != null ? val.toString() : '0'
  207. }
  208. // 获取已出库数量
  209. const getOutCount = (item: any | null): string => {
  210. if (item == null) return '0'
  211. const jsonItem = item as UTSJSONObject
  212. const val = jsonItem['outQuantity']
  213. return val != null ? val.toString() : '0'
  214. }
  215. // 获取已完成数量
  216. const getFinishedCount = (item: any | null): string => {
  217. if (item == null) return '0'
  218. const jsonItem = item as UTSJSONObject
  219. const val = jsonItem['finishedCount']
  220. return val != null ? val.toString() : '0'
  221. }
  222. // 获取待审核数量 (status=1)
  223. const getPendingAuditCount = (item: any | null): string => {
  224. if (item == null) return '0'
  225. const jsonItem = item as UTSJSONObject
  226. const val = jsonItem['pendingAuditCount']
  227. return val != null ? val.toString() : '0'
  228. }
  229. // 获取待领取数量 (status=2 + status=4)
  230. const getPendingReceiveCount = (item: any | null): string => {
  231. if (item == null) return '0'
  232. const jsonItem = item as UTSJSONObject
  233. const val = jsonItem['pendingReceiveCount']
  234. return val != null ? val.toString() : '0'
  235. }
  236. // 获取待采购数量 (status=3 + status=4)
  237. const getPendingPurchaseCount = (item: any | null): string => {
  238. if (item == null) return '0'
  239. const jsonItem = item as UTSJSONObject
  240. const val = jsonItem['pendingPurchaseCount']
  241. return val != null ? val.toString() : '0'
  242. }
  243. // 加载列表数据
  244. const loadData = async (isRefresh: boolean): Promise<void> => {
  245. if (loading.value) return
  246. try {
  247. loading.value = true
  248. if (isRefresh) {
  249. page.value = 1
  250. }
  251. const searchKeyword = keyword.value != null ? keyword.value : ''
  252. const isPendingReceive = currentStatus.value === 'PENDING_RECEIVE'
  253. const statusParam = isPendingReceive ? '' : (currentStatus.value != null ? currentStatus.value : '')
  254. console.log('loadData - statusParam:', statusParam, 'isPendingReceive:', isPendingReceive)
  255. const result = await getPurchaseApplyList(page.value, pageSize, searchKeyword, statusParam, currentUserId, isPendingReceive)
  256. console.log('getPurchaseApplyList result:', result)
  257. const resultObj = result as UTSJSONObject
  258. const rows = resultObj['rows']
  259. const total = resultObj['total'] as number
  260. console.log('rows:', rows, 'total:', total)
  261. if (rows != null) {
  262. const newData = rows as any[]
  263. if (isRefresh) {
  264. dataList.value = newData
  265. } else {
  266. dataList.value = [...dataList.value, ...newData]
  267. }
  268. hasMore.value = dataList.value.length < total
  269. } else {
  270. if (isRefresh) {
  271. dataList.value = []
  272. }
  273. hasMore.value = false
  274. }
  275. } catch (e) {
  276. console.error('加载失败:', e)
  277. } finally {
  278. loading.value = false
  279. refreshing.value = false
  280. }
  281. }
  282. // 下拉刷新
  283. const handleRefresh = (): void => {
  284. refreshing.value = true
  285. loadData(true)
  286. }
  287. // 加载更多
  288. const loadMore = (): void => {
  289. if (!hasMore.value || loading.value) return
  290. page.value++
  291. loadData(false)
  292. }
  293. // 搜索
  294. const handleSearch = (): void => {
  295. const timer = searchTimer
  296. if (timer != null) {
  297. clearTimeout(timer)
  298. }
  299. searchTimer = setTimeout(() => {
  300. loadData(true)
  301. }, 300)
  302. }
  303. // 清空搜索关键字
  304. const clearKeyword = (): void => {
  305. keyword.value = ''
  306. loadData(true)
  307. }
  308. // 切换状态
  309. const handleStatusChange = (status: string): void => {
  310. currentStatus.value = status
  311. loadData(true)
  312. }
  313. const handleRight = ():void=>{
  314. uni.navigateTo({
  315. url: `/pages/apply/applyNew?from=index`
  316. })
  317. }
  318. // 点击列表项
  319. const handleItemClick = (item: any | null, index: number): void => {
  320. if (item == null) return
  321. const jsonItem = item as UTSJSONObject
  322. const applyId = jsonItem['applyId']
  323. uni.navigateTo({
  324. url: `/pages/apply/applyInfo?id=${applyId}`
  325. })
  326. }
  327. // 初始化
  328. loadData(true)
  329. // 页面显示时刷新列表
  330. onShow(() => {
  331. loadData(true)
  332. loadPendingReceiveCount()
  333. })
  334. onMounted(() => {
  335. const userInfo = getUserInfo()
  336. if (userInfo != null) {
  337. const userName = userInfo['userName']
  338. currentUserId = userName != null ? userName.toString() : ''
  339. }
  340. // 获取页面参数,判断是否从index.uvue跳转过来
  341. const pages = getCurrentPages()
  342. const currentPage = pages[pages.length - 1]
  343. const options = currentPage.options
  344. if (options != null && options.from == 'new') {
  345. showRight.value = false
  346. }else{
  347. showRight.value = true
  348. }
  349. })
  350. </script>
  351. <style lang="scss">
  352. .list-page {
  353. flex: 1;
  354. background-color: #e8f0f9;
  355. }
  356. .search-block {
  357. background-color: #ffffff;
  358. }
  359. .pending-receive-bar {
  360. display: flex;
  361. flex-direction: row;
  362. align-items: center;
  363. padding: 20rpx 30rpx;
  364. background-color: #fff7e6;
  365. border-left: 6rpx solid #fa8c16;
  366. margin: 0 30rpx;
  367. border-radius: 8rpx;
  368. }
  369. .pending-receive-label {
  370. font-size: 28rpx;
  371. color: #fa8c16;
  372. font-weight: bold;
  373. }
  374. .pending-receive-count {
  375. margin-left: 16rpx;
  376. padding: 4rpx 16rpx;
  377. background-color: #fa8c16;
  378. color: #ffffff;
  379. font-size: 24rpx;
  380. border-radius: 20rpx;
  381. }
  382. .pending-receive-arrow {
  383. margin-left: auto;
  384. color: #999999;
  385. font-size: 28rpx;
  386. }
  387. .search-bar {
  388. padding: 20rpx 30rpx;
  389. }
  390. .status-tabs {
  391. display: flex;
  392. flex-direction: row;
  393. padding: 0rpx 30rpx 20rpx;
  394. background-color: #ffffff;
  395. white-space: nowrap;
  396. width: 100%;
  397. }
  398. .status-tab {
  399. display: inline-flex;
  400. flex-direction: row;
  401. align-items: center;
  402. padding: 16rpx 24rpx;
  403. text-align: center;
  404. position: relative;
  405. margin-right: 16rpx;
  406. border-radius: 8rpx;
  407. background-color: #f5f5f5;
  408. justify-content: center;
  409. align-items: center;
  410. &:last-child {
  411. margin-right: 0;
  412. }
  413. &.active {
  414. background-color: #007aff;
  415. }
  416. .status-tab-text {
  417. font-size: 26rpx;
  418. color: #666666;
  419. text-align: center;
  420. &.active-text {
  421. color: #ffffff;
  422. font-weight: bold;
  423. }
  424. }
  425. .tab-badge {
  426. margin-left: 8rpx;
  427. min-width: 32rpx;
  428. height: 32rpx;
  429. padding: 0 8rpx;
  430. background-color: #ff3b30;
  431. border-radius: 16rpx;
  432. justify-content: center;
  433. align-items: center;
  434. .tab-badge-text {
  435. font-size: 20rpx;
  436. color: #ffffff;
  437. }
  438. }
  439. }
  440. .search-box {
  441. flex-direction: row;
  442. align-items: center;
  443. height: 72rpx;
  444. padding: 0 24rpx;
  445. background-color: #f5f5f5;
  446. border-radius: 36rpx;
  447. .search-icon {
  448. width: 32rpx;
  449. height: 32rpx;
  450. margin-right: 12rpx;
  451. }
  452. .search-input {
  453. flex: 1;
  454. font-size: 28rpx;
  455. color: #333333;
  456. }
  457. .search-btn {
  458. padding: 10rpx 20rpx;
  459. background-color: #007aff;
  460. border-radius: 8rpx;
  461. margin-left: 10rpx;
  462. }
  463. .search-btn-text {
  464. color: #ffffff;
  465. font-size: 24rpx;
  466. }
  467. .clear-btn {
  468. width: 36rpx;
  469. height: 36rpx;
  470. border-radius: 18rpx;
  471. background-color: #cccccc;
  472. align-items: center;
  473. justify-content: center;
  474. margin-left: 10rpx;
  475. }
  476. .clear-btn-text {
  477. color: #ffffff;
  478. font-size: 24rpx;
  479. font-weight: bold;
  480. }
  481. }
  482. .list-item {
  483. margin: 10rpx 20rpx;
  484. background-color: #ffffff;
  485. border-radius: 16rpx;
  486. }
  487. .item-container {
  488. padding: 30rpx;
  489. }
  490. .item-header {
  491. flex-direction: row;
  492. align-items: center;
  493. margin-bottom: 20rpx;
  494. .item-title {
  495. flex: 1;
  496. font-size: 32rpx;
  497. color: #333333;
  498. font-weight: bold;
  499. }
  500. .item-status {
  501. font-size: 26rpx;
  502. padding: 6rpx 16rpx;
  503. border-radius: 6rpx;
  504. &.status-PREPARE {
  505. background-color: #f0f0f0;
  506. color: #666666;
  507. }
  508. &.status-CONFIRMED {
  509. background-color: #e6f7ff;
  510. color: #1890ff;
  511. }
  512. &.status-FINISHED {
  513. background-color: #f6ffed;
  514. color: #52c41a;
  515. }
  516. &.status-CANCEL {
  517. background-color: #fff1f0;
  518. color: #ff4d4f;
  519. }
  520. &.status-APPROVING {
  521. background-color: #d1f5f8;
  522. color: #ff007f;
  523. }
  524. &.status-WAITOUT {
  525. color: #fa8c16;
  526. }
  527. &.status-APPROVED {
  528. background-color: #ebfffd;
  529. color: #55ff00;
  530. }
  531. }
  532. }
  533. .item-info {
  534. padding: 20rpx;
  535. background-color: #f8f9fa;
  536. border-radius: 8rpx;
  537. .info-row {
  538. flex-direction: row;
  539. justify-content: space-between;
  540. margin-bottom: 16rpx;
  541. &:last-child {
  542. margin-bottom: 0;
  543. }
  544. .info-item {
  545. flex-direction: row;
  546. align-items: center;
  547. flex: 1;
  548. &:last-child {
  549. flex: 1;
  550. justify-content: flex-end;
  551. }
  552. .info-label {
  553. font-size: 26rpx;
  554. color: #666666;
  555. margin-right: 8rpx;
  556. white-space: nowrap;
  557. }
  558. .info-value {
  559. font-size: 26rpx;
  560. color: #333333;
  561. flex: 1;
  562. &.success {
  563. color: #52c41a;
  564. }
  565. &.warning {
  566. color: #faad14;
  567. }
  568. &.primary {
  569. color: #007aff;
  570. }
  571. &.purchase-status-0 {
  572. color: #faad14;
  573. }
  574. &.purchase-status-1 {
  575. color: #52c41a;
  576. }
  577. }
  578. }
  579. }
  580. }
  581. </style>