point.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // pages/point/point.js
  2. var BASEURL = require('../../utils/wxconstant.js')
  3. var baseUrl = BASEURL.BaseUrl()
  4. var baseutils = require('../../utils/baseUtils.js')
  5. var netUtil = require('../../utils/network.js')
  6. var pageSize = 1
  7. var isregistered
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. // tab切换
  14. currentTab: 0,
  15. clientHeight: '',
  16. /**
  17. * 页面配置
  18. */
  19. winWidth: 0,
  20. winHeight: 0,
  21. addList:[],
  22. minusList:[],
  23. points_rank:{}
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. var that = this
  30. /**
  31. * 获取系统信息
  32. */
  33. wx.getSystemInfo({
  34. success: function (res) {
  35. that.setData({
  36. winWidth: res.windowWidth,
  37. winHeight: res.windowHeight,
  38. clientHeight: res.windowHeight
  39. });
  40. }
  41. })
  42. },
  43. gotoWxlogin:function(){
  44. wx.showModal({
  45. title: '提示',
  46. content: '您当前尚未进行微信授权登录,是否立即前往?',
  47. success: function (res) {
  48. if (res.confirm) {
  49. wx.switchTab({
  50. url: '../mine/mine',
  51. })
  52. } else if (res.cancel) {
  53. return
  54. }
  55. }
  56. })
  57. },
  58. getHisPointData: function () {
  59. var that = this
  60. var data = {
  61. openid: wx.getStorageSync('openid'),
  62. pageCount:20,
  63. pageSize: pageSize
  64. }
  65. var url = baseUrl + BASEURL.getUrl.getAllRank
  66. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  67. if(res.data.success && res.data.data){
  68. if(pageSize == 1){
  69. that.setData({
  70. addList: res.data.data.addList,
  71. minusList: res.data.data.minusList,
  72. points_rank: res.data.data.points_rank
  73. })
  74. }else{
  75. that.setData({
  76. addList: [...that.data.addList, ...res.data.data.addList],
  77. minusList: [...that.data.minusList, ...res.data.data.minusList],
  78. points_rank: [...that.data.points_rank, ...res.data.data.points_rank],
  79. })
  80. }
  81. }
  82. }, function (res) {
  83. wx.showToast({
  84. title: '加载数据失败',
  85. icon: 'none',
  86. duration: 2000
  87. })
  88. })
  89. },
  90. enterAddPoint:function(){
  91. if (!isregistered) {
  92. this.gotoWxlogin()
  93. return
  94. }
  95. wx.navigateTo({
  96. url: '../pointapply/pointapply',
  97. })
  98. },
  99. enterMinusPoint:function(){
  100. if (!isregistered) {
  101. this.gotoWxlogin()
  102. return
  103. }
  104. wx.navigateTo({
  105. url: '../minusapply/minusapply',
  106. })
  107. },
  108. addListClick:function(event){
  109. // console.log("点击了", event.currentTarget.dataset.item)
  110. var itemdata = event.currentTarget.dataset.item
  111. wx.navigateTo({
  112. url: '../pointapply/pointapply?getisDetails=' + true + '&getItemdata=' + JSON.stringify(itemdata),
  113. })
  114. },
  115. minusListClick:function(){
  116. wx.navigateTo({
  117. url: '../minusapply/minusapply?getisDetails=' + true,
  118. })
  119. },
  120. /**
  121. * 点击tab切换
  122. */
  123. swichNav: function (e) {
  124. var that = this;
  125. // console.log('swichNav=', e)
  126. if (this.data.currentTab == e.target.dataset.current) {
  127. return false;
  128. } else {
  129. that.setData({
  130. currentTab: e.target.dataset.current
  131. })
  132. }
  133. },
  134. /**
  135. * 滑动切换tab
  136. */
  137. bindChange: function (e) {
  138. var that = this;
  139. if (e.detail.source == 'touch') {
  140. that.setData({ currentTab: e.detail.current });
  141. }
  142. },
  143. /**
  144. * 生命周期函数--监听页面初次渲染完成
  145. */
  146. onReady: function () {
  147. },
  148. /**
  149. * 生命周期函数--监听页面显示
  150. */
  151. onShow: function () {
  152. isregistered = wx.getStorageSync('isregistered')
  153. if (isregistered) {
  154. this.getHisPointData()
  155. } else {
  156. // that.gotoWxlogin()
  157. }
  158. },
  159. /**
  160. * 生命周期函数--监听页面隐藏
  161. */
  162. onHide: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面卸载
  166. */
  167. onUnload: function () {
  168. },
  169. /**
  170. * 页面相关事件处理函数--监听用户下拉动作
  171. */
  172. onPullDownRefresh: function () {
  173. var that = this
  174. wx.showNavigationBarLoading() //在标题栏中显示加载
  175. pageSize = 1
  176. that.getHisPointData()
  177. //模拟加载
  178. setTimeout(function () {
  179. // complete
  180. wx.hideNavigationBarLoading() //完成停止加载
  181. wx.stopPullDownRefresh() //停止下拉刷新
  182. }, 2000);
  183. },
  184. /**
  185. * 页面上拉触底事件的处理函数
  186. */
  187. onReachBottom: function () {
  188. pageSize++;
  189. this.getHisPointData()
  190. wx.showNavigationBarLoading();
  191. var that = this;
  192. setTimeout(function () { wx.hideNavigationBarLoading() }, 2000);
  193. },
  194. /**
  195. * 用户点击右上角分享
  196. */
  197. onShareAppMessage: function () {
  198. }
  199. })