index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // pages/index/vote/index.js
  2. const app = getApp();
  3. import HTTP from "../../../../requestFn/Api"
  4. Page({
  5. data: {
  6. garden_id: null,
  7. vote_list: [],
  8. page: 1,
  9. page_size: 10,
  10. hasMore:true,
  11. indicatorDots: false, //小点
  12. indicatorColor: "white", //指示点颜色
  13. activeColor: "coral", //当前选中的指示点颜色
  14. autoplay: true, //是否自动轮播
  15. interval: 5000, //间隔时间
  16. duration: 3000, //滑动时间,
  17. timestamp:0,
  18. },
  19. onLoad(options) {
  20. const that = this;
  21. const {
  22. garden_id
  23. } = app.globalData
  24. if(garden_id){
  25. that.setData({
  26. garden_id,
  27. })
  28. }
  29. },
  30. onShow(){
  31. this.init();
  32. },
  33. init(){
  34. var timestamp = Date.parse(new Date());
  35. timestamp = timestamp / 1000;
  36. this.setData({
  37. page:1,
  38. hasMore:true,
  39. timestamp
  40. })
  41. this.getVote_list(true);
  42. },
  43. onReachBottom() {
  44. if(!this.data.hasMore){
  45. wx.showToast({
  46. title: '没有更多数据了',
  47. icon:'none'
  48. })
  49. return console.log('没有更多数据了');
  50. }
  51. this.getVote_list()
  52. },
  53. //投票列表
  54. async getVote_list(flag=false) {
  55. const that = this;
  56. let {
  57. page,
  58. page_size,
  59. vote_list,
  60. garden_id
  61. } = that.data;
  62. let res = await HTTP.GetVote({
  63. garden_id,
  64. page,
  65. page_size
  66. })
  67. that.setData({
  68. vote_list:flag?res.list:[...vote_list,...res.list],
  69. page:++page,
  70. hasMore:res.list.length===page_size
  71. })
  72. },
  73. goDetail(e) {
  74. const that = this;
  75. const {
  76. id
  77. } = e.currentTarget
  78. const data = that.data.vote_list.filter(item => item.id == id)
  79. wx.navigateTo({
  80. url: './detail/index',
  81. success: function (res) {
  82. res.eventChannel.emit('acceptDataFromOpenerPage', {
  83. data
  84. })
  85. }
  86. })
  87. },
  88. onPullDownRefresh: function () {
  89. app.onRefresh();
  90. this.init();
  91. },
  92. })