index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="settings-root">
  3. <erp-nav-bar title="个人资料设置" />
  4. <!-- 资料列表 -->
  5. <view class="settings-list" :style="{ marginTop: '10px' }">
  6. <view class="item-row avatar-row" @click="doChooseImage">
  7. <text class="item-label">头像</text>
  8. <view class="item-right">
  9. <view class="avatar-wrapper">
  10. <image class="avatar-img" :src="myInfo.avatarUrl || 'https://img.icons8.com/color/144/user.png'"
  11. mode="aspectFill"></image>
  12. <view class="avatar-uploading" v-if="uploading">
  13. <text class="uploading-text">上传中...</text>
  14. </view>
  15. </view>
  16. <text class="icon-more"></text>
  17. </view>
  18. </view>
  19. <view class="item-row" @click="doEditName">
  20. <text class="item-label">用户昵称</text>
  21. <view class="item-right">
  22. <text class="item-value">{{ myInfo.userName }}</text>
  23. <text class="icon-more"></text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="settings-list mt-30">
  28. <view class="item-row no-tap">
  29. <text class="item-label">手机号码</text>
  30. <view class="item-right">
  31. <text class="item-value readonly">{{ myInfo.phone }}</text>
  32. </view>
  33. </view>
  34. <view class="item-row no-tap">
  35. <text class="item-label">授权客户</text>
  36. <view class="item-right">
  37. <text class="item-value readonly">{{ myInfo.authClientName || myInfo.authClientRowId || '无'
  38. }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="footer-bar">
  43. <button class="btn-confirm" @click="saveProfile" :disabled="uploading">确认保存</button>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import ErpNavBar from '@/components/erp-nav-bar.vue';
  49. import { getMyInfo, updateMyInfo } from '@/api/system/customer.js';
  50. import { uploadFile } from '@/api/resource/oss.js';
  51. export default {
  52. components: { ErpNavBar },
  53. data() {
  54. return {
  55. uploading: false,
  56. pendingAvatarOssId: null,
  57. myInfo: {
  58. avatarUrl: '',
  59. userName: '',
  60. phone: '',
  61. avatar: null,
  62. authClientRowId: '',
  63. authClientName: ''
  64. }
  65. }
  66. },
  67. async onLoad() {
  68. await this.loadInfo();
  69. },
  70. methods: {
  71. async loadInfo() {
  72. try {
  73. uni.showLoading({ title: '加载中' });
  74. const res = await getMyInfo();
  75. uni.hideLoading();
  76. const d = res.data;
  77. this.myInfo = {
  78. avatarUrl: d.avatarUrl || '',
  79. userName: d.userName || '',
  80. phone: d.phone || '',
  81. avatar: d.avatar || null,
  82. authClientRowId: d.authClientRowId || '',
  83. authClientName: d.authClientName || ''
  84. };
  85. this.pendingAvatarOssId = null;
  86. } catch (e) {
  87. uni.hideLoading();
  88. uni.showToast({ title: '加载失败', icon: 'none' });
  89. }
  90. },
  91. doChooseImage() {
  92. uni.chooseImage({
  93. count: 1,
  94. sizeType: ['compressed'],
  95. sourceType: ['album', 'camera'],
  96. success: async (res) => {
  97. const tempPath = res.tempFilePaths[0];
  98. this.myInfo.avatarUrl = tempPath;
  99. this.uploading = true;
  100. try {
  101. const uploadRes = await uploadFile(tempPath);
  102. this.pendingAvatarOssId = uploadRes.ossId;
  103. uni.showToast({ title: '头像上传成功', icon: 'success' });
  104. } catch (e) {
  105. uni.showToast({ title: '头像上传失败', icon: 'none' });
  106. this.myInfo.avatarUrl = '';
  107. } finally {
  108. this.uploading = false;
  109. }
  110. }
  111. });
  112. },
  113. doEditName() {
  114. uni.showModal({
  115. title: '设置昵称',
  116. content: this.myInfo.userName,
  117. editable: true,
  118. confirmColor: '#C1001C',
  119. success: (res) => {
  120. if (res.confirm) {
  121. this.myInfo.userName = res.content || this.myInfo.userName;
  122. }
  123. }
  124. });
  125. },
  126. saveProfile() {
  127. if (this.uploading) return;
  128. uni.showModal({
  129. title: '确认保存',
  130. content: `昵称:${this.myInfo.userName}\n手机:${this.myInfo.phone}\n请确认以上信息是否填写正确?`,
  131. confirmText: '确认',
  132. cancelText: '取消',
  133. confirmColor: '#C1001C',
  134. success: async (res) => {
  135. if (!res.confirm) return;
  136. try {
  137. uni.showLoading({ title: '保存中' });
  138. const payload = { userName: this.myInfo.userName };
  139. if (this.pendingAvatarOssId !== null) {
  140. payload.avatar = this.pendingAvatarOssId;
  141. }
  142. await updateMyInfo(payload);
  143. uni.hideLoading();
  144. uni.showToast({ title: '保存成功', icon: 'success' });
  145. setTimeout(() => { uni.navigateBack(); }, 1200);
  146. } catch (e) {
  147. uni.hideLoading();
  148. uni.showToast({ title: e.message || '保存失败', icon: 'none' });
  149. }
  150. }
  151. });
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped>
  157. .settings-root {
  158. width: 100vw;
  159. height: 100vh;
  160. background: #f8fafb;
  161. display: flex;
  162. flex-direction: column;
  163. }
  164. .settings-list {
  165. background: #fff;
  166. padding: 0 40rpx;
  167. }
  168. .mt-30 {
  169. margin-top: 30rpx;
  170. }
  171. .item-row {
  172. display: flex;
  173. justify-content: space-between;
  174. align-items: center;
  175. min-height: 110rpx;
  176. border-bottom: 2rpx solid #f9f9f9;
  177. }
  178. .item-row:last-child {
  179. border-bottom: none;
  180. }
  181. .avatar-row {
  182. height: 180rpx;
  183. }
  184. .item-label {
  185. font-size: 32rpx;
  186. color: #333;
  187. }
  188. .item-right {
  189. display: flex;
  190. align-items: center;
  191. }
  192. .avatar-wrapper {
  193. position: relative;
  194. width: 110rpx;
  195. height: 110rpx;
  196. margin-right: 20rpx;
  197. }
  198. .avatar-img {
  199. width: 110rpx;
  200. height: 110rpx;
  201. border-radius: 50%;
  202. background: #eee;
  203. }
  204. .avatar-uploading {
  205. position: absolute;
  206. top: 0;
  207. left: 0;
  208. width: 100%;
  209. height: 100%;
  210. border-radius: 50%;
  211. background: rgba(0, 0, 0, 0.45);
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. }
  216. .uploading-text {
  217. font-size: 20rpx;
  218. color: #fff;
  219. }
  220. .item-value {
  221. font-size: 30rpx;
  222. color: #666;
  223. margin-right: 15rpx;
  224. }
  225. .item-value.readonly {
  226. color: #aaa;
  227. margin-right: 0;
  228. }
  229. .icon-more {
  230. width: 14rpx;
  231. height: 14rpx;
  232. border-top: 3rpx solid #ccc;
  233. border-right: 3rpx solid #ccc;
  234. transform: rotate(45deg);
  235. }
  236. .footer-bar {
  237. padding: 40rpx;
  238. margin-top: auto;
  239. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  240. }
  241. .btn-confirm {
  242. width: 100%;
  243. height: 90rpx;
  244. background: #C1001C;
  245. color: #fff;
  246. border-radius: 45rpx;
  247. font-size: 32rpx;
  248. font-weight: bold;
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. }
  253. </style>