article-list.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <app-layout>
  3. <view style="height: 100%;background-color: #f7f7f7;position: absolute;width: 100%">
  4. <view class='article-list' v-for="item in list" :key="item.id">
  5. <app-form-id @click="toDetail(item.id)">
  6. <view class='article-item main-between'>
  7. <text class="t-omit" style="width: 90%">{{item.title}}</text>
  8. <image class='enter' src='/static/image/icon/arrow-right.png'></image>
  9. </view>
  10. </app-form-id>
  11. </view>
  12. </view>
  13. </app-layout>
  14. </template>
  15. <script>
  16. import { mapState } from "vuex";
  17. export default {
  18. data() {
  19. return {
  20. page: 2,
  21. loading: false,
  22. list: []
  23. }
  24. },
  25. computed: {
  26. ...mapState({
  27. title: state => state.mallConfig.bar_title
  28. })
  29. },
  30. methods: {
  31. getList() {
  32. let that = this;
  33. that.$showLoading({
  34. text: '加载中...'
  35. });
  36. this.$request({
  37. url: that.$api.article.list,
  38. method: 'get',
  39. }).then(response=>{
  40. that.$hideLoading();
  41. if(response.code == 0) {
  42. this.list = response.data.list;
  43. }
  44. }).catch(e => {
  45. that.$hideLoading();
  46. });
  47. },
  48. getMore() {
  49. let that = this;
  50. if(that.loading) {
  51. return false
  52. }
  53. that.loading = true;
  54. uni.showLoading({
  55. title: '加载中...'
  56. });
  57. that.$request({
  58. url: that.$api.article.list,
  59. data: {
  60. page: that.page
  61. },
  62. }).then(response=>{
  63. that.loading = false;
  64. uni.hideLoading();
  65. if(response.code == 0) {
  66. if(response.data.list.length > 0) {
  67. that.list = that.list.concat(response.data.list);
  68. that.page++;
  69. }else {
  70. uni.showToast({
  71. title: '没有更多内容',
  72. icon: 'none',
  73. duration: 1000
  74. });
  75. that.loading = true;
  76. }
  77. }
  78. }).catch(e => {
  79. that.loading = false;
  80. uni.hideLoading();
  81. });
  82. },
  83. toDetail(id) {
  84. uni.navigateTo({
  85. url: '/pages/article/article-detail/article-detail?id=' + id
  86. });
  87. }
  88. },
  89. onLoad() {
  90. this.getList();
  91. },
  92. onReachBottom() {
  93. this.getMore();
  94. },
  95. onShareAppMessage: function() {
  96. let that = this;
  97. for(let i in that.title) {
  98. if(that.title[i].name == '文章中心') {
  99. return that.$shareAppMessage({
  100. title: that.title[i].new_name,
  101. path: "/pages/article/article-list/article-list",
  102. });
  103. }
  104. }
  105. },
  106. }
  107. </script>
  108. <style scoped lang="scss">
  109. .article-item {
  110. height: #{100rpx};
  111. line-height: #{100rpx};
  112. background-color: #fff;
  113. border-bottom: #{1rpx} solid #e2e2e2;
  114. padding: 0 #{30rpx};
  115. }
  116. .enter {
  117. margin-top: #{39rpx};
  118. width: #{12rpx};
  119. height: #{22rpx};
  120. }
  121. </style>