index.vue 8.3 KB

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