index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const util = require("../../../utils/util")
  2. const app = getApp()
  3. Page({
  4. data: {
  5. articalId:0,
  6. isLike:0,
  7. info:{},
  8. confirmModal: false,
  9. publishModal: false,
  10. content:'',
  11. categorys:{},
  12. userInfo:{},
  13. isLeader:0,
  14. logs:[]
  15. },
  16. preview( e ){
  17. var imgs = [];
  18. let brirf = this.data.info.brief||''
  19. brirf.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
  20. imgs.push(capture);
  21. });
  22. if( imgs.length > 0 ){
  23. wx.previewImage({
  24. current: imgs[0],
  25. urls: imgs
  26. })
  27. }
  28. },
  29. openDialog( e ){
  30. let param = {content:''}
  31. param[e.currentTarget.dataset.id] =true
  32. this.setData( param )
  33. },
  34. closeDialog( e ){
  35. let param = {content:''}
  36. param[e.currentTarget.dataset.id] =false
  37. this.setData( param )
  38. },
  39. onLoad: function (options) {
  40. let articalId = +options.articalId||2135;
  41. this.setData({articalId})
  42. },
  43. onShow: function(){
  44. app.checkLogin( this.loadData )
  45. },
  46. inputContent(e){
  47. let content = e.detail.value
  48. this.setData({ content });
  49. },
  50. confirmArtical: function (e) {
  51. let articalId = this.data.info.articalId
  52. let content = this.data.content;
  53. let action = 1
  54. if( !content ){
  55. util.showMsg("请留下宝贵意见")
  56. return
  57. }
  58. let info = this.data.info;
  59. app.formPost( "artical/confirmArtical", {articalId,content,action}).then( res=>{
  60. if( res.code == 200 ){
  61. info.status = 2
  62. app.showMsg( "确认成功")
  63. this.setData({info, confirmModal:false})
  64. }
  65. })
  66. },
  67. publishArtical:function (e) {
  68. let articalId = this.data.info.articalId
  69. let content = this.data.content;
  70. let action = 1
  71. if( !content ){
  72. util.showMsg("请留下宝贵意见")
  73. return
  74. }
  75. app.formPost( "artical/publishArtical", {articalId,content,action}).then( res=>{
  76. if( res.code == 200 ){
  77. info.status = 3
  78. app.showMsg( "发布成功")
  79. this.setData({info, confirmModal:false})
  80. }
  81. })
  82. },
  83. loadData(){
  84. let articalId = this.data.articalId
  85. app.formPost( "weixin/getArticalInfo", {articalId}).then( res=>{
  86. if( res.code == 200 ){
  87. let {isLike,info,logs, isLeader} = res.data
  88. this.setData({isLike,info,logs,isLeader})
  89. }
  90. })
  91. },
  92. downloadUrl( url ){
  93. wx.downloadFile({
  94. url: url,
  95. timeout: 0,
  96. success: (res) => {
  97. var rr=res.tempFilePath;
  98. wx.openDocument({
  99. filePath:rr,
  100. showMenu: true,
  101. success(res) {
  102. wx.showToast({
  103. title: '保存成功',
  104. icon: 'success',
  105. duration: 2000
  106. })
  107. }
  108. })
  109. },
  110. fail: (res) => {
  111. console.log("res_fail", res)
  112. },
  113. complete: (res) => {
  114. console.log("res_complete", res)
  115. },
  116. })
  117. },
  118. download(){
  119. let articalId = this.data.info.articalId;
  120. app.formPost( "artical/downloadFile", {articalId}).then( res=>{
  121. if( res.code == 200 ){
  122. this.downloadUrl( res.data )
  123. }
  124. })
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function () {
  130. let {title, articalId} = this.data.info;
  131. return {
  132. title: title,
  133. path: `/pages/artical/info/index?articalId=${articalId}`
  134. }
  135. }
  136. })