details.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/details/details.js
  2. const { getGoodsDetail, getUserInfoList, addUserRelation } = 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. let _this = this.data;
  46. let $id = parseInt(_this.id);
  47. let addUserRelationOption = {
  48. goodsId:$id,
  49. owner:wx.getStorageSync('uid'),
  50. target:_this.uid,
  51. type:1
  52. }
  53. console.log(addUserRelationOption);
  54. addUserRelation(addUserRelationOption).then((res) => {
  55. console.log(res);
  56. wx.navigateTo({
  57. url: '/pages/chat/chat?toUid=' + this.data.uid + '&goodsId=' + this.data.id + '&pic=' + this.data.pic,
  58. })
  59. }).catch((err) => {
  60. console.log(err);
  61. })
  62. },
  63. GoodsDetail() {
  64. getGoodsDetail(this.data).then((res) => {
  65. const { code, data, message} = res.data;
  66. console.log(data);
  67. //通过获取详细信息将商品的描述获取并渲染
  68. this.setData({
  69. desc: data.Desc,
  70. ownerId: data.ownerId
  71. })
  72. }).catch((err) => {
  73. console.log(err);
  74. })
  75. },
  76. getUserInfo() {
  77. var owner = {data: {id: [this.data.uid]}};
  78. console.log(owner);
  79. getUserInfoList(owner).then((res) => {
  80. console.log(res);
  81. const {users} = res.data.data;
  82. this.setData({
  83. avatar: users[0].avatar,
  84. ownerName: users[0].name
  85. })
  86. }).catch((err) => {
  87. console.log(err);
  88. })
  89. },
  90. /**
  91. * 生命周期函数--监听页面初次渲染完成
  92. */
  93. onReady() {
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow() {
  99. },
  100. /**
  101. * 生命周期函数--监听页面隐藏
  102. */
  103. onHide() {
  104. },
  105. /**
  106. * 生命周期函数--监听页面卸载
  107. */
  108. onUnload() {
  109. },
  110. /**
  111. * 页面相关事件处理函数--监听用户下拉动作
  112. */
  113. onPullDownRefresh() {
  114. },
  115. /**
  116. * 页面上拉触底事件的处理函数
  117. */
  118. onReachBottom() {
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage() {
  124. }
  125. })