details.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // pages/details/details.js
  2. const { getGoodsDetail, getUserInfoList } = require('../../API/appraise')
  3. const { formatTime } = require('../../utils/util')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. id: 0,
  10. title: "",
  11. price: 0,
  12. pic: [],
  13. desc: "",
  14. uid: String,
  15. time: Number,
  16. ownerId: String,
  17. avatar: String,
  18. ownerName: String
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. console.log(options);
  25. //将传递过来的关于商品的数据渲染到页面
  26. this.setData({
  27. id: options.id,//商品id
  28. title: options.title,
  29. price: options.price,
  30. pic: options.img,
  31. // uid: parseInt(options.uid)
  32. uid: options.uid//卖家id
  33. })
  34. // console.log(this.data.uid);
  35. //获取时间戳
  36. var date = Date.parse(new Date())
  37. date = date / 1000
  38. this.setData({
  39. time: date
  40. })
  41. this.GoodsDetail();
  42. this.getUserInfo();
  43. },
  44. toChat() {
  45. wx.navigateTo({
  46. url: '/pages/chat/chat?toUid=' + this.data.uid + '&goodsId=' + this.data.id + '&pic=' + this.data.pic,
  47. })
  48. },
  49. GoodsDetail() {
  50. getGoodsDetail(this.data).then((res) => {
  51. const { code, data, message} = res.data;
  52. console.log(data);
  53. //通过获取详细信息将商品的描述获取并渲染
  54. this.setData({
  55. desc: data.Desc,
  56. ownerId: data.ownerId
  57. })
  58. }).catch((err) => {
  59. console.log(err);
  60. })
  61. },
  62. getUserInfo() {
  63. var owner = {data: {id: [this.data.uid]}};
  64. console.log(owner);
  65. getUserInfoList(owner).then((res) => {
  66. console.log(res);
  67. const {users} = res.data.data;
  68. this.setData({
  69. avatar: users[0].avatar,
  70. ownerName: users[0].name
  71. })
  72. }).catch((err) => {
  73. console.log(err);
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady() {
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow() {
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide() {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload() {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh() {
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom() {
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage() {
  110. }
  111. })