index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import {
  2. getBanner,
  3. getIndexList
  4. } from '../../services/index.js'
  5. import {
  6. imgServerUrl,
  7. imgServerUrl_new
  8. } from '../../config/config.js'
  9. var app = getApp();
  10. Page({
  11. data: {
  12. //banner图
  13. imgList: [
  14. // imgServerUrl_new + "/uploadfiles/banner/bannermina/banner1.jpg",
  15. // imgServerUrl_new + "/uploadfiles/banner/bannermina/banner2.jpg",
  16. // imgServerUrl_new + "/uploadfiles/banner/bannermina/banner3.jpg",
  17. // imgServerUrl_new + "/uploadfiles/banner/bannermina/banner4.jpg"
  18. ],
  19. activity: [{
  20. src: imgServerUrl + "/images/home/quanzhi.png",
  21. text: "全职工作"
  22. },
  23. {
  24. src: imgServerUrl + "/images/home/jianzhi.png",
  25. text: "兼职工作"
  26. },
  27. {
  28. src: imgServerUrl + "/images/home/fanxian.png",
  29. text: "入职奖励"
  30. },
  31. {
  32. src: imgServerUrl + "/images/home/jipin.png",
  33. text: "高薪急聘"
  34. }
  35. ],
  36. activity_two: [{
  37. src: imgServerUrl + "/images/home/fuli.png"
  38. },
  39. {
  40. src: imgServerUrl + "/images/home/quanmin.png"
  41. }
  42. ],
  43. cityCode: '',
  44. keyWord: '',
  45. pageNo: 1, //当前分页
  46. isScroll: true, //是否可以滚动
  47. filter: -1, //岗位类型
  48. userInfo: {},
  49. hasUserInfo: false,
  50. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  51. list: [],
  52. showNoMore: "没有更多信息...", //显示已无更多
  53. broadcastList: [
  54. '热心达人!用户孟潞帮朋友找到工作,获得500元推荐入职奖励!',
  55. '棒棒哒!用户沈佳宜努力工作了30天,获得3000元入职奖励!',
  56. '恭喜恭喜!用户秦寒推荐新用户注册,获得5元推荐注册奖励!',
  57. '给你点赞!用户张汉文完成拼工在职30天,获得1000元拼工团奖励!',
  58. '厉害了!用户李丽刚刚完善了个人简历,好工作正在赶来的路上!'
  59. ],
  60. },
  61. onLoad: function(options) {
  62. if (app.globalData.userInfo) {
  63. console.log('有info===', app.globalData)
  64. this.start();
  65. } else if (this.data.canIUse) {
  66. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  67. // 所以此处加入 callback 以防止这种情况
  68. app.userInfoReadyCallback = res => {
  69. console.log('userInfoReadyCallback===', res.userInfo)
  70. app.globalData.userInfo = res.userInfo;
  71. this.start();
  72. }
  73. } else {
  74. // 在没有 open-type=getUserInfo 版本的兼容处理
  75. wx.getUserInfo({
  76. success: res => {
  77. app.globalData.userInfo = res.userInfo
  78. console.log('兼容处理===', app.globalData)
  79. this.start();
  80. }
  81. })
  82. }
  83. },
  84. start() {
  85. this.fetchBanner();
  86. this.fetchList();
  87. },
  88. onShow: function() {
  89. let cityName = wx.getStorageSync('city') || app.globalData.userInfo.city || '无锡'
  90. console.log(cityName)
  91. this.setData({
  92. cityName: cityName
  93. })
  94. },
  95. //下拉刷新
  96. onPullDownRefresh: function() {
  97. this.setData({
  98. pageNo: 1, //当前分页
  99. isScroll: true, //是否可以滚动
  100. filter: -1, //岗位类型
  101. list: [],
  102. })
  103. this.start();
  104. wx.stopPullDownRefresh();
  105. },
  106. //上拉加载
  107. onReachBottom: function() {
  108. var pageNo = this.data.pageNo + 1;
  109. this.setData({
  110. pageNo
  111. })
  112. this.fetchList();
  113. },
  114. onShareAppMessage: function(e) {
  115. console.log(e)
  116. },
  117. // 获取banner图
  118. fetchBanner() {
  119. let paramsObj = {
  120. application: 0
  121. }
  122. Object.assign(paramsObj);
  123. getBanner(paramsObj).then(data => {
  124. this.setData({
  125. imgList: data.data.bannerList
  126. })
  127. })
  128. },
  129. //获取热门列表数据
  130. fetchList(params) {
  131. if (!this.data.isScroll) {
  132. return false
  133. }
  134. let paramsObj = {
  135. cityCode: this.data.cityCode,
  136. pageNo: this.data.pageNo,
  137. user_id: app.globalData.userId,
  138. user_token: app.globalData.userToken
  139. }
  140. Object.assign(paramsObj);
  141. getIndexList(paramsObj).then(data => {
  142. var pageNo = data.data.pageNo;
  143. let setData = {};
  144. // 是否可以滚动加载数据
  145. if (data.data.isLast) {
  146. setData.isScroll = false
  147. }
  148. if (data.data.hotPosition.length != 0) {
  149. setData.list = this.data.list.concat(data.data.hotPosition)
  150. setData.pageNo = pageNo;
  151. } else {
  152. setData.list = this.data.list;
  153. }
  154. this.setData({
  155. ...setData
  156. })
  157. })
  158. },
  159. //改变列表
  160. changeList(e) {
  161. const {
  162. index
  163. } = e.currentTarget.dataset
  164. this.workType(index)
  165. },
  166. //判断当前工作类型
  167. workType(index) {
  168. switch (index) {
  169. case 0:
  170. wx.navigateTo({
  171. url: '../fulltime/index',
  172. })
  173. break;
  174. case 1:
  175. wx.navigateTo({
  176. url: '../parttime/index',
  177. })
  178. break;
  179. case 2:
  180. wx.navigateTo({
  181. url: '../reward/index',
  182. })
  183. break;
  184. case 3:
  185. wx.navigateTo({
  186. url: '../jipin/index',
  187. })
  188. break;
  189. }
  190. },
  191. changeList2(e) {
  192. const {
  193. index
  194. } = e.currentTarget.dataset
  195. this.workType2(index)
  196. },
  197. workType2(index) {
  198. switch (index) {
  199. case 0:
  200. wx.navigateTo({
  201. url: '../fuli/index',
  202. })
  203. break;
  204. case 1:
  205. wx.navigateTo({
  206. url: '../agent/index',
  207. })
  208. break;
  209. }
  210. },
  211. //去详情页
  212. toDetail(e) {
  213. const {
  214. id,
  215. cate
  216. } = e.currentTarget.dataset
  217. wx.navigateTo({
  218. url: '../detail/index?hpPositionId=' + id + "&cate=" + cate,
  219. })
  220. },
  221. //轮播图跳转详情页
  222. toDetail_slide(e) {
  223. var id = e.currentTarget.dataset.id;
  224. var arr;
  225. if (id) {
  226. arr = id.split(",");
  227. var positionId = arr[1];
  228. var cate = arr[0];
  229. wx.navigateTo({
  230. url: '../detail/index?hpPositionId=' + positionId + "&cate=" + cate,
  231. })
  232. }
  233. },
  234. // 去搜索页
  235. toSearch() {
  236. wx.navigateTo({
  237. url: '../search/index',
  238. })
  239. },
  240. // 去城市选择页
  241. toCity() {
  242. wx.navigateTo({
  243. url: '../city/index',
  244. })
  245. },
  246. imageLoad() {
  247. var that = this
  248. var query = wx.createSelectorQuery()
  249. query.select('.slide-image').boundingClientRect()
  250. query.exec(function(res) {
  251. console.log(res)
  252. that.setData({
  253. swiperH: res[0].height
  254. })
  255. })
  256. }
  257. })