data.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view>
  3. <u-navbar title="个人资料"></u-navbar>
  4. <view class="data">
  5. <view class="data-img">
  6. <view class="data-icon">
  7. <u-icon name="camera-fill" custom-prefix="custom-icon" color="#fff" size="32"></u-icon>
  8. </view>
  9. <u-avatar :src="form.headImg+'?x-oss-process=image/resize,m_fill,w_256,h_256'" size="216" @click="uploadPhoto"></u-avatar>
  10. </view>
  11. <view class="data-input">
  12. <u-form :model="form" ref="uForm" >
  13. <u-form-item label-position="top" label="昵称"><u-input v-model="form.nickName" /></u-form-item>
  14. </u-form>
  15. </view>
  16. <u-button class="login-btn" type="success" shape="circle" @click="submit">提交</u-button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import * as userApi from '@/apis/user.js'
  22. import * as loginApi from '@/apis/login.js'
  23. export default {
  24. data() {
  25. return {
  26. userId: '',
  27. form: {
  28. nickName: '',
  29. headImg: '',
  30. },
  31. }
  32. },
  33. onReady() {
  34. if(this.carhelp.getPersonInfo()) {
  35. this.form.nickName = this.carhelp.getPersonInfo().nickName;
  36. this.form.headImg = this.carhelp.getPersonInfo().headImg;
  37. }
  38. },
  39. methods: {
  40. uploadPhoto() {
  41. // 上传图片
  42. let _self = this;
  43. uni.chooseImage({
  44. count: 1, //默认9
  45. sourceType: ['album', 'camera'], //从相册选择
  46. success: (res) => {
  47. let imgFile = res.tempFilePaths;
  48. var token = this.carhelp.getToken()
  49. for (let i = 0; i < imgFile.length; i++) {
  50. wx.uploadFile({
  51. url: process.car.BASE_URL + "uploadPicture",
  52. name: 'photoFile',
  53. header: {
  54. 'Authorization': token,
  55. 'accept': 'application/json',
  56. //#ifdef MP-WEIXIN
  57. "Content-Type": "multipart/form-data", //记得设置
  58. //#endif
  59. },
  60. filePath: imgFile[0],
  61. success: function(result) {
  62. let imgUrls = JSON.parse(result.data)
  63. _self.form.headImg = imgUrls.data;
  64. }
  65. })
  66. }
  67. },
  68. });
  69. },
  70. submit() {
  71. uni.showLoading({
  72. title: "加载中",
  73. mask: true,
  74. })
  75. userApi.updatePersonInformation(this.form).then((res) => {
  76. uni.hideLoading();
  77. this.carhelp.getPersonInfo().nickName = this.form.nickName;
  78. this.carhelp.getPersonInfo().headImg = this.form.headImg;
  79. uni.navigateBack({
  80. })
  81. }).catch(error => {
  82. uni.showToast({
  83. title: error,
  84. icon: "none"
  85. })
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style>
  92. page{
  93. background: #fff;
  94. }
  95. </style>
  96. <style lang="scss" scoped>
  97. .data-icon{
  98. height: 28px;
  99. width: 28px;
  100. background-color: #00B962;
  101. border-radius: 14px;
  102. border: 2px solid #fff;
  103. text-align: center;
  104. line-height: 24px;
  105. position: absolute;
  106. z-index: 999;
  107. right: 0;
  108. bottom:0px
  109. }
  110. .data-img{
  111. margin: 30px auto;
  112. height: 108px;
  113. width: 108px;
  114. position: relative;
  115. }
  116. .data-input{
  117. margin: 0 40px;
  118. }
  119. .login-btn {
  120. margin: 28px ;
  121. background-color:#00B962!important;
  122. border-color: #00B962!important;
  123. color:#fff!important;
  124. }
  125. </style>