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