List.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="new-list">
  3. <div class="new-item hand" v-for="item in newList" :key="item.id" @click="navTo('/knowledge/rescue/detail?id='+ item.id)">
  4. <div class="title clamp">
  5. <span class="title-icon"></span>
  6. {{ item.title }}
  7. </div>
  8. <div class="time">{{ item.release_time?item.release_time:item.add_time | time }}</div>
  9. </div>
  10. <el-pagination layout="prev, pager, next" :total="total" background prev-text="上一页" next-text="下一页"
  11. @current-change="currentChange" :page-size="15" hide-on-single-page></el-pagination>
  12. </div>
  13. </template>
  14. <script>
  15. import {
  16. getList
  17. } from '../../../request/api.js';
  18. export default {
  19. data() {
  20. return {
  21. newList: [],
  22. total: 0,
  23. page: 1,
  24. limit: 15
  25. };
  26. },
  27. filters: {
  28. time(val) {
  29. let arr = val.split(' ')
  30. let str = arr[0]
  31. str = str.replace(/-/g, '.')
  32. return str
  33. }
  34. },
  35. created() {
  36. this.getList()
  37. },
  38. methods: {
  39. navTo(url) {
  40. this.$router.push(url);
  41. },
  42. currentChange(e) {
  43. this.page = e
  44. this.getList()
  45. },
  46. getList() {
  47. let obj = this
  48. getList({
  49. page: obj.page,
  50. limit: obj.limit
  51. },48).then(res => {
  52. obj.newList = res.data.list.sort(this.compare('id'))
  53. obj.total = res.data.count
  54. })
  55. },
  56. compare(attribute) {
  57. return function(obj1, obj2) {
  58. var val1 = obj1[attribute];
  59. var val2 = obj2[attribute];
  60. if (val1 < val2) {
  61. return 1;
  62. } else if (val1 > val2) {
  63. return -1;
  64. } else {
  65. return 0;
  66. }
  67. }
  68. }
  69. }
  70. };
  71. </script>
  72. <style lang="scss" scoped>
  73. .new-list {
  74. // padding: 0px 72px 0 40px;
  75. .new-item {
  76. display: flex;
  77. justify-content: space-between;
  78. font-size: 18px;
  79. font-family: PingFang SC;
  80. font-weight: 500;
  81. color: #666666;
  82. height: 40px;
  83. border-bottom: 1px solid #E5E5E5;
  84. line-height: 40px;
  85. &:hover {
  86. color: red;
  87. .title {
  88. .title-icon {
  89. border-left-color: red;
  90. }
  91. }
  92. }
  93. .title {
  94. width: 500px;
  95. .title-icon {
  96. display: inline-block;
  97. width: 0;
  98. height: 0;
  99. width: 0;
  100. height: 0;
  101. border-top: 6px solid transparent;
  102. border-left: 8px solid #d2d2d2;
  103. border-bottom: 6px solid transparent;
  104. }
  105. }
  106. }
  107. }
  108. /deep/ .el-pagination {
  109. margin-top: 50px;
  110. text-align: center;
  111. }
  112. </style>