You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
7.6 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. <script setup>
  2. import { ref, watch, nextTick, onMounted } from 'vue'
  3. import { useRoute } from 'vue-router'
  4. import { ElMessage } from 'element-plus'
  5. import API from '@/util/http.js'
  6. import moment from 'moment'
  7. import { useI18n } from 'vue-i18n'
  8. import { useAdminStore } from "@/store/index.js"
  9. import { storeToRefs } from "pinia"
  10. const { t } = useI18n()
  11. const route = useRoute()
  12. const adminStore = useAdminStore()
  13. const { flag } = storeToRefs(adminStore)
  14. const tableData = ref([])
  15. const total = ref(0)
  16. const loading = ref(false)
  17. const selectData = ref({
  18. jwcode: '',
  19. walletId: ''
  20. })
  21. const getObj = ref({
  22. pageNum: 1,
  23. pageSize: 20
  24. })
  25. const tableRef = ref(null)
  26. const scrollTableTop = () => {
  27. tableRef.value?.setScrollTop?.(0)
  28. }
  29. // 精网号去空格
  30. const trimJwCode = () => {
  31. if (selectData.value.jwcode) {
  32. selectData.value.jwcode = selectData.value.jwcode.replace(/\s/g, '');
  33. }
  34. }
  35. // 获取类型文本
  36. const getWalletRecordTypeText = (item) => {
  37. const type = Number(item.type)
  38. if (type === 0) {
  39. return t('clientCount.recharge')
  40. }
  41. if (type === 1) {
  42. return t('clientCount.consume')
  43. }
  44. if (type === 2) {
  45. return t('clientCount.refund')
  46. }
  47. return item.typeText || t('clientCount.other')
  48. }
  49. // 格式化金额
  50. const format3 = (num) => {
  51. return num.toLocaleString('en-US')
  52. }
  53. // 统一获取数据的方法
  54. const getWalletData = async () => {
  55. if (!selectData.value.walletId) return;
  56. if (selectData.value.jwcode) {
  57. const numberRegex = /^\d{1,9}$/;
  58. if (!numberRegex.test(selectData.value.jwcode)) {
  59. ElMessage.error(t('elmessage.checkJwcodeFormat'))
  60. return
  61. }
  62. }
  63. loading.value = true
  64. try {
  65. const params = {
  66. pageNum: getObj.value.pageNum,
  67. pageSize: getObj.value.pageSize,
  68. userWalletRecord: {
  69. walletId: selectData.value.walletId,
  70. jwcode: selectData.value.jwcode ? Number(selectData.value.jwcode) : null
  71. }
  72. }
  73. const result = await API({
  74. url: '/cashCollection/selectWalletRecords',
  75. method: 'post',
  76. data: params
  77. })
  78. if (result.code === 200) {
  79. tableData.value = result.data.list.map(item => ({
  80. ...item,
  81. time: moment(item.createTime).format('YYYY-MM-DD HH:mm:ss'),
  82. typeText: getWalletRecordTypeText(item),
  83. amount: Number(item.amount) || 0,
  84. desc: item.description || '',
  85. orderNo: item.orderCode,
  86. status: item.status === 0 ? 1 : 2,
  87. userName: item.userName || '-',
  88. jwcode: item.jwcode || '-'
  89. }))
  90. total.value = result.data.total
  91. await nextTick()
  92. scrollTableTop()
  93. } else {
  94. ElMessage.error(result.msg || t('elmessage.getDataFailed'))
  95. }
  96. } catch (error) {
  97. console.error('获取钱包明细失败:', error)
  98. } finally {
  99. loading.value = false
  100. }
  101. }
  102. // 搜索
  103. const search = function () {
  104. trimJwCode()
  105. getObj.value.pageNum = 1
  106. getWalletData()
  107. }
  108. // 重置
  109. const reset = function () {
  110. selectData.value.jwcode = ''
  111. getObj.value.pageNum = 1
  112. getWalletData()
  113. }
  114. // 分页改变
  115. const handlePageSizeChange = function (val) {
  116. getObj.value.pageSize = val
  117. getWalletData()
  118. }
  119. const handleCurrentChange = function (val) {
  120. getObj.value.pageNum = val
  121. getWalletData()
  122. }
  123. // 监听全局flag变化重新请求数据
  124. watch(flag, (newFlag, oldFlag) => {
  125. if (newFlag !== oldFlag) {
  126. getWalletData()
  127. }
  128. })
  129. // 核心:监听路由参数变化
  130. watch(
  131. () => route.query.type,
  132. (newType) => {
  133. if (newType) {
  134. selectData.value.walletId = newType
  135. getObj.value.pageNum = 1
  136. getWalletData()
  137. }
  138. },
  139. { immediate: true }
  140. )
  141. </script>
  142. <template>
  143. <div style="display: flex; flex-direction: column; height: 100%;">
  144. <el-card class="card1" style="margin-bottom: 1vh;">
  145. <div class="head-card">
  146. <div class="head-card-element">
  147. <el-text class="mx-1" size="large">{{ $t('common_list.jwcode') }}</el-text>
  148. <el-input v-model="selectData.jwcode" style="width: 240px" :placeholder="$t('common_list.jwcodePlaceholder')" clearable />
  149. </div>
  150. <div class="head-card-btn">
  151. <el-button type="default" @click="reset">{{ $t('common.reset') }}</el-button>
  152. <el-button type="primary" @click="search">{{ $t('common.search') }}</el-button>
  153. </div>
  154. </div>
  155. </el-card>
  156. <el-card class="card2">
  157. <div style="height: 69vh; overflow-y: auto">
  158. <el-table ref="tableRef" :data="tableData" v-loading="loading" style="width: 100%; height: 69vh" :row-style="{ height: '50px' }">
  159. <el-table-column type="index" :label="$t('common_list.id')" width="80px" fixed="left">
  160. <template #default="scope">
  161. <span>{{ scope.$index + 1 + (getObj.pageNum - 1) * getObj.pageSize }}</span>
  162. </template>
  163. </el-table-column>
  164. <el-table-column prop="userName" :label="$t('common_list.name')" width="140" />
  165. <el-table-column prop="jwcode" :label="$t('common_list.jwcode')" width="140" />
  166. <el-table-column prop="time" :label="$t('clientCount.time')" align="center" width="180">
  167. <template #default="scope">{{ scope.row.time }}</template>
  168. </el-table-column>
  169. <el-table-column prop="typeText" :label="$t('clientCount.transactionType')" align="center" width="120" />
  170. <el-table-column prop="amount" :label="$t('common_list.money')" align="center" width="120">
  171. <template #default="scope">
  172. <span :style="{ color: scope.row.amount >= 0 ? '#67C23A' : '#F56C6C', fontWeight: 'bold' }">
  173. {{ scope.row.amount > 0 ? '+' + format3(scope.row.amount) : format3(scope.row.amount) }}
  174. </span>
  175. </template>
  176. </el-table-column>
  177. <el-table-column prop="desc" :label="$t('clientCount.transactionDesc')" align="center" min-width="150" />
  178. <el-table-column prop="orderNo" :label="$t('clientCount.transactionOrderNo')" align="center" width="220" />
  179. <el-table-column prop="status" :label="$t('clientCount.transactionStatus')" align="center" width="150" fixed="right">
  180. <template #default="scope">
  181. <el-tag :type="scope.row.status === 1 ? 'success' : scope.row.status === 2 ? 'danger' : 'info'" :effect="scope.row.status === 1 ? 'light' : 'plain'">
  182. {{ scope.row.status === 1 ? t('common_list.normal') : scope.row.status === 2 ? t('common_list.refunded') : t('clientCount.exceptionData') }}
  183. </el-tag>
  184. </template>
  185. </el-table-column>
  186. </el-table>
  187. </div>
  188. <!-- 分页 -->
  189. <div class="pagination" style="margin-top: 20px">
  190. <el-pagination background :current-page="getObj.pageNum" :page-size="getObj.pageSize" :page-sizes="[10, 20, 50, 100]"
  191. layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handlePageSizeChange"
  192. @current-change="handleCurrentChange"></el-pagination>
  193. </div>
  194. </el-card>
  195. </div>
  196. </template>
  197. <style scoped lang="scss">
  198. .card1 {
  199. background: #F3FAFE;
  200. }
  201. .card2 {
  202. background: #E7F4FD;
  203. flex: 1;
  204. display: flex;
  205. flex-direction: column;
  206. :deep(.el-card__body) {
  207. padding: 20px;
  208. flex: 1;
  209. display: flex;
  210. flex-direction: column;
  211. overflow: hidden;
  212. }
  213. }
  214. :deep(.el-table__header-wrapper),
  215. :deep(.el-table__body-wrapper),
  216. :deep(.el-table__cell),
  217. :deep(.el-table__body td) {
  218. background-color: #F3FAFE !important;
  219. }
  220. :deep(.el-table__header th) {
  221. background-color: #F3FAFE !important;
  222. }
  223. :deep(.el-table__row:hover > .el-table__cell) {
  224. background-color: #E5EBFE !important;
  225. }
  226. .pagination {
  227. display: flex;
  228. }
  229. .head-card {
  230. display: flex;
  231. }
  232. .head-card-element {
  233. margin-right: 20px;
  234. }
  235. .head-card-btn {
  236. margin-left: auto;
  237. }
  238. </style>