index.js 3.6 KB

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