detail.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. id: 0,
  8. info: {},
  9. list: [],
  10. keyword: '',
  11. page: 1,
  12. no_more: false,
  13. is_first: true,
  14. tabCur:0,
  15. total:{},
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. let id = options.id;
  22. this.setData({id:id});
  23. this.getSite();
  24. },
  25. /**
  26. * 页面相关事件处理函数--监听用户下拉动作
  27. */
  28. onPullDownRefresh: function () {
  29. if (this.data.tabCur == 1) {
  30. this.setData({list:[],page:1,no_more:false,keyword:''});
  31. this.getCount();
  32. this.getList();
  33. } else {
  34. this.getSite();
  35. }
  36. wx.stopPullDownRefresh();
  37. },
  38. /**
  39. * 页面上拉触底事件的处理函数
  40. */
  41. onReachBottom: function () {
  42. if (this.data.tabCur == 1) {
  43. this.getList();
  44. }
  45. },
  46. /**
  47. * 用户点击右上角分享
  48. */
  49. onShareAppMessage: function () {
  50. let info = this.data.info
  51. return {
  52. title: info.site_name,
  53. path: "/pages/site/detail/detail?id="+info.id,
  54. };
  55. },
  56. //切换
  57. tabSelect(e) {
  58. let tabCur = e.currentTarget.dataset.id;
  59. if (tabCur == 1 && this.data.is_first) {
  60. this.setData({is_first:false});
  61. this.getCount();
  62. this.getList();
  63. }
  64. this.setData({tabCur: tabCur});
  65. },
  66. //站点
  67. getSite(){
  68. let self = this;
  69. app.post('activity/site/detail',{id:this.data.id},function(res){
  70. if (res.image_display) {
  71. res.image_display = res.image_display.replace(/\<img/gi, '<img style="max-width:100%;display:block;" ');
  72. }
  73. self.setData({info:res});
  74. });
  75. },
  76. //统计
  77. getCount(){
  78. let self = this;
  79. app.post('activity/site/getCount',{id:this.data.id},function(res){
  80. self.setData({total:res});
  81. });
  82. },
  83. //列表
  84. getList() {
  85. var self = this;
  86. if (self.data.no_more) {
  87. return false;
  88. }
  89. app.post('activity/activity/index',{
  90. page:self.data.page,
  91. user_id:self.data.id,
  92. keyword: self.data.keyword,
  93. },function(res){
  94. if (res.length < 10) {
  95. self.setData({no_more:true});
  96. }
  97. let list = self.data.list;
  98. list = list.concat(res);
  99. let page = self.data.page;
  100. page++;
  101. self.setData({list:list,page:page});
  102. });
  103. },
  104. bindSearch(e){
  105. this.setData({list:[],page:1,no_more:false});
  106. this.getList();
  107. },
  108. nav() {
  109. let info = this.data.info;
  110. if (info.latitude > 0) {
  111. wx.openLocation({
  112. latitude: info.latitude - 0, //维度
  113. longitude: info.longitude - 0, //经度
  114. name: info.site_name, //目的地定位名称
  115. scale: 15, //缩放比例
  116. address: info.address //导航详细地址
  117. })
  118. } else {
  119. app.msg('该驿站管理员暂未录入地址!');
  120. }
  121. },
  122. })