index.uvue 16 KB

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