details.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. var WxParse = require('../../wxParse/wxParse.js');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. pageType: {}, //类型 0 为广场进入 1为发布历史进入 2为门户进入
  12. tnoticeid: {}, //公告id
  13. msgObj: {}, //详情
  14. coverFiles: [], //封面
  15. defaultFiles: [], //附件
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. //默认通告广场
  22. let data = {
  23. "accesstoken": wx.getStorageSync('userData').token,
  24. "classname": "customer.notice.notice",
  25. "method": "query_noticeMain",
  26. "content": {
  27. "tnoticeid": options.id
  28. }
  29. };
  30. //历史发布
  31. if (options.type == 1) {
  32. data.classname = "customer.noticemag.noticemag";
  33. };
  34. //无状态进入
  35. if (options.type == 2) {
  36. data = {
  37. "classname": "publicmethod.homepage.homepage",
  38. "method": "query_noticeMain",
  39. "content": {
  40. "tnoticeid": options.id
  41. }
  42. }
  43. }
  44. //开始阅读
  45. _Http.basic(data).then(res => {
  46. let attinfos = res.data[0].attinfos,
  47. coverFiles = [],
  48. defaultFiles = [];
  49. for (let i = 0; i < attinfos.length; i++) {
  50. (attinfos[i].ftype == "default") ? defaultFiles.push(attinfos[i]): coverFiles.push(attinfos[i])
  51. }
  52. var that = this;
  53. var article = res.data[0].fcontent;
  54. WxParse.wxParse('article', 'html', article, that, 5);
  55. res.data[0].checkdate = res.data[0].checkdate.slice(0, res.data[0].checkdate.lastIndexOf('.'));
  56. this.setData({
  57. tnoticeid: options.id,
  58. msgObj: res.data[0],
  59. coverFiles,
  60. defaultFiles,
  61. pageType: options.type
  62. })
  63. })
  64. },
  65. /* 查看附件 */
  66. downLoadFiles(e) {
  67. const {
  68. index
  69. } = e.currentTarget.dataset,
  70. that = this,
  71. data = this.data.defaultFiles[index];
  72. // console.log(data)
  73. wx.downloadFile({
  74. url: data.fobsurl,
  75. success: function (res) {
  76. var filePath = res.tempFilePath;
  77. //页面显示加载动画
  78. wx.openDocument({
  79. filePath: filePath,
  80. success: function (res) {
  81. console.log('打开文档成功')
  82. }
  83. })
  84. },
  85. })
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady: function () {},
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. if (this.data.pageType == 0) {
  106. _Http.basic({
  107. "accesstoken": wx.getStorageSync('userData').token,
  108. "classname": "customer.notice.notice",
  109. "method": "noticeexit",
  110. "content": {
  111. "tnoticeid": this.data.tnoticeid
  112. }
  113. }).then(res => {
  114. console.log(res)
  115. })
  116. }
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. }
  133. })