index.uvue 13 KB

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