index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <view class="requirement-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="toggleEdit">
  10. <text class="edit-text">{{ isEditing ? '保存' : '编辑' }}</text>
  11. </view>
  12. </view>
  13. <scroll-view scroll-y class="content">
  14. <!-- 提示说明 -->
  15. <view class="tips-section">
  16. <text class="tips-icon">💡</text>
  17. <text class="tips-text">设置您的理想对象条件,系统会为您推荐更匹配的用户</text>
  18. </view>
  19. <!-- 基本条件 -->
  20. <view class="section">
  21. <view class="section-title">基本条件</view>
  22. <!-- <view class="item-row">
  23. <text class="label">性别</text>
  24. <picker v-if="isEditing" :range="genderOptions" range-key="label" :value="getGenderIndex()" @change="onGenderChange">
  25. <view class="picker-value">{{ getGenderText() }}</view>
  26. </picker>
  27. <text v-else class="value">{{ getGenderText() }}</text>
  28. </view> -->
  29. <view class="item-row">
  30. <text class="label">年龄范围</text>
  31. <view class="range-input" v-if="isEditing">
  32. <input class="range-value" type="number" v-model="requirement.minAge" placeholder="最小" />
  33. <text class="range-divider">-</text>
  34. <input class="range-value" type="number" v-model="requirement.maxAge" placeholder="最大" />
  35. <text class="range-unit">岁</text>
  36. </view>
  37. <text v-else class="value">{{ getAgeRangeText() }}</text>
  38. </view>
  39. <view class="item-row">
  40. <text class="label">身高范围</text>
  41. <view class="range-input" v-if="isEditing">
  42. <input class="range-value" type="number" v-model="requirement.minHeight" placeholder="最小" />
  43. <text class="range-divider">-</text>
  44. <input class="range-value" type="number" v-model="requirement.maxHeight" placeholder="最大" />
  45. <text class="range-unit">cm</text>
  46. </view>
  47. <text v-else class="value">{{ getHeightRangeText() }}</text>
  48. </view>
  49. <view class="item-row">
  50. <text class="label">学历要求</text>
  51. <picker v-if="isEditing" :range="educationOptions" :value="getEducationIndex()" @change="onEducationChange">
  52. <view class="picker-value">{{ getEducationText() }}</view>
  53. </picker>
  54. <text v-else class="value">{{ getEducationText() }}</text>
  55. </view>
  56. </view>
  57. <!-- 经济条件 -->
  58. <view class="section">
  59. <view class="section-title">经济条件</view>
  60. <view class="item-row">
  61. <text class="label">薪资要求</text>
  62. <picker v-if="isEditing" :range="salaryOptions" :value="getSalaryIndex()" @change="onSalaryChange">
  63. <view class="picker-value">{{ getSalaryText() }}</view>
  64. </picker>
  65. <text v-else class="value">{{ getSalaryText() }}</text>
  66. </view>
  67. <view class="item-row">
  68. <text class="label">房产要求</text>
  69. <picker v-if="isEditing" :range="houseOptions" range-key="label" :value="getHouseIndex()" @change="onHouseChange">
  70. <view class="picker-value">{{ getHouseText() }}</view>
  71. </picker>
  72. <text v-else class="value">{{ getHouseText() }}</text>
  73. </view>
  74. <view class="item-row">
  75. <text class="label">车辆要求</text>
  76. <picker v-if="isEditing" :range="carOptions" range-key="label" :value="getCarIndex()" @change="onCarChange">
  77. <view class="picker-value">{{ getCarText() }}</view>
  78. </picker>
  79. <text v-else class="value">{{ getCarText() }}</text>
  80. </view>
  81. </view>
  82. <!-- 婚姻状况 -->
  83. <view class="section">
  84. <view class="section-title">婚姻状况</view>
  85. <view class="item-row">
  86. <text class="label">婚姻要求</text>
  87. <picker v-if="isEditing" :range="maritalOptions" :value="getMaritalIndex()" @change="onMaritalChange">
  88. <view class="picker-value">{{ getMaritalText() }}</view>
  89. </picker>
  90. <text v-else class="value">{{ getMaritalText() }}</text>
  91. </view>
  92. </view>
  93. <!-- 地区要求 -->
  94. <view class="section">
  95. <view class="section-title">地区要求</view>
  96. <view class="item-row">
  97. <text class="label">期望城市</text>
  98. <input v-if="isEditing" class="input" v-model="requirement.preferredCity" placeholder="如:北京、上海" />
  99. <text v-else class="value">{{ requirement.preferredCity || '不限' }}</text>
  100. </view>
  101. </view>
  102. <!-- 其他要求 -->
  103. <view class="section">
  104. <view class="section-title">其他要求</view>
  105. <view class="item-column">
  106. <text class="label">其他说明</text>
  107. <textarea
  108. v-if="isEditing"
  109. class="textarea"
  110. v-model="requirement.otherRequirements"
  111. placeholder="请描述您对理想对象的其他要求"
  112. maxlength="500"
  113. ></textarea>
  114. <text v-else class="value multi-line">{{ requirement.otherRequirements || '暂无其他要求' }}</text>
  115. </view>
  116. </view>
  117. </scroll-view>
  118. </view>
  119. </template>
  120. <script>
  121. export default {
  122. data() {
  123. return {
  124. gatewayURL: 'https://api.zhongruanke.cn',
  125. currentUserId: null,
  126. isEditing: false,
  127. requirement: {
  128. minAge: null,
  129. maxAge: null,
  130. minHeight: null,
  131. maxHeight: null,
  132. educationLevel: null,
  133. salaryRange: null,
  134. house: null,
  135. car: null,
  136. maritalStatus: null,
  137. preferredCity: '',
  138. otherRequirements: ''
  139. },
  140. educationOptions: ['不限', '高中及以上', '专科及以上', '本科及以上', '硕士及以上', '博士及以上'],
  141. salaryOptions: ['不限', '5k+', '10k+', '20k+', '50k+'],
  142. houseOptions: [
  143. { value: 0, label: '不限' },
  144. { value: 1, label: '有房' }
  145. ],
  146. carOptions: [
  147. { value: 0, label: '不限' },
  148. { value: 1, label: '有车' }
  149. ],
  150. maritalOptions: ['不限', '未婚', '离异', '丧偶']
  151. }
  152. },
  153. onLoad() {
  154. this.currentUserId = uni.getStorageSync('userId') || 1
  155. this.loadRequirement()
  156. },
  157. methods: {
  158. goBack() {
  159. if (this.isEditing) {
  160. uni.showModal({
  161. title: '提示',
  162. content: '您正在编辑,是否保存后返回?',
  163. cancelText: '直接返回',
  164. confirmText: '保存',
  165. success: (res) => {
  166. if (res.confirm) {
  167. this.saveRequirement(true)
  168. } else {
  169. uni.navigateBack()
  170. }
  171. }
  172. })
  173. } else {
  174. uni.navigateBack()
  175. }
  176. },
  177. toggleEdit() {
  178. if (this.isEditing) {
  179. this.saveRequirement()
  180. } else {
  181. this.isEditing = true
  182. }
  183. },
  184. loadRequirement() {
  185. uni.showLoading({ title: '加载中...' })
  186. uni.request({
  187. url: `${this.gatewayURL}/api/partner-requirement/${this.currentUserId}`,
  188. method: 'GET',
  189. success: (res) => {
  190. if (res.data.code === 200 && res.data.data) {
  191. // 将后端返回的数据映射到前端字段
  192. const data = res.data.data
  193. this.requirement = {
  194. minAge: data.minAge,
  195. maxAge: data.maxAge,
  196. minHeight: data.minHeight,
  197. maxHeight: data.maxHeight,
  198. educationLevel: data.educationLevel,
  199. salaryRange: data.salaryRange,
  200. house: data.house,
  201. car: data.car,
  202. maritalStatus: data.maritalStatus,
  203. preferredCity: data.preferredCity || '',
  204. otherRequirements: data.otherRequirements || ''
  205. }
  206. }
  207. },
  208. fail: (err) => {
  209. console.error('加载失败:', err)
  210. uni.showToast({
  211. title: '加载失败',
  212. icon: 'none'
  213. })
  214. },
  215. complete: () => {
  216. uni.hideLoading()
  217. }
  218. })
  219. },
  220. saveRequirement(needGoBack = false) {
  221. uni.showLoading({ title: '保存中...' })
  222. // 准备提交的数据
  223. const data = {
  224. userId: this.currentUserId,
  225. minAge: this.requirement.minAge || null,
  226. maxAge: this.requirement.maxAge || null,
  227. minHeight: this.requirement.minHeight || null,
  228. maxHeight: this.requirement.maxHeight || null,
  229. educationLevel: this.requirement.educationLevel,
  230. salaryRange: this.requirement.salaryRange,
  231. house: this.requirement.house,
  232. car: this.requirement.car,
  233. maritalStatus: this.requirement.maritalStatus,
  234. preferredCity: this.requirement.preferredCity || '',
  235. otherRequirements: this.requirement.otherRequirements || ''
  236. }
  237. uni.request({
  238. url: `${this.gatewayURL}/api/partner-requirement/save`,
  239. method: 'POST',
  240. data: data,
  241. header: {
  242. 'Content-Type': 'application/json'
  243. },
  244. success: (res) => {
  245. if (res.data.code === 200) {
  246. uni.showToast({
  247. title: '保存成功',
  248. icon: 'success'
  249. })
  250. this.isEditing = false
  251. if (needGoBack) {
  252. setTimeout(() => {
  253. uni.navigateBack()
  254. }, 1000)
  255. }
  256. } else {
  257. uni.showToast({
  258. title: res.data.msg || '保存失败',
  259. icon: 'none'
  260. })
  261. }
  262. },
  263. fail: (err) => {
  264. console.error('保存失败:', err)
  265. uni.showToast({
  266. title: '保存失败',
  267. icon: 'none'
  268. })
  269. },
  270. complete: () => {
  271. uni.hideLoading()
  272. }
  273. })
  274. },
  275. // // 获取文本方法
  276. // getGenderText() {
  277. // const option = this.genderOptions.find(item => item.value === this.requirement.gender)
  278. // return option ? option.label : '不限'
  279. // },
  280. getAgeRangeText() {
  281. if (!this.requirement.minAge && !this.requirement.maxAge) return '不限'
  282. if (this.requirement.minAge && !this.requirement.maxAge) return this.requirement.minAge + '岁以上'
  283. if (!this.requirement.minAge && this.requirement.maxAge) return this.requirement.maxAge + '岁以下'
  284. return this.requirement.minAge + '-' + this.requirement.maxAge + '岁'
  285. },
  286. getHeightRangeText() {
  287. if (!this.requirement.minHeight && !this.requirement.maxHeight) return '不限'
  288. if (this.requirement.minHeight && !this.requirement.maxHeight) return this.requirement.minHeight + 'cm以上'
  289. if (!this.requirement.minHeight && this.requirement.maxHeight) return this.requirement.maxHeight + 'cm以下'
  290. return this.requirement.minHeight + '-' + this.requirement.maxHeight + 'cm'
  291. },
  292. getEducationText() {
  293. if (this.requirement.educationLevel === null || this.requirement.educationLevel === undefined) return '不限'
  294. return this.educationOptions[this.requirement.educationLevel] || '不限'
  295. },
  296. getSalaryText() {
  297. if (this.requirement.salaryRange === null || this.requirement.salaryRange === undefined) return '不限'
  298. return this.salaryOptions[this.requirement.salaryRange] || '不限'
  299. },
  300. getHouseText() {
  301. const option = this.houseOptions.find(item => item.value === this.requirement.house)
  302. return option ? option.label : '不限'
  303. },
  304. getCarText() {
  305. const option = this.carOptions.find(item => item.value === this.requirement.car)
  306. return option ? option.label : '不限'
  307. },
  308. getMaritalText() {
  309. if (this.requirement.maritalStatus === null || this.requirement.maritalStatus === undefined) return '不限'
  310. return this.maritalOptions[this.requirement.maritalStatus] || '不限'
  311. },
  312. // 获取索引方法
  313. getGenderIndex() {
  314. const index = this.genderOptions.findIndex(item => item.value === this.requirement.gender)
  315. return Math.max(0, index)
  316. },
  317. getEducationIndex() {
  318. return this.requirement.educationLevel || 0
  319. },
  320. getSalaryIndex() {
  321. return this.requirement.salaryRange || 0
  322. },
  323. getHouseIndex() {
  324. const index = this.houseOptions.findIndex(item => item.value === this.requirement.house)
  325. return Math.max(0, index)
  326. },
  327. getCarIndex() {
  328. const index = this.carOptions.findIndex(item => item.value === this.requirement.car)
  329. return Math.max(0, index)
  330. },
  331. getMaritalIndex() {
  332. return this.requirement.maritalStatus || 0
  333. },
  334. // 选择器变更方法
  335. onGenderChange(e) {
  336. this.requirement.gender = this.genderOptions[parseInt(e.detail.value)].value
  337. },
  338. onEducationChange(e) {
  339. this.requirement.educationLevel = parseInt(e.detail.value)
  340. },
  341. onSalaryChange(e) {
  342. this.requirement.salaryRange = parseInt(e.detail.value)
  343. },
  344. onHouseChange(e) {
  345. this.requirement.house = this.houseOptions[parseInt(e.detail.value)].value
  346. },
  347. onCarChange(e) {
  348. this.requirement.car = this.carOptions[parseInt(e.detail.value)].value
  349. },
  350. onMaritalChange(e) {
  351. this.requirement.maritalStatus = parseInt(e.detail.value)
  352. }
  353. }
  354. }
  355. </script>
  356. <style lang="scss" scoped>
  357. * {
  358. box-sizing: border-box;
  359. }
  360. .requirement-page {
  361. min-height: 100vh;
  362. background: linear-gradient(180deg, #FF8A9B 0%, #FFB4C0 25%, #FFF0F2 50%, #F8F8F8 100%);
  363. display: flex;
  364. flex-direction: column;
  365. }
  366. /* 顶部导航栏 */
  367. .header {
  368. display: flex;
  369. align-items: center;
  370. justify-content: space-between;
  371. padding: 25rpx 30rpx;
  372. padding-top: calc(25rpx + env(safe-area-inset-top));
  373. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  374. box-shadow: 0 4rpx 20rpx rgba(255, 138, 155, 0.2);
  375. .back-btn {
  376. width: 70rpx;
  377. height: 70rpx;
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. background: rgba(255, 255, 255, 0.2);
  382. border-radius: 50%;
  383. .back-icon {
  384. font-size: 44rpx;
  385. color: #FFFFFF;
  386. font-weight: bold;
  387. }
  388. }
  389. .header-title {
  390. font-size: 38rpx;
  391. font-weight: bold;
  392. color: #FFFFFF;
  393. }
  394. .edit-btn {
  395. padding: 12rpx 30rpx;
  396. background: rgba(255, 255, 255, 0.3);
  397. border-radius: 35rpx;
  398. .edit-text {
  399. font-size: 28rpx;
  400. color: #FFFFFF;
  401. font-weight: 500;
  402. }
  403. }
  404. }
  405. .content {
  406. flex: 1;
  407. padding: 20rpx 0rpx;
  408. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  409. }
  410. /* 提示区域 */
  411. .tips-section {
  412. background: linear-gradient(135deg, #E8F5E8 0%, #D4EDDA 100%);
  413. border-radius: 15rpx;
  414. padding: 20rpx 25rpx;
  415. margin-bottom: 25rpx;
  416. display: flex;
  417. align-items: center;
  418. border-left: 6rpx solid #28A745;
  419. .tips-icon {
  420. font-size: 32rpx;
  421. margin-right: 15rpx;
  422. flex-shrink: 0;
  423. }
  424. .tips-text {
  425. font-size: 26rpx;
  426. color: #28A745;
  427. line-height: 1.5;
  428. }
  429. }
  430. /* 区块样式 */
  431. .section {
  432. background: #FFFFFF;
  433. border-radius: 20rpx;
  434. padding: 30rpx 0;
  435. margin-bottom: 25rpx;
  436. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  437. .section-title {
  438. font-size: 32rpx;
  439. font-weight: bold;
  440. color: #333333;
  441. margin-bottom: 25rpx;
  442. padding: 0 30rpx;
  443. }
  444. .item-row {
  445. display: flex;
  446. align-items: center;
  447. padding: 25rpx 30rpx 25rpx 30rpx;
  448. border-bottom: 1rpx solid #F5F5F5;
  449. &:last-child {
  450. border-bottom: none;
  451. }
  452. .label {
  453. font-size: 28rpx;
  454. color: #333333;
  455. font-weight: 500;
  456. flex: 1;
  457. }
  458. .value,
  459. .picker-value {
  460. text-align: right;
  461. font-size: 28rpx;
  462. color: #666666;
  463. min-width: 120rpx;
  464. flex-shrink: 0;
  465. }
  466. .input {
  467. text-align: right;
  468. font-size: 28rpx;
  469. color: #333333;
  470. min-width: 200rpx;
  471. flex-shrink: 0;
  472. }
  473. .range-input {
  474. flex: 1;
  475. display: flex;
  476. align-items: center;
  477. justify-content: flex-end;
  478. .range-value {
  479. width: 100rpx;
  480. height: 60rpx;
  481. text-align: center;
  482. border: 1rpx solid #E0E0E0;
  483. border-radius: 8rpx;
  484. font-size: 26rpx;
  485. background: #FAFAFA;
  486. box-sizing: border-box;
  487. }
  488. .range-divider {
  489. margin: 0 10rpx;
  490. color: #999999;
  491. font-size: 24rpx;
  492. }
  493. .range-unit {
  494. margin-left: 10rpx;
  495. font-size: 24rpx;
  496. color: #999999;
  497. width: 40rpx;
  498. }
  499. }
  500. }
  501. .item-column {
  502. padding: 25rpx 30rpx 25rpx 30rpx;
  503. .label {
  504. display: block;
  505. font-size: 28rpx;
  506. color: #333333;
  507. font-weight: 500;
  508. margin-bottom: 20rpx;
  509. }
  510. .textarea {
  511. width: 100%;
  512. min-height: 160rpx;
  513. padding: 20rpx;
  514. border: 1rpx solid #E0E0E0;
  515. border-radius: 10rpx;
  516. font-size: 26rpx;
  517. line-height: 1.6;
  518. background: #FAFAFA;
  519. box-sizing: border-box;
  520. }
  521. .value {
  522. font-size: 26rpx;
  523. color: #666666;
  524. &.multi-line {
  525. display: block;
  526. line-height: 1.8;
  527. }
  528. }
  529. }
  530. }
  531. </style>