details.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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为发布历史进入
  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. _Http.basic(data).then(res => {
  36. let attinfos = res.data[0].attinfos,
  37. coverFiles = [],
  38. defaultFiles = [];
  39. for (let i = 0; i < attinfos.length; i++) {
  40. (attinfos[i].ftype == "default") ? defaultFiles.push(attinfos[i]): coverFiles.push(attinfos[i])
  41. }
  42. var that = this;
  43. var article = res.data[0].fcontent;
  44. WxParse.wxParse('article', 'html', article, that, 5);
  45. this.setData({
  46. tnoticeid: options.id,
  47. msgObj: res.data[0],
  48. coverFiles,
  49. defaultFiles,
  50. pageType: options.type
  51. })
  52. })
  53. },
  54. /* 下载附件 */
  55. downLoadFiles(e) {
  56. const {
  57. index
  58. } = e.currentTarget.dataset,
  59. that = this,
  60. data = this.data.defaultFiles[index];
  61. // console.log(data)
  62. wx.downloadFile({
  63. url: data.fobsurl,
  64. success: function (res) {
  65. var filePath = res.tempFilePath;
  66. //页面显示加载动画
  67. wx.openDocument({
  68. filePath: filePath,
  69. success: function (res) {
  70. console.log('打开文档成功')
  71. }
  72. })
  73. },
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () {},
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. if (this.data.pageType == 0) {
  95. _Http.basic({
  96. "accesstoken": wx.getStorageSync('userData').token,
  97. "classname": "customer.notice.notice",
  98. "method": "noticeexit",
  99. "content": {
  100. "tnoticeid": this.data.tnoticeid
  101. }
  102. }).then(res => {
  103. console.log(res)
  104. })
  105. }
  106. },
  107. /**
  108. * 页面相关事件处理函数--监听用户下拉动作
  109. */
  110. onPullDownRefresh: function () {
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function () {
  116. },
  117. /**
  118. * 用户点击右上角分享
  119. */
  120. onShareAppMessage: function () {
  121. }
  122. })