You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {
  2. toLink
  3. } from '../../../utils/nav';
  4. import {imagePrefix} from '../../../utils/dataHelper'
  5. const reqInterface = require("../../../api/models");
  6. import {
  7. ImageUrl
  8. } from '../../../utils/imageHelper';
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. ImageObj: ImageUrl,
  15. logined: false,
  16. wxInfo: null,
  17. getNickName: [],
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady() {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow() {
  33. let self = this;
  34. let token = wx.getStorageSync('token') ? wx.getStorageSync('token') : ''
  35. if (token) {
  36. self.setData({
  37. logined: true
  38. })
  39. self.getWxInfo()
  40. } else {
  41. self.setData({
  42. logined: false
  43. })
  44. }
  45. },
  46. getWxInfo() {
  47. reqInterface.POSTConsumerinfoQuery().then(res => {
  48. this.setData({
  49. 'wxInfo.avatar': res.avatar ? imagePrefix() + res.avatar : imagePrefix() + wx.getStorageSync('avatar'),
  50. 'wxInfo.userName': res.nickName ? res.nickName : wx.getStorageSync('userName')
  51. })
  52. })
  53. },
  54. nicknameValue(e) {
  55. let self = this;
  56. self.data.getNickName.push(e.detail.value)
  57. self.setData({
  58. getNickName: self.data.getNickName
  59. })
  60. if (self.data.getNickName.length >= 2) {
  61. reqInterface.PostConsumerinfoUpdate({
  62. nickName: self.data.getNickName[self.data.getNickName.length - 1],
  63. avatar: wx.getStorageSync('avatar') ? wx.getStorageSync('avatar') : ''
  64. }).then(res => {
  65. self.setData({
  66. 'wxInfo.userName': self.data.getNickName[self.data.getNickName.length - 1],
  67. getNickName: []
  68. })
  69. wx.setStorageSync('userName', self.data.wxInfo.userName);
  70. })
  71. }
  72. },
  73. onChooseAvatar(e) {
  74. let self = this;
  75. reqInterface.PostImageUpload(e.detail.avatarUrl).then(res => {
  76. wx.setStorageSync('avatar', res.data.path);
  77. reqInterface.PostConsumerinfoUpdate({
  78. nickName: self.data.wxInfo ? self.data.wxInfo.userName : '',
  79. avatar: res.data.path
  80. }).then(res => {
  81. self.setData({
  82. 'wxInfo.avatar': e.detail.avatarUrl,
  83. })
  84. })
  85. })
  86. },
  87. toLogin() {
  88. toLink('/pages/login/index/index')
  89. },
  90. toSetting() {
  91. toLink('/pages/setting/index/index')
  92. },
  93. toSchedule() {
  94. toLink('/pages/my/schedule/index')
  95. },
  96. toApply() {
  97. if (wx.getStorageSync('token')) {
  98. wx.navigateTo({
  99. url: '/pages/home/guide/detail/index',
  100. })
  101. } else {
  102. wx.showToast({
  103. title: '请先登录',
  104. icon: 'none'
  105. })
  106. }
  107. },
  108. imageError(e) {
  109. this.setData({
  110. 'wxInfo.avatar': this.data.ImageObj.unLogin,
  111. })
  112. },
  113. })