index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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, uploadFile } from '@/api/fulfiller'
  109. import { getAreaStationList } from '@/api/system/areaStation'
  110. export default {
  111. data() {
  112. return {
  113. userInfo: {
  114. name: '',
  115. workType: '',
  116. workStatus: '',
  117. city: '',
  118. avatar: '/static/touxiang.png',
  119. stationName: '',
  120. stationFullName: ''
  121. },
  122. isStatusPickerShow: false,
  123. isCityPickerShow: false,
  124. // 城市站点级联选择器
  125. selectStep: 0,
  126. selectedPathway: [],
  127. currentCityList: [],
  128. selectedCityId: null,
  129. fullTree: [] // 树形结构数据
  130. }
  131. },
  132. onLoad() {
  133. this.loadUserInfo();
  134. uni.$on('updateName', (newName) => {
  135. this.userInfo.name = newName;
  136. });
  137. },
  138. onUnload() {
  139. uni.$off('updateName');
  140. },
  141. methods: {
  142. // 加载用户信息 @author steelwei
  143. async loadUserInfo() {
  144. uni.showLoading({ title: '加载中...' });
  145. try {
  146. const res = await getMyProfile();
  147. if (res.code === 200) {
  148. const data = res.data;
  149. this.userInfo = {
  150. name: data.realName || data.name,
  151. workType: data.workType === 'full_time' ? '全职' : '兼职',
  152. workStatus: this.formatStatus(data.status),
  153. city: data.cityName || '',
  154. avatar: data.avatarUrl || '/static/touxiang.png',
  155. stationName: data.stationName || '',
  156. stationFullName: data.cityName && data.stationName ? `${data.cityName}/${data.stationName}` : (data.stationName || '未分配站点')
  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. navBack() {
  178. uni.navigateBack({ delta: 1 });
  179. },
  180. // 修改头像 @author steelwei
  181. changeAvatar() {
  182. uni.chooseImage({
  183. count: 1,
  184. success: async (res) => {
  185. const tempFilePath = res.tempFilePaths[0];
  186. // 上传图片到服务器
  187. uni.showLoading({ title: '上传中...' });
  188. try {
  189. const uploadRes = await uploadFile(tempFilePath);
  190. if (uploadRes.code === 200) {
  191. const { url, ossId } = uploadRes.data;
  192. // 调用接口更新头像 @author steelwei
  193. const result = await updateAvatar(ossId);
  194. if (result.code === 200) {
  195. this.userInfo.avatar = url;
  196. uni.showToast({ title: '修改成功', icon: 'success' });
  197. } else {
  198. uni.showToast({ title: result.msg || '修改失败', icon: 'none' });
  199. }
  200. }
  201. } catch (error) {
  202. console.error('修改头像失败:', error);
  203. uni.showToast({ title: '上传失败', icon: 'none' });
  204. } finally {
  205. uni.hideLoading();
  206. }
  207. }
  208. });
  209. },
  210. editName() {
  211. uni.navigateTo({
  212. url: `/pages/mine/settings/profile/edit-name?name=${this.userInfo.name}`
  213. });
  214. },
  215. showStatusPicker() {
  216. this.isStatusPickerShow = true;
  217. },
  218. closeStatusPicker() {
  219. this.isStatusPickerShow = false;
  220. },
  221. // 选择状态 @author steelwei
  222. async selectStatus(statusText) {
  223. const statusMap = {
  224. '接单中': 'busy',
  225. '休息中': 'resting'
  226. };
  227. const status = statusMap[statusText];
  228. try {
  229. const res = await updateStatus(status);
  230. if (res.code === 200) {
  231. this.userInfo.workStatus = statusText;
  232. uni.showToast({ title: '状态已更新', icon: 'success' });
  233. } else {
  234. uni.showToast({ title: res.msg || '修改失败', icon: 'none' });
  235. }
  236. } catch (error) {
  237. console.error('修改状态失败:', error);
  238. uni.showToast({ title: '网络错误', icon: 'none' });
  239. } finally {
  240. this.closeStatusPicker();
  241. }
  242. },
  243. // 城市和站点级联选择器 @author steelwei
  244. async showCityPicker() {
  245. this.isCityPickerShow = true;
  246. if (this.fullTree.length === 0) {
  247. await this.loadAreaStationTree();
  248. }
  249. if (this.selectedPathway.length === 0) {
  250. this.resetCityPicker();
  251. }
  252. },
  253. async loadAreaStationTree() {
  254. try {
  255. uni.showLoading({ title: '加载中...' });
  256. const res = await getAreaStationList();
  257. const list = res.data || [];
  258. // 列表转树形结构
  259. let map = {};
  260. let roots = [];
  261. list.forEach(node => {
  262. map[node.id] = { ...node, children: [] };
  263. });
  264. list.forEach(node => {
  265. if (node.parentId === 0 || !map[node.parentId]) {
  266. roots.push(map[node.id]);
  267. } else {
  268. map[node.parentId].children.push(map[node.id]);
  269. }
  270. });
  271. this.fullTree = roots;
  272. } catch (err) {
  273. console.error('加载站点数据失败:', err);
  274. this.fullTree = [];
  275. } finally {
  276. uni.hideLoading();
  277. }
  278. },
  279. resetCityPicker() {
  280. this.selectStep = 0;
  281. this.selectedPathway = [];
  282. this.currentCityList = this.fullTree;
  283. },
  284. closeCityPicker() {
  285. this.isCityPickerShow = false;
  286. },
  287. selectCityItem(item) {
  288. this.selectedPathway[this.selectStep] = item;
  289. // 如果有下级(如城市下的区域,区域下的站点)则继续选
  290. if (item.children && item.children.length > 0) {
  291. this.selectStep++;
  292. this.selectedPathway = this.selectedPathway.slice(0, this.selectStep);
  293. this.currentCityList = item.children;
  294. } else {
  295. // 没有下级,直接确认
  296. this.selectedCityId = item.id;
  297. this.confirmCity();
  298. }
  299. },
  300. jumpToStep(step) {
  301. this.selectStep = step;
  302. if (step === 0) {
  303. this.currentCityList = this.fullTree;
  304. } else {
  305. const parent = this.selectedPathway[step - 1];
  306. this.currentCityList = parent ? parent.children : [];
  307. }
  308. },
  309. // 确认城市与站点选择 @author steelwei
  310. async confirmCity() {
  311. if (this.selectedPathway.length === 0) {
  312. uni.showToast({ title: '请选择站点', icon: 'none' });
  313. return;
  314. }
  315. // 找出最后选中的节点 (站点)
  316. let stationNode = this.selectedPathway[this.selectedPathway.length - 1];
  317. // 将路径名称用 / 加起来
  318. const fullName = this.selectedPathway.map(i => i.name).join('/');
  319. const reqData = {
  320. stationId: stationNode.id
  321. };
  322. try {
  323. const res = await updateCity(reqData);
  324. if (res.code === 200) {
  325. this.userInfo.stationFullName = fullName;
  326. uni.showToast({ title: '修改成功', icon: 'success' });
  327. this.closeCityPicker();
  328. // 重置以便下一次打开
  329. this.selectedPathway = [];
  330. } else {
  331. uni.showToast({ title: res.msg || '修改失败', icon: 'none' });
  332. }
  333. } catch (error) {
  334. console.error('修改失败:', error);
  335. uni.showToast({ title: '网络错误', icon: 'none' });
  336. }
  337. }
  338. }
  339. }
  340. </script>
  341. <style>
  342. page {
  343. background-color: #F8F8F8;
  344. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  345. }
  346. .custom-header {
  347. position: fixed;
  348. top: 0;
  349. left: 0;
  350. width: 100%;
  351. height: 88rpx;
  352. padding-top: var(--status-bar-height);
  353. background-color: #fff;
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. padding-left: 30rpx;
  358. padding-right: 30rpx;
  359. box-sizing: content-box;
  360. z-index: 100;
  361. }
  362. .header-placeholder {
  363. height: calc(88rpx + var(--status-bar-height));
  364. }
  365. .back-icon {
  366. width: 40rpx;
  367. height: 40rpx;
  368. }
  369. .header-title {
  370. font-size: 28rpx; /* 14pt */
  371. font-weight: bold;
  372. color: #333;
  373. }
  374. .header-right {
  375. width: 40rpx;
  376. }
  377. .container {
  378. padding: 20rpx 30rpx;
  379. }
  380. .group-card {
  381. background-color: #fff;
  382. border-radius: 20rpx;
  383. padding: 0 30rpx;
  384. margin-bottom: 30rpx;
  385. }
  386. .list-item {
  387. display: flex;
  388. justify-content: space-between;
  389. align-items: center;
  390. height: 100rpx;
  391. border-bottom: 1px solid #F5F5F5;
  392. }
  393. .list-item.no-border {
  394. border-bottom: none;
  395. }
  396. .item-title {
  397. font-size: 28rpx;
  398. color: #333;
  399. }
  400. .item-right {
  401. display: flex;
  402. align-items: center;
  403. }
  404. .arrow-icon {
  405. width: 28rpx;
  406. height: 28rpx;
  407. opacity: 0.5;
  408. margin-left: 10rpx;
  409. }
  410. .user-avatar {
  411. width: 64rpx; /* Smaller avatar */
  412. height: 64rpx;
  413. border-radius: 50%;
  414. }
  415. .item-value {
  416. font-size: 28rpx;
  417. color: #999;
  418. }
  419. .item-value-black {
  420. font-size: 28rpx;
  421. color: #333;
  422. font-weight: 500;
  423. }
  424. .tag-blue-outline {
  425. font-size: 24rpx;
  426. color: #2979FF;
  427. border: 1px solid #2979FF;
  428. padding: 4rpx 20rpx;
  429. border-radius: 30rpx;
  430. background-color: #fff;
  431. }
  432. /* Popup Styles */
  433. .popup-mask {
  434. position: fixed;
  435. top: 0;
  436. left: 0;
  437. width: 100%;
  438. height: 100%;
  439. background-color: rgba(0,0,0,0.5);
  440. z-index: 999;
  441. display: flex;
  442. align-items: flex-end;
  443. }
  444. .popup-content {
  445. width: 100%;
  446. background-color: #fff;
  447. border-top-left-radius: 20rpx;
  448. border-top-right-radius: 20rpx;
  449. padding-bottom: 30rpx; /* Safe area */
  450. }
  451. .popup-title {
  452. text-align: center;
  453. font-size: 28rpx;
  454. color: #999;
  455. padding: 30rpx 0;
  456. border-bottom: 1px solid #eee;
  457. }
  458. .popup-item {
  459. text-align: center;
  460. font-size: 32rpx;
  461. color: #333;
  462. padding: 30rpx 0;
  463. border-bottom: 1px solid #eee;
  464. }
  465. .popup-cancel {
  466. text-align: center;
  467. font-size: 32rpx;
  468. color: #333;
  469. padding: 30rpx 0;
  470. margin-top: 20rpx;
  471. border-top: 10rpx solid #f5f5f5;
  472. }
  473. .popup-header-row {
  474. display: flex;
  475. justify-content: space-between;
  476. padding: 30rpx;
  477. border-bottom: 1px solid #eee;
  478. }
  479. .popup-btn-cancel { font-size: 28rpx; color: #666; }
  480. .popup-title-text { font-size: 32rpx; font-weight: bold; color: #333; }
  481. .popup-btn-confirm { font-size: 28rpx; color: #FF5722; font-weight: bold; }
  482. /* 级联城市选择器(与我要加入页面一致) */
  483. .picker-body {
  484. display: flex;
  485. height: 500rpx;
  486. }
  487. .timeline-area {
  488. width: 240rpx;
  489. padding: 20rpx;
  490. background: #f8f8f8;
  491. border-right: 1px solid #eee;
  492. overflow-y: auto;
  493. }
  494. .timeline-item {
  495. display: flex;
  496. align-items: center;
  497. padding: 16rpx 0;
  498. font-size: 26rpx;
  499. color: #666;
  500. }
  501. .timeline-item.active {
  502. color: #FF5722;
  503. font-weight: bold;
  504. }
  505. .timeline-dot {
  506. width: 16rpx;
  507. height: 16rpx;
  508. border-radius: 50%;
  509. background: #ccc;
  510. margin-right: 12rpx;
  511. flex-shrink: 0;
  512. }
  513. .timeline-item.active .timeline-dot {
  514. background: #FF5722;
  515. }
  516. .list-area {
  517. flex: 1;
  518. height: 100%;
  519. }
  520. .list-area .list-item {
  521. padding: 24rpx 30rpx;
  522. font-size: 28rpx;
  523. color: #333;
  524. border-bottom: 1px solid #f5f5f5;
  525. }
  526. </style>