message.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 key = "commodityPicture";
  27. let key1 = "avatarUrl";
  28. let key2 = "merchantName";
  29. let key3 = "id";
  30. Page({
  31. /**
  32. * 页面的初始数据
  33. */
  34. data: {
  35. message:[]
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad(options) {
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady() {
  46. var message = this.data.message;
  47. // addUserRelation(addRelationOption).then((res) => {
  48. // console.log(res);
  49. // }).catch((err) => {
  50. // console.log(err);
  51. // })
  52. getUserRelation(getRelationOption).then((res) => {
  53. console.log(res);
  54. const fUid = res.data.data.fUid;
  55. let fUidLength = fUid.length;
  56. let target = [];
  57. for(let i=0;i<fUidLength;i++)
  58. {
  59. target[i] = fUid[i].target;
  60. }
  61. var goodsId = [];
  62. for(let i=0;i<fUidLength;i++)
  63. {
  64. goodsId[i] = fUid[i].goodsId;
  65. }
  66. console.log(target);
  67. console.log(goodsId);
  68. getUserInfoListOption.data.uid = target;
  69. console.log(getUserInfoListOption);
  70. getUserInfoList(getUserInfoListOption).then((res) => {
  71. console.log(res);
  72. const users = res.data.data.users;
  73. for(let i=0;i<users.length;i++)
  74. {
  75. message.push({item:{}});
  76. message[i][key3] = i+1;
  77. message[i].item[key1] = users[i].avatar;
  78. message[i].item[key2] = users[i].name;
  79. }
  80. console.log(message);
  81. getGoodsInfoListOption.data.id = goodsId;
  82. getGoodsInfoList(getGoodsInfoListOption).then((res => {
  83. console.log(res);
  84. const goods = res.data.data.goods;
  85. for(let i=0;i<goods.length;i++)
  86. {
  87. message[i].item[key] = goods[i].Pic;
  88. }
  89. this.setData({
  90. message:message
  91. })
  92. })).catch((err) => {
  93. console.log(err);
  94. })
  95. }).catch((err) => {
  96. console.log(err);
  97. })
  98. }).catch((err) => {
  99. console.log(err);
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload() {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh() {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom() {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage() {
  131. }
  132. })