index.uvue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <template>
  2. <uni-navbar-lite :show-right=false 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. <view class="status-tabs">
  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 === 'CONFIRMED' }"
  30. @tap="handleStatusChange('CONFIRMED')"
  31. >
  32. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'CONFIRMED' }">待领取</text>
  33. </view>
  34. <view
  35. class="status-tab"
  36. :class="{ 'active': currentStatus === 'PENDING' }"
  37. @tap="handleStatusChange('PENDING')"
  38. >
  39. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'PENDING' }">待签收</text>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 列表内容 -->
  44. <common-list
  45. :dataList="dataList"
  46. :loading="loading"
  47. :refreshing="refreshing"
  48. :hasMore="hasMore"
  49. @refresh="handleRefresh"
  50. @loadMore="loadMore"
  51. @itemClick="handleItemClick"
  52. >
  53. <template #default="{ item, index }">
  54. <view class="list-item">
  55. <view class="item-container">
  56. <view class="item-header">
  57. <text class="item-title">{{ getSalseCode(item) }}</text>
  58. <text class="item-status" :class="'status-' + getStatus(item)">{{ getStatusText(item) }}</text>
  59. </view>
  60. <view class="item-info">
  61. <view class="info-row">
  62. <view class="info-item">
  63. <text class="info-label">创建人</text>
  64. <text class="info-value">{{ getCreateBy(item) }}</text>
  65. </view>
  66. <view class="info-item">
  67. <text class="info-label">领用对象</text>
  68. <text class="info-value">{{ getReceiverDept(item)}}{{ getReceiverUser(item) }}</text>
  69. </view>
  70. </view>
  71. <view class="info-row">
  72. <view class="info-item">
  73. <text class="info-label">创建时间</text>
  74. <text class="info-value">{{ getCreateTime(item) }}</text>
  75. </view>
  76. </view>
  77. <view class="info-row stat-row">
  78. <view class="info-item" v-if="getStatus(item) == 'FINISHED'">
  79. <text class="info-label stat-label">已签收</text>
  80. <text class="info-value success stat-value">{{ getSignedCount(item) }}</text>
  81. </view>
  82. <view class="info-item" v-if="getStatus(item) == 'FINISHED'">
  83. <text class="info-label stat-label">待签收</text>
  84. <text class="info-value warning stat-value">{{ getUnsignedCount(item) }}</text>
  85. </view>
  86. <view class="info-item" v-if="getStatus(item) == 'CONFIRMED'">
  87. <text class="info-label stat-label">待出库</text>
  88. <text class="info-value warning stat-value">{{ getTotalCount(item) }}</text>
  89. </view>
  90. </view>
  91. <view v-if="item != null && getStatus(item) == 'FINISHED' && getUnsignedCount(item) != '0'" class="sign-all-btn-wrap">
  92. <text class="sign-all-btn" @click.stop="handleSignAll(item)">一键签收</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. </common-list>
  99. </view>
  100. </template>
  101. <script setup lang="uts">
  102. import { ref, onMounted } from 'vue'
  103. import { onLoad, onShow } from '@dcloudio/uni-app';
  104. import { getProductSalseList, signReceiveAll } from '../../api/out/index'
  105. import { getUserInfo } from '../../utils/storage'
  106. let searchTimer: number | null = null
  107. // 列表数据
  108. const dataList = ref<any[]>([])
  109. const keyword = ref<string>("")
  110. const currentStatus = ref<string>("")
  111. const page = ref<number>(1)
  112. const pageSize: number = 10
  113. const hasMore = ref<boolean>(true)
  114. const loading = ref<boolean>(false)
  115. const refreshing = ref<boolean>(false)
  116. // 当前用户ID
  117. let currentUserId: string = ''
  118. // 获取出库单号
  119. const getSalseCode = (item: any | null): string => {
  120. if (item == null) return ''
  121. const jsonItem = item as UTSJSONObject
  122. const val = jsonItem['salseCode']
  123. return val != null ? val.toString() : ''
  124. }
  125. // 获取状态
  126. const getStatus = (item: any | null): string => {
  127. if (item == null) return ''
  128. const jsonItem = item as UTSJSONObject
  129. const val = jsonItem['status']
  130. return val != null ? val.toString() : ''
  131. }
  132. // 获取状态文本
  133. const getStatusText = (item: any | null): string => {
  134. if (item == null) return ''
  135. const status = getStatus(item)
  136. switch (status) {
  137. case 'PREPARE': return '待确认'
  138. case 'CONFIRMED': return '待出库'
  139. case 'EXECUTING': return '执行中'
  140. case 'FINISHED': return '已完成'
  141. case 'CANCEL': return '已取消'
  142. default: return status
  143. }
  144. }
  145. // 获取创建人
  146. const getCreateBy = (item: any | null): string => {
  147. if (item == null) return ''
  148. const jsonItem = item as UTSJSONObject
  149. const val = jsonItem['createNickName']
  150. return val != null ? val.toString() : ''
  151. }
  152. // 获取领用人
  153. const getReceiverUser = (item: any | null): string => {
  154. if (item == null) return ''
  155. const jsonItem = item as UTSJSONObject
  156. const val = jsonItem['receiverUser']
  157. return val != null ? '-' + val.toString() : ''
  158. }
  159. // 获取领用部门
  160. const getReceiverDept = (item: any | null): string => {
  161. if (item == null) return ''
  162. const jsonItem = item as UTSJSONObject
  163. const val = jsonItem['receiverDept']
  164. return val != null ? val.toString() : ''
  165. }
  166. // 获取创建时间
  167. const getCreateTime = (item: any | null): string => {
  168. if (item == null) return ''
  169. const jsonItem = item as UTSJSONObject
  170. const val = jsonItem['createTime']
  171. return val != null ? val.toString() : ''
  172. }
  173. // 获取已签收数量
  174. const getSignedCount = (item: any | null): string => {
  175. if (item == null) return '0'
  176. const jsonItem = item as UTSJSONObject
  177. const val = jsonItem['signedCount']
  178. return val != null ? val.toString() : '0'
  179. }
  180. // 获取未签收数量
  181. const getUnsignedCount = (item: any | null): string => {
  182. if (item == null) return '0'
  183. const jsonItem = item as UTSJSONObject
  184. const val = jsonItem['unsignedCount']
  185. return val != null ? val.toString() : '0'
  186. }
  187. // 获取总数(待出库数量)
  188. const getTotalCount = (item: any | null): string => {
  189. if (item == null) return '0'
  190. const jsonItem = item as UTSJSONObject
  191. const val = jsonItem['totalCount']
  192. return val != null ? val.toString() : '0'
  193. }
  194. // 加载列表数据
  195. const loadData = async (isRefresh: boolean): Promise<void> => {
  196. if (loading.value) return
  197. try {
  198. loading.value = true
  199. if (isRefresh) {
  200. page.value = 1
  201. }
  202. const signStatus = currentStatus.value === 'PENDING' ? 'PENDING' : (currentStatus.value === 'CONFIRMED' ? 'CONFIRMED' : '')
  203. const result = await getProductSalseList(page.value, pageSize, keyword.value, currentUserId, signStatus)
  204. const resultObj = result as UTSJSONObject
  205. const rows = resultObj['rows']
  206. const total = resultObj['total'] as number
  207. if (rows != null) {
  208. const newData = rows as any[]
  209. if (isRefresh) {
  210. dataList.value = newData
  211. } else {
  212. dataList.value = [...dataList.value, ...newData]
  213. }
  214. hasMore.value = dataList.value.length < total
  215. } else {
  216. if (isRefresh) {
  217. dataList.value = []
  218. }
  219. hasMore.value = false
  220. }
  221. } catch (e) {
  222. console.error('加载失败:', e)
  223. } finally {
  224. loading.value = false
  225. refreshing.value = false
  226. }
  227. }
  228. // 搜索
  229. const handleSearch = (): void => {
  230. const timer = searchTimer
  231. if (timer != null) {
  232. clearTimeout(timer)
  233. }
  234. searchTimer = setTimeout(() => {
  235. loadData(true)
  236. }, 300)
  237. }
  238. // 清空搜索关键字
  239. const clearKeyword = (): void => {
  240. keyword.value = ''
  241. loadData(true)
  242. }
  243. // 切换状态标签
  244. const handleStatusChange = (status: string): void => {
  245. currentStatus.value = status
  246. page.value = 1
  247. loadData(true)
  248. }
  249. // 下拉刷新
  250. const handleRefresh = (): void => {
  251. refreshing.value = true
  252. loadData(true)
  253. }
  254. // 加载更多
  255. const loadMore = (): void => {
  256. if (!hasMore.value || loading.value) return
  257. page.value++
  258. loadData(false)
  259. }
  260. // 点击列表项
  261. const handleItemClick = (item: any): void => {
  262. const jsonItem = item as UTSJSONObject
  263. const salseId = jsonItem['salseId']
  264. uni.navigateTo({
  265. url: `/pages/out/detail?id=${salseId}`
  266. })
  267. }
  268. // 一键签收
  269. const handleSignAll = (item: any | null): void => {
  270. if (item == null) return
  271. const jsonItem = item as UTSJSONObject
  272. const salseId = jsonItem['salseId']
  273. if (salseId == null) {
  274. uni.showToast({ title: '数据错误', icon: 'none' })
  275. return
  276. }
  277. const idStr = salseId.toString()
  278. uni.showModal({
  279. title: '提示',
  280. content: '确认一键签收所有物料?',
  281. success: (res) => {
  282. if (res.confirm) {
  283. signReceiveAll(idStr).then(() => {
  284. uni.showToast({ title: '签收成功', icon: 'success' })
  285. loadData(true)
  286. }).catch((e) => {
  287. const error = e as UTSError
  288. const errMsg = error?.message ?? '签收失败'
  289. uni.showToast({ title: errMsg, icon: 'none' })
  290. })
  291. }
  292. }
  293. })
  294. }
  295. // 初始化用户信息
  296. const initUserInfo = () => {
  297. const userInfo = getUserInfo()
  298. if (userInfo != null) {
  299. const userId = userInfo['userId']
  300. if (userId != null) {
  301. if (typeof userId === 'number') {
  302. currentUserId = userId.toString()
  303. } else if (typeof userId === 'string') {
  304. currentUserId = userId
  305. } else {
  306. currentUserId = userId as string
  307. }
  308. }
  309. }
  310. }
  311. // 初始化
  312. onMounted(() => {
  313. initUserInfo()
  314. loadData(true)
  315. })
  316. // 页面显示时刷新列表
  317. onShow(() => {
  318. initUserInfo()
  319. loadData(true)
  320. })
  321. </script>
  322. <style lang="scss">
  323. .page-container {
  324. flex: 1;
  325. background-color: #f5f8fe;
  326. padding-top: env(safe-area-inset-top);
  327. background-color: #e8f0f9;
  328. padding: 20rpx 10rpx 20rpx 10rpx;
  329. }
  330. .list-page {
  331. flex: 1;
  332. background-color: #e8f0f9;
  333. }
  334. .search-block {
  335. background-color: #ffffff;
  336. border-radius: 15rpx;
  337. }
  338. .search-bar {
  339. padding: 20rpx 30rpx;
  340. }
  341. .search-box {
  342. flex-direction: row;
  343. align-items: center;
  344. height: 72rpx;
  345. padding: 0 24rpx;
  346. background-color: #f5f5f5;
  347. border-radius: 36rpx;
  348. .search-icon {
  349. width: 32rpx;
  350. height: 32rpx;
  351. margin-right: 12rpx;
  352. }
  353. .search-input {
  354. flex: 1;
  355. font-size: 28rpx;
  356. color: #333333;
  357. }
  358. .search-btn {
  359. padding: 10rpx 20rpx;
  360. background-color: #007aff;
  361. border-radius: 8rpx;
  362. margin-left: 10rpx;
  363. }
  364. .search-btn-text {
  365. color: #ffffff;
  366. font-size: 24rpx;
  367. }
  368. .clear-btn {
  369. width: 36rpx;
  370. height: 36rpx;
  371. border-radius: 18rpx;
  372. background-color: #cccccc;
  373. align-items: center;
  374. justify-content: center;
  375. margin-left: 10rpx;
  376. }
  377. .clear-btn-text {
  378. color: #ffffff;
  379. font-size: 24rpx;
  380. font-weight: bold;
  381. }
  382. }
  383. .status-tabs {
  384. display: flex;
  385. flex-direction: row;
  386. padding: 0rpx 30rpx 20rpx;
  387. background-color: #ffffff;
  388. }
  389. .status-tab {
  390. flex: 1;
  391. padding: 16rpx 0;
  392. text-align: center;
  393. margin-right: 16rpx;
  394. border-radius: 8rpx;
  395. background-color: #f5f5f5;
  396. justify-content: center;
  397. align-items: center;
  398. &:last-child {
  399. margin-right: 0;
  400. }
  401. &.active {
  402. background-color: #007aff;
  403. }
  404. .status-tab-text {
  405. font-size: 26rpx;
  406. color: #666666;
  407. &.active-text {
  408. color: #ffffff;
  409. font-weight: bold;
  410. }
  411. }
  412. }
  413. .list-item {
  414. margin: 8rpx 10rpx;
  415. background-color: #ffffff;
  416. border-radius: 12rpx;
  417. }
  418. .item-container {
  419. padding: 20rpx;
  420. }
  421. .item-header {
  422. flex-direction: row;
  423. align-items: center;
  424. justify-content: space-between;
  425. margin-bottom: 12rpx;
  426. .item-title {
  427. font-size: 28rpx;
  428. color: #333333;
  429. font-weight: bold;
  430. }
  431. .item-status {
  432. font-size: 24rpx;
  433. padding: 8rpx 16rpx;
  434. border-radius: 8rpx;
  435. &.status-PREPARE {
  436. background-color: #fff7e6;
  437. color: #fa8c16;
  438. }
  439. &.status-CONFIRMED {
  440. background-color: #e6f7ff;
  441. color: #1890ff;
  442. }
  443. &.status-EXECUTING {
  444. background-color: #f9f0ff;
  445. color: #722ed1;
  446. }
  447. &.status-FINISHED {
  448. background-color: #f6ffed;
  449. color: #52c41a;
  450. }
  451. &.status-CANCEL {
  452. background-color: #fff1f0;
  453. color: #ff4d4f;
  454. }
  455. }
  456. }
  457. .item-info {
  458. .info-row {
  459. flex-direction: row;
  460. margin-bottom: 5rpx;
  461. &:last-child {
  462. margin-bottom: 0;
  463. }
  464. }
  465. .stat-row {
  466. padding: 6rpx 0;
  467. }
  468. .stat-label {
  469. font-size: 28rpx;
  470. color: #333333;
  471. font-weight: 600;
  472. }
  473. .stat-value {
  474. font-size: 28rpx;
  475. font-weight: 600;
  476. }
  477. .info-item {
  478. flex: 1;
  479. flex-direction: row;
  480. }
  481. .sign-all-btn-wrap {
  482. margin-top: 5rpx;
  483. align-items: flex-end;
  484. }
  485. .sign-all-btn {
  486. padding: 12rpx 32rpx;
  487. background-color: #007aff;
  488. color: #ffffff;
  489. font-size: 24rpx;
  490. border-radius: 8rpx;
  491. text-align: center;
  492. }
  493. .info-label {
  494. font-size: 24rpx;
  495. color: #999999;
  496. margin-right: 8rpx;
  497. }
  498. .info-value {
  499. font-size: 24rpx;
  500. color: #333333;
  501. &.success {
  502. color: #52c41a;
  503. }
  504. &.warning {
  505. color: #fa8c16;
  506. }
  507. }
  508. }
  509. </style>