index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view class="settings-root">
  3. <erp-nav-bar title="个人资料设置" />
  4. <!-- 资料列表 -->
  5. <view class="settings-list">
  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.name }}</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. <view class="settings-list mt-30">
  36. <view class="item-row" @click="goResetPassword">
  37. <text class="item-label">修改密码</text>
  38. <view class="item-right">
  39. <text class="icon-more"></text>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 授权客户列表 -->
  44. <view class="section-card" style="margin-top: 30rpx;">
  45. <view class="section-header">
  46. <view class="sh-left">
  47. <view class="sh-indicator"></view>
  48. <text class="section-title">授权客户</text>
  49. </view>
  50. <view class="sh-count" v-if="myInfo.authClientList">
  51. <text class="count-num">{{ myInfo.authClientList.length }}</text>
  52. <text class="count-unit">个</text>
  53. </view>
  54. </view>
  55. <view v-if="myInfo.authClientList && myInfo.authClientList.length > 0" class="client-list">
  56. <view class="client-item" v-for="(client, idx) in myInfo.authClientList" :key="idx">
  57. <view class="ci-avatar">
  58. <text class="ci-char">{{ (client.name || '-')[0] }}</text>
  59. </view>
  60. <view class="ci-body">
  61. <text class="ci-name">{{ client.name || '-' }}</text>
  62. <view class="ci-meta">
  63. <text class="ci-tag" v-if="client.clientClass">{{ client.clientClass }}</text>
  64. <text class="ci-date" v-if="client.enterDate">{{ client.enterDate }}</text>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="no-client" v-else>
  70. <text class="no-client-text">暂无授权客户</text>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import ErpNavBar from '@/components/erp-nav-bar.vue';
  77. import { getMyInfo, updateMyInfo } from '@/api/system/employee.js';
  78. import { getClientByIds } from '@/api/erp/client.js';
  79. import { uploadFile } from '@/api/resource/oss.js';
  80. export default {
  81. components: { ErpNavBar },
  82. data() {
  83. return {
  84. uploading: false,
  85. myInfo: {
  86. avatarUrl: '',
  87. name: '',
  88. phone: '',
  89. avatar: null,
  90. authClientList: []
  91. }
  92. }
  93. },
  94. async onLoad() {
  95. await this.loadInfo();
  96. },
  97. methods: {
  98. async loadInfo() {
  99. try {
  100. uni.showLoading({ title: '加载中' });
  101. const res = await getMyInfo();
  102. uni.hideLoading();
  103. const d = res.data;
  104. let clientList = [];
  105. if (d.authClientFRowIDs) {
  106. try {
  107. const clientRes = await getClientByIds(d.authClientFRowIDs);
  108. clientList = clientRes.data || [];
  109. } catch (e) {
  110. console.error('加载授权客户失败', e);
  111. }
  112. }
  113. this.myInfo = {
  114. avatarUrl: d.avatarUrl || '',
  115. name: d.name || '',
  116. phone: d.phone || '',
  117. avatar: d.avatar || null,
  118. authClientList: clientList
  119. };
  120. } catch (e) {
  121. uni.hideLoading();
  122. uni.showToast({ title: e || '加载失败', icon: 'none' });
  123. }
  124. },
  125. doChooseImage() {
  126. uni.chooseImage({
  127. count: 1,
  128. sizeType: ['compressed'],
  129. sourceType: ['album', 'camera'],
  130. success: async (res) => {
  131. const tempPath = res.tempFilePaths[0];
  132. const previousUrl = this.myInfo.avatarUrl;
  133. this.myInfo.avatarUrl = tempPath;
  134. this.uploading = true;
  135. try {
  136. const uploadRes = await uploadFile(tempPath);
  137. uni.showLoading({ title: '保存中' });
  138. await updateMyInfo({ avatar: uploadRes.ossId });
  139. uni.hideLoading();
  140. this.myInfo.avatar = uploadRes.ossId;
  141. this.myInfo.avatarUrl = uploadRes.url;
  142. uni.showToast({ title: '头像更新成功', icon: 'success' });
  143. } catch (e) {
  144. uni.hideLoading();
  145. this.myInfo.avatarUrl = previousUrl;
  146. uni.showToast({ title: e || '头像更新失败', icon: 'none' });
  147. } finally {
  148. this.uploading = false;
  149. }
  150. }
  151. });
  152. },
  153. doEditName() {
  154. uni.showModal({
  155. title: '设置昵称',
  156. content: this.myInfo.name,
  157. editable: true,
  158. confirmColor: '#C1001C',
  159. success: async (res) => {
  160. if (!res.confirm) return;
  161. const newName = res.content || this.myInfo.name;
  162. if (newName === this.myInfo.name) return;
  163. try {
  164. uni.showLoading({ title: '保存中' });
  165. await updateMyInfo({ name: newName });
  166. uni.hideLoading();
  167. this.myInfo.name = newName;
  168. uni.showToast({ title: '昵称更新成功', icon: 'success' });
  169. } catch (e) {
  170. uni.hideLoading();
  171. uni.showToast({ title: e || '昵称更新失败', icon: 'none' });
  172. }
  173. }
  174. });
  175. },
  176. goResetPassword() {
  177. uni.navigateTo({
  178. url: '/pages/mine/settings/resetPassword/index'
  179. });
  180. }
  181. }
  182. }
  183. </script>
  184. <style scoped>
  185. .settings-root {
  186. width: 100vw;
  187. height: 100vh;
  188. background: #F4F6F9;
  189. display: flex;
  190. flex-direction: column;
  191. }
  192. .settings-list {
  193. background: #fff;
  194. margin: 20rpx 24rpx 0;
  195. border-radius: 20rpx;
  196. padding: 0 36rpx;
  197. box-shadow: 0 2rpx 16rpx rgba(0, 0, 0, 0.02);
  198. }
  199. .mt-30 {
  200. margin-top: 24rpx;
  201. }
  202. .item-row {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. min-height: 104rpx;
  207. border-bottom: 1rpx solid #F0F0F3;
  208. }
  209. .item-row:last-child {
  210. border-bottom: none;
  211. }
  212. .avatar-row {
  213. min-height: 140rpx;
  214. }
  215. .item-label {
  216. font-size: 30rpx;
  217. color: #1A1A2E;
  218. font-weight: 500;
  219. }
  220. .item-right {
  221. display: flex;
  222. align-items: center;
  223. }
  224. .avatar-wrapper {
  225. position: relative;
  226. width: 96rpx;
  227. height: 96rpx;
  228. margin-right: 16rpx;
  229. }
  230. .avatar-img {
  231. width: 96rpx;
  232. height: 96rpx;
  233. border-radius: 24rpx;
  234. background: #F4F6F9;
  235. }
  236. .avatar-uploading {
  237. position: absolute;
  238. top: 0;
  239. left: 0;
  240. width: 100%;
  241. height: 100%;
  242. border-radius: 24rpx;
  243. background: rgba(0, 0, 0, 0.45);
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. }
  248. .uploading-text {
  249. font-size: 20rpx;
  250. color: #fff;
  251. }
  252. .item-value {
  253. font-size: 28rpx;
  254. color: #8896A8;
  255. margin-right: 12rpx;
  256. }
  257. .item-value.readonly {
  258. color: #B0B8C5;
  259. margin-right: 0;
  260. }
  261. .icon-more {
  262. width: 14rpx;
  263. height: 14rpx;
  264. border-top: 3rpx solid #CBD2DB;
  265. border-right: 3rpx solid #CBD2DB;
  266. transform: rotate(45deg);
  267. }
  268. .section-card {
  269. background: #fff;
  270. border-radius: 24rpx;
  271. padding: 36rpx;
  272. margin: 0 24rpx;
  273. box-shadow: 0 2rpx 16rpx rgba(0, 0, 0, 0.02);
  274. }
  275. .section-header {
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. margin-bottom: 28rpx;
  280. }
  281. .sh-left {
  282. display: flex;
  283. align-items: center;
  284. gap: 16rpx;
  285. }
  286. .sh-indicator {
  287. width: 6rpx;
  288. height: 36rpx;
  289. background: linear-gradient(180deg, #C1001C 0%, #E8553D 100%);
  290. border-radius: 3rpx;
  291. }
  292. .section-title {
  293. font-size: 30rpx;
  294. font-weight: 700;
  295. color: #1A1A2E;
  296. }
  297. .sh-count {
  298. display: flex;
  299. align-items: baseline;
  300. background: #F4F6F9;
  301. border-radius: 16rpx;
  302. padding: 6rpx 20rpx;
  303. }
  304. .count-num {
  305. font-size: 28rpx;
  306. font-weight: 700;
  307. color: #C1001C;
  308. }
  309. .count-unit {
  310. font-size: 22rpx;
  311. color: #8896A8;
  312. margin-left: 2rpx;
  313. }
  314. .client-list {
  315. display: flex;
  316. flex-direction: column;
  317. gap: 4rpx;
  318. }
  319. .client-item {
  320. display: flex;
  321. align-items: center;
  322. padding: 22rpx 0;
  323. border-bottom: 1rpx solid #F0F0F3;
  324. }
  325. .client-item:last-child {
  326. border-bottom: none;
  327. }
  328. .ci-avatar {
  329. width: 76rpx;
  330. height: 76rpx;
  331. border-radius: 20rpx;
  332. background: linear-gradient(135deg, #F9EAEC 0%, #FFF1F2 100%);
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. margin-right: 20rpx;
  337. flex-shrink: 0;
  338. }
  339. .ci-char {
  340. font-size: 34rpx;
  341. font-weight: 700;
  342. color: #C1001C;
  343. }
  344. .ci-body {
  345. flex: 1;
  346. display: flex;
  347. flex-direction: column;
  348. gap: 8rpx;
  349. min-width: 0;
  350. }
  351. .ci-name {
  352. font-size: 30rpx;
  353. color: #1A1A2E;
  354. font-weight: 600;
  355. overflow: hidden;
  356. text-overflow: ellipsis;
  357. white-space: nowrap;
  358. }
  359. .ci-meta {
  360. display: flex;
  361. align-items: center;
  362. gap: 14rpx;
  363. }
  364. .ci-tag {
  365. font-size: 22rpx;
  366. color: #5A6577;
  367. background: #F4F6F9;
  368. padding: 4rpx 14rpx;
  369. border-radius: 8rpx;
  370. }
  371. .ci-date {
  372. font-size: 22rpx;
  373. color: #B0B8C5;
  374. }
  375. .no-client {
  376. display: flex;
  377. justify-content: center;
  378. padding: 40rpx 0;
  379. }
  380. .no-client-text {
  381. font-size: 26rpx;
  382. color: #B0B8C5;
  383. }
  384. </style>