user.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: null,
  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. if (res.data.userHistory) {
  27. for (var list in res.data.userHistory) {
  28. for (var i = 0; i < res.data.userHistory[list].length; i++) {
  29. var goods = res.data.userHistory[list][i];
  30. if (goods.time) {
  31. res.data.userHistory[list][i].time = goods.time.split(' ')[0]
  32. }
  33. if (goods.postTime) {
  34. res.data.userHistory[list][i].postTime = goods.postTime.split(' ')[0]
  35. }
  36. if (goods.soldTime) {
  37. res.data.userHistory[list][i].soldTime = goods.soldTime.split(' ')[0]
  38. }
  39. }
  40. }
  41. that.setData({
  42. historyList: res.data.userHistory,
  43. })
  44. }
  45. //计算卖家来平台第几天
  46. let registerTime = res.data.user.registerTime
  47. registerTime = registerTime.replace('T', ' ').replace(/-/g, '/').split(".")[0];
  48. let duration = new Date().getTime() - new Date(registerTime).getTime();
  49. let dates = parseInt(Math.floor(duration) / (1000 * 60 * 60 * 24));
  50. that.setData({
  51. userInfo: res.data.user,
  52. soldCount: res.data.soldCount,
  53. userDates: dates
  54. });
  55. } else {
  56. console.log(res.errmsg)
  57. }
  58. });
  59. },
  60. preview: function(event) {
  61. let url = event.currentTarget.dataset.url
  62. url = url.slice(0, -3) + 0 //浏览头像大图,分辨率
  63. wx.previewImage({
  64. urls: [url] // 需要预览的图片http链接列表
  65. })
  66. console.log(url)
  67. },
  68. /**
  69. * 生命周期函数--监听页面加载
  70. */
  71. onLoad: function(options) {
  72. // 页面初始化 options为页面跳转所带来的参数
  73. this.setData({
  74. userId: options.userId
  75. });
  76. this.getUserPage();
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function() {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function() {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function() {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function() {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function() {
  102. },
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function() {
  107. },
  108. openGoods(event) {
  109. let goodsId = event.currentTarget.dataset.id
  110. wx.navigateTo({
  111. url: '/pages/goods/goods?id=' + goodsId,
  112. });
  113. },
  114. onReachBottom: function() {
  115. console.log("拉到底")
  116. this.setData({
  117. page: this.data.page + 1
  118. })
  119. // this.getUserPageMore()
  120. },
  121. })