edit-profile.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view class="edit-profile">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="handleBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">编辑资料</text>
  9. <view class="right-empty"></view>
  10. </view>
  11. <scroll-view scroll-y class="content">
  12. <!-- 头像上传区域 -->
  13. <view class="avatar-section">
  14. <view class="avatar-container">
  15. <image class="avatar" :src="userInfo.avatar || defaultAvatar" mode="aspectFill"></image>
  16. <view class="avatar-upload-btn" @click="handleAvatarUpload">
  17. <text class="upload-icon">📷</text>
  18. </view>
  19. </view>
  20. <text class="avatar-text">更换头像</text>
  21. </view>
  22. <!-- 表单区域 -->
  23. <view class="form-section">
  24. <!-- 姓名 -->
  25. <view class="form-item">
  26. <view class="form-label">
  27. <text class="label-icon">👤</text>
  28. <text class="label-text">姓名</text>
  29. </view>
  30. <input
  31. class="form-input"
  32. v-model="userInfo.name"
  33. placeholder="请输入姓名"
  34. placeholder-style="color: #999"
  35. >
  36. </view>
  37. <!-- 性别 -->
  38. <view class="form-item">
  39. <view class="form-label">
  40. <text class="label-icon">⚧️</text>
  41. <text class="label-text">性别</text>
  42. </view>
  43. <picker class="form-picker gender-picker" @change="handleGenderChange" :value="genderIndex" :range="genderOptions">
  44. <view class="picker-content">
  45. {{ userInfo.gender || '请选择性别' }}
  46. </view>
  47. </picker>
  48. </view>
  49. <!-- 个人简介 -->
  50. <view class="form-item">
  51. <view class="form-label">
  52. <text class="label-icon">📝</text>
  53. <text class="label-text">个人简介</text>
  54. </view>
  55. <textarea
  56. class="form-textarea"
  57. v-model="userInfo.bio"
  58. placeholder="请输入个人简介"
  59. placeholder-style="color: #999"
  60. maxlength="200"
  61. auto-height
  62. ></textarea>
  63. </view>
  64. <!-- 邮箱 -->
  65. <view class="form-item">
  66. <view class="form-label">
  67. <text class="label-icon">📧</text>
  68. <text class="label-text">邮箱</text>
  69. </view>
  70. <input
  71. class="form-input"
  72. v-model="userInfo.email"
  73. placeholder="请输入邮箱"
  74. placeholder-style="color: #999"
  75. type="email"
  76. >
  77. </view>
  78. <!-- 省市区选择 -->
  79. <view class="form-item">
  80. <view class="form-label">
  81. <text class="label-icon">📍</text>
  82. <text class="label-text">所在地区</text>
  83. </view>
  84. <picker
  85. class="form-picker"
  86. mode="multiSelector"
  87. :value="multiIndex"
  88. :range="multiArray"
  89. @columnchange="handleColumnChange"
  90. @change="handleMultiPickerChange"
  91. >
  92. <view class="picker-content">{{ selectedArea || '请选择地区' }}</view>
  93. </picker>
  94. </view>
  95. <!-- 详细地址 -->
  96. <view class="form-item">
  97. <view class="form-label">
  98. <text class="label-icon">🏠</text>
  99. <text class="label-text">详细地址</text>
  100. </view>
  101. <textarea
  102. class="form-textarea"
  103. v-model="userInfo.address_detail"
  104. placeholder="请输入详细地址"
  105. placeholder-style="color: #999"
  106. maxlength="255"
  107. auto-height
  108. ></textarea>
  109. </view>
  110. </view>
  111. <!-- 保存按钮 -->
  112. <view class="save-btn-section">
  113. <button class="save-btn" @click="handleSave">保存</button>
  114. </view>
  115. </scroll-view>
  116. </view>
  117. </template>
  118. <script>
  119. export default {
  120. data() {
  121. return {
  122. // 默认头像
  123. defaultAvatar: 'https://q.qlogo.cn/qqapp/1105591438/05E13358B43B3D39D6AC2D6888828201/100',
  124. // 用户信息
  125. userInfo: {
  126. avatar: '',
  127. name: '',
  128. gender: '',
  129. bio: '我是一名专业的红娘,拥有丰富的婚恋服务经验,已成功帮助1200对单身男女找到幸福。',
  130. email: '',
  131. province_id: '',
  132. city_id: '',
  133. area_id: '',
  134. address_detail: '',
  135. province_name: '',
  136. city_name: '',
  137. area_name: ''
  138. },
  139. // 省市区多列选择器数据
  140. multiArray: [
  141. ['北京市', '天津市', '河北省', '山西省', '内蒙古自治区'],
  142. ['石家庄市', '唐山市', '秦皇岛市', '邯郸市', '邢台市', '保定市'],
  143. ['竞秀区', '莲池区', '满城区', '清苑区', '徐水区', '涞水县']
  144. ],
  145. multiIndex: [0, 0, 0],
  146. selectedArea: '',
  147. // 省市区详细数据(用于动态加载)
  148. areaData: {
  149. '北京市': {
  150. '北京市': ['东城区', '西城区', '朝阳区', '海淀区', '丰台区', '石景山区']
  151. },
  152. '天津市': {
  153. '天津市': ['和平区', '河东区', '河西区', '南开区', '河北区', '红桥区']
  154. },
  155. '河北省': {
  156. '石家庄市': ['长安区', '桥西区', '新华区', '井陉矿区', '裕华区', '藁城区'],
  157. '唐山市': ['路南区', '路北区', '古冶区', '开平区', '丰南区', '丰润区'],
  158. '秦皇岛市': ['海港区', '山海关区', '北戴河区', '抚宁区', '青龙满族自治县'],
  159. '邯郸市': ['邯山区', '丛台区', '复兴区', '峰峰矿区', '肥乡区', '永年区'],
  160. '邢台市': ['桥东区', '桥西区', '邢台县', '临城县', '内丘县', '柏乡县'],
  161. '保定市': ['竞秀区', '莲池区', '满城区', '清苑区', '徐水区', '涞水县']
  162. },
  163. '山西省': {
  164. '太原市': ['小店区', '迎泽区', '杏花岭区', '尖草坪区', '万柏林区', '晋源区']
  165. },
  166. '内蒙古自治区': {
  167. '呼和浩特市': ['新城区', '回民区', '玉泉区', '赛罕区', '土默特左旗']
  168. }
  169. },
  170. // 性别选项
  171. genderOptions: ['男', '女'],
  172. genderIndex: 0
  173. }
  174. },
  175. onLoad() {
  176. // 从本地存储获取用户信息
  177. this.loadUserInfo()
  178. },
  179. methods: {
  180. // 加载用户信息
  181. loadUserInfo() {
  182. const userInfo = uni.getStorageSync('matchmakerUserInfo')
  183. if (userInfo) {
  184. this.userInfo = {...this.userInfo, ...userInfo}
  185. // 设置性别索引
  186. this.genderIndex = this.genderOptions.indexOf(this.userInfo.gender) || 0
  187. // 如果有省市区信息,设置选中的区域文本
  188. if (this.userInfo.province_name && this.userInfo.city_name && this.userInfo.area_name) {
  189. this.selectedArea = `${this.userInfo.province_name} ${this.userInfo.city_name} ${this.userInfo.area_name}`
  190. // 设置对应的索引
  191. const provinceIndex = this.multiArray[0].indexOf(this.userInfo.province_name)
  192. if (provinceIndex !== -1) {
  193. this.multiIndex[0] = provinceIndex
  194. // 更新城市列表
  195. this.updateCityList(provinceIndex)
  196. const cityIndex = this.multiArray[1].indexOf(this.userInfo.city_name)
  197. if (cityIndex !== -1) {
  198. this.multiIndex[1] = cityIndex
  199. // 更新区县列表
  200. this.updateAreaList(provinceIndex, cityIndex)
  201. const areaIndex = this.multiArray[2].indexOf(this.userInfo.area_name)
  202. if (areaIndex !== -1) {
  203. this.multiIndex[2] = areaIndex
  204. }
  205. }
  206. }
  207. }
  208. }
  209. },
  210. // 更新城市列表
  211. updateCityList(provinceIndex) {
  212. const province = this.multiArray[0][provinceIndex]
  213. const cities = Object.keys(this.areaData[province] || {})
  214. this.multiArray[1] = cities
  215. this.multiIndex[1] = 0
  216. this.updateAreaList(provinceIndex, 0)
  217. },
  218. // 更新区县列表
  219. updateAreaList(provinceIndex, cityIndex) {
  220. const province = this.multiArray[0][provinceIndex]
  221. const city = this.multiArray[1][cityIndex]
  222. const areas = this.areaData[province]?.[city] || []
  223. this.multiArray[2] = areas
  224. this.multiIndex[2] = 0
  225. },
  226. // 处理列变化
  227. handleColumnChange(e) {
  228. const column = e.detail.column
  229. const value = e.detail.value
  230. this.multiIndex[column] = value
  231. // 根据列索引更新对应的数据
  232. if (column === 0) {
  233. // 省份变化,更新城市和区县
  234. this.updateCityList(value)
  235. } else if (column === 1) {
  236. // 城市变化,更新区县
  237. this.updateAreaList(this.multiIndex[0], value)
  238. }
  239. },
  240. // 处理多列选择器确认
  241. handleMultiPickerChange(e) {
  242. this.multiIndex = e.detail.value
  243. const province = this.multiArray[0][this.multiIndex[0]]
  244. const city = this.multiArray[1][this.multiIndex[1]]
  245. const area = this.multiArray[2][this.multiIndex[2]]
  246. this.selectedArea = `${province} ${city} ${area}`
  247. // 更新用户信息
  248. this.userInfo.province_id = this.multiIndex[0] + 1
  249. this.userInfo.city_id = this.multiIndex[1] + 1
  250. this.userInfo.area_id = this.multiIndex[2] + 1
  251. this.userInfo.province_name = province
  252. this.userInfo.city_name = city
  253. this.userInfo.area_name = area
  254. },
  255. // 返回上一页
  256. async handleBack() {
  257. uni.navigateBack({
  258. delta: 1
  259. })
  260. },
  261. // 更换头像
  262. handleAvatarUpload() {
  263. uni.chooseImage({
  264. count: 1,
  265. sizeType: ['compressed'],
  266. sourceType: ['album', 'camera'],
  267. success: (res) => {
  268. const tempFilePath = res.tempFilePaths[0]
  269. // 这里可以添加上传图片到服务器的逻辑
  270. this.userInfo.avatar = tempFilePath
  271. uni.showToast({
  272. title: '头像更换成功',
  273. icon: 'success'
  274. })
  275. }
  276. })
  277. },
  278. // 性别选择变化
  279. handleGenderChange(e) {
  280. const index = e.detail.value
  281. this.genderIndex = index
  282. this.userInfo.gender = this.genderOptions[index]
  283. },
  284. // 保存资料
  285. handleSave() {
  286. // 验证表单
  287. if (!this.userInfo.name) {
  288. uni.showToast({
  289. title: '请输入姓名',
  290. icon: 'none'
  291. })
  292. return
  293. }
  294. if (!this.userInfo.gender) {
  295. uni.showToast({
  296. title: '请选择性别',
  297. icon: 'none'
  298. })
  299. return
  300. }
  301. // 保存到本地存储
  302. uni.setStorageSync('matchmakerUserInfo', this.userInfo)
  303. // 提示保存成功
  304. uni.showToast({
  305. title: '资料保存成功',
  306. icon: 'success'
  307. })
  308. // 返回上一页
  309. setTimeout(() => {
  310. this.handleBack()
  311. }, 1500)
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .edit-profile {
  318. min-height: 100vh;
  319. background: #FFFFFF;
  320. display: flex;
  321. flex-direction: column;
  322. }
  323. /* 顶部导航栏 */
  324. .header {
  325. display: flex;
  326. align-items: center;
  327. justify-content: space-between;
  328. padding: 25rpx 30rpx;
  329. padding-top: calc(25rpx + env(safe-area-inset-top));
  330. background: #FFFFFF;
  331. border-bottom: 1rpx solid #F0F0F0;
  332. .back-btn {
  333. width: 44rpx;
  334. height: 44rpx;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. .back-icon {
  339. font-size: 40rpx;
  340. color: #333;
  341. }
  342. }
  343. .header-title {
  344. font-size: 38rpx;
  345. font-weight: bold;
  346. color: #333;
  347. }
  348. .right-empty {
  349. width: 44rpx;
  350. }
  351. }
  352. .content {
  353. flex: 1;
  354. padding-bottom: 40rpx;
  355. }
  356. /* 头像上传区域 */
  357. .avatar-section {
  358. display: flex;
  359. flex-direction: column;
  360. align-items: center;
  361. padding: 40rpx 0;
  362. border-bottom: 1rpx solid #F0F0F0;
  363. .avatar-container {
  364. position: relative;
  365. width: 160rpx;
  366. height: 160rpx;
  367. margin-bottom: 20rpx;
  368. .avatar {
  369. width: 100%;
  370. height: 100%;
  371. border-radius: 50%;
  372. background: #F5F5F5;
  373. }
  374. .avatar-upload-btn {
  375. position: absolute;
  376. bottom: 0;
  377. right: 0;
  378. width: 48rpx;
  379. height: 48rpx;
  380. display: flex;
  381. align-items: center;
  382. justify-content: center;
  383. background: #FFFFFF;
  384. border: 2rpx solid #E91E63;
  385. border-radius: 50%;
  386. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  387. .upload-icon {
  388. font-size: 28rpx;
  389. color: #E91E63;
  390. }
  391. }
  392. }
  393. .avatar-text {
  394. font-size: 28rpx;
  395. color: #E91E63;
  396. font-weight: 500;
  397. }
  398. }
  399. /* 表单区域 */
  400. .form-section {
  401. padding: 0 30rpx;
  402. .form-item {
  403. display: flex;
  404. flex-direction: column;
  405. padding: 25rpx 0;
  406. border-bottom: 1rpx solid #F5F5F5;
  407. &:last-child {
  408. border-bottom: none;
  409. }
  410. .form-label {
  411. display: flex;
  412. align-items: center;
  413. margin-bottom: 15rpx;
  414. .label-icon {
  415. font-size: 28rpx;
  416. margin-right: 12rpx;
  417. }
  418. .label-text {
  419. font-size: 28rpx;
  420. color: #333;
  421. font-weight: 500;
  422. }
  423. }
  424. .form-input,
  425. .form-picker {
  426. width: 90%;
  427. font-size: 28rpx;
  428. color: #333;
  429. padding: 18rpx 20rpx;
  430. background: #F9F9F9;
  431. border-radius: 12rpx;
  432. border: 1rpx solid #E0E0E0;
  433. &.readonly {
  434. background: #F5F5F5;
  435. color: #999;
  436. }
  437. }
  438. .form-picker {
  439. display: flex;
  440. align-items: center;
  441. .picker-content {
  442. flex: 1;
  443. }
  444. }
  445. /* 性别选择器特定样式 */
  446. .gender-picker {
  447. width: 10%;
  448. }
  449. .form-textarea {
  450. width: 90%;
  451. font-size: 28rpx;
  452. color: #333;
  453. padding: 20rpx;
  454. background: #F9F9F9;
  455. border-radius: 12rpx;
  456. border: 1rpx solid #E0E0E0;
  457. min-height: 160rpx;
  458. line-height: 1.5;
  459. }
  460. }
  461. }
  462. /* 保存按钮 */
  463. .save-btn-section {
  464. padding: 40rpx 30rpx;
  465. .save-btn {
  466. width: 100%;
  467. height: 90rpx;
  468. background: linear-gradient(135deg, #E91E63 0%, #FF6B8A 100%);
  469. color: #FFFFFF;
  470. font-size: 32rpx;
  471. font-weight: bold;
  472. border-radius: 45rpx;
  473. border: none;
  474. box-shadow: 0 6rpx 20rpx rgba(233, 30, 99, 0.3);
  475. transition: all 0.3s ease;
  476. &:active {
  477. transform: scale(0.98);
  478. box-shadow: 0 3rpx 10rpx rgba(233, 30, 99, 0.2);
  479. }
  480. }
  481. }
  482. </style>