index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const _Http = getApp().globalData.http;
  2. let editor = null;
  3. Component({
  4. options: {
  5. addGlobalClass: true
  6. },
  7. data: {
  8. lookItem: null,
  9. show: false,
  10. height: 0,
  11. countDown: 10,
  12. Interval: null,
  13. sat_noticeids: [],
  14. },
  15. methods: {
  16. getList() {
  17. _Http.basic({
  18. id: 20221111090904,
  19. content: {
  20. nocache: true,
  21. "pageNumber": 1,
  22. "pageSize": 9999,
  23. "pageTotal": 1,
  24. "where": {
  25. "condition": "",
  26. isread: 0
  27. }
  28. }
  29. }).then(res => {
  30. console.log("未读通告", res)
  31. if (res.msg != '成功') return;
  32. if (res.data.length) {
  33. res.data = res.data.map(v => {
  34. v.inquire = false;
  35. return v
  36. });
  37. this.setData({
  38. lookItem: res.data[0],
  39. list: res.data,
  40. show: true
  41. });
  42. this.getDetail();
  43. }
  44. })
  45. },
  46. getDetail() {
  47. let lookItem = this.data.lookItem;
  48. _Http.basic({
  49. "classname": "saletool.notice.notice",
  50. "method": "queryNoticeMain",
  51. "content": {
  52. "sat_noticeid": lookItem.sat_noticeid
  53. }
  54. }).then(res => {
  55. console.log("通告详情", res)
  56. if (res.msg != '成功') return;
  57. lookItem.content = res.data.content;
  58. lookItem.inquire = true;
  59. this.data.list[lookItem.rowindex - 1].content = res.data.content;
  60. if (!this.data.sat_noticeids.some(v => v == res.data.sat_noticeid)) {
  61. this.data.sat_noticeids.push(res.data.sat_noticeid)
  62. this.setData({
  63. countDown: 10
  64. })
  65. this.data.Interval = setInterval(() => {
  66. if (this.data.countDown == 0) {
  67. clearInterval(this.data.Interval)
  68. this.setData({
  69. Interval: null
  70. })
  71. } else {
  72. this.setData({
  73. countDown: this.data.countDown - 1
  74. })
  75. }
  76. }, 1000);
  77. }
  78. this.setData({
  79. lookItem
  80. });
  81. this.rander(lookItem.content)
  82. });
  83. },
  84. async rander(html) {
  85. this.setHeight().then(s => {
  86. if (editor == null) {
  87. wx.createSelectorQuery().in(this).select('#editor').context(function (res) {
  88. editor = res.context;
  89. this.rander(html)
  90. }).exec()
  91. } else {
  92. editor.setContents({
  93. html,
  94. complete: res => {
  95. console.log("渲染富文本", res)
  96. if (this.data.height == 0) setTimeout(() => {
  97. this.rander(html)
  98. }, 50)
  99. }
  100. })
  101. };
  102. })
  103. },
  104. setHeight() {
  105. return new Promise(async (resolve) => {
  106. let boxHeight = await this.queryElement(".box", "height"),
  107. headHeight = await this.queryElement(".head", "height"),
  108. bottomHeight = await this.queryElement(".bottom", "height"),
  109. height = boxHeight - headHeight - bottomHeight - 5;
  110. this.setData({
  111. height
  112. })
  113. resolve(height)
  114. })
  115. },
  116. queryElement(element, field) {
  117. return new Promise((resolve, reject) => {
  118. wx.createSelectorQuery().in(this).select(element).boundingClientRect().exec(res => {
  119. resolve(field ? res[0][field] : res[0])
  120. })
  121. })
  122. },
  123. changeLook(e) {
  124. if (this.data.countDown != 0) return;
  125. let lookItem = this.data.lookItem;
  126. this.rander("")
  127. switch (e.target.id) {
  128. case "previous":
  129. lookItem = this.data.list[lookItem.rowindex - 2];
  130. this.setData({
  131. lookItem
  132. });
  133. lookItem.inquire ? this.rander(lookItem.content) : this.getDetail();
  134. break;
  135. case "next":
  136. lookItem = this.data.list[lookItem.rowindex];
  137. this.setData({
  138. lookItem
  139. });
  140. lookItem.inquire ? this.rander(lookItem.content) : this.getDetail();
  141. break;
  142. default:
  143. this.setData({
  144. show: false
  145. })
  146. break;
  147. }
  148. }
  149. },
  150. lifetimes: {
  151. attached() {
  152. wx.createSelectorQuery().in(this).select('#editor').context(function (res) {
  153. editor = res.context;
  154. }).exec()
  155. this.getList()
  156. }
  157. }
  158. })