me.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. let util = require('../../utils/util.js')
  2. const api = require('../../utils/o2Api.js');
  3. const o2Api = require('../../utils/o2Api.js');
  4. Page({
  5. data: {
  6. showDialog: false,
  7. showLogoutDialog: false,
  8. dialogLabel: '',
  9. dialogValue: '',
  10. dialogPlaceholder: '',
  11. dialogParam: '',
  12. avatarUrl: '',
  13. person: {}
  14. },
  15. onLoad: function () {
  16. this.loadPersonInfo();
  17. },
  18. onShow: function() {
  19. this.avatar();
  20. },
  21. loadPersonInfo: function() {
  22. //获取用户信息
  23. api.me().then(info => {
  24. this.setData({
  25. person: info
  26. });
  27. }).catch(err => {
  28. api.o2Error(err);
  29. });
  30. },
  31. //获取头像文件
  32. avatar: function() {
  33. var who = wx.getStorageSync('who');
  34. var tokenName = wx.getStorageSync('tokenName');
  35. var token = '';
  36. if (who && who.token) {
  37. token = who.token;
  38. }
  39. var url = api.myAvatarUrl();
  40. var _self = this;
  41. wx.downloadFile({
  42. url: url,
  43. header: {
  44. tokenName: token
  45. },
  46. success(res) {
  47. if (res.statusCode === 200) {
  48. console.log(res)
  49. var filePath = res.tempFilePath
  50. _self.setData({
  51. avatarUrl: filePath
  52. });
  53. } else {
  54. _self.setData({
  55. avatarUrl: '../../assets/img/icon_my_avatar.png'
  56. });
  57. }
  58. },
  59. fail(res) {
  60. _self.setData({
  61. avatarUrl: '../../assets/img/icon_my_avatar.png'
  62. });
  63. }
  64. })
  65. },
  66. handleContact: function(e) {
  67. //点击客服消息可以传送路径和query参数过来
  68. console.log(e.detail.path)
  69. console.log(e.detail.query)
  70. },
  71. bindTapLogout: function(event) {
  72. this.setData({
  73. showLogoutDialog: true
  74. });
  75. },
  76. bindTapAvatar: function(event) {
  77. wx.navigateTo({
  78. url: './cropper-avatar',
  79. });
  80. },
  81. bindTapLine: function(event) {
  82. console.log(event);
  83. let param = event.currentTarget.dataset.param;
  84. let value = '';
  85. let placeholder = '';
  86. let label = '';
  87. if (!param) {
  88. return;
  89. } else if (param == 'mail') {
  90. value = this.data.person.mail;
  91. label = '邮件地址';
  92. placeholder = '请输入邮件地址';
  93. } else if (param == 'mobile') {
  94. value = this.data.person.mobile;
  95. label = '手机号码';
  96. placeholder = '请输入手机号码';
  97. } else if (param == 'officePhone') {
  98. value = this.data.person.officePhone;
  99. label = '办公电话';
  100. placeholder = '请输入办公电话';
  101. } else if (param == 'signature') {
  102. value = this.data.person.signature;
  103. label = '个人签名';
  104. placeholder = '请输入个人签名';
  105. }
  106. this.setData({
  107. showDialog: true,
  108. dialogLabel: label,
  109. dialogPlaceholder: placeholder,
  110. dialogValue: value,
  111. dialogParam: param
  112. });
  113. },
  114. getDialogInputValue: function(event) {
  115. this.data.dialogValue = event.detail.value;
  116. },
  117. tapDialogButton: function(event) {
  118. console.log(event);
  119. var value = this.data.dialogValue;
  120. var param = this.data.dialogParam;
  121. console.log('value:', value, ',param:', param);
  122. this.setData({
  123. showDialog: false,
  124. dialogLabel: '',
  125. dialogValue: '',
  126. dialogParam: ''
  127. });
  128. if (event.detail.index == 1) {
  129. const person = JSON.parse(JSON.stringify(this.data.person));//Object.clone(this.data.person);
  130. if (!value ) {
  131. var value = ''
  132. }
  133. if (param == 'mail') {
  134. person.mail = value;
  135. this.putPerson(person);
  136. }else if (param == 'mobile') {
  137. person.mobile = value;
  138. this.putPerson(person);
  139. }else if (param == 'officePhone') {
  140. person.officePhone = value;
  141. this.putPerson(person);
  142. }else if (param == 'signature') {
  143. person.signature = value;
  144. this.putPerson(person);
  145. }
  146. }
  147. },
  148. putPerson: function(person) {
  149. api.putMyInfo(person).then(id => {
  150. this.setData({
  151. person: person
  152. });
  153. util.toast('更新成功!');
  154. }).catch(err => {
  155. o2Api.o2Error(err);
  156. //this.loadPersonInfo();
  157. })
  158. },
  159. tapDialogLogoutButton: function(event) {
  160. this.setData({
  161. showLogoutDialog: false
  162. })
  163. if (event.detail.index == 1) {
  164. api.logout().then(res => {
  165. console.log('登出', res);
  166. wx.removeStorageSync('who');
  167. wx.removeStorageSync('cookie');
  168. wx.redirectTo({
  169. url: '../login/login'
  170. });
  171. }).catch(err => {
  172. console.log('登出错误', err);
  173. wx.removeStorageSync('who');
  174. wx.removeStorageSync('cookie');
  175. wx.redirectTo({
  176. url: '../login/login'
  177. });
  178. })
  179. }
  180. }
  181. })