details.js 3.3 KB

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