index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. index: 0,
  6. records:[],
  7. info:{},
  8. isLoadMore: true,
  9. pageIndex: 1,
  10. pageSize: 20,
  11. },
  12. onLoad: function (options) {
  13. this.setData({ index: parseInt(options.index) || 0 });
  14. this.getInfo();
  15. this.getCoinList(true);
  16. },
  17. getInfo(){
  18. var self = this;
  19. util.ajax({
  20. func: "coin/countinfo",
  21. load: false
  22. }, function (res) {
  23. if (res.code == 0) {
  24. self.setData({ info: res.data });
  25. }
  26. });
  27. },
  28. getCoinList(load){
  29. var self = this;
  30. util.ajax({
  31. func: self.data.index == 0 ? "coin/records" :"coin/invite_list",
  32. data: { "pageIndex": self.data.pageIndex, "pageSize": self.data.pageSize },
  33. load: load
  34. }, function (res) {
  35. if(res.code == 0){
  36. let isLoadMore = true;
  37. let newData = res.data.records;
  38. let oldData = !load ? newData : [...self.data.records, ...newData];
  39. if (newData.length < self.data.pageSize && oldData.length > self.data.pageSize) {
  40. isLoadMore = false;
  41. }
  42. for (let i = 0; i < oldData.length - 1; i++) {
  43. oldData[i].avatar = oldData[i].avatar ? oldData[i].avatar : '/images/default_logo.jpg';
  44. if (self.data.index == 0) {
  45. oldData[i].priceStats = (oldData[i].price.toString().indexOf("-") == -1 ? 0 : 1);
  46. }
  47. }
  48. self.setData({ records: oldData, isLoadMore: isLoadMore });
  49. }else
  50. util.showTips(res.reason);
  51. });
  52. },
  53. binderror(e){
  54. var records = this.data.records, index = e.currentTarget.dataset.index;
  55. records[index].avatar = '/images/default_logo.jpg';
  56. this.setData({ records });
  57. },
  58. tabs(e){
  59. if (e.currentTarget.dataset.index!=this.data.index) {
  60. this.setData({ index: e.currentTarget.dataset.index, isLoadMore: true, pageIndex: 1});
  61. this.getCoinList(false);
  62. }
  63. },
  64. onPullDownRefresh: function () {
  65. var self = this;
  66. wx.showNavigationBarLoading();
  67. setTimeout(function () {
  68. self.setData({ pageIndex: 1 });
  69. self.getCoinList(false);
  70. wx.hideNavigationBarLoading();
  71. wx.stopPullDownRefresh();
  72. }, 1000);
  73. },
  74. onReachBottom: function () {
  75. var self = this;
  76. if (self.data.isLoadMore == false) return false;
  77. setTimeout(function () {
  78. self.setData({ pageIndex: self.data.pageIndex + 1 });
  79. self.getCoinList(true);
  80. }, 1000);
  81. },
  82. onShareAppMessage() {
  83. return {
  84. title: '个人钱包',
  85. path: '/pages/account/coin/index'
  86. }
  87. }
  88. })