CreditLedgerTable.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div class="cl-board">
  3. <el-table
  4. :data="rows"
  5. size="small"
  6. style="width:100%"
  7. @row-click="onRowClick"
  8. :row-class-name="rowClass"
  9. >
  10. <el-table-column prop="userId" label="学员ID" width="90" />
  11. <el-table-column prop="year" label="年度" width="80" />
  12. <el-table-column prop="theory" label="理论学时" width="100">
  13. <template slot-scope="{ row }">{{ toHours(row.theory) }}</template>
  14. </el-table-column>
  15. <el-table-column prop="practice" label="实践学时" width="100">
  16. <template slot-scope="{ row }">{{ toHours(row.practice) }}</template>
  17. </el-table-column>
  18. <el-table-column prop="total" label="总学时" width="100">
  19. <template slot-scope="{ row }">
  20. <b>{{ toHours(row.total) }}</b>
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="effectiveAt" label="生效时间" min-width="150">
  24. <template slot-scope="{ row }">{{ fmtTime(row.effectiveAt) }}</template>
  25. </el-table-column>
  26. <el-table-column prop="status" label="状态" width="120">
  27. <template slot-scope="{ row }">
  28. <el-tag :type="statusMap[row.status] ? statusMap[row.status].type : 'info'" size="mini">
  29. {{ statusMap[row.status] ? statusMap[row.status].label : row.status }}
  30. </el-tag>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. </div>
  35. </template>
  36. <script>
  37. export default {
  38. name: 'CreditLedgerTable',
  39. props: {
  40. // 后端 ledgerPending 行:{ledgerId, sourceType, sourceCategory, hours, status, effectiveAt, sourceDesc, createdAt}
  41. // 组件按 userId×year 聚合展示(父层传已聚合数据)
  42. rows: {
  43. type: Array,
  44. default: function () { return [] }
  45. }
  46. },
  47. data: function () {
  48. return {
  49. statusMap: {
  50. pending: { type: 'warning', label: '待生效' },
  51. effective: { type: 'success', label: '已生效' },
  52. objected: { type: 'danger', label: '有异议' },
  53. rejected: { type: 'info', label: '已驳回' }
  54. }
  55. }
  56. },
  57. methods: {
  58. toHours: function (minutes) {
  59. var n = Number(minutes || 0)
  60. var h = Math.floor(n / 60)
  61. var m = n % 60
  62. if (h === 0) return m + '分钟'
  63. if (m === 0) return h + '小时'
  64. return h + '小时' + m + '分'
  65. },
  66. fmtTime: function (v) {
  67. if (!v) return '-'
  68. var s = String(v).replace('T', ' ')
  69. return s.length > 16 ? s.substring(0, 16) : s
  70. },
  71. rowClass: function (params) {
  72. return params.row.status === 'objected' ? 'row-objected' : ''
  73. },
  74. onRowClick: function (row) {
  75. this.$emit('detail', row)
  76. }
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. .row-objected {
  82. box-shadow: inset 3px 0 0 #C0392B;
  83. }
  84. </style>