index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. activity: [{
  15. src: "/images/happyjob/quanzhi.png",
  16. text: "全职工作"
  17. },
  18. {
  19. src: "/images/happyjob/jianzhi.png",
  20. text: "兼职工作"
  21. },
  22. {
  23. src: "/images/happyjob/fanxian.png",
  24. text: "入职奖励"
  25. },
  26. {
  27. src: "/images/happyjob/jipin.png",
  28. text: "高薪急聘"
  29. }
  30. ],
  31. activity_two: [{
  32. src: "/images/happyjob/fuli.png"
  33. },
  34. {
  35. src: "/images/happyjob/quanmin.png"
  36. }
  37. ],
  38. cityCode: '',
  39. keyWord: '',
  40. pageNo: 1, //当前分页
  41. isScroll: true, //是否可以滚动
  42. filter: -1, //岗位类型
  43. userInfo: {},
  44. hasUserInfo: false,
  45. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  46. list: [],
  47. showNoMore: "没有更多信息...", //显示已无更多
  48. broadcastList: [],
  49. imgServerUrl: imgServerUrl,
  50. hasLocation1: false,
  51. },
  52. onLoad: function(options) {
  53. if (!wx.getStorageSync('areaList')) {
  54. wx.setStorageSync('areaList', [{
  55. "countryCode": "",
  56. "countryName": "不限",
  57. "firstNameLetter": "X"
  58. }, {
  59. "countryCode": "320205",
  60. "countryName": "锡山区",
  61. "firstNameLetter": "X"
  62. },
  63. {
  64. "countryCode": "320206",
  65. "countryName": "惠山区",
  66. "firstNameLetter": "H"
  67. },
  68. {
  69. "countryCode": "320211",
  70. "countryName": "滨湖区",
  71. "firstNameLetter": "B"
  72. },
  73. {
  74. "countryCode": "320213",
  75. "countryName": "梁溪区",
  76. "firstNameLetter": "L"
  77. },
  78. {
  79. "countryCode": "320214",
  80. "countryName": "新吴区",
  81. "firstNameLetter": "X"
  82. },
  83. {
  84. "countryCode": "320281",
  85. "countryName": "江阴市",
  86. "firstNameLetter": "J"
  87. },
  88. {
  89. "countryCode": "320282",
  90. "countryName": "宜兴市",
  91. "firstNameLetter": "Y"
  92. }
  93. ])
  94. }
  95. this.start();
  96. },
  97. doArrow(e) {
  98. const index = e.currentTarget.dataset.index;
  99. const list = this.data.list;
  100. this.setData({
  101. [`list[${index}].up`]: !list[index].up
  102. })
  103. },
  104. reload() {
  105. this.onPullDownRefresh();
  106. },
  107. start() {
  108. this.fetchBanner();
  109. this.fetchList();
  110. },
  111. onShow: function() {
  112. var self = this;
  113. let cityName = wx.getStorageSync('city') || '无锡';
  114. let cityCode = wx.getStorageSync('cityCode') || '320200';
  115. this.setData({
  116. cityName: cityName,
  117. cityCode: cityCode
  118. })
  119. if (self.data.hasLocation1) {
  120. self.setData({
  121. pageNo: 1, //当前分页
  122. isScroll: true, //是否可以滚动
  123. filter: -1, //岗位类型
  124. list: [],
  125. hasLocation1: false
  126. })
  127. self.start();
  128. }
  129. },
  130. //下拉刷新
  131. onPullDownRefresh: function() {
  132. this.setData({
  133. pageNo: 1, //当前分页
  134. isScroll: true, //是否可以滚动
  135. filter: -1, //岗位类型
  136. list: [],
  137. })
  138. this.start();
  139. wx.stopPullDownRefresh();
  140. },
  141. //上拉加载
  142. onReachBottom: function() {
  143. var pageNo = this.data.pageNo + 1;
  144. this.setData({
  145. pageNo
  146. })
  147. this.fetchList();
  148. },
  149. onShareAppMessage: function(e) {
  150. },
  151. // 获取banner图
  152. fetchBanner() {
  153. let paramsObj = {
  154. application: 0
  155. }
  156. Object.assign(paramsObj);
  157. getBanner(paramsObj).then(data => {
  158. this.setData({
  159. imgList: data.data.bannerList,
  160. broadcastList: data.data.broadcastList
  161. })
  162. })
  163. },
  164. //获取热门列表数据
  165. fetchList(params) {
  166. if (!this.data.isScroll) {
  167. return false
  168. }
  169. let paramsObj = {
  170. cityCode: this.data.cityCode,
  171. pageNo: this.data.pageNo
  172. }
  173. Object.assign(paramsObj);
  174. getIndexList(paramsObj).then(data => {
  175. var pageNo = data.data.pageNo;
  176. let setData = {};
  177. // 是否可以滚动加载数据
  178. if (data.data.isLast) {
  179. setData.isScroll = false
  180. }
  181. if (data.data.hotPosition.length != 0) {
  182. setData.list = this.data.list.concat(data.data.hotPosition)
  183. setData.pageNo = pageNo;
  184. } else {
  185. setData.list = this.data.list;
  186. }
  187. this.setData({
  188. offline: false,
  189. ...setData
  190. })
  191. }).catch(() => {
  192. this.setData({
  193. offline: true
  194. })
  195. })
  196. },
  197. //改变列表
  198. changeList(e) {
  199. const {
  200. index
  201. } = e.currentTarget.dataset
  202. this.workType(index)
  203. },
  204. //判断当前工作类型
  205. workType(index) {
  206. switch (index) {
  207. case 0:
  208. wx.navigateTo({
  209. url: '../fulltime/index',
  210. })
  211. break;
  212. case 1:
  213. wx.navigateTo({
  214. url: '../parttime/index',
  215. })
  216. break;
  217. case 2:
  218. wx.navigateTo({
  219. url: '../reward/index',
  220. })
  221. break;
  222. case 3:
  223. wx.navigateTo({
  224. url: '../jipin/index',
  225. })
  226. break;
  227. }
  228. },
  229. changeList2(e) {
  230. const {
  231. index
  232. } = e.currentTarget.dataset
  233. this.workType2(index)
  234. },
  235. workType2(index) {
  236. switch (index) {
  237. case 0:
  238. wx.navigateTo({
  239. url: '../fuli/index',
  240. })
  241. break;
  242. case 1:
  243. wx.navigateTo({
  244. url: '../agent/index',
  245. })
  246. break;
  247. }
  248. },
  249. //去详情页
  250. toDetail(e) {
  251. const {
  252. id,
  253. cate
  254. } = e.currentTarget.dataset
  255. wx.navigateTo({
  256. url: '../detail/index?hpPositionId=' + id + "&cate=" + cate,
  257. })
  258. },
  259. //轮播图跳转详情页
  260. toDetail_slide(e) {
  261. var id = e.currentTarget.dataset.id;
  262. var url = e.currentTarget.dataset.url;
  263. var arr;
  264. if (id) {
  265. arr = id.split(",");
  266. var positionId = arr[1];
  267. var cate = arr[0];
  268. wx.navigateTo({
  269. url: '../detail/index?hpPositionId=' + positionId + "&cate=" + cate,
  270. })
  271. } else if (url) {
  272. wx.navigateTo({
  273. url: '../web-view/web-view?url=' + url,
  274. })
  275. }
  276. },
  277. // 去搜索页
  278. toSearch() {
  279. wx.navigateTo({
  280. url: '../search/index',
  281. })
  282. },
  283. // 去城市选择页
  284. toCity() {
  285. wx.navigateTo({
  286. url: '../city/index',
  287. })
  288. },
  289. imageLoad() {
  290. var that = this
  291. var query = wx.createSelectorQuery()
  292. query.select('.slide-image').boundingClientRect()
  293. query.exec(function(res) {
  294. console.log(res)
  295. that.setData({
  296. swiperH: res[0].height
  297. })
  298. })
  299. }
  300. })