user.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // pages/user/user.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. const $api = require('../../utils/api.js').API;
  5. var logindata={}
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. usercode: '',
  12. phone:'',
  13. phcode:'',
  14. openid: '',
  15. info: {},
  16. userinfo:{},
  17. todayinfo:{},
  18. todayMoney:'',
  19. status:0,
  20. text:'获取验证码'
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.getUserData()
  27. },
  28. zx(){
  29. wx.navigateTo({
  30. url: '../message/message',
  31. })
  32. },
  33. getcode(){
  34. if(this.data.phone.length>=11){
  35. $api.sendcode({phone:this.data.phone}).then(res=>{
  36. this.countdown()
  37. })
  38. }else{
  39. wx.showToast({
  40. icon: 'none',
  41. title: '请输入正确的手机号',
  42. })
  43. }
  44. },
  45. countdown(){
  46. var count=60,_this=this;
  47. var timer=setInterval(c,1000)
  48. function c(){
  49. if(count>0){
  50. count--;
  51. _this.setData({
  52. text:count+"s重新发送"
  53. })
  54. }else{
  55. _this.setData({
  56. text:'获取验证码'
  57. })
  58. clearInterval(timer)
  59. }
  60. }
  61. },
  62. getUserData() {
  63. $api.getAuthinfo().then(res=>{
  64. wx.setNavigationBarTitle({
  65. title: '',
  66. })
  67. if(res.data.data.role==0){
  68. wx.navigateTo({
  69. url: '../apply/apply',
  70. })
  71. }else{
  72. this.setData({
  73. usercode: res.data.data.usercode,
  74. userinfo: res.data.data,
  75. status:3
  76. })
  77. }
  78. })
  79. .catch(err=>{
  80. this.setData({
  81. userinfo: {},
  82. status:0
  83. })
  84. })
  85. },
  86. getTodayData() {
  87. $api.getMineLatest().then(res=>{
  88. this.setData({
  89. todayinfo: res.data.data,
  90. todayMoney:((res.data.data.today_fund - res.data.data.yesterday_fund)*10000).toFixed(2)
  91. })
  92. })
  93. .catch(err=>{
  94. this.setData({
  95. todayinfo: {},
  96. status:0
  97. })
  98. })
  99. },
  100. inputchange(e) {
  101. this.setData({
  102. phone: e.detail.value
  103. })
  104. },
  105. codechange(e) {
  106. this.setData({
  107. phcode: e.detail.value
  108. })
  109. },
  110. logout() {
  111. wx.removeStorage({
  112. key: 'userInfo'
  113. })
  114. wx.setNavigationBarTitle({
  115. title: '登录',
  116. })
  117. this.setData({
  118. userinfo: {},
  119. usercode: ''
  120. })
  121. },
  122. /**登陆 */
  123. login: function () {
  124. var _this=this;
  125. // if (!this.data.usercode) {
  126. // wx.showToast({
  127. // icon: 'none',
  128. // title: '请输入用户代码',
  129. // })
  130. // return;
  131. // }
  132. wx.getUserProfile({
  133. desc: '用于完善会员资料',
  134. success: res=> {
  135. //获取基本信息
  136. var data = {
  137. nickName: res.userInfo.nickName,
  138. avatarUrl: res.userInfo.avatarUrl,
  139. usercode: this.data.usercode
  140. }
  141. wx.showLoading({
  142. title: '正在登陆',
  143. })
  144. wx.login({
  145. success(res) {
  146. //获取code
  147. $api.getOpenid({ code: res.code})
  148. .then(res => {
  149. //获取openid
  150. if (res.data.code != 0) {
  151. wx.showToast({
  152. icon: 'none',
  153. title: res.data.message,
  154. })
  155. wx.hideLoading();
  156. return;
  157. }
  158. data.openid = res.data.data.openid;
  159. logindata=data
  160. $api.login(data)
  161. .then(res=>{
  162. //登录成功
  163. _this.setData({
  164. status:res.data.data.status
  165. })
  166. wx.hideLoading();
  167. wx.setNavigationBarTitle({
  168. title: '',
  169. })
  170. if (res.data.code != 0) {
  171. wx.showToast({
  172. icon: 'none',
  173. title: res.data.message,
  174. })
  175. return;
  176. }
  177. wx.setStorage({
  178. key: 'userInfo',
  179. data: res.data.data,
  180. })
  181. if(res.data.data.status == 3){
  182. _this.getUserData()
  183. _this.getTodayData()
  184. // wx.switchTab({
  185. // url: '../index/index',
  186. // })
  187. }
  188. })
  189. .catch(err=>{
  190. wx.hideLoading();
  191. })
  192. })
  193. .catch(err => {
  194. //请求失败
  195. wx.hideLoading();
  196. })
  197. }
  198. })
  199. }
  200. })
  201. },
  202. login1(){
  203. logindata.phone=this.data.phone
  204. logindata.phcode=this.data.phcode
  205. $api.login(logindata).then(res=>{
  206. if(res.data.code == 0){
  207. this.getUserData()
  208. this.getTodayData()
  209. }
  210. })
  211. },
  212. login2(){
  213. $api.bindphone({phone:this.data.phone,phcode:this.data.phcode}).then(res=>{
  214. if(res.data.code == 0){
  215. this.getUserData()
  216. this.getTodayData()
  217. }
  218. })
  219. },
  220. onCustomerService(){
  221. wx.openCustomerServiceChat({
  222. extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},
  223. corpId: 'wwc4de479c81db4706',
  224. success(res) {}
  225. })
  226. },
  227. /**
  228. * 生命周期函数--监听页面初次渲染完成
  229. */
  230. onReady: function () {
  231. },
  232. /**
  233. * 生命周期函数--监听页面显示
  234. */
  235. onShow: function () {
  236. //判断是否报名
  237. $api.getAuthinfo().then(res=>{
  238. if(res.data.data.role==0){
  239. wx.navigateTo({
  240. url: '../apply/apply',
  241. })
  242. }
  243. })
  244. this.getTodayData()
  245. },
  246. /**
  247. * 生命周期函数--监听页面隐藏
  248. */
  249. onHide: function () {
  250. },
  251. /**
  252. * 生命周期函数--监听页面卸载
  253. */
  254. onUnload: function () {
  255. },
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh: function () {
  260. },
  261. /**
  262. * 页面上拉触底事件的处理函数
  263. */
  264. onReachBottom: function () {
  265. },
  266. /**
  267. * 用户点击右上角分享
  268. */
  269. onShareAppMessage: function () {
  270. }
  271. })