index.uvue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. <custom-tabbar :current="3" />
  93. </view>
  94. </template>
  95. <script setup lang="uts">
  96. import { ref, onShow, onMounted } from 'vue'
  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. onMounted(() => {
  283. const userInfo = getUserInfo()
  284. if (userInfo != null) {
  285. const userId = userInfo['userId']
  286. currentUserId = userId != null ? userId.toString() : ''
  287. }
  288. loadData(true)
  289. })
  290. // 页面显示时刷新列表
  291. onShow(() => {
  292. loadData(true)
  293. })
  294. </script>
  295. <style lang="scss">
  296. .page-container {
  297. flex: 1;
  298. background-color: #f5f8fe;
  299. padding-top: env(safe-area-inset-top);
  300. background-color: #e8f0f9;
  301. padding: 20rpx 10rpx 20rpx 10rpx;
  302. }
  303. .list-page {
  304. flex: 1;
  305. background-color: #e8f0f9;
  306. }
  307. .search-block {
  308. background-color: #ffffff;
  309. border-radius: 15rpx;
  310. }
  311. .search-bar {
  312. padding: 20rpx 30rpx;
  313. }
  314. .search-box {
  315. flex-direction: row;
  316. align-items: center;
  317. height: 72rpx;
  318. padding: 0 24rpx;
  319. background-color: #f5f5f5;
  320. border-radius: 36rpx;
  321. .search-icon {
  322. width: 32rpx;
  323. height: 32rpx;
  324. margin-right: 12rpx;
  325. }
  326. .search-input {
  327. flex: 1;
  328. font-size: 28rpx;
  329. color: #333333;
  330. }
  331. .search-btn {
  332. padding: 10rpx 20rpx;
  333. background-color: #007aff;
  334. border-radius: 8rpx;
  335. margin-left: 10rpx;
  336. }
  337. .search-btn-text {
  338. color: #ffffff;
  339. font-size: 24rpx;
  340. }
  341. .clear-btn {
  342. width: 36rpx;
  343. height: 36rpx;
  344. border-radius: 18rpx;
  345. background-color: #cccccc;
  346. align-items: center;
  347. justify-content: center;
  348. margin-left: 10rpx;
  349. }
  350. .clear-btn-text {
  351. color: #ffffff;
  352. font-size: 24rpx;
  353. font-weight: bold;
  354. }
  355. }
  356. .status-tabs {
  357. display: flex;
  358. flex-direction: row;
  359. padding: 0rpx 30rpx 20rpx;
  360. background-color: #ffffff;
  361. }
  362. .status-tab {
  363. flex: 1;
  364. padding: 16rpx 0;
  365. text-align: center;
  366. margin-right: 16rpx;
  367. border-radius: 8rpx;
  368. background-color: #f5f5f5;
  369. justify-content: center;
  370. align-items: center;
  371. &:last-child {
  372. margin-right: 0;
  373. }
  374. &.active {
  375. background-color: #007aff;
  376. }
  377. .status-tab-text {
  378. font-size: 26rpx;
  379. color: #666666;
  380. &.active-text {
  381. color: #ffffff;
  382. font-weight: bold;
  383. }
  384. }
  385. }
  386. .list-item {
  387. margin: 8rpx 10rpx;
  388. background-color: #ffffff;
  389. border-radius: 12rpx;
  390. }
  391. .item-container {
  392. padding: 20rpx;
  393. }
  394. .item-header {
  395. flex-direction: row;
  396. align-items: center;
  397. justify-content: space-between;
  398. margin-bottom: 12rpx;
  399. .item-title {
  400. font-size: 28rpx;
  401. color: #333333;
  402. font-weight: bold;
  403. }
  404. .item-status {
  405. font-size: 24rpx;
  406. padding: 8rpx 16rpx;
  407. border-radius: 8rpx;
  408. &.status-PREPARE {
  409. background-color: #fff7e6;
  410. color: #fa8c16;
  411. }
  412. &.status-CONFIRMED {
  413. background-color: #e6f7ff;
  414. color: #1890ff;
  415. }
  416. &.status-EXECUTING {
  417. background-color: #f9f0ff;
  418. color: #722ed1;
  419. }
  420. &.status-FINISHED {
  421. background-color: #f6ffed;
  422. color: #52c41a;
  423. }
  424. &.status-CANCEL {
  425. background-color: #fff1f0;
  426. color: #ff4d4f;
  427. }
  428. }
  429. }
  430. .item-info {
  431. .info-row {
  432. flex-direction: row;
  433. margin-bottom: 5rpx;
  434. &:last-child {
  435. margin-bottom: 0;
  436. }
  437. }
  438. .stat-row {
  439. padding: 6rpx 0;
  440. }
  441. .stat-label {
  442. font-size: 28rpx;
  443. color: #333333;
  444. font-weight: 600;
  445. }
  446. .stat-value {
  447. font-size: 28rpx;
  448. font-weight: 600;
  449. }
  450. .info-item {
  451. flex: 1;
  452. flex-direction: row;
  453. }
  454. .sign-all-btn-wrap {
  455. margin-top: 5rpx;
  456. align-items: flex-end;
  457. }
  458. .sign-all-btn {
  459. padding: 12rpx 32rpx;
  460. background-color: #007aff;
  461. color: #ffffff;
  462. font-size: 24rpx;
  463. border-radius: 8rpx;
  464. text-align: center;
  465. }
  466. .info-label {
  467. font-size: 24rpx;
  468. color: #999999;
  469. margin-right: 8rpx;
  470. }
  471. .info-value {
  472. font-size: 24rpx;
  473. color: #333333;
  474. &.success {
  475. color: #52c41a;
  476. }
  477. &.warning {
  478. color: #fa8c16;
  479. }
  480. }
  481. }
  482. </style>