point.js 5.7 KB

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