mine.js 5.0 KB

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