123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- // pages/message/message.js
- const {getUserRelation,addUserRelation, getUserInfoList, getGoodsInfoList} = require('../../API/appraise')
- import messageMap from '../../utils/util'
- var getRelationOption = {
- data:{
-
- }
- }
- var addRelationOption = {
- data:{
- "goodsId":9,
- "owner": '7386090454720188416',
- "target": '7384540497554968576',
- "type":1
- }
- }
- var getUserInfoListOption = {
- data:{
- uid:[]
- }
- }
- var getGoodsInfoListOption = {
- data:{
- id:[]
- }
- }
- 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: "http://192.168.31.30:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg",
- // // commodityPicture: "https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg",
- // // merchantName: "daisy"
- // // }
- // }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- 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;
- for(let i=0;i<users.length;i++)
- {
- message.push({item:{}});
- message[i][key3] = i+1;
- message[i].item[key1] = users[i].avatar;
- message[i].item[key2] = users[i].name;
- message[i].item['targetId'] = users[i].uid;
-
- }
- 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) {
- wx.connectSocket({
- url: 'ws://192.168.31.30:8084'+'/chat'+'?uid='+wx.getStorageSync('uid'),
- })
- // 监听
- wx.onSocketOpen((result) => {
- console.log("websocket连接已打开");
- })
- // 失败监控
- wx.onSocketError((result) => {
- console.log("websocket连接失败", result);
- })
- // 监听服务器的数据返回
- wx.onSocketMessage((result) => {
- console.log("服务器的数据返回", result);
-
- })
- console.log(e.target.dataset.item);
- let item = e.target.dataset.item;
- wx.navigateTo({
- url: '/pages/chat/chat?toUid='+item.targetId+'?goodsId='+item.goodsId+'?nickName',
- })
- }
-
- })
|