123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- // pages/message/message.js
- const {getUserRelation,addUserRelation, getUserInfoList, getGoodsInfoList,getLatestChattingRecord} = require('../../API/appraise')
- import messageMap from '../../utils/util'
- var baseUrl = 'http://192.168.31.27:8084';
- var getRelationOption = {
- data:{
-
- }
- }
- var addRelationOption = {
- data:{
- "goodsId":9,
- "owner": '7386090454720188416',
- "target": '7384540497554968576',
- "type":1
- }
- }
- var getUserInfoListOption = {
- data:{
- uid:[]
- }
- }
- var getGoodsInfoListOption = {
- data:{
- id:[],
- }
- }
- var getLatestChattingRecordOption = {
- uid: '',
- target: ''
- }
- var key = "commodityPicture";
- let key1 = "avatarUrl";
- let key2 = "merchantName";
- let key3 = "id";
- function sendSocketMessage(msg){
- wx.sendSocketMessage({
- data: msg,
- })
- }
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- message:[
- // {
- // id:1,
- // item:{
- // avatarUrl: baseUrl+"/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg",
- // commodityPicture: "https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg",
- // merchantName: "daisy",
- // lastMessageRecord:'你好',
- // messageTime:'11-7 21:42'
- // }
- // },
- // {
- // id:2,
- // item:{
- // avatarUrl: "https://img.js.design/assets/img/61c6d4ab9cd4d011e8f0b298.png",
- // commodityPicture: "https://img.js.design/assets/smartFill/img334164da748e08.jpg",
- // merchantName: "kaka",
- // lastMessageRecord:'价格可以商量一下吗',
- // messageTime:'11-6 21:11'
- // }
- // },
- // {
- // id:3,
- // item:{
- // avatarUrl: baseUrl+"/pics/1698845584tmp_69fe84d4b7b444512c31c8693e95336113d42d50aaca0699.jpg",
- // commodityPicture: "https://img.js.design/assets/img/64ca428a87e21a113298b895.jpg",
- // merchantName: "cherry",
- // lastMessageRecord:'OK',
- // messageTime:'11-4 19:46'
- // }
- // },
- // {
- // id:4,
- // item:{
- // avatarUrl: baseUrl+"/pics/1698846108tmp_c0bcb90fd9ef93e065c22b977d7bc8aea17a1ac1e8393c21.jpg",
- // commodityPicture: "https://img.js.design/assets/smartFill/img313164da746310.jpg",
- // merchantName: "666",
- // lastMessageRecord:'期待下次交易',
- // messageTime:'11-1 21:30'
- // }
- // },
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- var message = this.data.message;
- // addUserRelation(addRelationOption).then((res) => {
- // console.log(res);
- // }).catch((err) => {
- // console.log(err);
- // })
- getRelationOption.data = {
- uid: wx.getStorageSync('uid'),
- }
- getUserRelation(getRelationOption).then((res) => {
- console.log(res);
- const fUid = res.data.data.fUid;
- let fUidLength = fUid.length;
- let target = [];
- for(let i=0;i<fUidLength;i++)
- {
- target[i] = fUid[i].target;
- }
- var goodsId = [];
- for(let i=0;i<fUidLength;i++)
- {
- goodsId[i] = fUid[i].goodsId;
- }
- console.log(target);
- console.log(goodsId);
- getUserInfoListOption.data.uid = target;
- console.log(getUserInfoListOption);
- getUserInfoList(getUserInfoListOption).then((res) => {
- console.log(res);
- const users = res.data.data.users;
- let targetIds = [];
- for(let i=0;i<users.length;i++)
- {
- message.push({item:{}});
- message[i][key3] = i+1;
- message[i].item[key1] = baseUrl+users[i].avatar.slice(25);
- message[i].item[key2] = users[i].name;
- message[i].item['targetId'] = users[i].uid;
- targetIds.push(users[i].uid);
- }
- //获取最后一条聊天记录
- // for(let v of targetIds){
- // getLatestChattingRecordOption.uid = wx.getStorageSync('uid');
- // getLatestChattingRecordOption.target = v;
- // getLatestChattingRecord(getLatestChattingRecordOption).then((res=>{
- // console.log(res);
- // })).catch((err=>{
- // console.log(err);
- // }))
- // }
- console.log(message);
- getGoodsInfoListOption.data.id = goodsId;
- getGoodsInfoList(getGoodsInfoListOption).then((res => {
- console.log(res);
- const goods = res.data.data.goods;
- for(let i=0;i<goods.length;i++)
- {
- message[i].item[key] = goods[i].Pic;
- message[i].item['goodsId'] = goods[i].Id;
- }
- this.setData({
- message:message
- })
- })).catch((err) => {
- console.log(err);
- })
- }).catch((err) => {
- console.log(err);
- })
- }).catch((err) => {
- console.log(err);
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- toChat(e) {
- let item = e.target.dataset.item;
- console.log(item);
- wx.navigateTo({
- url: '/pages/chat/chat?toUid='+item.targetId+'&goodsId='+item.goodsId,
- })
- }
-
- })
|