user.js 6.3 KB

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