index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {
  2. getAuthorityMsg,
  3. getMessageRecord,
  4. msgTopping
  5. } from '~/api/message'
  6. import reachBottom from '~/mixins/reachBottom'
  7. const app = getApp()
  8. Page({
  9. behaviors: [reachBottom],
  10. data: {
  11. targetId: "",
  12. menu: {
  13. show: false,
  14. top: 0,
  15. left: 0
  16. },
  17. menuH: 0,
  18. authorityMsg: {},
  19. uid: ''
  20. },
  21. onLoad(options) {
  22. this.setData({
  23. uid: wx.getStorageSync('uid')
  24. })
  25. },
  26. onShow() {
  27. if (typeof this.getTabBar === 'function') {
  28. this.getTabBar().setData({
  29. selected: 3
  30. })
  31. }
  32. this.getAuthorityMsg()
  33. this.resetData()
  34. wx.createSelectorQuery().select('.menu').boundingClientRect((rect) => {
  35. this.setData({
  36. menuH: rect.height
  37. })
  38. }).exec()
  39. },
  40. async getAuthorityMsg() {
  41. let authorityMsg = await getAuthorityMsg()
  42. console.log(authorityMsg);
  43. this.setData({
  44. authorityMsg
  45. })
  46. },
  47. loadMore() {
  48. this.getData(getMessageRecord)
  49. },
  50. setSearch({
  51. detail
  52. }) {
  53. /* console.log(detail)
  54. if (!detail.value) {
  55. this.setData({
  56. nullList: false,
  57. list: []
  58. });
  59. }
  60. this.setData({
  61. text: detail.value
  62. }); */
  63. },
  64. async search() {
  65. if (!this.data.text) {
  66. this.setData({
  67. list: []
  68. });
  69. return;
  70. }
  71. this.setData({
  72. list,
  73. });
  74. },
  75. onLongPress(e) {
  76. console.log(e);
  77. let {
  78. currentTarget,
  79. detail,
  80. touches,
  81. target
  82. } = e
  83. let remainingW = app.globalData.windowWidth - touches[0].clientX
  84. let remainingH = app.globalData.windowHeight - touches[0].clientY
  85. let menuH = this.data.menuH
  86. let wFlag = remainingW - 145 > 0
  87. let hFlag = remainingH - menuH + 10 > 0
  88. let {
  89. receiverUid,
  90. senderUid
  91. } = currentTarget.dataset.item
  92. this.setData({
  93. targetId: receiverUid != this.data.uid ? receiverUid : senderUid,
  94. menu: {
  95. show: true,
  96. top: hFlag ? touches[0].clientY : touches[0].clientY - menuH,
  97. left: wFlag ? touches[0].clientX : touches[0].clientX - 135
  98. }
  99. })
  100. },
  101. cancelMenu() {
  102. this.setData({
  103. 'menu.show': false
  104. })
  105. },
  106. async msgTopping() {
  107. await msgTopping({
  108. topUid: this.data.targetId
  109. })
  110. this.cancelMenu()
  111. this.getAuthorityMsg()
  112. this.resetData()
  113. },
  114. delMessage() {
  115. this.setData({
  116. 'menu.show': false
  117. })
  118. },
  119. jump({
  120. currentTarget
  121. }) {
  122. wx.navigateTo({
  123. url: `/pages/${currentTarget.dataset.url}/index`,
  124. })
  125. },
  126. jumpChat({
  127. currentTarget
  128. }) {
  129. console.log(currentTarget.dataset);
  130. /* wx.navigateTo({
  131. url: `/pages/${currentTarget.dataset.url}/index`,
  132. }) */
  133. },
  134. })