collect.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view>
  3. <block v-for="(item,index) in plist" :key="index">
  4. <view class="cu-card article no-card solid-bottom">
  5. <view class="cu-item shadow">
  6. <view class="title" @click="goDetail(item.article.id)"><view class="text-cut">{{item.article.title}}</view></view>
  7. <view class="content">
  8. <image :src="item.article.tilpic" mode="aspectFill" @click="goDetail(item.article.id)"></image>
  9. <view class="desc">
  10. <view class="text-content" @click="goDetail(item.article.id)">{{item.article.summary}}</view>
  11. <view class="flex justify-between">
  12. <view class="text-gray text-sm">收藏于:{{item.createtime}}</view>
  13. <view class="cu-tag bg-red light sm round" @click="delCollect(index)">删除</view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </block>
  20. <uni-load-more :status="pstatus"></uni-load-more>
  21. </view>
  22. </template>
  23. <script>
  24. import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
  25. var _this;
  26. export default {
  27. components: {
  28. uniLoadMore
  29. },
  30. data() {
  31. return {
  32. userinfo: {},
  33. pstatus: 'more',
  34. ppage: 1,
  35. psize: 20,
  36. plist: []
  37. };
  38. },
  39. onLoad: function(){
  40. _this = this;
  41. _this.userinfo = _this.checkLogin("/pages/my/collect");
  42. _this.getMore();
  43. },
  44. onPullDownRefresh: function() {
  45. _this.ppage = 1;
  46. _this.pstatus = 'more';
  47. _this.plist = [];
  48. _this.getMore();
  49. },
  50. onReachBottom: function() {
  51. if (_this.pstatus !== 'more') {
  52. return;
  53. }
  54. _this.getMore();
  55. },
  56. methods: {
  57. getMore: function() {
  58. _this.$req.ajax({
  59. path: "my/listcollect",
  60. data: {
  61. ppage: _this.ppage,
  62. psize: _this.psize,
  63. userid: _this.userinfo.id
  64. }
  65. }).then((data) => {
  66. _this.pstatus = data.pstatus;
  67. _this.plist = _this.plist.concat(data.plist);
  68. _this.ppage += 1;
  69. uni.stopPullDownRefresh();
  70. }).catch((err) => {
  71. uni.showModal({
  72. title: '信息提示',
  73. content: err,
  74. showCancel: false
  75. });
  76. });
  77. },
  78. goDetail: function(articleid) {
  79. uni.navigateTo({
  80. url: '/pages/article/detail?articleid=' + articleid
  81. });
  82. },
  83. delCollect: function(index) {
  84. console.log("_this.plist[index].id: " + JSON.stringify(_this.plist[index].id));
  85. _this.$req.ajax({
  86. path: "my/delcollect",
  87. data: {
  88. id: _this.plist[index].id,
  89. userid: _this.userinfo.id
  90. }
  91. }).then((data) => {
  92. uni.showModal({
  93. title: '信息提示',
  94. content: '收藏移除成功',
  95. showCancel: false,
  96. success: function(res) {
  97. if (res.confirm) {
  98. _this.plist.splice(index, 1);
  99. }
  100. }
  101. });
  102. }).catch((err) => {
  103. uni.showModal({
  104. title: '信息提示',
  105. content: err,
  106. showCancel: false
  107. });
  108. });
  109. }
  110. }
  111. }
  112. </script>
  113. <style>
  114. </style>