history.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {},
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. this.setData({
  15. userid: wx.getStorageSync('userData').userid,
  16. timdialogid: options.id,
  17. pageType: options.type
  18. })
  19. this.query_imdialogMessage();
  20. },
  21. query_imdialogMessage() {
  22. let condition = "",
  23. begdate = '',
  24. enddate = '';
  25. _Http.basic({
  26. "accesstoken": wx.getStorageSync('userData').token,
  27. "classname": "system.im.imdialog.imdialog",
  28. "method": "query_imdialogMessage",
  29. "content": {
  30. "pageNumber": this.data.pageNumber,
  31. "pageSize": 50,
  32. "timdialogid": this.data.timdialogid,
  33. "where": {
  34. "condition": condition,
  35. "begdate": begdate,
  36. "enddate": enddate
  37. }
  38. }
  39. }).then(async res => {
  40. console.log("聊天记录", res)
  41. if (res.msg != '成功') return wx.showToast({
  42. title: res.data,
  43. icon: "none"
  44. });
  45. let list = res.data;
  46. list = list.reverse();
  47. if (res.pageNumber != 1) {
  48. if (this.data.pageType == '话题') list = await this.querySubject(list);
  49. list = list.concat(this.data.socketMsgQueue);
  50. this.setData({
  51. socketMsgQueue: list,
  52. toView: `item${res.data.length - 1}`,
  53. triggered: false
  54. })
  55. } else {
  56. if (this.data.pageType == '话题') list = await this.querySubject(list);
  57. this.setData({
  58. socketMsgQueue: list,
  59. toView: `item${res.data.length - 1}`,
  60. pageTotal: res.pageTotal
  61. })
  62. }
  63. /* if (res.pageNumber != 1) {
  64. let list = res.data;
  65. list = list.reverse();
  66. list = list.concat(this.data.socketMsgQueue);
  67. this.setData({
  68. socketMsgQueue: list
  69. })
  70. } else {
  71. let list = res.data;
  72. list = list.reverse();
  73. this.setData({
  74. socketMsgQueue: list,
  75. toView: `item${res.data.length - 1}`,
  76. pageTotal: res.pageTotal
  77. })
  78. } */
  79. })
  80. },
  81. async querySubject(array) {
  82. console.log("列表", array)
  83. let list = [];
  84. for (let index = 0; index < array.length; index++) {
  85. await _Http.basic({
  86. "accesstoken": wx.getStorageSync('userData').token,
  87. "classname": "system.im.imdialog.imdialog",
  88. "method": "querySubject",
  89. "content": {
  90. "timsubjectid": array[index].message.data.ownerid
  91. }
  92. }, false).then(res => {
  93. if (res.data.length != 0 && res.data[0].imsubjectcontent.length != 0) {
  94. res.data[0].sendfrom = array[index].message.sendfrom;
  95. res.data[0].timdialogid = array[index].message.timdialogid;
  96. if (res.data[0].closedate != null) {
  97. let time = res.data[0].closedate.split('.');
  98. res.data[0].closedate = time[0];
  99. } else {
  100. let time = res.data[0].createdate.split('.');
  101. res.data[0].createdate = time[0];
  102. }
  103. let obj = {
  104. message: res.data[0]
  105. }
  106. list.push(obj);
  107. }
  108. })
  109. }
  110. return list;
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function () {
  141. },
  142. /**
  143. * 用户点击右上角分享
  144. */
  145. onShareAppMessage: function () {
  146. }
  147. })