index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="default-main ba-table-box">
  3. <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
  4. <!-- 表格顶部菜单 -->
  5. <TableHeader
  6. :buttons="['refresh', 'add', 'comSearch', 'quickSearch', 'columnDisplay']"
  7. :quick-search-placeholder="
  8. t('Quick search placeholder', { fields: t('user.moneyLog.User name') + '/' + t('user.moneyLog.User nickname') })
  9. "
  10. >
  11. <el-button v-if="!isEmpty(state.userInfo)" v-blur class="table-header-operate">
  12. <span class="table-header-operate-text">
  13. {{ state.userInfo.username + '(ID:' + state.userInfo.id + ') ' + t('user.scoreLog.integral') + ':' + state.userInfo.score }}
  14. </span>
  15. </el-button>
  16. </TableHeader>
  17. <!-- 表格 -->
  18. <!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
  19. <Table />
  20. <!-- 表单 -->
  21. <PopupForm />
  22. </div>
  23. </template>
  24. <script setup lang="ts">
  25. import { debounce, isEmpty, parseInt } from 'lodash-es'
  26. import { provide, reactive, watch } from 'vue'
  27. import { useI18n } from 'vue-i18n'
  28. import { useRoute } from 'vue-router'
  29. import PopupForm from './popupForm.vue'
  30. import { add, url } from '/@/api/backend/user/scoreLog'
  31. import { baTableApi } from '/@/api/common'
  32. import TableHeader from '/@/components/table/header/index.vue'
  33. import Table from '/@/components/table/index.vue'
  34. import baTableClass from '/@/utils/baTable'
  35. defineOptions({
  36. name: 'user/scoreLog',
  37. })
  38. const { t } = useI18n()
  39. const route = useRoute()
  40. const defalutUser = (route.query.user_id ?? '') as string
  41. const state = reactive({
  42. userInfo: {} as anyObj,
  43. })
  44. const baTable = new baTableClass(
  45. new baTableApi(url),
  46. {
  47. column: [
  48. { type: 'selection', align: 'center', operator: false },
  49. { label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
  50. { label: t('user.moneyLog.User ID'), prop: 'user_id', align: 'center', width: 70 },
  51. { label: t('user.moneyLog.User name'), prop: 'user.username', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
  52. {
  53. label: t('user.moneyLog.User nickname'),
  54. prop: 'user.nickname',
  55. align: 'center',
  56. operator: 'LIKE',
  57. operatorPlaceholder: t('Fuzzy query'),
  58. },
  59. { label: t('user.scoreLog.Change points'), prop: 'score', align: 'center', operator: 'RANGE', sortable: 'custom' },
  60. { label: t('user.moneyLog.Before change'), prop: 'before', align: 'center', operator: 'RANGE', sortable: 'custom' },
  61. { label: t('user.moneyLog.After change'), prop: 'after', align: 'center', operator: 'RANGE', sortable: 'custom' },
  62. {
  63. label: t('user.moneyLog.remarks'),
  64. prop: 'memo',
  65. align: 'center',
  66. operator: 'LIKE',
  67. operatorPlaceholder: t('Fuzzy query'),
  68. showOverflowTooltip: true,
  69. },
  70. { label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
  71. ],
  72. dblClickNotEditColumn: ['all'],
  73. },
  74. {
  75. defaultItems: {
  76. user_id: defalutUser,
  77. memo: '',
  78. },
  79. }
  80. )
  81. // 表单提交后
  82. baTable.after.onSubmit = () => {
  83. getUserInfo(baTable.comSearch.form.user_id)
  84. }
  85. baTable.mount()
  86. baTable.getData()
  87. provide('baTable', baTable)
  88. const getUserInfo = debounce((userId: string) => {
  89. if (userId && parseInt(userId) > 0) {
  90. add(userId).then((res) => {
  91. state.userInfo = res.data.user
  92. })
  93. } else {
  94. state.userInfo = {}
  95. }
  96. }, 300)
  97. getUserInfo(baTable.comSearch.form.user_id)
  98. watch(
  99. () => baTable.comSearch.form.user_id,
  100. (newVal) => {
  101. baTable.form.defaultItems!.user_id = newVal
  102. getUserInfo(newVal)
  103. }
  104. )
  105. </script>
  106. <style scoped lang="scss"></style>