// pages/details/details.js const { getGoodsDetail, getUserInfoList } = require('../../API/appraise') const { formatTime } = require('../../utils/util') Page({ /** * 页面的初始数据 */ data: { id: 0, title: "", price: 0, pic: [], desc: "", uid: String, time: Number, ownerId: String, avatar: String, ownerName: String }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); //将传递过来的关于商品的数据渲染到页面 this.setData({ id: options.id,//商品id title: options.title, price: options.price, pic: options.img, // uid: parseInt(options.uid) uid: options.uid//卖家id }) // console.log(this.data.uid); //获取时间戳 var date = Date.parse(new Date()) date = date / 1000 this.setData({ time: date }) this.GoodsDetail(); this.getUserInfo(); }, toChat() { wx.navigateTo({ url: '/pages/chat/chat?toUid=' + this.data.uid + '&goodsId=' + this.data.id, }) }, GoodsDetail() { getGoodsDetail(this.data).then((res) => { const { code, data, message} = res.data; console.log(data); //通过获取详细信息将商品的描述获取并渲染 this.setData({ desc: data.Desc, ownerId: data.ownerId }) }).catch((err) => { console.log(err); }) }, getUserInfo() { var owner = {data: {id: [this.data.uid]}}; console.log(owner); getUserInfoList(owner).then((res) => { console.log(res); const {users} = res.data.data; this.setData({ avatar: users[0].avatar, ownerName: users[0].name }) }).catch((err) => { console.log(err); }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })