shareActivity.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. img: util.config.imgPath,
  6. pickers:[],
  7. pickerIndex:0,
  8. tabsIndex: 0,
  9. queryData:{
  10. pageIndex: 1,
  11. pageSize: 10,
  12. cities: '永康',
  13. },
  14. info:{},
  15. list:[],
  16. total: 0,
  17. loadMore: true
  18. },
  19. onLoad: function () {
  20. // this.getCity();
  21. this.userInfo()
  22. },
  23. bindCityChange(e) {
  24. this.data.queryData.pageIndex = 1;
  25. this.data.queryData.cities = this.data.pickers[e.detail.value];
  26. this.setData({pickerIndex:e.detail.value,queryData: this.data.queryData})
  27. this.getList(false);
  28. },
  29. userInfo(){
  30. let that = this;
  31. util.ajax({
  32. func: "v2/user/info",
  33. load: false
  34. }, function (res) {
  35. if (res.code == 0 && res.data) {
  36. that.setData({info:res.data})
  37. that.getList(false);
  38. }
  39. });
  40. },
  41. setTabbar(e){
  42. let index = e.currentTarget.dataset.index;
  43. this.data.queryData.pageIndex = 1;
  44. this.setData({ tabsIndex :index, queryData: this.data.queryData, list: [] });
  45. this.getList(true);
  46. },
  47. stat() {
  48. let that = this;
  49. util.ajax({
  50. func: 'v2/user/stat',
  51. load: false
  52. }, data => {
  53. if (data.code == 0) {
  54. that.setData({ stat: data.data });
  55. }
  56. });
  57. },
  58. getList(load){
  59. let that = this;
  60. console.log(that.data.queryData)
  61. util.ajax({
  62. func:`v2/${that.data.info.roleType}/articles`,
  63. data:{...that.data.queryData, days: that.data.tabsIndex == 4 ? 5 : that.data.tabsIndex },
  64. load: load
  65. },function(res){
  66. if (res.code == 0) {
  67. let loadMore = true, newData = res.data.list || [], oldData = !load ? newData : [...that.data.list, ...newData];
  68. if (newData.length < that.data.queryData.pageSize && oldData.length > that.data.queryData.pageSize) loadMore = false;
  69. that.setData({ list: oldData, loadMore ,total: res.data.total});
  70. } else
  71. util.showTips(res.reason);
  72. });
  73. },
  74. errorImg(e){
  75. this.data.list[e.currentTarget.dataset.index].logo = "/images/noimg.png";
  76. this.setData({list:this.data.list });
  77. },
  78. onPullDownRefresh() {
  79. var self = this;
  80. wx.showNavigationBarLoading();
  81. setTimeout(function () {
  82. self.data.queryData.pageIndex = 1;
  83. self.setData({ queryData: self.data.queryData });
  84. self.getList(false);
  85. wx.hideNavigationBarLoading();
  86. wx.stopPullDownRefresh();
  87. }, 1000);
  88. },
  89. onReachBottom() {
  90. var self = this;
  91. if (self.data.loadMore == false || self.data.total <= self.data.queryData.pageSize) return false;
  92. setTimeout(function () {
  93. self.data.queryData.pageIndex = self.data.queryData.pageIndex + 1;
  94. self.setData({ queryData: self.data.queryData });
  95. self.getList(true);
  96. }, 1000);
  97. },
  98. })