updateinfo.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import * as API_Common from '@/apis/common'
  2. import * as WxJsApi from '@/utils/wxJsApi.js'
  3. import * as API from '@/apis/my.js'
  4. export default {
  5. data() {
  6. return {
  7. user:{},
  8. pic:'/static/img/user.png',
  9. show:true,
  10. }
  11. },
  12. onLoad() {
  13. },
  14. methods: {
  15. upload(){
  16. WxJsApi.chooseImage(1).then(res=>{
  17. var formData = {
  18. 'photoName': '1.jpg',
  19. 'photoFile': res.localData
  20. }
  21. API_Common.upload(formData).then(response => {
  22. if(response.data){
  23. this.pic=response.data
  24. this.$refs.common.showLoading(false,"上传成功!")
  25. }else{
  26. this.$refs.common.showLoading(false,"图片过大,请上传其他照片!")
  27. }
  28. }).catch(error => {
  29. this.$refs.common.showLoading(false,error)
  30. })
  31. })
  32. },
  33. submit(){
  34. if(!this.user.name){
  35. this.$refs.common.alert('用户名不能为空')
  36. return
  37. }
  38. this.$refs.common.showLoading();
  39. this.user.faceImage=this.pic;
  40. this.user.acceptMessage=(this.user.acceptMessage?1:0)
  41. API.updateUserInfo(this.user).then((res) => {
  42. this.carhelp.setPersonInfo(this.user);
  43. this.$refs.common.setFnc(function(){
  44. uni.switchTab({
  45. url: '/pages/my/index'
  46. });
  47. })
  48. this.$refs.common.alert2("操作成功!");
  49. }).catch(error => {
  50. this.$refs.common.showLoading(false,error);
  51. })
  52. },
  53. gotoUrl(url){
  54. uni.navigateTo({
  55. url:url
  56. })
  57. },
  58. showphone(phone){
  59. if(!phone){
  60. return "";
  61. }
  62. if(phone.length!=11){
  63. return "";
  64. }
  65. return phone.substring(0,3)+'****'+phone.substring(8);
  66. },
  67. signOut(){
  68. this.carhelp.signOut()
  69. uni.redirectTo({
  70. url: '/pages/car/login'
  71. })
  72. }
  73. },onReady(){
  74. WxJsApi.getWxConfig()
  75. this.user=this.carhelp.getPersonInfo();
  76. if(this.user.faceImage){
  77. this.pic=this.user.faceImage;
  78. }
  79. }
  80. }