message.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // pages/message/message.js
  2. const {getUserRelation,addUserRelation, getUserInfoList, getGoodsInfoList,getLatestChattingRecord} = require('../../API/appraise')
  3. import messageMap from '../../utils/util'
  4. var baseUrl = 'http://192.168.31.27:8084';
  5. var getRelationOption = {
  6. data:{
  7. }
  8. }
  9. var addRelationOption = {
  10. data:{
  11. "goodsId":9,
  12. "owner": '7386090454720188416',
  13. "target": '7384540497554968576',
  14. "type":1
  15. }
  16. }
  17. var getUserInfoListOption = {
  18. data:{
  19. uid:[]
  20. }
  21. }
  22. var getGoodsInfoListOption = {
  23. data:{
  24. id:[],
  25. }
  26. }
  27. var getLatestChattingRecordOption = {
  28. uid: '',
  29. target: ''
  30. }
  31. var key = "commodityPicture";
  32. let key1 = "avatarUrl";
  33. let key2 = "merchantName";
  34. let key3 = "id";
  35. function sendSocketMessage(msg){
  36. wx.sendSocketMessage({
  37. data: msg,
  38. })
  39. }
  40. Page({
  41. /**
  42. * 页面的初始数据
  43. */
  44. data: {
  45. message:[
  46. // {
  47. // id:1,
  48. // item:{
  49. // avatarUrl: baseUrl+"/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg",
  50. // commodityPicture: "https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg",
  51. // merchantName: "daisy",
  52. // lastMessageRecord:'你好',
  53. // messageTime:'11-7 21:42'
  54. // }
  55. // },
  56. // {
  57. // id:2,
  58. // item:{
  59. // avatarUrl: "https://img.js.design/assets/img/61c6d4ab9cd4d011e8f0b298.png",
  60. // commodityPicture: "https://img.js.design/assets/smartFill/img334164da748e08.jpg",
  61. // merchantName: "kaka",
  62. // lastMessageRecord:'价格可以商量一下吗',
  63. // messageTime:'11-6 21:11'
  64. // }
  65. // },
  66. // {
  67. // id:3,
  68. // item:{
  69. // avatarUrl: baseUrl+"/pics/1698845584tmp_69fe84d4b7b444512c31c8693e95336113d42d50aaca0699.jpg",
  70. // commodityPicture: "https://img.js.design/assets/img/64ca428a87e21a113298b895.jpg",
  71. // merchantName: "cherry",
  72. // lastMessageRecord:'OK',
  73. // messageTime:'11-4 19:46'
  74. // }
  75. // },
  76. // {
  77. // id:4,
  78. // item:{
  79. // avatarUrl: baseUrl+"/pics/1698846108tmp_c0bcb90fd9ef93e065c22b977d7bc8aea17a1ac1e8393c21.jpg",
  80. // commodityPicture: "https://img.js.design/assets/smartFill/img313164da746310.jpg",
  81. // merchantName: "666",
  82. // lastMessageRecord:'期待下次交易',
  83. // messageTime:'11-1 21:30'
  84. // }
  85. // },
  86. ]
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad(options) {
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady() {
  97. var message = this.data.message;
  98. // addUserRelation(addRelationOption).then((res) => {
  99. // console.log(res);
  100. // }).catch((err) => {
  101. // console.log(err);
  102. // })
  103. getRelationOption.data = {
  104. uid: wx.getStorageSync('uid'),
  105. }
  106. getUserRelation(getRelationOption).then((res) => {
  107. console.log(res);
  108. const fUid = res.data.data.fUid;
  109. let fUidLength = fUid.length;
  110. let target = [];
  111. for(let i=0;i<fUidLength;i++)
  112. {
  113. target[i] = fUid[i].target;
  114. }
  115. var goodsId = [];
  116. for(let i=0;i<fUidLength;i++)
  117. {
  118. goodsId[i] = fUid[i].goodsId;
  119. }
  120. console.log(target);
  121. console.log(goodsId);
  122. getUserInfoListOption.data.uid = target;
  123. console.log(getUserInfoListOption);
  124. getUserInfoList(getUserInfoListOption).then((res) => {
  125. console.log(res);
  126. const users = res.data.data.users;
  127. let targetIds = [];
  128. for(let i=0;i<users.length;i++)
  129. {
  130. message.push({item:{}});
  131. message[i][key3] = i+1;
  132. message[i].item[key1] = baseUrl+users[i].avatar.slice(25);
  133. message[i].item[key2] = users[i].name;
  134. message[i].item['targetId'] = users[i].uid;
  135. targetIds.push(users[i].uid);
  136. }
  137. //获取最后一条聊天记录
  138. // for(let v of targetIds){
  139. // getLatestChattingRecordOption.uid = wx.getStorageSync('uid');
  140. // getLatestChattingRecordOption.target = v;
  141. // getLatestChattingRecord(getLatestChattingRecordOption).then((res=>{
  142. // console.log(res);
  143. // })).catch((err=>{
  144. // console.log(err);
  145. // }))
  146. // }
  147. console.log(message);
  148. getGoodsInfoListOption.data.id = goodsId;
  149. getGoodsInfoList(getGoodsInfoListOption).then((res => {
  150. console.log(res);
  151. const goods = res.data.data.goods;
  152. for(let i=0;i<goods.length;i++)
  153. {
  154. message[i].item[key] = goods[i].Pic;
  155. message[i].item['goodsId'] = goods[i].Id;
  156. }
  157. this.setData({
  158. message:message
  159. })
  160. })).catch((err) => {
  161. console.log(err);
  162. })
  163. }).catch((err) => {
  164. console.log(err);
  165. })
  166. }).catch((err) => {
  167. console.log(err);
  168. })
  169. },
  170. /**
  171. * 生命周期函数--监听页面显示
  172. */
  173. onShow() {
  174. },
  175. /**
  176. * 生命周期函数--监听页面隐藏
  177. */
  178. onHide() {
  179. },
  180. /**
  181. * 生命周期函数--监听页面卸载
  182. */
  183. onUnload() {
  184. },
  185. /**
  186. * 页面相关事件处理函数--监听用户下拉动作
  187. */
  188. onPullDownRefresh() {
  189. },
  190. /**
  191. * 页面上拉触底事件的处理函数
  192. */
  193. onReachBottom() {
  194. },
  195. /**
  196. * 用户点击右上角分享
  197. */
  198. onShareAppMessage() {
  199. },
  200. toChat(e) {
  201. let item = e.target.dataset.item;
  202. console.log(item);
  203. wx.navigateTo({
  204. url: '/pages/chat/chat?toUid='+item.targetId+'&goodsId='+item.goodsId,
  205. })
  206. }
  207. })