index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="box">
  3. <view class="flex1 overh boxtop">
  4. <tablist :tablist="tablist" :tabval="tabval" @getCheck="getCheck"></tablist>
  5. </view>
  6. <view class="stepbox" :style="tabval==2?'padding-top:0px':''">
  7. <box-list :datainfo="list" :type="type" @getDetail="getDetail"></box-list>
  8. </view>
  9. <loading></loading>
  10. </view>
  11. </template>
  12. <script>
  13. import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
  14. import {getDictionaryFn} from "@/api/mine/register.js";
  15. import {getNewsList} from "@/api/work/index.js"
  16. import tablist from '@/components/tabs/index.vue'
  17. import boxList from "@/news/components/box/list.vue"
  18. export default {
  19. components:{tablist,boxList},
  20. data(){
  21. return{
  22. list:[],
  23. pageSize: 10,
  24. pageNum: 1,
  25. reachflag: true,
  26. tabval:'',
  27. tablist:[],
  28. wtdt:'',
  29. type:'article',//article:文章,avideo:视频
  30. }
  31. },
  32. onShow() {
  33. },
  34. onLoad: function() {
  35. this.init();
  36. },
  37. // 上拉触底加载更多触发事件
  38. onReachBottom() {
  39. if (this.reachflag) {
  40. this.pageNum++
  41. this.getDataFn()
  42. }
  43. },
  44. methods:{
  45. checkPermi,checkRole,
  46. init(){
  47. //新闻类型
  48. getDictionaryFn('newtype').then(res => {
  49. if (res.code == 200) {
  50. this.tablist = res.data.map(v => {
  51. this.tabval=res.data[0].dictValue
  52. return {
  53. dictLabel: v.dictLabel,
  54. dictValue: v.dictValue
  55. }
  56. })
  57. this.getDataFn()
  58. }
  59. })
  60. },
  61. getCheck(val){
  62. this.tabval=val;
  63. if(val==2){
  64. this.type="avideo";
  65. }else{
  66. this.type="article";
  67. }
  68. this.getrefreshData()
  69. },
  70. getrefreshData(){
  71. this.pageNum=1;
  72. this.list=[];
  73. this.reachflag=true;
  74. this.getDataFn()
  75. },
  76. getDetail(e){
  77. this.$tab.navigateTo(`/news/pages/article/detail?id=${e}`)
  78. },
  79. getDataFn(){
  80. var params={
  81. pageSize:this.pageSize,
  82. pageNum: this.pageNum,
  83. status:'0',//0启用,1不启用
  84. newType:this.tabval
  85. }
  86. getNewsList(params).then(res=>{
  87. if(res.code==200){
  88. if (res.rows.length < this.pageSize) {
  89. this.reachflag = false
  90. this.wtdt = '到底了~';
  91. } else {
  92. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  93. if (num < res.total) {
  94. this.reachflag = true
  95. this.wtdt = ''
  96. } else {
  97. this.reachflag = false
  98. this.wtdt = '到底了~';
  99. }
  100. }
  101. var arr=JSON.parse(JSON.stringify(res.rows));
  102. if(this.tabval==2){
  103. arr=res.rows.map(v => {
  104. if(v.newUrl){
  105. v.newUrl=v.newUrl.split(',')
  106. }
  107. return v
  108. })
  109. }
  110. if (this.pageNum == 1) {
  111. this.list = arr;
  112. } else {
  113. this.list = this.list.concat(arr)
  114. }
  115. }else{
  116. this.$toast(res.msg)
  117. }
  118. })
  119. },
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .boxtop{padding: 18rpx 0 0;background-color: #ffffff;
  125. position: fixed;left: 0;top: 0;right: 0;z-index: 2;
  126. }
  127. .box{padding-top: 100rpx;}
  128. .stepbox{padding: 24rpx 24rpx 0;}
  129. </style>