user.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var user = require('../../services/user.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. userId: '',
  11. page: 1,
  12. size: 10000,
  13. userInfo: {},
  14. historyList: {},
  15. soldCount: 0,
  16. userDates:0
  17. },
  18. getUserPage() {
  19. let that = this;
  20. util.request(api.UserPage + '/' + this.data.userId, {
  21. page: this.data.page,
  22. size: this.data.size
  23. }).then(function(res) {
  24. if (res.errno === 0) {
  25. console.log(res.data);
  26. for (var list in res.data.userHistory) {
  27. for (var i = 0; i < res.data.userHistory[list].length; i++) {
  28. var goods = res.data.userHistory[list][i];
  29. if (goods.time) {
  30. res.data.userHistory[list][i].time = goods.time.split(' ')[0]
  31. }
  32. if (goods.postTime) {
  33. res.data.userHistory[list][i].postTime = goods.postTime.split(' ')[0]
  34. }
  35. if (goods.soldTime) {
  36. res.data.userHistory[list][i].soldTime = goods.soldTime.split(' ')[0]
  37. }
  38. }
  39. }
  40. //计算卖家来平台第几天
  41. let registerTime = res.data.user.registerTime
  42. let duration = new Date().getTime() - new Date(registerTime).getTime();
  43. let dates = parseInt(Math.floor(duration) / (1000 * 60 * 60 * 24));
  44. that.setData({
  45. userInfo: res.data.user,
  46. historyList: res.data.userHistory,
  47. soldCount: res.data.soldCount,
  48. userDates: dates
  49. });
  50. } else {
  51. console.log(res.errmsg)
  52. }
  53. });
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: function(options) {
  59. // 页面初始化 options为页面跳转所带来的参数
  60. this.setData({
  61. userId: options.userId
  62. });
  63. this.getUserPage();
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function() {
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function() {
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function() {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function() {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function() {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function() {
  94. },
  95. openGoods(event) {
  96. let goodsId = event.currentTarget.dataset.id
  97. wx.navigateTo({
  98. url: '/pages/goods/goods?id=' + goodsId,
  99. });
  100. },
  101. onReachBottom: function() {
  102. console.log("拉到底")
  103. this.setData({
  104. page: this.data.page + 1
  105. })
  106. // this.getUserPageMore()
  107. },
  108. })