mine.js 5.2 KB

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