home.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. default_marker: {
  8. iconPath: "/common/images/map_marker.png",
  9. latitude: 24.824768,
  10. longitude: 118.57343,
  11. width: 30,
  12. height: 30,
  13. title: '泉州(晋江)国际人才港',
  14. },
  15. markers: [],
  16. latitude: 24.824768,
  17. longitude: 118.57343,
  18. keyword: '',
  19. list: [],
  20. page: 1,
  21. no_more: false,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. this.getList();
  28. },
  29. getList() {
  30. let self = this;
  31. let page = self.data.page;
  32. app.post('business/business/index',{page:page,keyword:self.data.keyword},function(res){
  33. //尾页
  34. if (res.length < 10) {
  35. self.setData({no_more:true});
  36. }
  37. //首页
  38. let markers = self.data.markers;
  39. if (res.length > 0) {
  40. let default_marker = self.data.default_marker;
  41. for (let i = 0; i < res.length; i++) {
  42. let marker = {height:default_marker.height,iconPath:default_marker.iconPath,width:default_marker.width};
  43. marker.latitude = res[i].latitude;
  44. marker.longitude = res[i].longitude;
  45. marker.title = res[i].title;
  46. marker.id = res[i].id;
  47. markers.push(marker);
  48. }
  49. if (page == 1) {
  50. self.setData({latitude:res[0].latitude,longitude:res[0].longitude});
  51. }
  52. }
  53. //数据合并
  54. let list = self.data.list;
  55. list = list.concat(res);
  56. page++;
  57. self.setData({list:list,page:page,markers:markers});
  58. });
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh: function () {
  64. this.setData({markers:[],list:[],keyword:'',page:1,no_more:false});
  65. this.getList();
  66. wx.stopPullDownRefresh();
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {
  72. this.getList();
  73. },
  74. //设置地点
  75. setLocation(e) {
  76. let marker = this.data.default_marker;
  77. marker.latitude = e.currentTarget.dataset.lat;
  78. marker.longitude = e.currentTarget.dataset.lon;
  79. marker.title = e.currentTarget.dataset.title;
  80. this.setData({latitude:marker.latitude,longitude:marker.longitude});
  81. },
  82. //拔打电话
  83. callMobile(e){
  84. let mobile = e.currentTarget.dataset.mobile;
  85. if (mobile == '') {
  86. app.msg('暂无联系方式!');
  87. return false;
  88. }
  89. wx.makePhoneCall({
  90. phoneNumber: mobile
  91. })
  92. },
  93. //详情
  94. toDetail(e) {
  95. wx.navigateTo({
  96. url: '/pages/business/detail/detail?id=' + e.currentTarget.dataset.id,
  97. })
  98. },
  99. toAd() {
  100. wx.navigateTo({
  101. url: '/pages/business/ad/ad',
  102. })
  103. },
  104. //搜索
  105. bindSearch() {
  106. this.setData({list:[],markers:[],page:1,no_more:false});
  107. this.getList();
  108. },
  109. bindInput() {
  110. },
  111. /**
  112. * 用户点击右上角分享
  113. */
  114. onShareAppMessage: function () {
  115. return {
  116. title: "晋爱人才",
  117. path: "/pages/home/home/home",
  118. };
  119. }
  120. })