home.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. CustomBar: app.globalData.CustomBar,
  8. headerHeight: 0,
  9. default_marker: {
  10. iconPath: "/common/images/map_marker.png",
  11. latitude: 24.824768,
  12. longitude: 118.57343,
  13. width: 40,
  14. height: 40,
  15. title: '泉州(晋江)国际人才港',
  16. },
  17. markers: [],
  18. latitude: 24.824768,
  19. longitude: 118.57343,
  20. keyword: '',
  21. list: [],
  22. tab_index : 'business',
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. this.getList();
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady: function () {
  34. let query = wx.createSelectorQuery();
  35. let self = this;
  36. query.select('#header').boundingClientRect(rect=>{
  37. let height = rect.height;
  38. self.setData({headerHeight:height});
  39. }).exec();
  40. },
  41. getList() {
  42. let self = this;
  43. let url = 'business/business/index';
  44. if (this.data.tab_index == 'site') {
  45. url = 'activity/site/all';
  46. }
  47. app.post(url,{keyword:self.data.keyword},function(res){
  48. //首页
  49. let marker = JSON.parse(JSON.stringify(self.data.default_marker));
  50. if (res.length > 0) {
  51. let markers = [];
  52. for (var i = 0; i < res.length; i++) {
  53. markers.push({
  54. id: res[i].id,
  55. latitude: res[i].latitude,
  56. longitude: res[i].longitude,
  57. iconPath: "/common/images/map_marker.png",
  58. width: 40,
  59. height: 40,
  60. label: {
  61. content: res[i].title ? res[i].title : res[i].site_name,
  62. borderRadius: 3, //边框圆角
  63. borderWidth: 1, //边框宽度
  64. borderColor: '#ffffff', //边框颜色
  65. bgColor: '#ffffff', //背景色
  66. padding: 5, //文本边缘留白
  67. textAlign: 'center' //文本对齐方式。有效值: left, right, center
  68. }
  69. });
  70. }
  71. self.setData({latitude:markers[0].latitude,longitude:markers[0].longitude,markers:markers});
  72. } else {
  73. self.setData({latitude:marker.latitude,longitude:marker.longitude,markers:[marker]});
  74. }
  75. self.setData({list:res});
  76. });
  77. },
  78. changeTab(e) {
  79. this.setData({tab_index:e.currentTarget.dataset.index});
  80. this.getList();
  81. },
  82. bindSearch() {
  83. this.getList();
  84. },
  85. toBusiness() {
  86. wx.navigateTo({
  87. url: '/pages/business/home/home',
  88. })
  89. },
  90. toSite() {
  91. wx.navigateTo({
  92. url: '/pages/site/home/home',
  93. })
  94. },
  95. bindMarker(e) {
  96. if (this.data.tab_index == 'business') {
  97. wx.navigateTo({
  98. url: '/pages/business/detail/detail?id=' + e.detail.markerId,
  99. })
  100. } else {
  101. wx.navigateTo({
  102. url: '/pages/site/detail/detail?id=' + e.detail.markerId,
  103. })
  104. }
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. return {
  111. title: "晋爱人才",
  112. path: "/pages/home/home/home",
  113. };
  114. }
  115. })