SchoolUserHeader.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="com-school-user-header" v-if="info">
  3. <view class="header">
  4. <button class="avatarBtn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  5. <image class="avatar" :src="info.avatar" mode="scaleToFill"></image>
  6. </button>
  7. </view>
  8. <view class="user">
  9. <view class="name">{{info.nickname}}</view>
  10. <view class="icon">
  11. <image src="/static/images/gl.png" mode="widthFix" class="img"></image>
  12. <image src="/static/images/coffeecup.png" mode="widthFix" class="img"></image>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import {
  19. mapState,
  20. mapMutations
  21. } from 'vuex'
  22. export default {
  23. name:"SchoolUserHeader",
  24. props:{
  25. info:{
  26. type:Object,
  27. default:()=>{
  28. return null
  29. }
  30. }
  31. },
  32. watch:{
  33. 'info':{
  34. handler(val){
  35. console.log(this.userInfo);
  36. console.log("val",val);
  37. },
  38. deep:true,
  39. immediate:true,
  40. }
  41. },
  42. computed: {
  43. ...mapState(['systemInfo', 'store_id', 'userInfo']),
  44. },
  45. data() {
  46. return {
  47. };
  48. },
  49. methods:{
  50. onChooseAvatar(e) {
  51. let _this=this;
  52. const { avatarUrl } = e.detail;
  53. this.avatar = avatarUrl;
  54. uni.uploadFile({
  55. url: siteinfo.siteroot + '/index.php?s=/api/upload/upload',
  56. filePath: avatarUrl,
  57. name: 'file',
  58. formData: {
  59. 'openId': _this.userInfo.openid,
  60. 'token': uni.getStorageSync('token'),
  61. },
  62. success: ({data}) => {
  63. let res = JSON.parse(data);
  64. if (res.code == 2) {
  65. // this.userInfo.avatar = res.src;
  66. _this.info.avatar=res.src;
  67. _this.onSave();
  68. } else {
  69. uni.showToast({
  70. title: res.msg,
  71. icon: 'none',
  72. mask: true
  73. });
  74. }
  75. },
  76. fail: () => {
  77. uni.showToast({
  78. title: '头像上传失败,请稍后重试~',
  79. icon: 'none',
  80. mask: true
  81. });
  82. }
  83. });
  84. },
  85. onSave(e){
  86. let _this=this;
  87. let par={
  88. openid:_this.userInfo.openid,
  89. avatar:_this.info.avatar,
  90. nickname:_this.userInfo.nickname,
  91. gender:_this.userInfo.gender,
  92. born:_this.userInfo.born,
  93. province:_this.userInfo.province,
  94. city:_this.userInfo.city,
  95. district:_this.userInfo.district,
  96. }
  97. _this.$http.request('member/saveMemberInfo',par, "", "", true).then(res => {
  98. }).catch(err => {
  99. })
  100. },
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. @import "./SchoolUserHeader.scss"
  106. </style>