index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const util = require("../../../utils/util")
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. departmentId:0,
  10. keyword:'',
  11. from:0,
  12. size:10,
  13. department:{departmentId:0},
  14. articalList:[]
  15. },
  16. onLoad: function (options) {
  17. let departmentId = +options.departmentId
  18. if( departmentId ){
  19. wx.setStorageSync('@departmentId', departmentId)
  20. this.setData({departmentId})
  21. }
  22. app.checkLogin( this.loadData )
  23. },
  24. loadData(){
  25. let departmentId = this.data.departmentId;
  26. app.getDepartments( departments=>{
  27. let department = {}
  28. for( let i in departments){
  29. if( departments[i].departmentId == departmentId){
  30. department = departments[i]
  31. break
  32. }
  33. }
  34. this.setData({department, from:0})
  35. //
  36. wx.setNavigationBarTitle({
  37. title: department.department
  38. })
  39. })
  40. this.loadArtical( )
  41. },
  42. loadArtical( cb ){
  43. let {from, size, departmentId,keyword, articalList} = this.data
  44. let param = { from, size, departmentId, keyword }
  45. app.formPost( "weixin/getArticalList", param).then( res=>{
  46. if( res.code == 200 ){
  47. if( from == 0) articalList = []
  48. from= res.data.from;
  49. articalList = articalList.concat( res.data.list );
  50. this.setData( {from, articalList})
  51. }
  52. cb &&cb()
  53. })
  54. },
  55. onInputEvent(e){
  56. let {value} = e.detail;
  57. if( this.data.keyword == value) return;
  58. this.setData({keyword: value, from:0})
  59. },
  60. onReady: function () {
  61. },
  62. onShow: function () {
  63. },
  64. onHide: function () {
  65. },
  66. onUnload: function () {
  67. },
  68. onPullDownRefresh: function () {
  69. wx.showNavigationBarLoading();
  70. this.setData( {from:0})
  71. this.loadArtical( ()=>{
  72. wx.hideNavigationBarLoading();
  73. wx.stopPullDownRefresh();
  74. })
  75. },
  76. onReachBottom: function () {
  77. var that = this
  78. let newFrom = that.data.from
  79. if (newFrom == -1) {
  80. wx.stopPullDownRefresh();
  81. return;
  82. }
  83. this.loadArtical( );
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. }
  90. })