index.vue 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003
  1. <template>
  2. <view class="profile-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">基本资料</text>
  9. <view class="edit-btn" @click="enableEdit">
  10. <text class="edit-text">{{ isEditing ? '保存' : '编辑' }}</text>
  11. </view>
  12. </view>
  13. <!-- 头像和基本信息 -->
  14. <view class="avatar-section">
  15. <view class="avatar-wrapper" @click="chooseAvatar">
  16. <image class="avatar" :src="profile.avatar || defaultAvatar" mode="aspectFill"></image>
  17. <view class="avatar-badge" v-if="profile.isVip">
  18. <text class="vip-icon">👑</text>
  19. </view>
  20. <view class="avatar-edit-hint">
  21. <text class="edit-hint-icon">📷</text>
  22. </view>
  23. </view>
  24. <text class="nickname">{{ profile.realName || profile.nickname || '未设置' }}</text>
  25. <text class="user-id">ID: {{ profile.userId || '未知' }}</text>
  26. </view>
  27. <!-- 编辑提示 -->
  28. <view class="edit-tip" v-if="!isEditing">
  29. <text class="tip-text">💡 点击任意字段即可编辑</text>
  30. </view>
  31. <scroll-view scroll-y class="content-scroll">
  32. <!-- 个人信息 -->
  33. <view class="section">
  34. <view class="section-title">个人信息</view>
  35. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  36. <text class="label">真实姓名</text>
  37. <input v-if="isEditing" class="input" v-model="profile.realName" placeholder="请输入真实姓名" />
  38. <text v-else class="value">{{ profile.realName || '未设置' }}</text>
  39. </view>
  40. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  41. <text class="label">身份证号</text>
  42. <input v-if="isEditing" class="input" v-model="profile.idCard" placeholder="请输入身份证号" />
  43. <text v-else class="value">{{ formatIdCard(profile.idCard) }}</text>
  44. <text class="verify-status verified" v-if="profile.idCard && profile.isRealNameVerified">✓已认证</text>
  45. <text class="verify-status unverified" v-else-if="!profile.idCard">未认证</text>
  46. </view>
  47. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  48. <text class="label">性别</text>
  49. <picker v-if="isEditing" :range="genderOptions" range-key="label" :value="getGenderIndex()" @change="onGenderChange">
  50. <view class="picker-value">{{ getGenderText() }}</view>
  51. </picker>
  52. <text v-else class="value">{{ getGenderText() }}</text>
  53. </view>
  54. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  55. <text class="label">出生日期</text>
  56. <picker v-if="isEditing" mode="date" :value="profile.birthDate" @change="onBirthDateChange">
  57. <view class="picker-value">{{ profile.birthDate || '请选择' }}</view>
  58. </picker>
  59. <text v-else class="value">{{ profile.birthDate || '未设置' }}</text>
  60. </view>
  61. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  62. <text class="label">身高</text>
  63. <input v-if="isEditing" class="input" type="number" v-model="profile.height" placeholder="请输入身高(cm)" />
  64. <text v-else class="value">{{ profile.height ? profile.height + ' cm' : '未设置' }}</text>
  65. </view>
  66. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  67. <text class="label">体重</text>
  68. <input v-if="isEditing" class="input" type="number" v-model="profile.weight" placeholder="请输入体重(kg)" />
  69. <text v-else class="value">{{ profile.weight ? profile.weight + ' kg' : '未设置' }}</text>
  70. </view>
  71. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  72. <text class="label">星座</text>
  73. <picker v-if="isEditing" :range="starOptions" @change="onStarChange">
  74. <view class="picker-value">{{ profile.star || '请选择' }}</view>
  75. </picker>
  76. <text v-else class="value">{{ profile.star || '未设置' }}</text>
  77. </view>
  78. <view class="info-item" :class="{ editing: isEditing }">
  79. <text class="label">生肖</text>
  80. <text class="value">{{ profile.animal || '未设置' }}</text>
  81. </view>
  82. <view class="info-item" :class="{ editing: isEditing }" @click="handleAreaClick">
  83. <text class="label">地区</text>
  84. <picker v-if="isEditing" mode="multiSelector" :range="multiAreaData" range-key="name" :value="multiAreaIndex" @change="onAreaChange" @columnchange="onAreaColumnChange">
  85. <view class="picker-value">{{ getAreaText() }}</view>
  86. </picker>
  87. <text v-else class="value">{{ getAreaText() }}</text>
  88. </view>
  89. </view>
  90. <!-- 学业与工作 -->
  91. <view class="section">
  92. <view class="section-title">学业与工作</view>
  93. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  94. <text class="label">学历</text>
  95. <picker v-if="isEditing" :range="educationOptions" :value="getEducationIndex()" @change="onEducationChange">
  96. <view class="picker-value">{{ getEducationText() }}</view>
  97. </picker>
  98. <text v-else class="value">{{ getEducationText() }}</text>
  99. <text class="verify-status verified" v-if="profile.educationLevel && profile.isEducationVerified">✓已认证</text>
  100. <text class="verify-status unverified" v-else-if="!profile.educationLevel">未认证</text>
  101. </view>
  102. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  103. <text class="label">学校名称</text>
  104. <input v-if="isEditing" class="input" v-model="profile.schoolName" placeholder="请输入学校名称" />
  105. <text v-else class="value">{{ profile.schoolName || '未设置' }}</text>
  106. </view>
  107. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  108. <text class="label">工作单位</text>
  109. <input v-if="isEditing" class="input" v-model="profile.company" placeholder="请输入工作单位" />
  110. <text v-else class="value">{{ profile.company || '未设置' }}</text>
  111. <text class="verify-status verified" v-if="profile.company && profile.isWorkVerified">✓已认证</text>
  112. <text class="verify-status unverified" v-else-if="!profile.company">未认证</text>
  113. </view>
  114. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  115. <text class="label">职位</text>
  116. <input v-if="isEditing" class="input" v-model="profile.jobTitle" placeholder="请输入职位" />
  117. <text v-else class="value">{{ profile.jobTitle || '未设置' }}</text>
  118. </view>
  119. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  120. <text class="label">薪资范围</text>
  121. <picker v-if="isEditing" :range="salaryOptions" :value="getSalaryIndex()" @change="onSalaryChange">
  122. <view class="picker-value">{{ getSalaryText() }}</view>
  123. </picker>
  124. <text v-else class="value">{{ getSalaryText() }}</text>
  125. </view>
  126. </view>
  127. <!-- 婚姻与住房 -->
  128. <view class="section">
  129. <view class="section-title">婚姻与住房</view>
  130. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  131. <text class="label">婚姻状况</text>
  132. <picker v-if="isEditing" :range="maritalOptions" :value="getMaritalIndex()" @change="onMaritalChange">
  133. <view class="picker-value">{{ getMaritalText() }}</view>
  134. </picker>
  135. <text v-else class="value">{{ getMaritalText() }}</text>
  136. <text class="verify-status verified" v-if="profile.maritalStatus !== null && profile.maritalStatus !== undefined && profile.isMaritalVerified">✓已认证</text>
  137. <text class="verify-status unverified" v-else-if="profile.maritalStatus === null || profile.maritalStatus === undefined">未认证</text>
  138. </view>
  139. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  140. <text class="label">房产</text>
  141. <picker v-if="isEditing" :range="houseOptions" range-key="label" :value="getHouseIndex()" @change="onHouseChange">
  142. <view class="picker-value">{{ getHouseText() }}</view>
  143. </picker>
  144. <text v-else class="value">{{ getHouseText() }}</text>
  145. </view>
  146. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  147. <text class="label">车辆</text>
  148. <picker v-if="isEditing" :range="carOptions" range-key="label" :value="getCarIndex()" @change="onCarChange">
  149. <view class="picker-value">{{ getCarText() }}</view>
  150. </picker>
  151. <text v-else class="value">{{ getCarText() }}</text>
  152. </view>
  153. </view>
  154. <!-- 兴趣爱好 -->
  155. <view class="section">
  156. <view class="section-title">兴趣爱好</view>
  157. <view class="info-item column" @click="startEdit">
  158. <text class="label">兴趣爱好标签</text>
  159. <view class="hobby-tags">
  160. <view class="hobby-tag"
  161. v-for="(hobby, index) in hobbyList"
  162. :key="index"
  163. @click.stop="isEditing ? removeHobbyTag(index) : null"
  164. :class="{ deletable: isEditing }"
  165. >
  166. {{ hobby }}
  167. <text class="delete-icon" v-if="isEditing">×</text>
  168. </view>
  169. <view class="hobby-tag add" v-if="isEditing" @click.stop="addHobby">
  170. + 添加
  171. </view>
  172. <view class="hobby-empty" v-if="hobbyList.length === 0 && !isEditing">
  173. <text class="empty-text">暂无标签</text>
  174. </view>
  175. </view>
  176. </view>
  177. </view>
  178. <!-- 隐私设置 -->
  179. <view class="section">
  180. <view class="section-title">隐私设置</view>
  181. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  182. <text class="label">薪资公开</text>
  183. <switch :checked="profile.privacySalary === 1" @change="onPrivacySalaryChange" :disabled="!isEditing" />
  184. </view>
  185. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  186. <text class="label">手机号公开</text>
  187. <switch :checked="profile.privacyPhone === 1" @change="onPrivacyPhoneChange" :disabled="!isEditing" />
  188. </view>
  189. </view>
  190. <!-- 真实度评分 -->
  191. <view class="section">
  192. <view class="section-title">真实度评分</view>
  193. <view class="authenticity-score">
  194. <view class="score-circle">
  195. <text class="score-number">{{ profile.authenticityScore || 0 }}</text>
  196. <text class="score-total">/100</text>
  197. </view>
  198. <view class="score-tips">
  199. <text class="tip-text">完善资料并通过认证可提升真实度评分</text>
  200. </view>
  201. </view>
  202. </view>
  203. <!-- 底部占位 -->
  204. <view class="bottom-placeholder"></view>
  205. </scroll-view>
  206. <!-- 标签选择弹窗 -->
  207. <view class="hobby-modal" v-if="showHobbyModal" @click="closeHobbyModal">
  208. <view class="modal-content" @click.stop>
  209. <view class="modal-header">
  210. <text class="modal-title">选择兴趣爱好标签</text>
  211. <text class="close-btn" @click="closeHobbyModal">×</text>
  212. </view>
  213. <scroll-view scroll-y class="modal-body">
  214. <!-- 预设标签分类 -->
  215. <view class="hobby-category" v-for="(category, index) in hobbyCategories" :key="index">
  216. <view class="category-title">
  217. <text class="category-icon">{{ category.icon }}</text>
  218. <text class="category-name">{{ category.name }}</text>
  219. </view>
  220. <view class="category-tags">
  221. <view class="preset-tag"
  222. v-for="(tag, tagIndex) in category.tags"
  223. :key="tagIndex"
  224. @click="selectPresetTag(tag)"
  225. :class="{ selected: hobbyList.includes(tag) }"
  226. >
  227. {{ tag }}
  228. <text class="check-icon" v-if="hobbyList.includes(tag)">✓</text>
  229. </view>
  230. </view>
  231. </view>
  232. <!-- 自定义输入 -->
  233. <view class="custom-input-section">
  234. <view class="category-title">
  235. <text class="category-icon">✏️</text>
  236. <text class="category-name">自定义标签</text>
  237. </view>
  238. <view class="input-wrapper">
  239. <input
  240. class="custom-input"
  241. v-model="customHobbyInput"
  242. placeholder="输入自定义标签"
  243. @confirm="addCustomTag"
  244. />
  245. <view class="add-custom-btn" @click="addCustomTag">
  246. <text class="add-text">添加</text>
  247. </view>
  248. </view>
  249. </view>
  250. </scroll-view>
  251. <view class="modal-footer">
  252. <text class="selected-count">已选择 {{ hobbyList.length }}/10 个标签</text>
  253. <view class="done-btn" @click="closeHobbyModal">
  254. <text class="done-text">完成</text>
  255. </view>
  256. </view>
  257. </view>
  258. </view>
  259. </view>
  260. </template>
  261. <script>
  262. import userAuth from '@/utils/userAuth.js'
  263. import { getZodiacByBirthday } from '@/utils/zodiac.js'
  264. import api from '@/utils/api.js'
  265. export default {
  266. data() {
  267. return {
  268. gatewayURL: 'http://localhost:8083',
  269. currentUserId: null,
  270. isEditing: false,
  271. defaultAvatar: 'https://via.placeholder.com/150',
  272. // 用户资料数据
  273. profile: {
  274. userId: null,
  275. avatar: uni.getStorageSync("userInfo").avatarUrl,
  276. nickname: '',
  277. realName: '',
  278. idCard: '',
  279. gender: null,
  280. birthDate: '',
  281. height: null,
  282. weight: null,
  283. star: '',
  284. animal: '',
  285. educationLevel: null,
  286. schoolName: '',
  287. company: '',
  288. jobTitle: '',
  289. salaryRange: null,
  290. maritalStatus: null,
  291. house: null,
  292. car: null,
  293. hobby: '',
  294. privacySalary: 0,
  295. privacyPhone: 0,
  296. authenticityScore: 0,
  297. isVip: false,
  298. isRealNameVerified: false,
  299. isEducationVerified: false,
  300. isWorkVerified: false,
  301. isMaritalVerified: false,
  302. provinceId: null,
  303. cityId: null,
  304. areaId: null
  305. },
  306. // 选项列表
  307. genderOptions: [
  308. { value: 1, label: '男' },
  309. { value: 2, label: '女' }
  310. ],
  311. starOptions: ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座',
  312. '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座'],
  313. animalOptions: ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'],
  314. educationOptions: ['高中', '专科', '本科', '硕士', '博士', '无'],
  315. salaryOptions: ['1-5k', '5-10k', '10-20k', '20-50k', '50k+'],
  316. maritalOptions: ['未婚', '离异', '丧偶'],
  317. houseOptions: [
  318. { value: 0, label: '无' },
  319. { value: 1, label: '有' }
  320. ],
  321. carOptions: [
  322. { value: 0, label: '无' },
  323. { value: 1, label: '有' }
  324. ],
  325. // 标签选择弹窗
  326. showHobbyModal: false,
  327. hobbyCategories: [
  328. {
  329. name: '运动健身',
  330. icon: '🏃',
  331. tags: ['运动', '健身', '瑜伽', '爬山', '游泳', '篮球', '足球', '网球']
  332. },
  333. {
  334. name: '文艺休闲',
  335. icon: '🎨',
  336. tags: ['旅游', '阅读', '音乐', '电影', '摄影', '绘画', '舞蹈', '唱歌']
  337. },
  338. {
  339. name: '技能爱好',
  340. icon: '🎹',
  341. tags: ['钢琴', '吉他', '书法', '茶艺', '烹饪', '园艺', '手工', '收藏']
  342. },
  343. {
  344. name: '生活方式',
  345. icon: '🌟',
  346. tags: ['美食', '游戏', '宠物', '时尚', '购物', '化妆']
  347. }
  348. ],
  349. customHobbyInput: '',
  350. // 省市区数据
  351. provinceList: [],
  352. cityList: [],
  353. areaList: [],
  354. multiAreaData: [[], [], []], // 三级联动数据
  355. multiAreaIndex: [0, 0, 0] // 三级联动索引
  356. }
  357. },
  358. computed: {
  359. hobbyList() {
  360. if (!this.profile.hobby) return []
  361. try {
  362. return JSON.parse(this.profile.hobby)
  363. } catch (e) {
  364. return this.profile.hobby.split(',').filter(item => item)
  365. }
  366. }
  367. },
  368. onLoad() {
  369. // 获取登录用户ID - 使用userAuth工具类
  370. this.currentUserId = userAuth.getUserId()
  371. console.log('=== 个人资料页面 ===')
  372. console.log('用户ID:', this.currentUserId)
  373. console.log('用户ID类型:', typeof this.currentUserId)
  374. // 检查是否已登录(userId为1也是合法的测试用户)
  375. if (this.currentUserId === null || this.currentUserId === undefined || this.currentUserId === 0) {
  376. console.log('未登录,检查登录状态')
  377. this.checkLoginStatus()
  378. } else {
  379. console.log('已登录,用户ID:', this.currentUserId)
  380. // 加载省市区数据
  381. this.loadAreaData()
  382. // 加载用户资料
  383. this.loadProfile()
  384. }
  385. },
  386. methods: {
  387. // 选择并上传头像
  388. chooseAvatar() {
  389. uni.showActionSheet({
  390. itemList: ['从相册选择', '拍照'],
  391. success: (res) => {
  392. if (res.tapIndex === 0) {
  393. // 从相册选择
  394. this.selectImage('album')
  395. } else if (res.tapIndex === 1) {
  396. // 拍照
  397. this.selectImage('camera')
  398. }
  399. }
  400. })
  401. },
  402. // 选择图片
  403. selectImage(sourceType) {
  404. uni.chooseImage({
  405. count: 1,
  406. sizeType: ['compressed'], // 使用压缩图
  407. sourceType: [sourceType],
  408. success: (res) => {
  409. const tempFilePath = res.tempFilePaths[0]
  410. console.log('选择的图片路径:', tempFilePath)
  411. // 上传图片
  412. this.uploadAvatar(tempFilePath)
  413. },
  414. fail: (err) => {
  415. console.error('选择图片失败:', err)
  416. uni.showToast({
  417. title: '选择图片失败',
  418. icon: 'none'
  419. })
  420. }
  421. })
  422. },
  423. // 上传头像
  424. uploadAvatar(filePath) {
  425. console.log('=== 开始上传头像 ===')
  426. console.log('文件路径:', filePath)
  427. console.log('上传URL:', this.gatewayURL + '/api/avatar/upload')
  428. console.log('用户ID:', this.currentUserId)
  429. uni.showLoading({
  430. title: '上传中...',
  431. mask: true
  432. })
  433. // 使用 uni.uploadFile 上传到服务器
  434. const uploadTask = uni.uploadFile({
  435. url: this.gatewayURL + '/api/avatar/upload',
  436. filePath: filePath,
  437. name: 'file',
  438. timeout: 60000, // 设置超时时间为60秒
  439. formData: {
  440. userId: this.currentUserId
  441. },
  442. success: (uploadRes) => {
  443. uni.hideLoading()
  444. console.log('上传响应:', uploadRes)
  445. console.log('状态码:', uploadRes.statusCode)
  446. // 检查HTTP状态码
  447. if (uploadRes.statusCode !== 200) {
  448. console.error('HTTP错误:', uploadRes.statusCode)
  449. uni.showToast({
  450. title: `服务器错误: ${uploadRes.statusCode}`,
  451. icon: 'none',
  452. duration: 3000
  453. })
  454. return
  455. }
  456. try {
  457. const result = JSON.parse(uploadRes.data)
  458. console.log('解析后的结果:', result)
  459. if (result.code === 200) {
  460. console.log('✅ 头像上传成功:', result.data)
  461. // 更新头像URL
  462. this.profile.avatar = result.data
  463. // 更新本地存储的用户信息
  464. const userInfo = uni.getStorageSync('userInfo')
  465. if (userInfo) {
  466. userInfo.avatarUrl = result.data
  467. uni.setStorageSync('userInfo', userInfo)
  468. console.log('已更新本地缓存')
  469. }
  470. uni.showToast({
  471. title: '头像上传成功',
  472. icon: 'success',
  473. duration: 2000
  474. })
  475. // 刷新页面数据
  476. setTimeout(() => {
  477. this.loadProfile()
  478. }, 500)
  479. } else {
  480. console.error('❌ 业务错误:', result.message)
  481. uni.showToast({
  482. title: result.message || '上传失败',
  483. icon: 'none',
  484. duration: 3000
  485. })
  486. }
  487. } catch (e) {
  488. console.error('❌ 解析响应失败:', e)
  489. console.error('原始响应数据:', uploadRes.data)
  490. uni.showToast({
  491. title: '服务器响应格式错误',
  492. icon: 'none',
  493. duration: 3000
  494. })
  495. }
  496. },
  497. fail: (err) => {
  498. uni.hideLoading()
  499. console.error('❌ 上传失败:', err)
  500. let errorMsg = '上传失败'
  501. if (err.errMsg) {
  502. if (err.errMsg.includes('timeout')) {
  503. errorMsg = '上传超时,请检查网络连接'
  504. } else if (err.errMsg.includes('fail')) {
  505. errorMsg = '网络连接失败'
  506. } else {
  507. errorMsg = err.errMsg
  508. }
  509. }
  510. uni.showToast({
  511. title: errorMsg,
  512. icon: 'none',
  513. duration: 3000
  514. })
  515. }
  516. })
  517. // 监听上传进度
  518. uploadTask.onProgressUpdate((res) => {
  519. console.log('上传进度:', res.progress + '%')
  520. if (res.progress % 20 === 0 || res.progress > 90) {
  521. console.log(`已上传 ${res.totalBytesSent}/${res.totalBytesExpectedToSend} 字节`)
  522. }
  523. })
  524. },
  525. // 检查登录状态
  526. checkLoginStatus() {
  527. const token = uni.getStorageSync('token')
  528. const userInfo = uni.getStorageSync('userInfo')
  529. if (!token || !userInfo) {
  530. // 没有登录信息,跳转到登录页
  531. uni.showModal({
  532. title: '需要登录',
  533. content: '请先登录后查看个人资料',
  534. showCancel: false,
  535. confirmText: '去登录',
  536. success: () => {
  537. uni.navigateTo({
  538. url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/profile/index')
  539. })
  540. }
  541. })
  542. return false
  543. }
  544. if (this.currentUserId === null || this.currentUserId === undefined || this.currentUserId === 0) {
  545. // 有登录信息但无法获取用户ID - 登录信息异常
  546. uni.showModal({
  547. title: '登录信息异常',
  548. content: '登录信息不完整,请重新登录',
  549. showCancel: false,
  550. confirmText: '重新登录',
  551. success: () => {
  552. // 清除异常的登录信息
  553. uni.clearStorageSync()
  554. uni.navigateTo({
  555. url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/profile/index')
  556. })
  557. }
  558. })
  559. return false
  560. }
  561. return true
  562. },
  563. // 加载用户资料
  564. loadProfile() {
  565. uni.showLoading({
  566. title: '加载中...'
  567. })
  568. uni.request({
  569. url: this.gatewayURL + '/api/user/profile?userId=' + this.currentUserId,
  570. method: 'GET',
  571. success: async (res) => {
  572. uni.hideLoading()
  573. console.log('=== 用户资料加载 ===')
  574. console.log('完整响应:', res.data)
  575. if (res.data && res.data.code === 200) {
  576. console.log('原始salaryRange:', res.data.data.salaryRange)
  577. console.log('完整返回数据:', JSON.stringify(res.data.data, null, 2))
  578. console.log('省市区ID:', {
  579. provinceId: res.data.data.provinceId,
  580. cityId: res.data.data.cityId,
  581. areaId: res.data.data.areaId
  582. })
  583. // 确保省市区ID正确赋值(处理可能的字段名不匹配)
  584. const profileData = { ...res.data.data }
  585. // 如果字段名是下划线格式,转换为驼峰格式
  586. if (profileData.province_id !== undefined && profileData.provinceId === undefined) {
  587. profileData.provinceId = profileData.province_id
  588. }
  589. if (profileData.city_id !== undefined && profileData.cityId === undefined) {
  590. profileData.cityId = profileData.city_id
  591. }
  592. if (profileData.area_id !== undefined && profileData.areaId === undefined) {
  593. profileData.areaId = profileData.area_id
  594. }
  595. this.profile = { ...this.profile, ...profileData }
  596. console.log('合并后的profile:', {
  597. provinceId: this.profile.provinceId,
  598. cityId: this.profile.cityId,
  599. areaId: this.profile.areaId
  600. })
  601. // 先加载省市区数据,然后再初始化索引和显示
  602. await this.loadAreaData()
  603. // 如果有省市区ID,加载对应的城市和区域数据,并初始化选择器索引
  604. if (this.profile.provinceId || this.profile.cityId || this.profile.areaId) {
  605. console.log('开始加载已保存的省市区数据...')
  606. // 先加载省份对应的城市
  607. if (this.profile.provinceId) {
  608. await this.loadCitiesForProvince(this.profile.provinceId)
  609. }
  610. // 再加载城市对应的区域
  611. if (this.profile.cityId) {
  612. await this.loadAreasForCity(this.profile.cityId)
  613. }
  614. // 最后初始化选择器索引
  615. setTimeout(() => {
  616. this.initAreaIndex()
  617. }, 300)
  618. }
  619. } else {
  620. uni.showToast({
  621. title: res.data?.message || '加载失败',
  622. icon: 'none'
  623. })
  624. }
  625. },
  626. fail: (err) => {
  627. uni.hideLoading()
  628. console.error('加载用户资料失败:', err)
  629. uni.showToast({
  630. title: '网络请求失败',
  631. icon: 'none'
  632. })
  633. }
  634. })
  635. },
  636. // 格式化身份证号(隐藏中间部分)
  637. formatIdCard(idCard) {
  638. if (!idCard) return '未设置'
  639. if (idCard.length < 8) return idCard
  640. return idCard.substring(0, 6) + '********' + idCard.substring(idCard.length - 4)
  641. },
  642. // 获取性别文本
  643. getGenderText() {
  644. const option = this.genderOptions.find(item => item.value === this.profile.gender)
  645. return option ? option.label : '未设置'
  646. },
  647. // 获取学历文本
  648. getEducationText() {
  649. if (this.profile.educationLevel === null || this.profile.educationLevel === undefined) return '未设置'
  650. const index = this.profile.educationLevel - 1
  651. return this.educationOptions[index] || '未设置'
  652. },
  653. // 获取薪资文本
  654. getSalaryText() {
  655. if (this.profile.salaryRange === null || this.profile.salaryRange === undefined) return '未设置'
  656. const index = this.profile.salaryRange - 1
  657. return this.salaryOptions[index] || '未设置'
  658. },
  659. // 获取薪资选择器的索引
  660. getSalaryIndex() {
  661. if (this.profile.salaryRange === null || this.profile.salaryRange === undefined) {
  662. return 0 // 默认选择第一项
  663. }
  664. const index = this.profile.salaryRange - 1
  665. // 确保索引在有效范围内
  666. return Math.max(0, Math.min(index, this.salaryOptions.length - 1))
  667. },
  668. // 获取性别选择器的索引
  669. getGenderIndex() {
  670. const option = this.genderOptions.findIndex(item => item.value === this.profile.gender)
  671. return Math.max(0, option)
  672. },
  673. // 获取学历选择器的索引
  674. getEducationIndex() {
  675. if (this.profile.educationLevel === null || this.profile.educationLevel === undefined) {
  676. return 0
  677. }
  678. const index = this.profile.educationLevel - 1
  679. return Math.max(0, Math.min(index, this.educationOptions.length - 1))
  680. },
  681. // 获取婚姻状况选择器的索引
  682. getMaritalIndex() {
  683. if (this.profile.maritalStatus === null || this.profile.maritalStatus === undefined) {
  684. return 0
  685. }
  686. return Math.max(0, Math.min(this.profile.maritalStatus, this.maritalOptions.length - 1))
  687. },
  688. // 获取房产选择器的索引
  689. getHouseIndex() {
  690. const option = this.houseOptions.findIndex(item => item.value === this.profile.house)
  691. return Math.max(0, option)
  692. },
  693. // 获取车辆选择器的索引
  694. getCarIndex() {
  695. const option = this.carOptions.findIndex(item => item.value === this.profile.car)
  696. return Math.max(0, option)
  697. },
  698. // 获取婚姻状况文本
  699. getMaritalText() {
  700. if (this.profile.maritalStatus === null || this.profile.maritalStatus === undefined) return '未设置'
  701. const index = this.profile.maritalStatus
  702. return this.maritalOptions[index] || '未设置'
  703. },
  704. // 获取房产文本
  705. getHouseText() {
  706. const option = this.houseOptions.find(item => item.value === this.profile.house)
  707. return option ? option.label : '未设置'
  708. },
  709. // 获取车辆文本
  710. getCarText() {
  711. const option = this.carOptions.find(item => item.value === this.profile.car)
  712. return option ? option.label : '未设置'
  713. },
  714. // 选择器改变事件
  715. onGenderChange(e) {
  716. this.profile.gender = this.genderOptions[parseInt(e.detail.value)].value
  717. },
  718. onBirthDateChange(e) {
  719. this.profile.birthDate = e.detail.value
  720. // 自动计算并设置生肖
  721. if (this.profile.birthDate) {
  722. const zodiac = getZodiacByBirthday(this.profile.birthDate)
  723. this.profile.animal = zodiac
  724. }
  725. },
  726. onStarChange(e) {
  727. this.profile.star = this.starOptions[parseInt(e.detail.value)]
  728. },
  729. onAnimalChange(e) {
  730. this.profile.animal = this.animalOptions[parseInt(e.detail.value)]
  731. },
  732. onEducationChange(e) {
  733. // 将字符串转换为数字
  734. this.profile.educationLevel = parseInt(e.detail.value) + 1
  735. },
  736. onSalaryChange(e) {
  737. console.log('=== 薪资选择变化 ===')
  738. console.log('选择的索引:', e.detail.value, typeof e.detail.value)
  739. console.log('对应的薪资选项:', this.salaryOptions[e.detail.value])
  740. // 将字符串转换为数字,避免字符串拼接问题
  741. this.profile.salaryRange = parseInt(e.detail.value) + 1
  742. console.log('更新后的salaryRange:', this.profile.salaryRange, typeof this.profile.salaryRange)
  743. console.log('更新后显示的文本:', this.getSalaryText())
  744. },
  745. onMaritalChange(e) {
  746. // 将字符串转换为数字
  747. this.profile.maritalStatus = parseInt(e.detail.value)
  748. },
  749. onHouseChange(e) {
  750. this.profile.house = this.houseOptions[parseInt(e.detail.value)].value
  751. },
  752. onCarChange(e) {
  753. this.profile.car = this.carOptions[parseInt(e.detail.value)].value
  754. },
  755. onPrivacySalaryChange(e) {
  756. this.profile.privacySalary = e.detail.value ? 1 : 0
  757. },
  758. onPrivacyPhoneChange(e) {
  759. this.profile.privacyPhone = e.detail.value ? 1 : 0
  760. },
  761. // 省市区相关方法
  762. // 加载省市区数据
  763. async loadAreaData() {
  764. try {
  765. console.log('开始加载省份数据...')
  766. // 加载省份列表
  767. const provinceRes = await api.area.getProvinces()
  768. console.log('省份数据返回:', provinceRes)
  769. // api.js 已经处理了数据格式,直接使用返回的数组
  770. if (Array.isArray(provinceRes)) {
  771. this.provinceList = provinceRes
  772. } else if (provinceRes && provinceRes.data) {
  773. this.provinceList = provinceRes.data
  774. } else if (provinceRes && provinceRes.code === 200 && provinceRes.data) {
  775. this.provinceList = provinceRes.data
  776. } else {
  777. this.provinceList = []
  778. }
  779. this.multiAreaData[0] = this.provinceList
  780. console.log('省份列表:', this.provinceList)
  781. // 如果有已选择的省份,加载对应的城市
  782. if (this.profile.provinceId) {
  783. await this.loadCitiesForProvince(this.profile.provinceId)
  784. } else if (this.provinceList.length > 0) {
  785. // 默认加载第一个省份的城市
  786. await this.loadCitiesForProvince(this.provinceList[0].id)
  787. }
  788. } catch (e) {
  789. console.error('加载省份失败:', e)
  790. uni.showToast({
  791. title: '加载省份数据失败',
  792. icon: 'none'
  793. })
  794. }
  795. },
  796. // 根据省份ID加载城市
  797. async loadCitiesForProvince(provinceId) {
  798. if (!provinceId) return
  799. try {
  800. console.log('加载城市数据,省份ID:', provinceId)
  801. const cityRes = await api.area.getCities(provinceId)
  802. console.log('城市数据返回:', cityRes)
  803. // api.js 已经处理了数据格式,直接使用返回的数组
  804. if (Array.isArray(cityRes)) {
  805. this.cityList = cityRes
  806. } else if (cityRes && cityRes.data) {
  807. this.cityList = cityRes.data
  808. } else if (cityRes && cityRes.code === 200 && cityRes.data) {
  809. this.cityList = cityRes.data
  810. } else {
  811. this.cityList = []
  812. }
  813. this.multiAreaData[1] = this.cityList
  814. console.log('城市列表:', this.cityList)
  815. // 如果有已选择的城市,加载对应的区域
  816. if (this.profile.cityId) {
  817. await this.loadAreasForCity(this.profile.cityId)
  818. } else if (this.cityList.length > 0) {
  819. // 默认加载第一个城市的区域
  820. await this.loadAreasForCity(this.cityList[0].id)
  821. } else {
  822. this.multiAreaData[2] = []
  823. this.areaList = []
  824. }
  825. } catch (e) {
  826. console.error('加载城市失败:', e)
  827. this.cityList = []
  828. this.multiAreaData[1] = []
  829. this.multiAreaData[2] = []
  830. this.areaList = []
  831. }
  832. },
  833. // 根据城市ID加载区域
  834. async loadAreasForCity(cityId) {
  835. if (!cityId) return
  836. try {
  837. console.log('加载区域数据,城市ID:', cityId)
  838. const areaRes = await api.area.getAreas(cityId)
  839. console.log('区域数据返回:', areaRes)
  840. // api.js 已经处理了数据格式,直接使用返回的数组
  841. if (Array.isArray(areaRes)) {
  842. this.areaList = areaRes
  843. } else if (areaRes && areaRes.data) {
  844. this.areaList = areaRes.data
  845. } else if (areaRes && areaRes.code === 200 && areaRes.data) {
  846. this.areaList = areaRes.data
  847. } else {
  848. this.areaList = []
  849. }
  850. this.multiAreaData[2] = this.areaList
  851. console.log('区域列表:', this.areaList)
  852. } catch (e) {
  853. console.error('加载区域失败:', e)
  854. this.areaList = []
  855. this.multiAreaData[2] = []
  856. }
  857. },
  858. // 省市区选择器列变化事件
  859. async onAreaColumnChange(e) {
  860. const column = e.detail.column // 列索引:0-省,1-市,2-区
  861. const row = e.detail.value // 选中的行索引
  862. if (column === 0) {
  863. // 选择了省份
  864. const province = this.provinceList[row]
  865. if (province && province.id) {
  866. this.multiAreaIndex[0] = row
  867. this.multiAreaIndex[1] = 0
  868. this.multiAreaIndex[2] = 0
  869. // 加载该省份的城市
  870. await this.loadCitiesForProvince(province.id)
  871. }
  872. } else if (column === 1) {
  873. // 选择了城市
  874. const city = this.cityList[row]
  875. if (city && city.id) {
  876. this.multiAreaIndex[1] = row
  877. this.multiAreaIndex[2] = 0
  878. // 加载该城市的区域
  879. await this.loadAreasForCity(city.id)
  880. }
  881. } else if (column === 2) {
  882. // 选择了区域
  883. this.multiAreaIndex[2] = row
  884. }
  885. },
  886. // 省市区选择器确认事件
  887. onAreaChange(e) {
  888. const values = e.detail.value
  889. this.multiAreaIndex = values
  890. // 设置选中的省市区ID
  891. if (this.provinceList[values[0]]) {
  892. this.profile.provinceId = this.provinceList[values[0]].id
  893. }
  894. if (this.cityList[values[1]]) {
  895. this.profile.cityId = this.cityList[values[1]].id
  896. }
  897. if (this.areaList[values[2]]) {
  898. this.profile.areaId = this.areaList[values[2]].id
  899. }
  900. },
  901. // 获取地区显示文本
  902. getAreaText() {
  903. // 如果没有省市区ID,返回未设置
  904. if (!this.profile.provinceId && !this.profile.cityId && !this.profile.areaId) {
  905. return '未设置'
  906. }
  907. let text = ''
  908. let hasText = false
  909. // 查找省份名称
  910. if (this.profile.provinceId) {
  911. if (this.provinceList.length > 0) {
  912. const province = this.provinceList.find(p => p.id === this.profile.provinceId)
  913. if (province) {
  914. text += province.name
  915. hasText = true
  916. }
  917. } else {
  918. // 如果省份列表还没加载,触发加载
  919. if (this.provinceList.length === 0) {
  920. this.loadAreaData()
  921. }
  922. return '加载中...'
  923. }
  924. }
  925. // 查找城市名称
  926. if (this.profile.cityId) {
  927. if (this.cityList.length > 0) {
  928. const city = this.cityList.find(c => c.id === this.profile.cityId)
  929. if (city) {
  930. text += (hasText ? ' ' : '') + city.name
  931. hasText = true
  932. }
  933. } else if (this.profile.provinceId) {
  934. // 如果城市列表还没加载但有省份ID,加载城市数据
  935. this.loadCitiesForProvince(this.profile.provinceId)
  936. return hasText ? text + ' 加载中...' : '加载中...'
  937. }
  938. }
  939. // 查找区域名称
  940. if (this.profile.areaId) {
  941. if (this.areaList.length > 0) {
  942. const area = this.areaList.find(a => a.id === this.profile.areaId)
  943. if (area) {
  944. text += (hasText ? ' ' : '') + area.name
  945. hasText = true
  946. }
  947. } else if (this.profile.cityId) {
  948. // 如果区域列表还没加载但有城市ID,加载区域数据
  949. this.loadAreasForCity(this.profile.cityId)
  950. return hasText ? text + ' 加载中...' : '加载中...'
  951. }
  952. }
  953. return text || '未设置'
  954. },
  955. // 初始化省市区选择器索引(根据已保存的ID)
  956. async initAreaIndex() {
  957. if (!this.profile.provinceId) {
  958. console.log('没有省份ID,跳过初始化')
  959. return
  960. }
  961. console.log('开始初始化省市区索引,当前省份ID:', this.profile.provinceId)
  962. console.log('省份列表长度:', this.provinceList.length)
  963. // 如果省份列表还没加载,先加载
  964. if (this.provinceList.length === 0) {
  965. console.log('省份列表为空,先加载数据')
  966. await this.loadAreaData()
  967. }
  968. // 查找省份索引
  969. const provinceIndex = this.provinceList.findIndex(p => p.id === this.profile.provinceId)
  970. console.log('找到的省份索引:', provinceIndex, '省份ID:', this.profile.provinceId)
  971. if (provinceIndex >= 0) {
  972. this.multiAreaIndex[0] = provinceIndex
  973. // 加载该省份的城市
  974. await this.loadCitiesForProvince(this.profile.provinceId)
  975. // 等待城市加载完成后再查找城市索引
  976. await new Promise(resolve => setTimeout(resolve, 300))
  977. if (this.profile.cityId) {
  978. const cityIndex = this.cityList.findIndex(c => c.id === this.profile.cityId)
  979. console.log('找到的城市索引:', cityIndex, '城市ID:', this.profile.cityId)
  980. if (cityIndex >= 0) {
  981. this.multiAreaIndex[1] = cityIndex
  982. // 加载该城市的区域
  983. await this.loadAreasForCity(this.profile.cityId)
  984. // 等待区域加载完成后再查找区域索引
  985. await new Promise(resolve => setTimeout(resolve, 300))
  986. if (this.profile.areaId) {
  987. const areaIndex = this.areaList.findIndex(a => a.id === this.profile.areaId)
  988. console.log('找到的区域索引:', areaIndex, '区域ID:', this.profile.areaId)
  989. if (areaIndex >= 0) {
  990. this.multiAreaIndex[2] = areaIndex
  991. }
  992. }
  993. }
  994. }
  995. // 强制更新视图
  996. this.$forceUpdate()
  997. } else {
  998. console.warn('未找到省份索引,省份ID:', this.profile.provinceId)
  999. console.log('当前省份列表:', this.provinceList.map(p => ({ id: p.id, name: p.name })))
  1000. }
  1001. },
  1002. // 显示标签选择弹窗
  1003. addHobby() {
  1004. this.showHobbyModal = true
  1005. },
  1006. // 关闭标签选择弹窗
  1007. closeHobbyModal() {
  1008. this.showHobbyModal = false
  1009. this.customHobbyInput = ''
  1010. },
  1011. // 选择预设标签
  1012. selectPresetTag(tag) {
  1013. if (this.hobbyList.includes(tag)) {
  1014. // 如果已选中,则移除
  1015. this.removeHobbyTag(this.hobbyList.indexOf(tag))
  1016. } else {
  1017. // 如果未选中,则添加
  1018. this.addHobbyTag(tag)
  1019. }
  1020. },
  1021. // 添加自定义标签
  1022. addCustomTag() {
  1023. const customTag = this.customHobbyInput.trim()
  1024. if (customTag) {
  1025. this.addHobbyTag(customTag)
  1026. this.customHobbyInput = ''
  1027. } else {
  1028. uni.showToast({
  1029. title: '请输入标签内容',
  1030. icon: 'none'
  1031. })
  1032. }
  1033. },
  1034. // 添加标签到列表
  1035. addHobbyTag(hobbyText) {
  1036. let currentHobbies = this.hobbyList.slice()
  1037. // 检查是否已存在
  1038. if (currentHobbies.includes(hobbyText)) {
  1039. uni.showToast({
  1040. title: '标签已存在',
  1041. icon: 'none'
  1042. })
  1043. return
  1044. }
  1045. // 限制标签数量
  1046. if (currentHobbies.length >= 10) {
  1047. uni.showToast({
  1048. title: '最多只能添加10个标签',
  1049. icon: 'none'
  1050. })
  1051. return
  1052. }
  1053. // 添加新标签
  1054. currentHobbies.push(hobbyText)
  1055. // 更新hobby字段(转为JSON格式)
  1056. this.profile.hobby = JSON.stringify(currentHobbies)
  1057. uni.showToast({
  1058. title: '标签添加成功',
  1059. icon: 'success'
  1060. })
  1061. },
  1062. // 移除标签
  1063. removeHobbyTag(index) {
  1064. uni.showModal({
  1065. title: '确认删除',
  1066. content: '确定要删除这个标签吗?',
  1067. success: (res) => {
  1068. if (res.confirm) {
  1069. let currentHobbies = this.hobbyList.slice()
  1070. currentHobbies.splice(index, 1)
  1071. // 更新hobby字段
  1072. this.profile.hobby = currentHobbies.length > 0 ? JSON.stringify(currentHobbies) : ''
  1073. uni.showToast({
  1074. title: '标签删除成功',
  1075. icon: 'success'
  1076. })
  1077. }
  1078. }
  1079. })
  1080. },
  1081. // 点击字段进入编辑模式
  1082. startEdit() {
  1083. if (!this.isEditing) {
  1084. this.isEditing = true
  1085. // 提示用户已进入编辑模式
  1086. uni.showToast({
  1087. title: '已进入编辑模式',
  1088. icon: 'none',
  1089. duration: 1000
  1090. })
  1091. }
  1092. },
  1093. // 处理地区点击事件
  1094. handleAreaClick() {
  1095. if (!this.isEditing) {
  1096. this.startEdit()
  1097. }
  1098. // 如果数据还没加载,立即加载
  1099. if (this.provinceList.length === 0) {
  1100. this.loadAreaData()
  1101. }
  1102. },
  1103. // 启用编辑/保存
  1104. enableEdit() {
  1105. if (this.isEditing) {
  1106. // 保存
  1107. this.saveProfile()
  1108. } else {
  1109. // 进入编辑模式
  1110. this.isEditing = true
  1111. }
  1112. },
  1113. // 保存资料
  1114. saveProfile(needGoBack = false) {
  1115. uni.showLoading({
  1116. title: '保存中...'
  1117. })
  1118. // 准备提交的数据(只包含扩展信息字段)
  1119. const submitData = {
  1120. userId: this.currentUserId,
  1121. realName: this.profile.realName,
  1122. idCard: this.profile.idCard,
  1123. height: this.profile.height,
  1124. weight: this.profile.weight,
  1125. gender: this.profile.gender,
  1126. birthDate: this.profile.birthDate,
  1127. star: this.profile.star,
  1128. animal: this.profile.animal,
  1129. educationLevel: this.profile.educationLevel,
  1130. schoolName: this.profile.schoolName,
  1131. company: this.profile.company,
  1132. jobTitle: this.profile.jobTitle,
  1133. salaryRange: this.profile.salaryRange,
  1134. maritalStatus: this.profile.maritalStatus,
  1135. house: this.profile.house,
  1136. car: this.profile.car,
  1137. hobby: this.profile.hobby,
  1138. privacySalary: this.profile.privacySalary,
  1139. privacyPhone: this.profile.privacyPhone,
  1140. provinceId: this.profile.provinceId || null,
  1141. cityId: this.profile.cityId || null,
  1142. areaId: this.profile.areaId || null
  1143. }
  1144. console.log('保存省市区数据:', {
  1145. provinceId: submitData.provinceId,
  1146. cityId: submitData.cityId,
  1147. areaId: submitData.areaId
  1148. })
  1149. uni.request({
  1150. url: this.gatewayURL + '/api/user/profile',
  1151. method: 'PUT',
  1152. data: submitData,
  1153. success: (res) => {
  1154. uni.hideLoading()
  1155. console.log('保存响应:', res.data)
  1156. if (res.data && res.data.code === 200) {
  1157. uni.showToast({
  1158. title: '保存成功',
  1159. icon: 'success',
  1160. duration: 1500
  1161. })
  1162. this.isEditing = false
  1163. // 更新 storage 中的 userInfo,特别是性别信息
  1164. const storedUserInfo = uni.getStorageSync('userInfo');
  1165. if (storedUserInfo) {
  1166. // 更新性别信息
  1167. if (submitData.gender !== undefined && submitData.gender !== null) {
  1168. storedUserInfo.gender = submitData.gender;
  1169. console.log('更新storage中的性别信息:', submitData.gender);
  1170. }
  1171. // 更新其他可能变化的字段
  1172. if (submitData.birthDate) {
  1173. storedUserInfo.birthDate = submitData.birthDate;
  1174. }
  1175. uni.setStorageSync('userInfo', storedUserInfo);
  1176. console.log('已更新storage中的userInfo');
  1177. }
  1178. // 重新加载资料
  1179. this.loadProfile()
  1180. // 如果需要返回,延迟执行返回操作
  1181. if (needGoBack) {
  1182. setTimeout(() => {
  1183. this.performGoBack()
  1184. }, 1000)
  1185. }
  1186. } else {
  1187. uni.showToast({
  1188. title: res.data?.message || '保存失败',
  1189. icon: 'none'
  1190. })
  1191. }
  1192. },
  1193. fail: (err) => {
  1194. uni.hideLoading()
  1195. console.error('保存失败:', err)
  1196. uni.showToast({
  1197. title: '网络请求失败',
  1198. icon: 'none'
  1199. })
  1200. }
  1201. })
  1202. },
  1203. // 返回上一页
  1204. goBack() {
  1205. try {
  1206. // 如果正在编辑,先提醒保存
  1207. if (this.isEditing) {
  1208. uni.showModal({
  1209. title: '提示',
  1210. content: '您正在编辑资料,是否保存后返回?',
  1211. showCancel: true,
  1212. cancelText: '直接返回',
  1213. confirmText: '保存并返回',
  1214. success: (res) => {
  1215. if (res.confirm) {
  1216. // 保存后返回
  1217. this.saveProfile(true)
  1218. } else {
  1219. // 直接返回
  1220. this.performGoBack()
  1221. }
  1222. }
  1223. })
  1224. } else {
  1225. // 直接返回
  1226. this.performGoBack()
  1227. }
  1228. } catch (error) {
  1229. console.error('返回操作异常:', error)
  1230. // 异常时直接跳转到我的页面
  1231. uni.navigateTo({
  1232. url: '/pages/mine/index'
  1233. })
  1234. }
  1235. },
  1236. // 执行返回操作
  1237. performGoBack() {
  1238. // 检查页面栈
  1239. const pages = getCurrentPages()
  1240. console.log('当前页面栈长度:', pages.length)
  1241. console.log('页面栈:', pages.map(p => p.route))
  1242. if (pages.length > 1) {
  1243. // 有上一页,正常返回
  1244. uni.navigateBack({
  1245. delta: 1,
  1246. success: () => {
  1247. console.log('返回成功')
  1248. },
  1249. fail: (err) => {
  1250. console.error('返回失败:', err)
  1251. // 返回失败时,提示用户并提供选择
  1252. uni.showModal({
  1253. title: '返回失败',
  1254. content: '无法返回上一页,是否跳转到我的页面?',
  1255. showCancel: true,
  1256. cancelText: '留在此页',
  1257. confirmText: '去我的页面',
  1258. success: (modalRes) => {
  1259. if (modalRes.confirm) {
  1260. uni.navigateTo({
  1261. url: '/pages/mine/index'
  1262. })
  1263. }
  1264. }
  1265. })
  1266. }
  1267. })
  1268. } else {
  1269. // 没有上一页,直接跳转到我的页面
  1270. console.log('页面栈只有一页,跳转到我的页面')
  1271. uni.navigateTo({
  1272. url: '/pages/mine/index'
  1273. })
  1274. }
  1275. }
  1276. }
  1277. }
  1278. </script>
  1279. <style lang="scss" scoped>
  1280. .profile-page {
  1281. min-height: 100vh;
  1282. background: linear-gradient(180deg, #FF8A9B 0%, #FFB4C0 25%, #FFF0F2 50%, #F8F8F8 100%);
  1283. display: flex;
  1284. flex-direction: column;
  1285. }
  1286. /* 顶部导航栏 */
  1287. .header {
  1288. position: relative;
  1289. display: flex;
  1290. align-items: center;
  1291. justify-content: center;
  1292. padding: 25rpx 30rpx;
  1293. padding-top: calc(25rpx + env(safe-area-inset-top));
  1294. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  1295. box-shadow: 0 4rpx 20rpx rgba(255, 138, 155, 0.2);
  1296. .back-btn {
  1297. position: absolute;
  1298. left: 30rpx;
  1299. width: 70rpx;
  1300. height: 70rpx;
  1301. display: flex;
  1302. align-items: center;
  1303. justify-content: center;
  1304. background: rgba(255, 255, 255, 0.2);
  1305. border-radius: 50%;
  1306. .back-icon {
  1307. font-size: 44rpx;
  1308. color: #FFFFFF;
  1309. font-weight: bold;
  1310. }
  1311. }
  1312. .header-title {
  1313. font-size: 38rpx;
  1314. font-weight: bold;
  1315. color: #FFFFFF;
  1316. letter-spacing: 2rpx;
  1317. }
  1318. .edit-btn {
  1319. position: absolute;
  1320. right: 30rpx;
  1321. padding: 12rpx 30rpx;
  1322. background: rgba(255, 255, 255, 0.3);
  1323. border-radius: 35rpx;
  1324. min-width: 100rpx;
  1325. display: flex;
  1326. align-items: center;
  1327. justify-content: center;
  1328. .edit-text {
  1329. font-size: 28rpx;
  1330. color: #FFFFFF;
  1331. font-weight: 500;
  1332. }
  1333. }
  1334. }
  1335. /* 头像区域 */
  1336. .avatar-section {
  1337. display: flex;
  1338. flex-direction: column;
  1339. align-items: center;
  1340. padding: 50rpx 0 40rpx;
  1341. .avatar-wrapper {
  1342. position: relative;
  1343. margin-bottom: 25rpx;
  1344. cursor: pointer;
  1345. .avatar {
  1346. width: 180rpx;
  1347. height: 180rpx;
  1348. border-radius: 90rpx;
  1349. border: 6rpx solid #FFFFFF;
  1350. box-shadow: 0 8rpx 30rpx rgba(255, 138, 155, 0.3);
  1351. }
  1352. .avatar-badge {
  1353. position: absolute;
  1354. bottom: 5rpx;
  1355. right: 5rpx;
  1356. width: 50rpx;
  1357. height: 50rpx;
  1358. background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  1359. border-radius: 25rpx;
  1360. display: flex;
  1361. align-items: center;
  1362. justify-content: center;
  1363. border: 4rpx solid #FFFFFF;
  1364. box-shadow: 0 4rpx 15rpx rgba(255, 215, 0, 0.4);
  1365. .vip-icon {
  1366. font-size: 28rpx;
  1367. }
  1368. }
  1369. .avatar-edit-hint {
  1370. position: absolute;
  1371. bottom: 0;
  1372. left: 0;
  1373. right: 0;
  1374. height: 60rpx;
  1375. background: rgba(0, 0, 0, 0.5);
  1376. border-radius: 0 0 90rpx 90rpx;
  1377. display: flex;
  1378. align-items: center;
  1379. justify-content: center;
  1380. .edit-hint-icon {
  1381. font-size: 32rpx;
  1382. color: #FFFFFF;
  1383. }
  1384. }
  1385. }
  1386. .nickname {
  1387. font-size: 40rpx;
  1388. font-weight: bold;
  1389. color: #333333;
  1390. margin-bottom: 12rpx;
  1391. }
  1392. .user-id {
  1393. font-size: 26rpx;
  1394. color: #999999;
  1395. background: rgba(255, 255, 255, 0.8);
  1396. padding: 8rpx 30rpx;
  1397. border-radius: 30rpx;
  1398. }
  1399. }
  1400. /* 编辑提示 */
  1401. .edit-tip {
  1402. margin: 0 30rpx;
  1403. background: linear-gradient(135deg, #E8F5E8 0%, #D4EDDA 100%);
  1404. border-radius: 15rpx;
  1405. padding: 20rpx 25rpx;
  1406. text-align: center;
  1407. border-left: 6rpx solid #28A745;
  1408. .tip-text {
  1409. font-size: 26rpx;
  1410. color: #28A745;
  1411. font-weight: 500;
  1412. }
  1413. }
  1414. /* 滚动内容区域 */
  1415. .content-scroll {
  1416. flex: 1;
  1417. padding: 20rpx 30rpx 0 30rpx;
  1418. box-sizing: border-box;
  1419. }
  1420. /* 各个section */
  1421. .section {
  1422. background-color: #FFFFFF;
  1423. border-radius: 20rpx;
  1424. padding: 30rpx 25rpx;
  1425. margin-bottom: 25rpx;
  1426. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  1427. width: 100%;
  1428. box-sizing: border-box;
  1429. .section-title {
  1430. font-size: 34rpx;
  1431. font-weight: bold;
  1432. color: #333333;
  1433. margin-bottom: 30rpx;
  1434. padding-bottom: 20rpx;
  1435. padding-left: 30rpx;
  1436. border-bottom: 3rpx solid #F0F0F0;
  1437. display: flex;
  1438. align-items: center;
  1439. position: relative;
  1440. &::before {
  1441. content: '';
  1442. position: absolute;
  1443. left: 5rpx;
  1444. width: 8rpx;
  1445. height: 32rpx;
  1446. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1447. border-radius: 4rpx;
  1448. }
  1449. }
  1450. .info-item {
  1451. display: flex;
  1452. align-items: center;
  1453. justify-content: space-between;
  1454. padding: 30rpx 0;
  1455. padding-left: 30rpx;
  1456. border-bottom: 1rpx solid #F5F5F5;
  1457. min-height: 80rpx;
  1458. position: relative;
  1459. transition: background-color 0.2s;
  1460. &:active {
  1461. background-color: #F8F8F8;
  1462. }
  1463. &:last-child {
  1464. border-bottom: none;
  1465. }
  1466. &.column {
  1467. flex-direction: column;
  1468. align-items: flex-start;
  1469. }
  1470. .label {
  1471. font-size: 30rpx;
  1472. color: #333333;
  1473. flex-shrink: 0;
  1474. width: 180rpx;
  1475. font-weight: 500;
  1476. }
  1477. .value {
  1478. flex: 1;
  1479. text-align: right;
  1480. font-size: 30rpx;
  1481. color: #666666;
  1482. padding-left: 20rpx;
  1483. }
  1484. .input {
  1485. flex: 1;
  1486. text-align: right;
  1487. font-size: 30rpx;
  1488. color: #333333;
  1489. padding-left: 20rpx;
  1490. }
  1491. .picker-value {
  1492. flex: 1;
  1493. text-align: right;
  1494. font-size: 30rpx;
  1495. color: #666666;
  1496. padding-left: 20rpx;
  1497. }
  1498. .verify-status {
  1499. margin-left: 15rpx;
  1500. font-size: 22rpx;
  1501. flex-shrink: 0;
  1502. &.verified {
  1503. color: #4CAF50;
  1504. }
  1505. &.unverified {
  1506. color: #999999;
  1507. }
  1508. }
  1509. switch {
  1510. flex-shrink: 0;
  1511. }
  1512. }
  1513. }
  1514. /* 爱好标签 */
  1515. .hobby-tags {
  1516. display: flex;
  1517. flex-wrap: wrap;
  1518. gap: 18rpx;
  1519. margin-top: 20rpx;
  1520. width: 100%;
  1521. .hobby-tag {
  1522. padding: 15rpx 30rpx;
  1523. background: linear-gradient(135deg, #FFE5EC 0%, #FFD0DC 100%);
  1524. border-radius: 35rpx;
  1525. font-size: 26rpx;
  1526. color: #FF6B8A;
  1527. font-weight: 500;
  1528. position: relative;
  1529. display: flex;
  1530. align-items: center;
  1531. transition: all 0.3s;
  1532. &.add {
  1533. border: 2rpx dashed #FF8A9B;
  1534. background: transparent;
  1535. color: #FF8A9B;
  1536. justify-content: center;
  1537. }
  1538. &.deletable {
  1539. padding-right: 50rpx;
  1540. &:active {
  1541. background: linear-gradient(135deg, #FFB8C5 0%, #FFA3B3 100%);
  1542. transform: scale(0.95);
  1543. }
  1544. }
  1545. .delete-icon {
  1546. position: absolute;
  1547. right: 15rpx;
  1548. top: 50%;
  1549. transform: translateY(-50%);
  1550. width: 30rpx;
  1551. height: 30rpx;
  1552. background: rgba(255, 255, 255, 0.8);
  1553. border-radius: 50%;
  1554. display: flex;
  1555. align-items: center;
  1556. justify-content: center;
  1557. font-size: 24rpx;
  1558. color: #FF6B8A;
  1559. font-weight: bold;
  1560. }
  1561. }
  1562. .hobby-empty {
  1563. width: 100%;
  1564. text-align: center;
  1565. padding: 40rpx 0;
  1566. .empty-text {
  1567. font-size: 26rpx;
  1568. color: #999999;
  1569. }
  1570. }
  1571. }
  1572. /* 真实度评分 */
  1573. .authenticity-score {
  1574. display: flex;
  1575. flex-direction: column;
  1576. align-items: center;
  1577. padding: 40rpx 0 20rpx;
  1578. .score-circle {
  1579. width: 200rpx;
  1580. height: 200rpx;
  1581. border-radius: 100rpx;
  1582. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1583. display: flex;
  1584. flex-direction: column;
  1585. align-items: center;
  1586. justify-content: center;
  1587. margin-bottom: 30rpx;
  1588. box-shadow: 0 10rpx 40rpx rgba(255, 107, 138, 0.4);
  1589. position: relative;
  1590. &::before {
  1591. content: '';
  1592. position: absolute;
  1593. width: 220rpx;
  1594. height: 220rpx;
  1595. border-radius: 110rpx;
  1596. border: 2rpx solid rgba(255, 138, 155, 0.3);
  1597. top: -10rpx;
  1598. left: -10rpx;
  1599. }
  1600. .score-number {
  1601. font-size: 68rpx;
  1602. font-weight: bold;
  1603. color: #FFFFFF;
  1604. line-height: 1;
  1605. }
  1606. .score-total {
  1607. font-size: 26rpx;
  1608. color: rgba(255, 255, 255, 0.95);
  1609. margin-top: 5rpx;
  1610. }
  1611. }
  1612. .score-tips {
  1613. background: rgba(255, 138, 155, 0.1);
  1614. padding: 15rpx 30rpx;
  1615. border-radius: 30rpx;
  1616. .tip-text {
  1617. font-size: 24rpx;
  1618. color: #FF6B8A;
  1619. text-align: center;
  1620. }
  1621. }
  1622. }
  1623. .bottom-placeholder {
  1624. height: 80rpx;
  1625. }
  1626. /* 标签选择弹窗 */
  1627. .hobby-modal {
  1628. position: fixed;
  1629. top: 0;
  1630. left: 0;
  1631. right: 0;
  1632. bottom: 0;
  1633. background: rgba(0, 0, 0, 0.6);
  1634. display: flex;
  1635. align-items: center;
  1636. justify-content: center;
  1637. z-index: 9999;
  1638. .modal-content {
  1639. width: 90%;
  1640. max-height: 80vh;
  1641. background: #FFFFFF;
  1642. border-radius: 30rpx;
  1643. overflow: hidden;
  1644. display: flex;
  1645. flex-direction: column;
  1646. }
  1647. .modal-header {
  1648. display: flex;
  1649. align-items: center;
  1650. justify-content: space-between;
  1651. padding: 40rpx 30rpx 20rpx;
  1652. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  1653. .modal-title {
  1654. font-size: 32rpx;
  1655. font-weight: bold;
  1656. color: #FFFFFF;
  1657. }
  1658. .close-btn {
  1659. width: 60rpx;
  1660. height: 60rpx;
  1661. display: flex;
  1662. align-items: center;
  1663. justify-content: center;
  1664. font-size: 40rpx;
  1665. color: #FFFFFF;
  1666. background: rgba(255, 255, 255, 0.2);
  1667. border-radius: 30rpx;
  1668. }
  1669. }
  1670. .modal-body {
  1671. flex: 1;
  1672. padding: 30rpx;
  1673. max-height: 60vh;
  1674. }
  1675. .hobby-category {
  1676. margin-bottom: 40rpx;
  1677. &:last-child {
  1678. margin-bottom: 0;
  1679. }
  1680. .category-title {
  1681. display: flex;
  1682. align-items: center;
  1683. margin-bottom: 20rpx;
  1684. .category-icon {
  1685. font-size: 36rpx;
  1686. margin-right: 15rpx;
  1687. }
  1688. .category-name {
  1689. font-size: 28rpx;
  1690. font-weight: bold;
  1691. color: #333333;
  1692. }
  1693. }
  1694. .category-tags {
  1695. display: flex;
  1696. flex-wrap: wrap;
  1697. gap: 15rpx;
  1698. .preset-tag {
  1699. padding: 12rpx 25rpx;
  1700. background: #F5F5F5;
  1701. border-radius: 30rpx;
  1702. font-size: 26rpx;
  1703. color: #666666;
  1704. position: relative;
  1705. transition: all 0.3s;
  1706. &.selected {
  1707. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1708. color: #FFFFFF;
  1709. padding-right: 45rpx;
  1710. }
  1711. &:active {
  1712. transform: scale(0.95);
  1713. }
  1714. .check-icon {
  1715. position: absolute;
  1716. right: 10rpx;
  1717. top: 50%;
  1718. transform: translateY(-50%);
  1719. font-size: 20rpx;
  1720. font-weight: bold;
  1721. }
  1722. }
  1723. }
  1724. }
  1725. .custom-input-section {
  1726. margin-top: 20rpx;
  1727. padding-top: 30rpx;
  1728. border-top: 1rpx solid #F0F0F0;
  1729. .input-wrapper {
  1730. display: flex;
  1731. align-items: center;
  1732. gap: 20rpx;
  1733. .custom-input {
  1734. flex: 1;
  1735. padding: 20rpx 25rpx;
  1736. background: #F8F8F8;
  1737. border-radius: 25rpx;
  1738. font-size: 26rpx;
  1739. border: 2rpx solid transparent;
  1740. &:focus {
  1741. border-color: #FF8A9B;
  1742. background: #FFFFFF;
  1743. }
  1744. }
  1745. .add-custom-btn {
  1746. padding: 20rpx 30rpx;
  1747. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1748. border-radius: 25rpx;
  1749. .add-text {
  1750. font-size: 26rpx;
  1751. color: #FFFFFF;
  1752. font-weight: 500;
  1753. }
  1754. }
  1755. }
  1756. }
  1757. .modal-footer {
  1758. display: flex;
  1759. align-items: center;
  1760. justify-content: space-between;
  1761. padding: 30rpx;
  1762. background: #F8F8F8;
  1763. .selected-count {
  1764. font-size: 26rpx;
  1765. color: #666666;
  1766. }
  1767. .done-btn {
  1768. padding: 20rpx 40rpx;
  1769. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1770. border-radius: 30rpx;
  1771. .done-text {
  1772. font-size: 28rpx;
  1773. color: #FFFFFF;
  1774. font-weight: bold;
  1775. }
  1776. }
  1777. }
  1778. }
  1779. </style>