index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <script setup lang="tsx">
  2. import { reactive, ref, watch, unref } from 'vue'
  3. import { getMoneyLog } from '@/api/money'
  4. import { useTable } from '@/hooks/web/useTable'
  5. import { Table, TableColumn } from '@/components/Table'
  6. import { ContentWrap } from '@/components/ContentWrap'
  7. import { FormSchema } from '@/components/Form'
  8. import { Search } from '@/components/Search'
  9. import { useSearch } from '@/hooks/web/useSearch'
  10. import { searchTime } from '@/utils/searchTime'
  11. import { searchMoney } from '@/api/money/types'
  12. const { searchRegister, searchMethods } = useSearch()
  13. const { setSchema } = searchMethods
  14. const { tableRegister, tableState, tableMethods } = useTable({
  15. fetchDataApi: async () => {
  16. const res = await getMoneyLog({
  17. ...searchParams.value,
  18. page: unref(currentPage) || 1,
  19. limit: unref(pageSize) || 10
  20. })
  21. if (types.value.length == 0) {
  22. types.value = res.data.types.list
  23. }
  24. return {
  25. list:
  26. res.data.data.data.map((ee) => {
  27. return ee
  28. }) || [],
  29. total: res.data.data.count || 0
  30. }
  31. }
  32. })
  33. const { dataList, loading, total, currentPage, pageSize } = tableState
  34. const { getList } = tableMethods
  35. const tableColumns = reactive<TableColumn[]>([
  36. {
  37. field: 'id',
  38. label: 'ID',
  39. align: 'center',
  40. width: 70
  41. },
  42. {
  43. field: 'nickname',
  44. label: '用户',
  45. minWidth: 100
  46. },
  47. {
  48. field: 'uid',
  49. label: '用户UID',
  50. align: 'center',
  51. headerAlign: 'center',
  52. minWidth: 80
  53. },
  54. {
  55. field: 'title',
  56. label: '类型',
  57. minWidth: 100
  58. },
  59. {
  60. field: 'number',
  61. label: '变动数量',
  62. minWidth: 100,
  63. slots: {
  64. default: (data: any) => {
  65. const row = data.row
  66. if (row.pm > 0) {
  67. return (
  68. <>
  69. <div class={'color-green'}>+{row.number}</div>
  70. </>
  71. )
  72. } else {
  73. return (
  74. <>
  75. <div class={'color-red'}>-{row.number}</div>
  76. </>
  77. )
  78. }
  79. }
  80. }
  81. },
  82. {
  83. field: 'balance',
  84. label: '变动后金额',
  85. minWidth: 100
  86. },
  87. {
  88. field: 'add_time',
  89. label: '时间',
  90. minWidth: 160
  91. },
  92. {
  93. field: 'mark',
  94. label: '备注',
  95. minWidth: 140
  96. },
  97. {
  98. field: 'status',
  99. label: '状态',
  100. width: 60,
  101. headerAlign: 'center',
  102. align: 'center',
  103. slots: {
  104. default: (data: any) => {
  105. const row = data.row
  106. if (row.status == 1) {
  107. return (
  108. <>
  109. <div class={'color-green'}>有效</div>
  110. </>
  111. )
  112. } else {
  113. return (
  114. <>
  115. <div class={'color-red'}>无效</div>
  116. </>
  117. )
  118. }
  119. }
  120. }
  121. }
  122. ])
  123. const searchSchema = reactive<FormSchema[]>([
  124. {
  125. field: 'uid',
  126. label: 'uid',
  127. component: 'Input',
  128. componentProps: {
  129. type: 'number',
  130. placeholder: '请输入用户UID'
  131. }
  132. },
  133. {
  134. field: 'nickname',
  135. label: '用户昵称',
  136. component: 'Input',
  137. componentProps: {
  138. type: 'number',
  139. placeholder: '请输入用户昵称'
  140. }
  141. },
  142. {
  143. field: 'type',
  144. label: '类型',
  145. component: 'Select',
  146. componentProps: {
  147. placeholder: '请选择类型',
  148. options: []
  149. }
  150. },
  151. searchTime
  152. ])
  153. const searchParams = ref<searchMoney>({
  154. uid: '',
  155. nickname: '',
  156. start_time: '',
  157. end_time: '',
  158. type: ''
  159. })
  160. const setSearchParams = (data: any) => {
  161. const search = searchParams.value
  162. search.uid = data.uid || ''
  163. console.log(data, 'data')
  164. search.nickname = data.nickname || ''
  165. if (data.time) {
  166. search.start_time = data.time[0] || ''
  167. search.end_time = data.time[1] || ''
  168. } else {
  169. search.start_time = ''
  170. search.end_time = ''
  171. }
  172. search.type = data.type || ''
  173. // searchParams.value = data
  174. getList()
  175. }
  176. const types = ref<any[]>([]) //查询类型
  177. watch(
  178. () => types.value,
  179. (val) => {
  180. console.log(val, 'val')
  181. if (val) {
  182. setSchema([
  183. {
  184. field: 'type',
  185. path: 'componentProps.options',
  186. value: val.map((res) => {
  187. return {
  188. label: res.title,
  189. value: res.type
  190. }
  191. })
  192. }
  193. ])
  194. searchParams.value.type = ''
  195. }
  196. }
  197. )
  198. </script>
  199. <template>
  200. <ContentWrap>
  201. <Search
  202. isCol
  203. :schema="searchSchema"
  204. @reset="setSearchParams"
  205. @search="setSearchParams"
  206. @register="searchRegister"
  207. />
  208. <div class="mb-10px"> </div>
  209. <Table
  210. v-model:current-page="currentPage"
  211. v-model:page-size="pageSize"
  212. :columns="tableColumns"
  213. default-expand-all
  214. node-key="id"
  215. stripe
  216. :data="dataList"
  217. :loading="loading"
  218. @register="tableRegister"
  219. :pagination="{
  220. total
  221. }"
  222. />
  223. </ContentWrap>
  224. </template>