mine.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. that.getEmp()
  110. },
  111. getEmp:function(){
  112. var that = this
  113. var data = {
  114. openid: wx.getStorageSync('openid'),
  115. }
  116. var url = baseUrl + BASEURL.getUrl.getEmp
  117. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  118. if (res.data.success && res.data.data.empId) {
  119. wx.setStorageSync('empId', res.data.data.empId)
  120. console.log("empId", wx.getStorageSync('empId'))
  121. }
  122. }, function (res) {
  123. wx.showToast({
  124. title: '加载数据失败',
  125. icon: 'none',
  126. duration: 2000
  127. })
  128. })
  129. },
  130. getMyRank:function(){
  131. var that = this
  132. var data = {
  133. openid: wx.getStorageSync('openid'),
  134. }
  135. var url = baseUrl + BASEURL.getUrl.getRank
  136. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  137. if (res.data.success){
  138. wx.setStorageSync('isregistered', res.data.data.isregistered)
  139. if (res.data.data.pointdata){
  140. var pointdata = res.data.data.pointdata
  141. that.setData({
  142. isregistered: res.data.data.isregistered,
  143. pointdata: pointdata,
  144. "curmonth_points": pointdata.curmonth_points == null ? '0' : pointdata.curmonth_points, //本月当前积分
  145. "curmonth_rank": pointdata.curmonth_rank == null ? '0' : pointdata.curmonth_rank,//本月当前排名
  146. "lastmonth_points": pointdata.lastmonth_points == null ? '0' : pointdata.lastmonth_points,//上月积分
  147. "lastmonth_rank": pointdata.lastmonth_rank == null ? '-' : pointdata.lastmonth_rank //上月排名
  148. })
  149. }
  150. }
  151. }, function (res) {
  152. wx.showToast({
  153. title: '加载数据失败',
  154. icon: 'none',
  155. duration: 2000
  156. })
  157. })
  158. },
  159. bindGetUserInfo: function (e) {
  160. var that = this
  161. var userInfo = e.detail.userInfo
  162. if (!userInfo) return
  163. console.log('bindGetUserInfo', userInfo)
  164. var nickName = userInfo.nickName
  165. var avatarUrl = userInfo.avatarUrl
  166. var gender = userInfo.gender //性别 0:未知、1:男、2:女
  167. var province = userInfo.province
  168. var city = userInfo.city
  169. var country = userInfo.country
  170. if (nickName && avatarUrl) {
  171. baseutils.getPersonlEmp()
  172. baseutils.judgeisReg()
  173. that.getMyRank()
  174. that.setData({
  175. wxNickname: nickName,
  176. wxHeader: avatarUrl,
  177. isLogin: true
  178. })
  179. try {
  180. wx.setStorageSync('wxavatarUrl', userInfo.avatarUrl)
  181. wx.setStorageSync('wxnickName', userInfo.nickName)
  182. } catch (e) {
  183. }
  184. }
  185. },
  186. comToast: function (title) {
  187. wx.showToast({
  188. title: title,
  189. icon: 'none',
  190. duration: 2000
  191. })
  192. },
  193. /**
  194. * 生命周期函数--监听页面隐藏
  195. */
  196. onHide: function () {
  197. },
  198. /**
  199. * 生命周期函数--监听页面卸载
  200. */
  201. onUnload: function () {
  202. },
  203. /**
  204. * 页面相关事件处理函数--监听用户下拉动作
  205. */
  206. onPullDownRefresh: function () {
  207. },
  208. /**
  209. * 页面上拉触底事件的处理函数
  210. */
  211. onReachBottom: function () {
  212. },
  213. /**
  214. * 用户点击右上角分享
  215. */
  216. onShareAppMessage: function () {
  217. }
  218. })