index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <view class="container">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header">
  5. <view class="header-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);">
  7. </image>
  8. </view>
  9. <text class="header-title">个人资料</text>
  10. <view class="header-right"></view>
  11. </view>
  12. <view class="header-placeholder"></view>
  13. <view class="group-card">
  14. <view class="list-item" @click="changeAvatar">
  15. <text class="item-title">头像</text>
  16. <view class="item-right">
  17. <image class="user-avatar" :src="userInfo.avatar" mode="aspectFill"></image>
  18. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  19. </view>
  20. </view>
  21. <view class="list-item" @click="editName">
  22. <text class="item-title">真实姓名</text>
  23. <view class="item-right">
  24. <text class="item-value">{{ userInfo.name }}</text>
  25. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="group-card">
  30. <!-- <view class="list-item">
  31. <text class="item-title">工作类型</text>
  32. <view class="tag-blue-outline">{{ userInfo.workType }}</view>
  33. </view> -->
  34. <view class="list-item" @click="showStatusPicker">
  35. <text class="item-title">工作状态</text>
  36. <view class="item-right">
  37. <text class="item-value-black">{{ userInfo.workStatus }}</text>
  38. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="group-card">
  43. <view class="list-item no-border" @click="showCityPicker">
  44. <text class="item-title">所属站点</text>
  45. <view class="item-right">
  46. <text class="item-value">{{ userInfo.stationFullName || '未分配站点' }}</text>
  47. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 工作状态选择弹窗 -->
  52. <view class="popup-mask" v-if="isStatusPickerShow" @click="closeStatusPicker">
  53. <view class="popup-content" @click.stop>
  54. <view class="popup-title">选择工作状态</view>
  55. <view class="popup-item" @click="selectStatus('接单中')">接单中</view>
  56. <view class="popup-item" @click="selectStatus('休息中')">休息中</view>
  57. <view class="popup-cancel" @click="closeStatusPicker">取消</view>
  58. </view>
  59. </view>
  60. <!-- 城市站点选择弹窗 (级联版树形结构) -->
  61. <view class="popup-mask" v-if="isCityPickerShow" @click="closeCityPicker">
  62. <view class="popup-content" @click.stop>
  63. <view class="popup-header-row">
  64. <text class="popup-btn-cancel" @click="closeCityPicker">取消</text>
  65. <text class="popup-title-text">请选择工作城市和站点</text>
  66. <text class="popup-btn-confirm" @click="confirmCity">确定</text>
  67. </view>
  68. <view class="picker-body">
  69. <!-- 左侧:垂直路径 -->
  70. <view class="timeline-area">
  71. <view class="timeline-item" v-for="(item, index) in selectedPathway" :key="index"
  72. @click="jumpToStep(index)">
  73. <view class="timeline-dot"></view>
  74. <text>{{ item.name }}</text>
  75. </view>
  76. <view class="timeline-item active" v-if="selectStep === selectedPathway.length">
  77. <view class="timeline-dot"></view>
  78. <text>请选择</text>
  79. </view>
  80. </view>
  81. <!-- 右侧:待选项列表 -->
  82. <scroll-view scroll-y class="list-area">
  83. <view class="list-item" v-for="item in currentCityList" :key="item.id"
  84. @click="selectCityItem(item)">
  85. {{ item.name }}
  86. </view>
  87. <view v-if="currentCityList.length === 0" style="padding:20rpx;color:#999">
  88. 无数据
  89. </view>
  90. </scroll-view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. // 引入 API @author steelwei
  98. import { getMyProfile, updateAvatar, updateName, updateStatus, updateCity } from '@/api/fulfiller/fulfiller'
  99. import { uploadFile } from '@/api/fulfiller/app'
  100. import { getAreaStationList } from '@/api/system/areaStation'
  101. export default {
  102. data() {
  103. return {
  104. userInfo: {
  105. name: '',
  106. workType: '',
  107. workStatus: '',
  108. city: '',
  109. avatar: '/static/touxiang.png',
  110. stationName: '',
  111. stationFullName: ''
  112. },
  113. isStatusPickerShow: false,
  114. isCityPickerShow: false,
  115. // 城市站点级联选择器
  116. selectStep: 0,
  117. selectedPathway: [],
  118. currentCityList: [],
  119. selectedCityId: null,
  120. fullTree: [] // 树形结构数据
  121. }
  122. },
  123. onLoad() {
  124. this.loadUserInfo();
  125. uni.$on('updateName', (newName) => {
  126. this.userInfo.name = newName;
  127. });
  128. },
  129. onUnload() {
  130. uni.$off('updateName');
  131. },
  132. methods: {
  133. // 加载用户信息 @author steelwei
  134. async loadUserInfo() {
  135. uni.showLoading({ title: '加载中...' });
  136. try {
  137. const res = await getMyProfile();
  138. if (res.code === 200) {
  139. const data = res.data;
  140. this.userInfo = {
  141. name: data.realName || data.name,
  142. workType: data.workType === 'full_time' ? '全职' : '兼职',
  143. workStatus: this.formatStatus(data.status),
  144. city: data.cityName || '',
  145. avatar: data.avatarUrl || '/static/touxiang.png',
  146. stationName: data.stationName || '',
  147. stationFullName: '加载中...'
  148. };
  149. // 异步查找完整路径
  150. if (data.stationId) {
  151. if (this.fullTree.length === 0) {
  152. await this.loadAreaStationTree();
  153. }
  154. this.userInfo.stationFullName = this.findStationFullName(data.stationId, this.fullTree) || data.stationName || '未分配站点';
  155. } else {
  156. this.userInfo.stationFullName = '未分配站点';
  157. }
  158. } else {
  159. uni.showToast({ title: res.msg || '加载失败', icon: 'none' });
  160. }
  161. } catch (error) {
  162. console.error('加载用户信息失败:', error);
  163. uni.showToast({ title: '网络错误', icon: 'none' });
  164. } finally {
  165. uni.hideLoading();
  166. }
  167. },
  168. // 格式化状态 @author steelwei
  169. formatStatus(status) {
  170. const statusMap = {
  171. 'busy': '接单中',
  172. 'resting': '休息中',
  173. 'disabled': '已禁用'
  174. };
  175. return statusMap[status] || status;
  176. },
  177. // 查找站点完整路径 (城市/区域/站点) @author steelwei
  178. findStationFullName(stationId, tree) {
  179. if (!stationId || !tree || tree.length === 0) return '';
  180. let path = [];
  181. const dfs = (nodes, targetId, currentPath) => {
  182. for (let node of nodes) {
  183. if (node.id === targetId) {
  184. path = [...currentPath, node.name];
  185. return true;
  186. }
  187. if (node.children && node.children.length > 0) {
  188. if (dfs(node.children, targetId, [...currentPath, node.name])) {
  189. return true;
  190. }
  191. }
  192. }
  193. return false;
  194. };
  195. dfs(tree, stationId, []);
  196. return path.join('/');
  197. },
  198. navBack() {
  199. uni.navigateBack({ delta: 1 });
  200. },
  201. // 修改头像 @author steelwei
  202. changeAvatar() {
  203. uni.chooseImage({
  204. count: 1,
  205. success: async (res) => {
  206. const tempFilePath = res.tempFilePaths[0];
  207. // 上传图片到服务器
  208. uni.showLoading({ title: '上传中...' });
  209. try {
  210. const uploadRes = await uploadFile(tempFilePath);
  211. if (uploadRes.code === 200) {
  212. const { url, ossId } = uploadRes.data;
  213. // 调用接口更新头像 @author steelwei
  214. const result = await updateAvatar(ossId);
  215. if (result.code === 200) {
  216. this.userInfo.avatar = url;
  217. uni.showToast({ title: '修改成功', icon: 'success' });
  218. } else {
  219. uni.showToast({ title: result.msg || '修改失败', icon: 'none' });
  220. }
  221. }
  222. } catch (error) {
  223. console.error('修改头像失败:', error);
  224. uni.showToast({ title: '上传失败', icon: 'none' });
  225. } finally {
  226. uni.hideLoading();
  227. }
  228. }
  229. });
  230. },
  231. editName() {
  232. uni.navigateTo({
  233. url: `/pages/mine/settings/profile/edit-name/index?name=${this.userInfo.name}`
  234. });
  235. },
  236. showStatusPicker() {
  237. this.isStatusPickerShow = true;
  238. },
  239. closeStatusPicker() {
  240. this.isStatusPickerShow = false;
  241. },
  242. // 选择状态 @author steelwei
  243. async selectStatus(statusText) {
  244. const statusMap = {
  245. '接单中': 'busy',
  246. '休息中': 'resting'
  247. };
  248. const status = statusMap[statusText];
  249. try {
  250. const res = await updateStatus(status);
  251. if (res.code === 200) {
  252. this.userInfo.workStatus = statusText;
  253. uni.showToast({ title: '状态已更新', icon: 'success' });
  254. } else {
  255. uni.showToast({ title: res.msg || '修改失败', icon: 'none' });
  256. }
  257. } catch (error) {
  258. console.error('修改状态失败:', error);
  259. uni.showToast({ title: '网络错误', icon: 'none' });
  260. } finally {
  261. this.closeStatusPicker();
  262. }
  263. },
  264. // 城市和站点级联选择器 @author steelwei
  265. async showCityPicker() {
  266. this.isCityPickerShow = true;
  267. if (this.fullTree.length === 0) {
  268. await this.loadAreaStationTree();
  269. }
  270. if (this.selectedPathway.length === 0) {
  271. this.resetCityPicker();
  272. }
  273. },
  274. async loadAreaStationTree() {
  275. try {
  276. uni.showLoading({ title: '加载中...' });
  277. const res = await getAreaStationList();
  278. const list = res.data || [];
  279. // 列表转树形结构
  280. let map = {};
  281. let roots = [];
  282. list.forEach(node => {
  283. map[node.id] = { ...node, children: [] };
  284. });
  285. list.forEach(node => {
  286. if (node.parentId === 0 || !map[node.parentId]) {
  287. roots.push(map[node.id]);
  288. } else {
  289. map[node.parentId].children.push(map[node.id]);
  290. }
  291. });
  292. this.fullTree = roots;
  293. } catch (err) {
  294. console.error('加载站点数据失败:', err);
  295. this.fullTree = [];
  296. } finally {
  297. uni.hideLoading();
  298. }
  299. },
  300. resetCityPicker() {
  301. this.selectStep = 0;
  302. this.selectedPathway = [];
  303. this.currentCityList = this.fullTree;
  304. },
  305. closeCityPicker() {
  306. this.isCityPickerShow = false;
  307. },
  308. selectCityItem(item) {
  309. this.selectedPathway[this.selectStep] = item;
  310. // 如果有下级(如城市下的区域,区域下的站点)则继续选
  311. if (item.children && item.children.length > 0) {
  312. this.selectStep++;
  313. this.selectedPathway = this.selectedPathway.slice(0, this.selectStep);
  314. this.currentCityList = item.children;
  315. } else {
  316. // 没有下级,直接确认
  317. this.selectedCityId = item.id;
  318. this.confirmCity();
  319. }
  320. },
  321. jumpToStep(step) {
  322. this.selectStep = step;
  323. if (step === 0) {
  324. this.currentCityList = this.fullTree;
  325. } else {
  326. const parent = this.selectedPathway[step - 1];
  327. this.currentCityList = parent ? parent.children : [];
  328. }
  329. },
  330. // 确认城市与站点选择 @author steelwei
  331. async confirmCity() {
  332. if (this.selectedPathway.length === 0) {
  333. uni.showToast({ title: '请选择站点', icon: 'none' });
  334. return;
  335. }
  336. // 找出最后选中的节点 (站点)
  337. let stationNode = this.selectedPathway[this.selectedPathway.length - 1];
  338. // 将路径名称用 / 加起来
  339. const fullName = this.selectedPathway.map(i => i.name).join('/');
  340. const reqData = {
  341. stationId: stationNode.id
  342. };
  343. try {
  344. const res = await updateCity(reqData);
  345. if (res.code === 200) {
  346. this.userInfo.stationFullName = fullName;
  347. uni.showToast({ title: '修改成功', icon: 'success' });
  348. this.closeCityPicker();
  349. // 重置以便下一次打开
  350. this.selectedPathway = [];
  351. } else {
  352. uni.showToast({ title: res.msg || '修改失败', icon: 'none' });
  353. }
  354. } catch (error) {
  355. console.error('修改失败:', error);
  356. uni.showToast({ title: '网络错误', icon: 'none' });
  357. }
  358. }
  359. }
  360. }
  361. </script>
  362. <style>
  363. page {
  364. background-color: #F8F8F8;
  365. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  366. }
  367. .custom-header {
  368. position: fixed;
  369. top: 0;
  370. left: 0;
  371. width: 100%;
  372. height: 88rpx;
  373. padding-top: var(--status-bar-height);
  374. background-color: #fff;
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. padding-left: 30rpx;
  379. padding-right: 30rpx;
  380. box-sizing: content-box;
  381. z-index: 100;
  382. }
  383. .header-placeholder {
  384. height: calc(88rpx + var(--status-bar-height));
  385. }
  386. .back-icon {
  387. width: 40rpx;
  388. height: 40rpx;
  389. }
  390. .header-title {
  391. font-size: 28rpx;
  392. /* 14pt */
  393. font-weight: bold;
  394. color: #333;
  395. }
  396. .header-right {
  397. width: 40rpx;
  398. }
  399. .container {
  400. padding: 20rpx 30rpx;
  401. }
  402. .group-card {
  403. background-color: #fff;
  404. border-radius: 20rpx;
  405. padding: 0 30rpx;
  406. margin-bottom: 30rpx;
  407. }
  408. .list-item {
  409. display: flex;
  410. justify-content: space-between;
  411. align-items: center;
  412. height: 100rpx;
  413. border-bottom: 1px solid #F5F5F5;
  414. }
  415. .list-item.no-border {
  416. border-bottom: none;
  417. }
  418. .item-title {
  419. font-size: 28rpx;
  420. color: #333;
  421. }
  422. .item-right {
  423. display: flex;
  424. align-items: center;
  425. }
  426. .arrow-icon {
  427. width: 28rpx;
  428. height: 28rpx;
  429. opacity: 0.5;
  430. margin-left: 10rpx;
  431. }
  432. .user-avatar {
  433. width: 64rpx;
  434. /* Smaller avatar */
  435. height: 64rpx;
  436. border-radius: 50%;
  437. }
  438. .item-value {
  439. font-size: 28rpx;
  440. color: #999;
  441. }
  442. .item-value-black {
  443. font-size: 28rpx;
  444. color: #333;
  445. font-weight: 500;
  446. }
  447. .tag-blue-outline {
  448. font-size: 24rpx;
  449. color: #2979FF;
  450. border: 1px solid #2979FF;
  451. padding: 4rpx 20rpx;
  452. border-radius: 30rpx;
  453. background-color: #fff;
  454. }
  455. /* Popup Styles */
  456. .popup-mask {
  457. position: fixed;
  458. top: 0;
  459. left: 0;
  460. width: 100%;
  461. height: 100%;
  462. background-color: rgba(0, 0, 0, 0.5);
  463. z-index: 999;
  464. display: flex;
  465. align-items: flex-end;
  466. }
  467. .popup-content {
  468. width: 100%;
  469. background-color: #fff;
  470. border-top-left-radius: 20rpx;
  471. border-top-right-radius: 20rpx;
  472. padding-bottom: 30rpx;
  473. /* Safe area */
  474. }
  475. .popup-title {
  476. text-align: center;
  477. font-size: 28rpx;
  478. color: #999;
  479. padding: 30rpx 0;
  480. border-bottom: 1px solid #eee;
  481. }
  482. .popup-item {
  483. text-align: center;
  484. font-size: 32rpx;
  485. color: #333;
  486. padding: 30rpx 0;
  487. border-bottom: 1px solid #eee;
  488. }
  489. .popup-cancel {
  490. text-align: center;
  491. font-size: 32rpx;
  492. color: #333;
  493. padding: 30rpx 0;
  494. margin-top: 20rpx;
  495. border-top: 10rpx solid #f5f5f5;
  496. }
  497. .popup-header-row {
  498. display: flex;
  499. justify-content: space-between;
  500. padding: 30rpx;
  501. border-bottom: 1px solid #eee;
  502. }
  503. .popup-btn-cancel {
  504. font-size: 28rpx;
  505. color: #666;
  506. }
  507. .popup-title-text {
  508. font-size: 32rpx;
  509. font-weight: bold;
  510. color: #333;
  511. }
  512. .popup-btn-confirm {
  513. font-size: 28rpx;
  514. color: #FF5722;
  515. font-weight: bold;
  516. }
  517. /* 级联城市选择器(与我要加入页面一致) */
  518. .picker-body {
  519. display: flex;
  520. height: 500rpx;
  521. }
  522. .timeline-area {
  523. width: 240rpx;
  524. padding: 20rpx;
  525. background: #f8f8f8;
  526. border-right: 1px solid #eee;
  527. overflow-y: auto;
  528. }
  529. .timeline-item {
  530. display: flex;
  531. align-items: center;
  532. padding: 16rpx 0;
  533. font-size: 26rpx;
  534. color: #666;
  535. }
  536. .timeline-item.active {
  537. color: #FF5722;
  538. font-weight: bold;
  539. }
  540. .timeline-dot {
  541. width: 16rpx;
  542. height: 16rpx;
  543. border-radius: 50%;
  544. background: #ccc;
  545. margin-right: 12rpx;
  546. flex-shrink: 0;
  547. }
  548. .timeline-item.active .timeline-dot {
  549. background: #FF5722;
  550. }
  551. .list-area {
  552. flex: 1;
  553. height: 100%;
  554. }
  555. .list-area .list-item {
  556. padding: 24rpx 30rpx;
  557. font-size: 28rpx;
  558. color: #333;
  559. border-bottom: 1px solid #f5f5f5;
  560. }
  561. </style>