index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const util = require("../../../utils/util")
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. departmentId:0,
  7. keyword:'',
  8. api:'',
  9. from:0,
  10. size:10,
  11. isLogin: false,
  12. userInfo:{},
  13. apis:{
  14. 'getViewArticalList':'浏览记录',
  15. 'getLikeArticalList':'收藏记录',
  16. 'getDownloadArticalList':'下载记录',
  17. 'waitConfirmArticalList':'审核审批',
  18. 'waitDownloadArticalList':'下载审批',
  19. 'waitPublishArticalList':'发布审批'
  20. },
  21. department:{departmentId:0},
  22. departments:[],
  23. articalList:[]
  24. },
  25. onLoad: function (options) {
  26. let api = options.api||'getViewArticalList'
  27. let title = this.data.apis[api]||'浏览记录'
  28. console.log( title, api, this.data.apis)
  29. wx.setNavigationBarTitle({
  30. title: title,
  31. })
  32. this.setData({api})
  33. },
  34. onShow(){
  35. if( this.data.isLogin ) return
  36. app.checkLogin( userInfo=>{
  37. this.setData({userInfo})
  38. this.loadData()
  39. } )
  40. },
  41. loadData(){
  42. this.loadArtical( )
  43. },
  44. getDetail(e){
  45. let id = e.currentTarget.dataset.id;
  46. wx.navigateTo({
  47. url: `/pages/artical/info/index?articalId=${id}`,
  48. })
  49. },
  50. loadArtical( cb ){
  51. let {from, size, api,keyword, articalList} = this.data
  52. let param = { from, size, keyword }
  53. app.formPost( `weixin/${api}`, param).then( res=>{
  54. if( res.code == 200 ){
  55. if( from == 0) articalList = []
  56. from= res.data.from;
  57. articalList = articalList.concat( res.data.list||[] );
  58. this.setData( {from, articalList})
  59. }
  60. cb &&cb()
  61. })
  62. },
  63. onInputEvent(e){
  64. let {value} = e.detail;
  65. if( this.data.keyword == value) return;
  66. this.setData({keyword: value, from:0})
  67. this.loadArtical( )
  68. },
  69. onPullDownRefresh: function () {
  70. wx.showNavigationBarLoading();
  71. this.setData( {from:0})
  72. this.loadArtical( ()=>{
  73. wx.hideNavigationBarLoading();
  74. wx.stopPullDownRefresh();
  75. })
  76. },
  77. onReachBottom: function () {
  78. var that = this
  79. let newFrom = that.data.from
  80. if (newFrom == -1) {
  81. wx.stopPullDownRefresh();
  82. return;
  83. }
  84. this.loadArtical( );
  85. },
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage: function () {
  90. }
  91. })