user.js 5.6 KB

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