|
|
@@ -91,6 +91,14 @@
|
|
|
<text class="label">生肖</text>
|
|
|
<text class="value">{{ profile.animal || '未设置' }}</text>
|
|
|
</view>
|
|
|
+
|
|
|
+ <view class="info-item" :class="{ editing: isEditing }" @click="handleAreaClick">
|
|
|
+ <text class="label">地区</text>
|
|
|
+ <picker v-if="isEditing" mode="multiSelector" :range="multiAreaData" range-key="name" :value="multiAreaIndex" @change="onAreaChange" @columnchange="onAreaColumnChange">
|
|
|
+ <view class="picker-value">{{ getAreaText() }}</view>
|
|
|
+ </picker>
|
|
|
+ <text v-else class="value">{{ getAreaText() }}</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
|
|
|
<!-- 学业与工作 -->
|
|
|
@@ -289,6 +297,7 @@
|
|
|
<script>
|
|
|
import userAuth from '@/utils/userAuth.js'
|
|
|
import { getZodiacByBirthday } from '@/utils/zodiac.js'
|
|
|
+ import api from '@/utils/api.js'
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
@@ -327,7 +336,10 @@
|
|
|
isRealNameVerified: false,
|
|
|
isEducationVerified: false,
|
|
|
isWorkVerified: false,
|
|
|
- isMaritalVerified: false
|
|
|
+ isMaritalVerified: false,
|
|
|
+ provinceId: null,
|
|
|
+ cityId: null,
|
|
|
+ areaId: null
|
|
|
},
|
|
|
|
|
|
// 选项列表
|
|
|
@@ -374,7 +386,14 @@
|
|
|
tags: ['美食', '游戏', '宠物', '时尚', '购物', '化妆']
|
|
|
}
|
|
|
],
|
|
|
- customHobbyInput: ''
|
|
|
+ customHobbyInput: '',
|
|
|
+
|
|
|
+ // 省市区数据
|
|
|
+ provinceList: [],
|
|
|
+ cityList: [],
|
|
|
+ areaList: [],
|
|
|
+ multiAreaData: [[], [], []], // 三级联动数据
|
|
|
+ multiAreaIndex: [0, 0, 0] // 三级联动索引
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -401,6 +420,8 @@
|
|
|
this.checkLoginStatus()
|
|
|
} else {
|
|
|
console.log('已登录,用户ID:', this.currentUserId)
|
|
|
+ // 加载省市区数据
|
|
|
+ this.loadAreaData()
|
|
|
// 加载用户资料
|
|
|
this.loadProfile()
|
|
|
}
|
|
|
@@ -609,17 +630,61 @@
|
|
|
uni.request({
|
|
|
url: this.gatewayURL + '/api/user/profile?userId=' + this.currentUserId,
|
|
|
method: 'GET',
|
|
|
- success: (res) => {
|
|
|
+ success: async (res) => {
|
|
|
uni.hideLoading()
|
|
|
console.log('=== 用户资料加载 ===')
|
|
|
console.log('完整响应:', res.data)
|
|
|
|
|
|
- if (res.data && res.data.code === 200) {
|
|
|
- console.log('原始salaryRange:', res.data.data.salaryRange)
|
|
|
- this.profile = { ...this.profile, ...res.data.data }
|
|
|
- console.log('合并后的profile.salaryRange:', this.profile.salaryRange)
|
|
|
- console.log('显示的薪资文本:', this.getSalaryText())
|
|
|
- } else {
|
|
|
+ if (res.data && res.data.code === 200) {
|
|
|
+ console.log('原始salaryRange:', res.data.data.salaryRange)
|
|
|
+ console.log('完整返回数据:', JSON.stringify(res.data.data, null, 2))
|
|
|
+ console.log('省市区ID:', {
|
|
|
+ provinceId: res.data.data.provinceId,
|
|
|
+ cityId: res.data.data.cityId,
|
|
|
+ areaId: res.data.data.areaId
|
|
|
+ })
|
|
|
+
|
|
|
+ // 确保省市区ID正确赋值(处理可能的字段名不匹配)
|
|
|
+ const profileData = { ...res.data.data }
|
|
|
+
|
|
|
+ // 如果字段名是下划线格式,转换为驼峰格式
|
|
|
+ if (profileData.province_id !== undefined && profileData.provinceId === undefined) {
|
|
|
+ profileData.provinceId = profileData.province_id
|
|
|
+ }
|
|
|
+ if (profileData.city_id !== undefined && profileData.cityId === undefined) {
|
|
|
+ profileData.cityId = profileData.city_id
|
|
|
+ }
|
|
|
+ if (profileData.area_id !== undefined && profileData.areaId === undefined) {
|
|
|
+ profileData.areaId = profileData.area_id
|
|
|
+ }
|
|
|
+
|
|
|
+ this.profile = { ...this.profile, ...profileData }
|
|
|
+ console.log('合并后的profile:', {
|
|
|
+ provinceId: this.profile.provinceId,
|
|
|
+ cityId: this.profile.cityId,
|
|
|
+ areaId: this.profile.areaId
|
|
|
+ })
|
|
|
+
|
|
|
+ // 先加载省市区数据,然后再初始化索引和显示
|
|
|
+ await this.loadAreaData()
|
|
|
+
|
|
|
+ // 如果有省市区ID,加载对应的城市和区域数据,并初始化选择器索引
|
|
|
+ if (this.profile.provinceId || this.profile.cityId || this.profile.areaId) {
|
|
|
+ console.log('开始加载已保存的省市区数据...')
|
|
|
+ // 先加载省份对应的城市
|
|
|
+ if (this.profile.provinceId) {
|
|
|
+ await this.loadCitiesForProvince(this.profile.provinceId)
|
|
|
+ }
|
|
|
+ // 再加载城市对应的区域
|
|
|
+ if (this.profile.cityId) {
|
|
|
+ await this.loadAreasForCity(this.profile.cityId)
|
|
|
+ }
|
|
|
+ // 最后初始化选择器索引
|
|
|
+ setTimeout(() => {
|
|
|
+ this.initAreaIndex()
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
uni.showToast({
|
|
|
title: res.data?.message || '加载失败',
|
|
|
icon: 'none'
|
|
|
@@ -779,6 +844,282 @@
|
|
|
this.profile.privacyPhone = e.detail.value ? 1 : 0
|
|
|
},
|
|
|
|
|
|
+ // 省市区相关方法
|
|
|
+ // 加载省市区数据
|
|
|
+ async loadAreaData() {
|
|
|
+ try {
|
|
|
+ console.log('开始加载省份数据...')
|
|
|
+ // 加载省份列表
|
|
|
+ const provinceRes = await api.area.getProvinces()
|
|
|
+ console.log('省份数据返回:', provinceRes)
|
|
|
+
|
|
|
+ // api.js 已经处理了数据格式,直接使用返回的数组
|
|
|
+ if (Array.isArray(provinceRes)) {
|
|
|
+ this.provinceList = provinceRes
|
|
|
+ } else if (provinceRes && provinceRes.data) {
|
|
|
+ this.provinceList = provinceRes.data
|
|
|
+ } else if (provinceRes && provinceRes.code === 200 && provinceRes.data) {
|
|
|
+ this.provinceList = provinceRes.data
|
|
|
+ } else {
|
|
|
+ this.provinceList = []
|
|
|
+ }
|
|
|
+
|
|
|
+ this.multiAreaData[0] = this.provinceList
|
|
|
+ console.log('省份列表:', this.provinceList)
|
|
|
+
|
|
|
+ // 如果有已选择的省份,加载对应的城市
|
|
|
+ if (this.profile.provinceId) {
|
|
|
+ await this.loadCitiesForProvince(this.profile.provinceId)
|
|
|
+ } else if (this.provinceList.length > 0) {
|
|
|
+ // 默认加载第一个省份的城市
|
|
|
+ await this.loadCitiesForProvince(this.provinceList[0].id)
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error('加载省份失败:', e)
|
|
|
+ uni.showToast({
|
|
|
+ title: '加载省份数据失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 根据省份ID加载城市
|
|
|
+ async loadCitiesForProvince(provinceId) {
|
|
|
+ if (!provinceId) return
|
|
|
+
|
|
|
+ try {
|
|
|
+ console.log('加载城市数据,省份ID:', provinceId)
|
|
|
+ const cityRes = await api.area.getCities(provinceId)
|
|
|
+ console.log('城市数据返回:', cityRes)
|
|
|
+
|
|
|
+ // api.js 已经处理了数据格式,直接使用返回的数组
|
|
|
+ if (Array.isArray(cityRes)) {
|
|
|
+ this.cityList = cityRes
|
|
|
+ } else if (cityRes && cityRes.data) {
|
|
|
+ this.cityList = cityRes.data
|
|
|
+ } else if (cityRes && cityRes.code === 200 && cityRes.data) {
|
|
|
+ this.cityList = cityRes.data
|
|
|
+ } else {
|
|
|
+ this.cityList = []
|
|
|
+ }
|
|
|
+
|
|
|
+ this.multiAreaData[1] = this.cityList
|
|
|
+ console.log('城市列表:', this.cityList)
|
|
|
+
|
|
|
+ // 如果有已选择的城市,加载对应的区域
|
|
|
+ if (this.profile.cityId) {
|
|
|
+ await this.loadAreasForCity(this.profile.cityId)
|
|
|
+ } else if (this.cityList.length > 0) {
|
|
|
+ // 默认加载第一个城市的区域
|
|
|
+ await this.loadAreasForCity(this.cityList[0].id)
|
|
|
+ } else {
|
|
|
+ this.multiAreaData[2] = []
|
|
|
+ this.areaList = []
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error('加载城市失败:', e)
|
|
|
+ this.cityList = []
|
|
|
+ this.multiAreaData[1] = []
|
|
|
+ this.multiAreaData[2] = []
|
|
|
+ this.areaList = []
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 根据城市ID加载区域
|
|
|
+ async loadAreasForCity(cityId) {
|
|
|
+ if (!cityId) return
|
|
|
+
|
|
|
+ try {
|
|
|
+ console.log('加载区域数据,城市ID:', cityId)
|
|
|
+ const areaRes = await api.area.getAreas(cityId)
|
|
|
+ console.log('区域数据返回:', areaRes)
|
|
|
+
|
|
|
+ // api.js 已经处理了数据格式,直接使用返回的数组
|
|
|
+ if (Array.isArray(areaRes)) {
|
|
|
+ this.areaList = areaRes
|
|
|
+ } else if (areaRes && areaRes.data) {
|
|
|
+ this.areaList = areaRes.data
|
|
|
+ } else if (areaRes && areaRes.code === 200 && areaRes.data) {
|
|
|
+ this.areaList = areaRes.data
|
|
|
+ } else {
|
|
|
+ this.areaList = []
|
|
|
+ }
|
|
|
+
|
|
|
+ this.multiAreaData[2] = this.areaList
|
|
|
+ console.log('区域列表:', this.areaList)
|
|
|
+ } catch (e) {
|
|
|
+ console.error('加载区域失败:', e)
|
|
|
+ this.areaList = []
|
|
|
+ this.multiAreaData[2] = []
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 省市区选择器列变化事件
|
|
|
+ async onAreaColumnChange(e) {
|
|
|
+ const column = e.detail.column // 列索引:0-省,1-市,2-区
|
|
|
+ const row = e.detail.value // 选中的行索引
|
|
|
+
|
|
|
+ if (column === 0) {
|
|
|
+ // 选择了省份
|
|
|
+ const province = this.provinceList[row]
|
|
|
+ if (province && province.id) {
|
|
|
+ this.multiAreaIndex[0] = row
|
|
|
+ this.multiAreaIndex[1] = 0
|
|
|
+ this.multiAreaIndex[2] = 0
|
|
|
+ // 加载该省份的城市
|
|
|
+ await this.loadCitiesForProvince(province.id)
|
|
|
+ }
|
|
|
+ } else if (column === 1) {
|
|
|
+ // 选择了城市
|
|
|
+ const city = this.cityList[row]
|
|
|
+ if (city && city.id) {
|
|
|
+ this.multiAreaIndex[1] = row
|
|
|
+ this.multiAreaIndex[2] = 0
|
|
|
+ // 加载该城市的区域
|
|
|
+ await this.loadAreasForCity(city.id)
|
|
|
+ }
|
|
|
+ } else if (column === 2) {
|
|
|
+ // 选择了区域
|
|
|
+ this.multiAreaIndex[2] = row
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 省市区选择器确认事件
|
|
|
+ onAreaChange(e) {
|
|
|
+ const values = e.detail.value
|
|
|
+ this.multiAreaIndex = values
|
|
|
+
|
|
|
+ // 设置选中的省市区ID
|
|
|
+ if (this.provinceList[values[0]]) {
|
|
|
+ this.profile.provinceId = this.provinceList[values[0]].id
|
|
|
+ }
|
|
|
+ if (this.cityList[values[1]]) {
|
|
|
+ this.profile.cityId = this.cityList[values[1]].id
|
|
|
+ }
|
|
|
+ if (this.areaList[values[2]]) {
|
|
|
+ this.profile.areaId = this.areaList[values[2]].id
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取地区显示文本
|
|
|
+ getAreaText() {
|
|
|
+ // 如果没有省市区ID,返回未设置
|
|
|
+ if (!this.profile.provinceId && !this.profile.cityId && !this.profile.areaId) {
|
|
|
+ return '未设置'
|
|
|
+ }
|
|
|
+
|
|
|
+ let text = ''
|
|
|
+ let hasText = false
|
|
|
+
|
|
|
+ // 查找省份名称
|
|
|
+ if (this.profile.provinceId) {
|
|
|
+ if (this.provinceList.length > 0) {
|
|
|
+ const province = this.provinceList.find(p => p.id === this.profile.provinceId)
|
|
|
+ if (province) {
|
|
|
+ text += province.name
|
|
|
+ hasText = true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果省份列表还没加载,触发加载
|
|
|
+ if (this.provinceList.length === 0) {
|
|
|
+ this.loadAreaData()
|
|
|
+ }
|
|
|
+ return '加载中...'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找城市名称
|
|
|
+ if (this.profile.cityId) {
|
|
|
+ if (this.cityList.length > 0) {
|
|
|
+ const city = this.cityList.find(c => c.id === this.profile.cityId)
|
|
|
+ if (city) {
|
|
|
+ text += (hasText ? ' ' : '') + city.name
|
|
|
+ hasText = true
|
|
|
+ }
|
|
|
+ } else if (this.profile.provinceId) {
|
|
|
+ // 如果城市列表还没加载但有省份ID,加载城市数据
|
|
|
+ this.loadCitiesForProvince(this.profile.provinceId)
|
|
|
+ return hasText ? text + ' 加载中...' : '加载中...'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找区域名称
|
|
|
+ if (this.profile.areaId) {
|
|
|
+ if (this.areaList.length > 0) {
|
|
|
+ const area = this.areaList.find(a => a.id === this.profile.areaId)
|
|
|
+ if (area) {
|
|
|
+ text += (hasText ? ' ' : '') + area.name
|
|
|
+ hasText = true
|
|
|
+ }
|
|
|
+ } else if (this.profile.cityId) {
|
|
|
+ // 如果区域列表还没加载但有城市ID,加载区域数据
|
|
|
+ this.loadAreasForCity(this.profile.cityId)
|
|
|
+ return hasText ? text + ' 加载中...' : '加载中...'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return text || '未设置'
|
|
|
+ },
|
|
|
+
|
|
|
+ // 初始化省市区选择器索引(根据已保存的ID)
|
|
|
+ async initAreaIndex() {
|
|
|
+ if (!this.profile.provinceId) {
|
|
|
+ console.log('没有省份ID,跳过初始化')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('开始初始化省市区索引,当前省份ID:', this.profile.provinceId)
|
|
|
+ console.log('省份列表长度:', this.provinceList.length)
|
|
|
+
|
|
|
+ // 如果省份列表还没加载,先加载
|
|
|
+ if (this.provinceList.length === 0) {
|
|
|
+ console.log('省份列表为空,先加载数据')
|
|
|
+ await this.loadAreaData()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找省份索引
|
|
|
+ const provinceIndex = this.provinceList.findIndex(p => p.id === this.profile.provinceId)
|
|
|
+ console.log('找到的省份索引:', provinceIndex, '省份ID:', this.profile.provinceId)
|
|
|
+
|
|
|
+ if (provinceIndex >= 0) {
|
|
|
+ this.multiAreaIndex[0] = provinceIndex
|
|
|
+
|
|
|
+ // 加载该省份的城市
|
|
|
+ await this.loadCitiesForProvince(this.profile.provinceId)
|
|
|
+
|
|
|
+ // 等待城市加载完成后再查找城市索引
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 300))
|
|
|
+
|
|
|
+ if (this.profile.cityId) {
|
|
|
+ const cityIndex = this.cityList.findIndex(c => c.id === this.profile.cityId)
|
|
|
+ console.log('找到的城市索引:', cityIndex, '城市ID:', this.profile.cityId)
|
|
|
+ if (cityIndex >= 0) {
|
|
|
+ this.multiAreaIndex[1] = cityIndex
|
|
|
+
|
|
|
+ // 加载该城市的区域
|
|
|
+ await this.loadAreasForCity(this.profile.cityId)
|
|
|
+
|
|
|
+ // 等待区域加载完成后再查找区域索引
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 300))
|
|
|
+
|
|
|
+ if (this.profile.areaId) {
|
|
|
+ const areaIndex = this.areaList.findIndex(a => a.id === this.profile.areaId)
|
|
|
+ console.log('找到的区域索引:', areaIndex, '区域ID:', this.profile.areaId)
|
|
|
+ if (areaIndex >= 0) {
|
|
|
+ this.multiAreaIndex[2] = areaIndex
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制更新视图
|
|
|
+ this.$forceUpdate()
|
|
|
+ } else {
|
|
|
+ console.warn('未找到省份索引,省份ID:', this.profile.provinceId)
|
|
|
+ console.log('当前省份列表:', this.provinceList.map(p => ({ id: p.id, name: p.name })))
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 显示标签选择弹窗
|
|
|
addHobby() {
|
|
|
this.showHobbyModal = true
|
|
|
@@ -884,6 +1225,17 @@
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 处理地区点击事件
|
|
|
+ handleAreaClick() {
|
|
|
+ if (!this.isEditing) {
|
|
|
+ this.startEdit()
|
|
|
+ }
|
|
|
+ // 如果数据还没加载,立即加载
|
|
|
+ if (this.provinceList.length === 0) {
|
|
|
+ this.loadAreaData()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 启用编辑/保存
|
|
|
enableEdit() {
|
|
|
if (this.isEditing) {
|
|
|
@@ -922,15 +1274,25 @@
|
|
|
car: this.profile.car,
|
|
|
hobby: this.profile.hobby,
|
|
|
privacySalary: this.profile.privacySalary,
|
|
|
- privacyPhone: this.profile.privacyPhone
|
|
|
+ privacyPhone: this.profile.privacyPhone,
|
|
|
+ provinceId: this.profile.provinceId || null,
|
|
|
+ cityId: this.profile.cityId || null,
|
|
|
+ areaId: this.profile.areaId || null
|
|
|
}
|
|
|
|
|
|
+ console.log('保存省市区数据:', {
|
|
|
+ provinceId: submitData.provinceId,
|
|
|
+ cityId: submitData.cityId,
|
|
|
+ areaId: submitData.areaId
|
|
|
+ })
|
|
|
+
|
|
|
uni.request({
|
|
|
url: this.gatewayURL + '/api/user/profile',
|
|
|
method: 'PUT',
|
|
|
data: submitData,
|
|
|
success: (res) => {
|
|
|
uni.hideLoading()
|
|
|
+ console.log('保存响应:', res.data)
|
|
|
|
|
|
if (res.data && res.data.code === 200) {
|
|
|
uni.showToast({
|
|
|
@@ -939,6 +1301,23 @@
|
|
|
duration: 1500
|
|
|
})
|
|
|
this.isEditing = false
|
|
|
+
|
|
|
+ // 更新 storage 中的 userInfo,特别是性别信息
|
|
|
+ const storedUserInfo = uni.getStorageSync('userInfo');
|
|
|
+ if (storedUserInfo) {
|
|
|
+ // 更新性别信息
|
|
|
+ if (submitData.gender !== undefined && submitData.gender !== null) {
|
|
|
+ storedUserInfo.gender = submitData.gender;
|
|
|
+ console.log('更新storage中的性别信息:', submitData.gender);
|
|
|
+ }
|
|
|
+ // 更新其他可能变化的字段
|
|
|
+ if (submitData.birthDate) {
|
|
|
+ storedUserInfo.birthDate = submitData.birthDate;
|
|
|
+ }
|
|
|
+ uni.setStorageSync('userInfo', storedUserInfo);
|
|
|
+ console.log('已更新storage中的userInfo');
|
|
|
+ }
|
|
|
+
|
|
|
// 重新加载资料
|
|
|
this.loadProfile()
|
|
|
|
|
|
@@ -1262,17 +1641,6 @@
|
|
|
align-items: flex-start;
|
|
|
}
|
|
|
|
|
|
- // 添加右侧编辑提示(只在非编辑模式显示)
|
|
|
- &:not(.editing)::after {
|
|
|
- content: '点击编辑';
|
|
|
- position: absolute;
|
|
|
- right: 30rpx;
|
|
|
- color: #CCCCCC;
|
|
|
- font-size: 22rpx;
|
|
|
- opacity: 0.5;
|
|
|
- pointer-events: none;
|
|
|
- }
|
|
|
-
|
|
|
.label {
|
|
|
font-size: 30rpx;
|
|
|
color: #333333;
|