split-record.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <view class="split-container">
  3. <!-- 筛选栏 -->
  4. <view class="filter-section">
  5. <view class="filter-row">
  6. <view class="filter-item">
  7. <text class="filter-label">站点</text>
  8. <picker mode="selector" :range="stationList" range-key="stationName" @change="handleStationChange">
  9. <view class="picker-value">
  10. <text :class="{ placeholder: !selectedStationName }">{{ selectedStationName || '全部站点' }}</text>
  11. <AppIcon name="chevron-down" :size="20" color="#999999" class="picker-arrow" />
  12. </view>
  13. </picker>
  14. </view>
  15. <view class="filter-item">
  16. <text class="filter-label">交易类型</text>
  17. <picker mode="selector" :range="typeOptions" range-key="label" @change="handleTypeChange">
  18. <view class="picker-value">
  19. <text :class="{ placeholder: !activeTypeLabel }">{{ activeTypeLabel || '全部类型' }}</text>
  20. <AppIcon name="chevron-down" :size="20" color="#999999" class="picker-arrow" />
  21. </view>
  22. </picker>
  23. </view>
  24. </view>
  25. <view class="filter-row">
  26. <view class="filter-item full-width">
  27. <text class="filter-label">交易流水号</text>
  28. <input type="text" placeholder="输入流水号搜索" v-model="tradeNo" @confirm="handleSearch" />
  29. </view>
  30. </view>
  31. <button class="search-btn" @click="handleSearch">查询</button>
  32. </view>
  33. <!-- 分账列表 -->
  34. <view class="split-list" v-if="list.length > 0">
  35. <view class="split-item" v-for="(item, index) in list" :key="index">
  36. <view class="item-header">
  37. <text class="item-type" :style="getTypeStyle(item.type)">{{ fmtDictName('SplitRecord.type', item.type) }}</text>
  38. <text class="item-amount">{{ formatAmount(item.amount) }}</text>
  39. </view>
  40. <view class="item-content">
  41. <view class="info-row">
  42. <text class="info-label">入账站点</text>
  43. <text class="info-value">{{ item.toStationName || item.toStationId || '-' }}</text>
  44. </view>
  45. <view class="info-row">
  46. <text class="info-label">出账站点</text>
  47. <text class="info-value">{{ item.fromStationName || item.fromStationId || '-' }}</text>
  48. </view>
  49. <view class="info-row">
  50. <text class="info-label">流水号</text>
  51. <text class="info-value trade-no">{{ item.tradeNo || '-' }}</text>
  52. </view>
  53. <view class="info-row">
  54. <text class="info-label">创建时间</text>
  55. <text class="info-value">{{ formatTime(item.createTime) }}</text>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 加载更多 -->
  61. <view class="load-more" v-if="list.length > 0">
  62. <text class="load-more-text" v-if="loadMoreStatus === 'more'">上拉加载更多</text>
  63. <text class="load-more-text" v-else-if="loadMoreStatus === 'loading'">正在加载...</text>
  64. <text class="load-more-text" v-else>没有更多数据了</text>
  65. </view>
  66. <!-- 空状态 -->
  67. <view class="empty-state" v-if="list.length === 0 && !loading">
  68. <view class="empty-icon-wrapper">
  69. <AppIcon name="trending-up" :size="80" color="#999999" />
  70. </view>
  71. <text class="empty-text">暂无分账记录</text>
  72. </view>
  73. <!-- 加载状态 -->
  74. <view class="loading-state" v-if="loading && list.length === 0">
  75. <view class="loading-spinner"></view>
  76. <text class="loading-text">加载中...</text>
  77. </view>
  78. </view>
  79. </template>
  80. <script setup>
  81. import { ref, onMounted } from 'vue'
  82. import { onReachBottom } from '@dcloudio/uni-app'
  83. import { getSplitRecords } from '../../api/finance.js'
  84. import { getStationList } from '../../api/station.js'
  85. import { formatTime, formatAmount, fmtDictName, getDictColor } from '../../utils/index.js'
  86. import { loadDicts } from '../../utils/dict.js'
  87. const list = ref([])
  88. const loading = ref(true)
  89. const page = ref(1)
  90. const pageSize = ref(10)
  91. const hasMore = ref(true)
  92. const loadMoreStatus = ref('more')
  93. const tradeNo = ref('')
  94. const stationList = ref([])
  95. const selectedStationId = ref('')
  96. const selectedStationName = ref('')
  97. const activeType = ref('')
  98. const activeTypeLabel = ref('')
  99. const typeOptions = [
  100. { label: '全部类型', value: '' }
  101. ]
  102. const getTypeStyle = (type) => {
  103. const color = getDictColor('SplitRecord.type', type)
  104. if (color) return { color, backgroundColor: `${color}1A` }
  105. return {}
  106. }
  107. const loadStations = async () => {
  108. try {
  109. const res = await getStationList({ pageSize: 1024 })
  110. if (res && res.code === 200) {
  111. const data = res.data
  112. stationList.value = data.records || data.list || data || []
  113. stationList.value.unshift({ stationId: '', stationName: '全部站点' })
  114. }
  115. } catch (error) {
  116. showToast('加载站点列表失败')
  117. }
  118. }
  119. const handleStationChange = (e) => {
  120. const index = e.detail.value
  121. const selected = stationList.value[index]
  122. if (selected) {
  123. selectedStationId.value = selected.stationId || ''
  124. selectedStationName.value = selected.stationName || ''
  125. }
  126. }
  127. const handleTypeChange = (e) => {
  128. const index = e.detail.value
  129. const selected = typeOptions[index]
  130. if (selected) {
  131. activeType.value = selected.value
  132. activeTypeLabel.value = selected.label
  133. }
  134. }
  135. const loadData = async (isLoadMore = false) => {
  136. if (!isLoadMore) {
  137. page.value = 1
  138. list.value = []
  139. hasMore.value = true
  140. loadMoreStatus.value = 'more'
  141. } else {
  142. loadMoreStatus.value = 'loading'
  143. }
  144. loading.value = true
  145. try {
  146. const params = {
  147. pageNum: page.value,
  148. pageSize: pageSize.value
  149. }
  150. if (selectedStationId.value) params.stationId = selectedStationId.value
  151. if (tradeNo.value) params.tradeNo = tradeNo.value
  152. if (activeType.value) params.type = activeType.value
  153. const res = await getSplitRecords(params)
  154. if (res && res.code === 200) {
  155. const data = res.data
  156. const records = data.records || data.list || data
  157. const total = data.total || 0
  158. const totalPages = Math.ceil(total / pageSize.value)
  159. hasMore.value = page.value < totalPages
  160. loadMoreStatus.value = hasMore.value ? 'more' : 'noMore'
  161. if (isLoadMore) {
  162. list.value = [...list.value, ...records]
  163. page.value++
  164. } else {
  165. list.value = records
  166. page.value = 2
  167. }
  168. // 从数据中提取交易类型,补充到 typeOptions
  169. if (!isLoadMore && records.length > 0) {
  170. const types = new Set()
  171. records.forEach(r => { if (r.type) types.add(r.type) })
  172. if (typeOptions.length === 1) {
  173. types.forEach(t => typeOptions.push({ label: fmtDictName('SplitRecord.type', t) || t, value: t }))
  174. }
  175. }
  176. }
  177. } catch (error) {
  178. showToast('加载分账记录失败')
  179. } finally {
  180. loading.value = false
  181. }
  182. }
  183. const loadMore = () => {
  184. if (hasMore.value && !loading.value && loadMoreStatus.value !== 'loading') {
  185. loadData(true)
  186. }
  187. }
  188. onReachBottom(() => {
  189. loadMore()
  190. })
  191. const handleSearch = () => {
  192. loadData()
  193. }
  194. onMounted(async () => {
  195. await loadDicts()
  196. loadStations()
  197. loadData()
  198. })
  199. </script>
  200. <style scoped>
  201. .split-container {
  202. min-height: 100vh;
  203. background-color: #F5F7FA;
  204. padding-bottom: 60rpx;
  205. }
  206. .filter-section {
  207. background-color: #FFFFFF;
  208. padding: 24rpx 20rpx 20rpx;
  209. margin-bottom: 16rpx;
  210. }
  211. .filter-row {
  212. display: flex;
  213. gap: 16rpx;
  214. margin-bottom: 12rpx;
  215. }
  216. .filter-item {
  217. flex: 1;
  218. }
  219. .filter-item.full-width {
  220. flex: none;
  221. width: 100%;
  222. }
  223. .filter-label {
  224. font-size: 24rpx;
  225. color: #999999;
  226. margin-bottom: 8rpx;
  227. display: block;
  228. }
  229. .picker-value {
  230. display: flex;
  231. justify-content: space-between;
  232. align-items: center;
  233. background-color: #F5F5F5;
  234. border-radius: 16rpx;
  235. padding: 14rpx 20rpx;
  236. font-size: 26rpx;
  237. }
  238. .picker-value .placeholder { color: #B0B0B0; }
  239. .picker-arrow { flex-shrink: 0; }
  240. .filter-item input {
  241. background-color: #F5F5F5;
  242. border-radius: 16rpx;
  243. padding: 14rpx 20rpx;
  244. font-size: 26rpx;
  245. height: 56rpx;
  246. }
  247. .search-btn {
  248. width: 100%;
  249. padding: 16rpx 0;
  250. background: #C6171E;
  251. color: #FFFFFF;
  252. border-radius: 16rpx;
  253. font-size: 28rpx;
  254. border: none;
  255. }
  256. .split-list {
  257. padding: 0 20rpx;
  258. }
  259. .split-item {
  260. background-color: #FFFFFF;
  261. border-radius: 24rpx;
  262. padding: 24rpx;
  263. margin-bottom: 16rpx;
  264. box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  265. }
  266. .item-header {
  267. display: flex;
  268. justify-content: space-between;
  269. align-items: center;
  270. padding-bottom: 16rpx;
  271. border-bottom: 1rpx solid #F0F0F0;
  272. margin-bottom: 16rpx;
  273. }
  274. .item-type {
  275. font-size: 24rpx;
  276. padding: 6rpx 24rpx;
  277. border-radius: 100rpx;
  278. font-weight: 500;
  279. }
  280. .item-amount {
  281. font-size: 32rpx;
  282. font-weight: 700;
  283. color: #C6171E;
  284. }
  285. .info-row {
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. padding: 10rpx 0;
  290. }
  291. .info-label {
  292. font-size: 26rpx;
  293. color: #999999;
  294. }
  295. .info-value {
  296. font-size: 26rpx;
  297. color: #1A1A1A;
  298. max-width: 380rpx;
  299. text-align: right;
  300. }
  301. .info-value.trade-no {
  302. font-size: 22rpx;
  303. word-break: break-all;
  304. }
  305. .load-more {
  306. display: flex;
  307. justify-content: center;
  308. padding: 24rpx 0;
  309. }
  310. .load-more-text { font-size: 24rpx; color: #999999; }
  311. .empty-state {
  312. display: flex;
  313. flex-direction: column;
  314. align-items: center;
  315. padding: 80rpx 0;
  316. }
  317. .empty-text { font-size: 28rpx; color: #999999; margin-top: 20rpx; }
  318. .loading-state {
  319. display: flex;
  320. flex-direction: column;
  321. align-items: center;
  322. padding: 80rpx 0;
  323. }
  324. .loading-text { font-size: 28rpx; color: #999999; margin-top: 16rpx; }
  325. </style>