split-record.vue 9.9 KB

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