index.vue 7.4 KB

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