index.uvue 15 KB

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