index.vue 5.9 KB

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