index.vue 19 KB

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