index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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>
  35. <!-- 授权客户列表 -->
  36. <view class="section-card" style="margin-top: 30rpx;">
  37. <view class="section-header">
  38. <text class="section-title">授权客户</text>
  39. <text class="section-desc" v-if="myInfo.authClientList">共 {{ myInfo.authClientList.length }} 个</text>
  40. </view>
  41. <view v-if="myInfo.authClientList && myInfo.authClientList.length > 0" class="client-list">
  42. <view class="client-item" v-for="(client, idx) in myInfo.authClientList" :key="idx">
  43. <view class="client-index">{{ idx + 1 }}</view>
  44. <view class="client-info">
  45. <text class="client-name">{{ client.name || '-' }}</text>
  46. <view class="client-meta">
  47. <text class="client-class">{{ client.clientClass || '-' }}</text>
  48. <text class="client-date" v-if="client.enterDate">{{ client.enterDate }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="no-client" v-else>
  54. <text class="no-client-text">暂无授权客户</text>
  55. </view>
  56. </view>
  57. <view class="footer-bar">
  58. <button class="btn-confirm" @click="saveProfile" :disabled="uploading">确认保存</button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import ErpNavBar from '@/components/erp-nav-bar.vue';
  64. import { getMyInfo, updateMyInfo } from '@/api/system/customer.js';
  65. import { uploadFile } from '@/api/resource/oss.js';
  66. export default {
  67. components: { ErpNavBar },
  68. data() {
  69. return {
  70. uploading: false,
  71. pendingAvatarOssId: null,
  72. myInfo: {
  73. avatarUrl: '',
  74. userName: '',
  75. phone: '',
  76. avatar: null,
  77. authClientList: []
  78. }
  79. }
  80. },
  81. async onLoad() {
  82. await this.loadInfo();
  83. },
  84. methods: {
  85. async loadInfo() {
  86. try {
  87. uni.showLoading({ title: '加载中' });
  88. const res = await getMyInfo();
  89. uni.hideLoading();
  90. const d = res.data;
  91. this.myInfo = {
  92. avatarUrl: d.avatarUrl || '',
  93. userName: d.userName || '',
  94. phone: d.phone || '',
  95. avatar: d.avatar || null,
  96. authClientList: d.authClientList || []
  97. };
  98. this.pendingAvatarOssId = null;
  99. } catch (e) {
  100. uni.hideLoading();
  101. uni.showToast({ title: e || '加载失败', icon: 'none' });
  102. }
  103. },
  104. doChooseImage() {
  105. uni.chooseImage({
  106. count: 1,
  107. sizeType: ['compressed'],
  108. sourceType: ['album', 'camera'],
  109. success: async (res) => {
  110. const tempPath = res.tempFilePaths[0];
  111. this.myInfo.avatarUrl = tempPath;
  112. this.uploading = true;
  113. try {
  114. const uploadRes = await uploadFile(tempPath);
  115. this.pendingAvatarOssId = uploadRes.ossId;
  116. uni.showToast({ title: '头像上传成功', icon: 'success' });
  117. } catch (e) {
  118. uni.showToast({ title: e || '头像上传失败', icon: 'none' });
  119. this.myInfo.avatarUrl = '';
  120. } finally {
  121. this.uploading = false;
  122. }
  123. }
  124. });
  125. },
  126. doEditName() {
  127. uni.showModal({
  128. title: '设置昵称',
  129. content: this.myInfo.userName,
  130. editable: true,
  131. confirmColor: '#C1001C',
  132. success: (res) => {
  133. if (res.confirm) {
  134. this.myInfo.userName = res.content || this.myInfo.userName;
  135. }
  136. }
  137. });
  138. },
  139. saveProfile() {
  140. if (this.uploading) return;
  141. uni.showModal({
  142. title: '确认保存',
  143. content: `昵称:${this.myInfo.userName}\n手机:${this.myInfo.phone}\n请确认以上信息是否填写正确?`,
  144. confirmText: '确认',
  145. cancelText: '取消',
  146. confirmColor: '#C1001C',
  147. success: async (res) => {
  148. if (!res.confirm) return;
  149. try {
  150. uni.showLoading({ title: '保存中' });
  151. const payload = { userName: this.myInfo.userName };
  152. if (this.pendingAvatarOssId !== null) {
  153. payload.avatar = this.pendingAvatarOssId;
  154. }
  155. await updateMyInfo(payload);
  156. uni.hideLoading();
  157. uni.showToast({ title: '保存成功', icon: 'success' });
  158. setTimeout(() => { uni.navigateBack(); }, 1200);
  159. } catch (e) {
  160. uni.hideLoading();
  161. uni.showToast({ title: e || '保存失败', icon: 'none' });
  162. }
  163. }
  164. });
  165. }
  166. }
  167. }
  168. </script>
  169. <style scoped>
  170. .settings-root {
  171. width: 100vw;
  172. height: 100vh;
  173. background: #f8fafb;
  174. display: flex;
  175. flex-direction: column;
  176. }
  177. .settings-list {
  178. background: #fff;
  179. padding: 0 40rpx;
  180. }
  181. .mt-30 {
  182. margin-top: 30rpx;
  183. }
  184. .item-row {
  185. display: flex;
  186. justify-content: space-between;
  187. align-items: center;
  188. min-height: 110rpx;
  189. border-bottom: 2rpx solid #f9f9f9;
  190. }
  191. .item-row:last-child {
  192. border-bottom: none;
  193. }
  194. .avatar-row {
  195. height: 180rpx;
  196. }
  197. .item-label {
  198. font-size: 32rpx;
  199. color: #333;
  200. }
  201. .item-right {
  202. display: flex;
  203. align-items: center;
  204. }
  205. .avatar-wrapper {
  206. position: relative;
  207. width: 110rpx;
  208. height: 110rpx;
  209. margin-right: 20rpx;
  210. }
  211. .avatar-img {
  212. width: 110rpx;
  213. height: 110rpx;
  214. border-radius: 50%;
  215. background: #eee;
  216. }
  217. .avatar-uploading {
  218. position: absolute;
  219. top: 0;
  220. left: 0;
  221. width: 100%;
  222. height: 100%;
  223. border-radius: 50%;
  224. background: rgba(0, 0, 0, 0.45);
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. }
  229. .uploading-text {
  230. font-size: 20rpx;
  231. color: #fff;
  232. }
  233. .item-value {
  234. font-size: 30rpx;
  235. color: #666;
  236. margin-right: 15rpx;
  237. }
  238. .item-value.readonly {
  239. color: #aaa;
  240. margin-right: 0;
  241. }
  242. .icon-more {
  243. width: 14rpx;
  244. height: 14rpx;
  245. border-top: 3rpx solid #ccc;
  246. border-right: 3rpx solid #ccc;
  247. transform: rotate(45deg);
  248. }
  249. .footer-bar {
  250. padding: 40rpx;
  251. margin-top: auto;
  252. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  253. }
  254. .btn-confirm {
  255. width: 100%;
  256. height: 90rpx;
  257. background: #C1001C;
  258. color: #fff;
  259. border-radius: 45rpx;
  260. font-size: 32rpx;
  261. font-weight: bold;
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. }
  266. .section-card {
  267. background: #fff;
  268. border-radius: 24rpx;
  269. padding: 30rpx 40rpx;
  270. }
  271. .section-header {
  272. display: flex;
  273. justify-content: space-between;
  274. align-items: center;
  275. margin-bottom: 24rpx;
  276. }
  277. .section-title {
  278. font-size: 32rpx;
  279. font-weight: bold;
  280. color: #333;
  281. }
  282. .section-desc {
  283. font-size: 24rpx;
  284. color: #999;
  285. }
  286. .client-list {
  287. display: flex;
  288. flex-direction: column;
  289. }
  290. .client-item {
  291. display: flex;
  292. align-items: center;
  293. padding: 24rpx 0;
  294. border-bottom: 1rpx solid #f5f6f7;
  295. }
  296. .client-item:last-child {
  297. border-bottom: none;
  298. }
  299. .client-index {
  300. width: 48rpx;
  301. height: 48rpx;
  302. border-radius: 50%;
  303. background: #F5F7FA;
  304. color: #666;
  305. font-size: 24rpx;
  306. font-weight: 600;
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. margin-right: 24rpx;
  311. flex-shrink: 0;
  312. }
  313. .client-info {
  314. flex: 1;
  315. display: flex;
  316. flex-direction: column;
  317. gap: 8rpx;
  318. min-width: 0;
  319. }
  320. .client-name {
  321. font-size: 28rpx;
  322. color: #333;
  323. font-weight: 500;
  324. }
  325. .client-meta {
  326. display: flex;
  327. align-items: center;
  328. gap: 16rpx;
  329. }
  330. .client-class {
  331. font-size: 24rpx;
  332. color: #C1001C;
  333. background: rgba(193, 0, 28, 0.06);
  334. padding: 2rpx 12rpx;
  335. border-radius: 6rpx;
  336. }
  337. .client-date {
  338. font-size: 22rpx;
  339. color: #999;
  340. }
  341. .no-client {
  342. display: flex;
  343. justify-content: center;
  344. padding: 40rpx 0;
  345. }
  346. .no-client-text {
  347. font-size: 26rpx;
  348. color: #ccc;
  349. }
  350. </style>