message.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // pages/message/message.js
  2. const {getUserRelation,addUserRelation, getUserInfoList, getGoodsInfoList} = require('../../API/appraise')
  3. var getRelationOption = {
  4. data:{
  5. uid: wx.getStorageSync('uid'),
  6. }
  7. }
  8. var addRelationOption = {
  9. data:{
  10. "goodsId":7,
  11. "owner": '7384540497554968576',
  12. "target": '7386092638421651456',
  13. "type":1
  14. }
  15. }
  16. var getUserInfoListOption = {
  17. data:{
  18. uid:[]
  19. }
  20. }
  21. var getGoodsInfoListOption = {
  22. data:{
  23. id:[]
  24. }
  25. }
  26. var message = [
  27. {
  28. // id:0,
  29. item:{
  30. // avatarUrl:'',
  31. // merchantName:'',
  32. // lastMessageRecord:'',
  33. // messageTime: '',
  34. // commodityPicture: ''
  35. }
  36. }
  37. ]
  38. var key = "commodityPicture";
  39. let key1 = "avatarUrl";
  40. let key2 = "merchantName";
  41. let key3 = "id";
  42. Page({
  43. /**
  44. * 页面的初始数据
  45. */
  46. data: {
  47. // message:message
  48. message: [
  49. {
  50. id:1,
  51. item:{
  52. avatarUrl: "http://192.168.31.28:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg",
  53. commodityPicture: "https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg",
  54. merchantName: "daisy",
  55. }
  56. },
  57. {
  58. id:2,
  59. item:{
  60. avatarUrl: "http://192.168.31.28:8084/pics/1698845584tmp_69fe84d4b7b444512c31c8693e95336113d42d50aaca0699.jpg",
  61. commodityPicture: "https://img.js.design/assets/img/64ca428a87e21a113298b895.jpg",
  62. merchantName: "cherry"
  63. }
  64. }
  65. ]
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. onLoad(options) {
  71. // addUserRelation(addRelationOption).then((res) => {
  72. // console.log(res);
  73. // }).catch((err) => {
  74. // console.log(err);
  75. // })
  76. getUserRelation(getRelationOption).then((res) => {
  77. console.log(res);
  78. console.log(res.data.data.fUid.length);
  79. var fUidLength = res.data.data.fUid.length;
  80. var target = [];
  81. for(var i=0;i<fUidLength;i++)
  82. {
  83. target[i] = res.data.data.fUid[i].target;
  84. }
  85. var goodsId = [];
  86. for(var i=0;i<fUidLength;i++)
  87. {
  88. goodsId[i] = res.data.data.fUid[i].goodsId;
  89. }
  90. console.log(target);
  91. console.log(goodsId);
  92. getUserInfoListOption.data.uid = target;
  93. console.log(getUserInfoListOption);
  94. getUserInfoList(getUserInfoListOption).then((res) => {
  95. console.log(res);
  96. for(var i=0;i<res.data.data.users.length;i++)
  97. {
  98. message[i][key3] = i+1;
  99. message[i].item[key1] = res.data.data.users[i].avatar;
  100. message[i].item[key2] = res.data.data.users[i].name;
  101. message.push({item:{}});
  102. }
  103. console.log(message);
  104. getGoodsInfoListOption.data.id = goodsId;
  105. getGoodsInfoList(getGoodsInfoListOption).then((res => {
  106. console.log(res);
  107. for(var i=0;i<res.data.data.goods.length;i++)
  108. {
  109. message[i].item[key] = res.data.data.goods[i].Pic;
  110. }
  111. console.log(message);
  112. })).catch((err) => {
  113. console.log(err);
  114. })
  115. }).catch((err) => {
  116. console.log(err);
  117. })
  118. }).catch((err) => {
  119. console.log(err);
  120. })
  121. this.setData({
  122. message:message,
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady() {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow() {
  134. // console.log(message);
  135. // this.setData({
  136. // message:message,
  137. // })
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload() {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh() {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom() {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage() {
  163. }
  164. })