index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // pages/jipin/index.js
  2. import {
  3. getGoodMoneyList
  4. } from '../../services/index.js'
  5. import {
  6. imgServerUrl,
  7. imgServerUrl_new
  8. } from '../../config/config.js'
  9. var $ = require('../../libs/gdconf.js');
  10. var app = getApp();
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. list: [],
  17. pageNo: 1, //当前分页
  18. isScroll: true, //是否可以滚动
  19. showNoMore: "没有更多信息...", //显示已无更多
  20. cityCode: '320200',
  21. cityName: '无锡',
  22. selectId: -1, //选中筛选的条件
  23. totalSalary: '', //薪资待遇排序(1:正序;2:倒序)
  24. sort: '', //距离排序(1:正序;2:倒序)
  25. longitude: '', //经度
  26. latitude: '', //纬度
  27. imgServerUrl: imgServerUrl,
  28. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function(options) {
  34. if (app.globalData.userInfo) {
  35. console.log('有info===', app.globalData)
  36. this.start();
  37. } else if (this.data.canIUse) {
  38. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  39. // 所以此处加入 callback 以防止这种情况
  40. app.userInfoReadyCallback = res => {
  41. console.log('userInfoReadyCallback===', res.userInfo)
  42. app.globalData.userInfo = res.userInfo;
  43. this.start();
  44. }
  45. } else {
  46. // 在没有 open-type=getUserInfo 版本的兼容处理
  47. wx.getUserInfo({
  48. success: res => {
  49. app.globalData.userInfo = res.userInfo
  50. console.log('兼容处理===', app.globalData)
  51. this.start();
  52. }
  53. })
  54. }
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function() {
  60. },
  61. start() {
  62. this.goodMoneyList();
  63. },
  64. //获取高薪急聘奖励列表数据
  65. goodMoneyList(params) {
  66. if (!this.data.isScroll) {
  67. return false
  68. }
  69. let paramsObj = {
  70. longitude: this.data.longitude,
  71. latitude: this.data.latitude,
  72. sort: this.data.sort,
  73. totalSalary: this.data.totalSalary,
  74. cityCode: this.data.cityCode,
  75. pageNo: this.data.pageNo,
  76. user_id: app.globalData.userId,
  77. user_token: app.globalData.userToken
  78. }
  79. Object.assign(paramsObj);
  80. getGoodMoneyList(paramsObj).then(data => {
  81. var pageNo = data.data.pageNo;
  82. let setData = {}
  83. // 是否可以滚动加载数据
  84. if (data.data.isLast) {
  85. setData.isScroll = false
  86. }
  87. if (data.data.goodmoneyPosition.length != 0) {
  88. setData.list = this.data.list.concat(data.data.goodmoneyPosition)
  89. setData.pageNo = pageNo;
  90. } else {
  91. setData.list = this.data.list;
  92. }
  93. this.setData({
  94. ...setData
  95. })
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function() {
  102. let cityName = wx.getStorageSync('city') || app.globalData.userInfo.city || '无锡'
  103. console.log(cityName)
  104. this.setData({
  105. cityName: cityName
  106. })
  107. },
  108. //获取当前定位
  109. cxgps: function(e) {
  110. var that = this;
  111. wx.showLoading({
  112. title: 'loading',
  113. mask: true
  114. });
  115. var distance = wx.getStorageSync('distance');
  116. if (distance) {
  117. console.log("fg22", distance)
  118. wx.hideLoading();
  119. that.setData({
  120. longitude: distance.longitude,
  121. latitude: distance.latitude
  122. })
  123. that.start();
  124. } else {
  125. wx.getSetting({
  126. success: function (res) {
  127. if (!res.authSetting['scope.userInfo'] || !res.authSetting['scope.userLocation']) {
  128. wx.hideLoading();
  129. wx.showModal({
  130. title: '授权提示',
  131. content: '当前服务需要获取您的位置信息,请确认授权',
  132. confirmText: '去授权',
  133. cancelText: '暂不授权',
  134. success: function (res) {
  135. if (res.confirm) {
  136. wx.openSetting();
  137. } else if (res.cancel) {
  138. }
  139. }
  140. })
  141. } else {
  142. $.map.getRegeo({
  143. success(data) {
  144. console.log("fg", data)
  145. wx.hideLoading();
  146. var data = data[0];
  147. that.setData({
  148. longitude: data.longitude,
  149. latitude: data.latitude
  150. })
  151. wx.setStorageSync('distance', data);
  152. that.start();
  153. }
  154. })
  155. }
  156. }
  157. })
  158. }
  159. },
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh: function() {
  164. this.setData({
  165. pageNo: 1, //当前分页
  166. isScroll: true, //是否可以滚动
  167. list: [],
  168. selectId: -1, //选中筛选的条件
  169. totalSalary: '', //薪资待遇排序(1:正序;2:倒序)
  170. sort: '', //距离排序(1:正序;2:倒序)
  171. longitude: "",
  172. latitude: ""
  173. })
  174. this.start();
  175. wx.stopPullDownRefresh();
  176. },
  177. /**
  178. * 页面上拉触底事件的处理函数
  179. */
  180. onReachBottom: function() {
  181. var pageNo = this.data.pageNo + 1;
  182. this.setData({
  183. pageNo
  184. })
  185. this.goodMoneyList();
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function() {
  191. },
  192. doSalay: function(e) {
  193. var totalSalary;
  194. if (this.data.totalSalary == 1) {
  195. totalSalary = 2;
  196. } else {
  197. totalSalary = 1;
  198. }
  199. this.setData({
  200. selectId: 0,
  201. totalSalary: totalSalary,
  202. sort: '', //重置
  203. pageNo: 1, //当前分页
  204. isScroll: true, //是否可以滚动
  205. list: [],
  206. longitude: "",
  207. latitude: ""
  208. })
  209. console.log("totalSalary", this.data.totalSalary)
  210. this.start();
  211. },
  212. doDistince: function(e) {
  213. var sort;
  214. if (this.data.sort == 1) {
  215. sort = 2;
  216. } else {
  217. sort = 1;
  218. }
  219. this.setData({
  220. selectId: 1,
  221. sort: sort,
  222. totalSalary: '', //重置
  223. pageNo: 1, //当前分页
  224. isScroll: true, //是否可以滚动
  225. list: [],
  226. })
  227. console.log("sort", this.data.sort)
  228. this.cxgps();
  229. },
  230. //去详情页
  231. toDetail(e) {
  232. const {
  233. id,
  234. cate
  235. } = e.currentTarget.dataset
  236. wx.navigateTo({
  237. url: '../detail/index?hpPositionId=' + id + "&cate=" + cate,
  238. })
  239. },
  240. })