InformationList.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div id="">
  3. <div class="table">
  4. <el-table
  5. :data="dataList"
  6. :cell-style='cellStyle'
  7. style="width: 100%;"
  8. :header-cell-style='headerstyle'>
  9. <el-table-column
  10. prop="name"
  11. label="人才姓名">
  12. </el-table-column>
  13. <el-table-column
  14. prop="type"
  15. label="职位类别"
  16. width="120">
  17. </el-table-column>
  18. <el-table-column
  19. prop="work"
  20. label="工作年限"
  21. width="110">
  22. </el-table-column>
  23. <el-table-column
  24. prop="address"
  25. label="所在地区"
  26. width="110">
  27. </el-table-column>
  28. </el-table>
  29. </div>
  30. <div>
  31. <div class="total">
  32. 共{{total}}项
  33. </div>
  34. <div class="page">
  35. <button class="button-left" @click="delpage"><</button>
  36. <button v-show="page-4 > 0">...</button>
  37. <button v-for="(t,index) in totalpage" @click="pageChoose(index)" v-if="pagenum == 1" v-show="index<page+4&&index>page-5" :class="{check:index+1 == page}">{{index+1}}</button>
  38. <button v-for="(t,index) in totalpage" @click="pageChoose(index)" v-if="pagenum == 2" v-show="index<page+3&&index>page-4" :class="{check:index+1 == page}">{{index+1}}</button>
  39. <button v-for="(t,index) in totalpage" @click="pageChoose(index)" v-if="pagenum == 3" v-show="index<page+3&&index>page-4" :class="{check:index+1 == page}">{{index+1}}</button>
  40. <button v-show="page+3 < totalpage">...</button>
  41. <button class="button-right" @click="addpage">></button>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. props: ['tableData'],
  49. data() {
  50. return {
  51. dataList: [],//显示数据
  52. page :1, //当前页数
  53. pagesize :10, //每页的数据
  54. pagenum: 1,//判断显示的页码
  55. }
  56. },
  57. mounted() {
  58. this.pagelist()
  59. },
  60. methods: {
  61. //表格样式
  62. cellStyle({row, column, rowIndex, columnIndex}) {
  63. return 'text-align:center;height: 70px';
  64. },
  65. //表格表头样式
  66. headerstyle() {
  67. return 'text-align:center;background:#2360F1;color:#ffffff;height: 47px'
  68. },
  69. //上一页
  70. delpage() {
  71. this.page > 1 && this.page--
  72. },
  73. //下一页
  74. addpage() {
  75. this.page < this.totalpage && this.page++
  76. },
  77. //每页数据
  78. pagelist() {
  79. if(this.page * this.pagesize > this.total){
  80. const last = this.total
  81. this.pushlist(last)
  82. }else {
  83. const last = this.page * this.pagesize
  84. this.pushlist(last)
  85. }
  86. },
  87. pushlist(last) {
  88. this.dataList = [];
  89. const start = (this.page - 1) * this.pagesize
  90. this.dataList = this.tableData.slice(start,last)
  91. },
  92. pageChoose(index) {
  93. this.page = index+1
  94. if(this.page < 5) {
  95. this.pagenum = 1
  96. }else if(this.page >= 5 && this.totalpage - this.page > 5) {
  97. this.pagenum = 2
  98. }else {
  99. this.pagenum = 3
  100. }
  101. }
  102. },
  103. computed: {
  104. //数据量
  105. total() {
  106. return this.tableData.length
  107. },
  108. //总页数
  109. totalpage() {
  110. return Math.ceil(this.total/this.pagesize)
  111. }
  112. },
  113. watch: {
  114. page() {
  115. this.pagelist()
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .total {
  122. margin: 10px;
  123. float:left;
  124. color: #666666;
  125. font-size: 15px;
  126. }
  127. .page {
  128. margin: 10px;
  129. float:right;
  130. display: flex;
  131. button {
  132. background-color: white;
  133. border: solid 1px;
  134. border-color: #DDDDDD;
  135. color: #666666;
  136. height: 24px;
  137. width: 24px;
  138. font-size: 10px;
  139. }
  140. .button-left {
  141. border-radius: 6px 0 0 6px;
  142. }
  143. .button-right {
  144. border-radius: 0 6px 6px 0;
  145. }
  146. .check {
  147. background: #F4F4F4;
  148. border: 2px solid #DDDDDD;
  149. }
  150. }
  151. </style>
  152. <style>
  153. .el-table .cell {
  154. white-space: pre-line;
  155. }
  156. </style>