index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // pages/reward/index.js
  2. import {
  3. getRewardList
  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. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function(options) {
  32. if (app.globalData.userInfo) {
  33. console.log('有info===', app.globalData)
  34. this.start();
  35. } else if (this.data.canIUse) {
  36. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  37. // 所以此处加入 callback 以防止这种情况
  38. app.userInfoReadyCallback = res => {
  39. console.log('userInfoReadyCallback===', res.userInfo)
  40. app.globalData.userInfo = res.userInfo;
  41. this.start();
  42. }
  43. } else {
  44. // 在没有 open-type=getUserInfo 版本的兼容处理
  45. wx.getUserInfo({
  46. success: res => {
  47. app.globalData.userInfo = res.userInfo
  48. console.log('兼容处理===', app.globalData)
  49. this.start();
  50. }
  51. })
  52. }
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function() {
  58. },
  59. start() {
  60. this.rewardList();
  61. },
  62. //获取入职奖励列表数据
  63. rewardList(params) {
  64. if (!this.data.isScroll) {
  65. return false
  66. }
  67. let paramsObj = {
  68. longitude: this.data.longitude,
  69. latitude: this.data.latitude,
  70. sort: this.data.sort,
  71. totalSalary: this.data.totalSalary,
  72. cityCode: this.data.cityCode,
  73. pageNo: this.data.pageNo,
  74. user_id: app.globalData.userId,
  75. user_token: app.globalData.userToken
  76. }
  77. Object.assign(paramsObj);
  78. getRewardList(paramsObj).then(data => {
  79. var pageNo = data.data.pageNo;
  80. let setData = {}
  81. // 是否可以滚动加载数据
  82. if (data.data.isLast) {
  83. setData.isScroll = false
  84. }
  85. if (data.data.rewardPosition.length != 0) {
  86. setData.list = this.data.list.concat(data.data.rewardPosition)
  87. setData.pageNo = pageNo;
  88. } else {
  89. setData.list = this.data.list;
  90. }
  91. this.setData({
  92. ...setData
  93. })
  94. })
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function() {
  100. let cityName = wx.getStorageSync('city') || app.globalData.userInfo.city || '无锡'
  101. console.log(cityName)
  102. this.setData({
  103. cityName: cityName
  104. })
  105. },
  106. //获取当前定位
  107. cxgps: function(e) {
  108. var that = this;
  109. wx.showLoading({
  110. title: 'loading',
  111. mask: true
  112. });
  113. var distance = wx.getStorageSync('distance');
  114. if (distance) {
  115. console.log("fg22", distance)
  116. wx.hideLoading();
  117. that.setData({
  118. longitude: distance.longitude,
  119. latitude: distance.latitude
  120. })
  121. that.start();
  122. } else {
  123. $.map.getRegeo({
  124. success(data) {
  125. console.log("fg", data)
  126. wx.hideLoading();
  127. var data = data[0];
  128. that.setData({
  129. longitude: data.longitude,
  130. latitude: data.latitude
  131. })
  132. wx.setStorageSync('distance', data);
  133. that.start();
  134. }
  135. })
  136. }
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function() {
  142. this.setData({
  143. pageNo: 1, //当前分页
  144. isScroll: true, //是否可以滚动
  145. list: [],
  146. selectId: -1, //选中筛选的条件
  147. totalSalary: '', //薪资待遇排序(1:正序;2:倒序)
  148. sort: '', //距离排序(1:正序;2:倒序)
  149. longitude: "",
  150. latitude: ""
  151. })
  152. this.start();
  153. wx.stopPullDownRefresh();
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function() {
  159. var pageNo = this.data.pageNo + 1;
  160. this.setData({
  161. pageNo
  162. })
  163. this.rewardList();
  164. },
  165. /**
  166. * 用户点击右上角分享
  167. */
  168. onShareAppMessage: function() {
  169. },
  170. doSalay: function(e) {
  171. var totalSalary;
  172. if (this.data.totalSalary == 1) {
  173. totalSalary = 2;
  174. } else {
  175. totalSalary = 1;
  176. }
  177. this.setData({
  178. selectId: 0,
  179. totalSalary: totalSalary,
  180. sort: '', //重置
  181. pageNo: 1, //当前分页
  182. isScroll: true, //是否可以滚动
  183. list: [],
  184. longitude: "",
  185. latitude: ""
  186. })
  187. console.log("totalSalary", this.data.totalSalary)
  188. this.start();
  189. },
  190. doDistince: function(e) {
  191. var sort;
  192. if (this.data.sort == 1) {
  193. sort = 2;
  194. } else {
  195. sort = 1;
  196. }
  197. this.setData({
  198. selectId: 1,
  199. sort: sort,
  200. totalSalary: '', //重置
  201. pageNo: 1, //当前分页
  202. isScroll: true, //是否可以滚动
  203. list: [],
  204. })
  205. console.log("sort", this.data.sort)
  206. this.cxgps();
  207. }
  208. })