index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. rander(html) {
  64. this.setHeight();
  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. }
  76. })
  77. };
  78. },
  79. async setHeight() {
  80. let boxHeight = await this.queryElement(".box", "height"),
  81. headHeight = await this.queryElement(".head", "height"),
  82. bottomHeight = await this.queryElement(".bottom", "height"),
  83. height = boxHeight - headHeight - bottomHeight - 5;
  84. this.setData({
  85. height
  86. })
  87. },
  88. queryElement(element, field) {
  89. return new Promise((resolve, reject) => {
  90. wx.createSelectorQuery().in(this).select(element).boundingClientRect().exec(res => {
  91. resolve(field ? res[0][field] : res[0])
  92. })
  93. })
  94. },
  95. changeLook(e) {
  96. let lookItem = this.data.lookItem;
  97. this.rander("")
  98. switch (e.target.id) {
  99. case "previous":
  100. lookItem = this.data.list[lookItem.rowindex - 2];
  101. this.setData({
  102. lookItem
  103. });
  104. lookItem.inquire ? this.rander(lookItem.content) : this.getDetail();
  105. break;
  106. case "next":
  107. lookItem = this.data.list[lookItem.rowindex];
  108. this.setData({
  109. lookItem
  110. });
  111. lookItem.inquire ? this.rander(lookItem.content) : this.getDetail();
  112. break;
  113. default:
  114. console.log("关闭")
  115. this.setData({
  116. show: false
  117. })
  118. break;
  119. }
  120. }
  121. },
  122. lifetimes: {
  123. attached() {
  124. wx.createSelectorQuery().in(this).select('#editor').context(function (res) {
  125. editor = res.context;
  126. }).exec()
  127. this.getList()
  128. }
  129. }
  130. })