index.uvue 21 KB

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