editProfile.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view>
  3. <u-navbar title="编辑个人信息" >
  4. <view class="slot-wrap" @click="save">
  5. 保存
  6. </view>
  7. </u-navbar>
  8. <view class="photo" @click="uploadPhoto">
  9. <u-avatar class="avatar"
  10. :src="form.headImg != null ? form.headImg : '../../assets/img/head.png'" size="160">
  11. </u-avatar>
  12. <view class="edit-photo">
  13. <img src="../../../assets/img/md-camera_alt@1x(1).png" alt="">
  14. </view>
  15. </view>
  16. <view class="change">
  17. 点击更换头像
  18. </view>
  19. <view class="pet-name">
  20. <view class="title">
  21. 学员姓名
  22. </view>
  23. <view class="name">
  24. <input type="text" name="" id="" v-model="form.nickName" style="text-align: right;">
  25. </view>
  26. </view>
  27. <view class="pet-name">
  28. <view class="title">
  29. 手机号码
  30. </view>
  31. <view class="name">
  32. <input type="text" name="" id="" style="text-align: right;">
  33. <image class="img" src="@/assets/img/riLine-edit-box-line.svg" mode=""></image>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import * as loginApi from '@/apis/login.js'
  40. import * as mineApi from '@/apis/youth/mine.js'
  41. export default {
  42. data() {
  43. return {
  44. form: {
  45. headImg: '',
  46. nickName: '',
  47. type: '2'
  48. }
  49. }
  50. },
  51. onReady() {
  52. this.getParentsInfo();
  53. },
  54. methods: {
  55. getParentsInfo() {
  56. uni.showLoading({
  57. title: "加载中",
  58. mask: true,
  59. })
  60. loginApi.findByOpenId({
  61. openId: this.carhelp.getOpenId()
  62. }).then((response) => {
  63. uni.hideLoading();
  64. this.form.headImg = response.data.regUser.headImg;
  65. this.form.nickName = response.data.regUser.nickName;
  66. }).catch(error => {
  67. uni.showToast({
  68. title: error,
  69. icon: "none"
  70. })
  71. })
  72. },
  73. save() {
  74. uni.showLoading({
  75. title: "加载中",
  76. mask: true,
  77. })
  78. mineApi.updateRegUser(this.form).then((response) => {
  79. uni.hideLoading();
  80. uni.navigateBack({
  81. })
  82. }).catch(error => {
  83. uni.showToast({
  84. title: error,
  85. icon: "none"
  86. })
  87. })
  88. },
  89. uploadPhoto() {
  90. let _self = this;
  91. var token = _self.carhelp.getToken()
  92. const crop = {
  93. quality: 100,
  94. width: 600,
  95. height: 600,
  96. resize: true
  97. };
  98. // 上传图片
  99. uni.chooseImage({
  100. count: 1,
  101. crop,
  102. success: async (res) => {
  103. //(res);
  104. let tempFile = res.tempFiles[0],
  105. avatar_file = {
  106. // #ifdef H5
  107. extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
  108. // #endif
  109. // #ifndef H5
  110. extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
  111. // #endif
  112. },
  113. filePath = res.tempFilePaths[0]
  114. // #ifndef APP-PLUS
  115. //(`filePath=${filePath}`)
  116. //非app端用前端组件剪裁头像,app端用内置的原生裁剪
  117. let fileData = await new Promise((callback) => {
  118. uni.navigateTo({
  119. url: '/pages/components/cropImage?path=' + filePath +
  120. `&options=${JSON.stringify(crop)}`,
  121. animationType: "fade-in",
  122. events: {
  123. success: url => {
  124. callback(url)
  125. }
  126. }
  127. });
  128. })
  129. // #endif
  130. //返回 base64 图片
  131. //(fileData);
  132. // var token = _self.carhelp.getToken()
  133. uni.showLoading({
  134. title: '上传中'
  135. });
  136. uni.request({
  137. url: process.car.BASE_URL + "/mobile/student/uploadBase64",
  138. method: 'POST',
  139. data: {
  140. photoBase64Data: fileData
  141. },
  142. header: {
  143. 'Authorization': token,
  144. 'content-type': 'application/x-www-form-urlencoded'
  145. },
  146. success: (res) => {
  147. let jsonData = res.data;
  148. _self.form.headImg = jsonData.data;
  149. // _self.save();
  150. uni.hideLoading();
  151. }
  152. });
  153. }
  154. });
  155. },
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. page{
  161. background-color: #fff;
  162. }
  163. ::v-deep.u-slot-content{
  164. justify-content: end;
  165. margin-right: 32rpx;
  166. color: rgba(13, 186, 199, 1);
  167. }
  168. .photo{
  169. margin: 20px auto 8px;
  170. width: 160rpx;
  171. height: 160rpx;
  172. position: relative;
  173. img{
  174. width: 100%;
  175. height: 100%;
  176. border-radius: 999px;
  177. }
  178. }
  179. .edit-photo{
  180. width: 56rpx;
  181. height: 56rpx;
  182. background-color: rgba(78, 141, 246, 1);
  183. border: 4rpx solid rgba(255, 255, 255, 1);
  184. text-align: center;
  185. border-radius: 999px;
  186. z-index: 999;
  187. position: absolute;
  188. right: 0;
  189. bottom: 0;
  190. img{
  191. width: 32rpx;
  192. height: 32rpx;
  193. margin-top: 8rpx;
  194. }
  195. }
  196. .change{
  197. color: rgba(13, 186, 199, 1);
  198. text-align: center;
  199. }
  200. .pet-name{
  201. margin-top: 20px;
  202. padding: 15px;
  203. border-bottom: 1px solid rgba(244, 244, 244, 1);
  204. display: flex;
  205. justify-content: space-between;
  206. .title{
  207. color: rgba(16, 16, 16, 1);
  208. font-weight: bold;
  209. }
  210. .name{
  211. color: rgba(136, 136, 136, 1);
  212. display: flex;
  213. align-items: center;
  214. .img{
  215. width: 32rpx;
  216. height: 32rpx;
  217. margin-left: 8rpx;
  218. }
  219. }
  220. }
  221. </style>