split-record.vue 10 KB

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