mine.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // pages/mine/mine.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 dateutil = require('../../utils/DateTime.js')
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. //id
  13. isregistered:false,
  14. idMyInfo:'idMyInfo',
  15. idCompanyInfo: 'idCompanyInfo',
  16. idAbout: 'idAbout',
  17. idgoBind:'idgoBind',
  18. pointdata:{},//本月、上月积分及排名
  19. "curmonth_points": 520, //本月当前积分
  20. "curmonth_rank": 1,//本月当前排名
  21. "lastmonth_points": 520,//上月积分
  22. "lastmonth_rank": 1 //上月排名
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. btnClick: function (event) {
  35. var that = this
  36. var id = event.currentTarget.id
  37. if (id == that.data.idMyInfo){
  38. if (!that.data.isregistered){
  39. wx.showModal({
  40. title: '提示',
  41. content: '您当前尚未与企业关联绑定,是否立即去绑定?',
  42. success: function (res) {
  43. if (res.confirm) {
  44. wx.navigateTo({
  45. url: '../bindphone/bindphone',
  46. })
  47. } else if (res.cancel) {
  48. return
  49. }
  50. }
  51. })
  52. }else{
  53. wx.navigateTo({
  54. url: '../perinfo/perinfo',
  55. })
  56. }
  57. } else if (id == that.data.idCompanyInfo){
  58. wx.navigateTo({
  59. url: '../corporateInfo/corporateInfo',
  60. })
  61. } else if (id == that.data.idAbout){
  62. } else if (id == that.data.idgoBind){
  63. wx.navigateTo({
  64. url: '../bindphone/bindphone',
  65. })
  66. }
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow: function () {
  72. var that = this
  73. this.setData({
  74. isregistered: wx.getStorageSync('isregistered'),
  75. isLogin: wx.getStorageSync('wxnickName') ? true : false,
  76. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  77. headerImg: wx.getStorageSync('wxavatarUrl'),
  78. wxNickname: wx.getStorageSync('wxnickName'),
  79. })
  80. that.getMyRank()
  81. },
  82. getMyRank:function(){
  83. var that = this
  84. var data = {
  85. openid: wx.getStorageSync('openid'),
  86. }
  87. var url = baseUrl + BASEURL.getUrl.getRank
  88. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  89. if (res.data.success){
  90. wx.setStorageSync('isregistered', res.data.data.isregistered)
  91. if (res.data.data.pointdata){
  92. var pointdata = res.data.data.pointdata
  93. that.setData({
  94. pointdata: pointdata,
  95. "curmonth_points": pointdata.curmonth_points, //本月当前积分
  96. "curmonth_rank": pointdata.curmonth_rank,//本月当前排名
  97. "lastmonth_points": pointdata.lastmonth_points,//上月积分
  98. "lastmonth_rank": pointdata.lastmonth_rank //上月排名
  99. })
  100. }
  101. }
  102. }, function (res) {
  103. wx.showToast({
  104. title: '加载数据失败',
  105. icon: 'none',
  106. duration: 2000
  107. })
  108. })
  109. },
  110. bindGetUserInfo: function (e) {
  111. var that = this
  112. var userInfo = e.detail.userInfo
  113. // console.log('bindGetUserInfo', userInfo)
  114. var nickName = userInfo.nickName
  115. var avatarUrl = userInfo.avatarUrl
  116. var gender = userInfo.gender //性别 0:未知、1:男、2:女
  117. var province = userInfo.province
  118. var city = userInfo.city
  119. var country = userInfo.country
  120. if (nickName && avatarUrl) {
  121. baseutils.getComOpenid() //获取openid
  122. baseutils.getPersonlEmp()
  123. baseutils.judgeisReg()
  124. that.setData({
  125. wxNickname: nickName,
  126. wxHeader: avatarUrl,
  127. isLogin: true
  128. })
  129. try {
  130. wx.setStorageSync('wxavatarUrl', userInfo.avatarUrl)
  131. wx.setStorageSync('wxnickName', userInfo.nickName)
  132. } catch (e) {
  133. }
  134. }
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload: function () {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh: function () {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom: function () {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage: function () {
  160. }
  161. })