mydy.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="content">
  3. <empty v-if="list.loaded === true && list.length === 0"></empty>
  4. <view style="background-color: #fff;">
  5. <view class="dy-wrap flex" v-for="item in list" @click="navTo('/pages/user/dydetail?id=' + item.id)">
  6. <view class="user-logo"><image :src="item.headimg" mode=""></image></view>
  7. <view class="user-num">
  8. <view class="user-name">{{ item.name }}</view>
  9. <view class="sub-num">发表文章:{{ item.essay }}</view>
  10. <view class="read-num">阅读量:{{ item.sort }}</view>
  11. </view>
  12. <view class="dy-btn" @click.stop="dingYue(item)" :class="{ dyue: !item.isDy }">{{ item.isDy ? '已订阅' : '+订阅' }}</view>
  13. </view>
  14. </view>
  15. <uni-load-more :status="loadingType"></uni-load-more>
  16. </view>
  17. </template>
  18. <script>
  19. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  20. import empty from '@/components/empty';
  21. import { subscribe } from '@/api/user.js';
  22. import { dingYue } from '@/api/art.js';
  23. export default {
  24. components: {
  25. empty,
  26. uniLoadMore
  27. },
  28. data() {
  29. return {
  30. isDy: true,
  31. page: 1,
  32. limit: 10,
  33. loadingType: 'more',
  34. list: []
  35. };
  36. },
  37. onLoad() {
  38. this.loadData();
  39. },
  40. onReachBottom() {
  41. this.loadData();
  42. },
  43. methods: {
  44. loadData() {
  45. const obj = this;
  46. if (obj.loadingType == 'noMore' || obj.loadingType == 'loading') {
  47. return;
  48. }
  49. obj.loadingType = 'loading';
  50. subscribe({
  51. page: obj.page,
  52. rows: obj.limit
  53. }).then(({ data }) => {
  54. if (data.data.length != '') {
  55. data.data.map(item => {
  56. item.isDy = true
  57. return item
  58. })
  59. obj.list = obj.list.concat(data.data);
  60. }
  61. if (data.data.length === obj.limit) {
  62. obj.page++;
  63. obj.loadingType = 'more';
  64. } else {
  65. obj.loadingType = 'noMore';
  66. }
  67. console.log(obj.loadingType);
  68. this.$set(obj.list, 'loaded', true);
  69. });
  70. },
  71. dingYue(item) {
  72. let obj = this;
  73. if (item.isDy) {
  74. uni.showModal({
  75. title: '提示',
  76. content: '是否取消关注?',
  77. complete(e) {
  78. if (e.confirm) {
  79. item.isDy = !item.isDy;
  80. dingYue({
  81. id: item.id
  82. }).then(res => {
  83. obj.$api.msg('已取消关注');
  84. });
  85. }
  86. }
  87. });
  88. } else {
  89. item.isDy = !item.isDy;
  90. dingYue({
  91. id: item.id
  92. }).then(res => {
  93. obj.$api.msg('关注成功');
  94. });
  95. }
  96. },
  97. navTo(url) {
  98. uni.navigateTo({
  99. url,
  100. fail() {
  101. uni.switchTab({
  102. url
  103. });
  104. }
  105. });
  106. }
  107. }
  108. };
  109. </script>
  110. <style lang="scss" scoped>
  111. page {
  112. background-color: #f8f8f8;
  113. }
  114. .content {
  115. }
  116. .dy-wrap {
  117. width: 707rpx;
  118. // background: #E9E9E9;
  119. margin: auto;
  120. border-bottom: #e9e9e9 solid 1px;
  121. padding: 20rpx 0;
  122. .user-logo {
  123. flex-shrink: 0;
  124. height: 100rpx;
  125. width: 100rpx;
  126. border-radius: 50%;
  127. image {
  128. width: 100%;
  129. height: 100%;
  130. border-radius: 50%;
  131. }
  132. }
  133. .user-num {
  134. flex-grow: 1;
  135. padding-left: 10rpx;
  136. font-size: 24rpx;
  137. font-weight: 500;
  138. color: #999999;
  139. .user-name {
  140. font-size: 34rpx;
  141. font-weight: 600;
  142. color: #333333;
  143. padding-right: 20rpx;
  144. padding: 0 20rpx 20rpx 0;
  145. }
  146. }
  147. .dy-btn {
  148. flex-shrink: 0;
  149. text-align: center;
  150. width: 136rpx;
  151. line-height: 66rpx;
  152. background: #e9e9e9;
  153. border-radius: 10rpx;
  154. font-size: 28rpx;
  155. font-weight: 500;
  156. color: #999999;
  157. }
  158. }
  159. .dyue {
  160. background: #e6645f !important;
  161. color: #fff !important;
  162. }
  163. </style>