mine.js 5.3 KB

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