edit-profile.vue 14 KB

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