123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- // pages/details/details.js
- const { getGoodsDetail, getUserInfoList, addUserRelation } = 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() {
- let _this = this.data;
- let $id = parseInt(_this.id);
- let addUserRelationOption = {
- goodsId:$id,
- owner:wx.getStorageSync('uid'),
- target:_this.uid,
- type:1
- }
- console.log(addUserRelationOption);
- addUserRelation(addUserRelationOption).then((res) => {
- console.log(res);
- wx.navigateTo({
- url: '/pages/chat/chat?toUid=' + this.data.uid + '&goodsId=' + this.data.id + '&pic=' + this.data.pic,
- })
- }).catch((err) => {
- console.log(err);
- })
- },
- 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() {
- }
- })
|