index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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: 'http://localhost:8083',
  125. currentUserId: null,
  126. isEditing: false,
  127. requirement: {
  128. gender: null,
  129. minAge: null,
  130. maxAge: null,
  131. minHeight: null,
  132. maxHeight: null,
  133. educationLevel: null,
  134. salaryRange: null,
  135. house: null,
  136. car: null,
  137. maritalStatus: null,
  138. preferredCity: '',
  139. otherRequirements: ''
  140. },
  141. genderOptions: [
  142. { value: 0, label: '不限' },
  143. { value: 1, label: '男' },
  144. { value: 2, label: '女' }
  145. ],
  146. educationOptions: ['不限', '高中及以上', '专科及以上', '本科及以上', '硕士及以上', '博士及以上'],
  147. salaryOptions: ['不限', '5k+', '10k+', '20k+', '50k+'],
  148. houseOptions: [
  149. { value: 0, label: '不限' },
  150. { value: 1, label: '有房' }
  151. ],
  152. carOptions: [
  153. { value: 0, label: '不限' },
  154. { value: 1, label: '有车' }
  155. ],
  156. maritalOptions: ['不限', '未婚', '离异', '丧偶']
  157. }
  158. },
  159. onLoad() {
  160. this.currentUserId = uni.getStorageSync('userId') || 1
  161. this.loadRequirement()
  162. },
  163. methods: {
  164. goBack() {
  165. if (this.isEditing) {
  166. uni.showModal({
  167. title: '提示',
  168. content: '您正在编辑,是否保存后返回?',
  169. cancelText: '直接返回',
  170. confirmText: '保存',
  171. success: (res) => {
  172. if (res.confirm) {
  173. this.saveRequirement(true)
  174. } else {
  175. uni.navigateBack()
  176. }
  177. }
  178. })
  179. } else {
  180. uni.navigateBack()
  181. }
  182. },
  183. toggleEdit() {
  184. if (this.isEditing) {
  185. this.saveRequirement()
  186. } else {
  187. this.isEditing = true
  188. }
  189. },
  190. loadRequirement() {
  191. uni.showLoading({ title: '加载中...' })
  192. // TODO: 调用后端接口
  193. setTimeout(() => {
  194. uni.hideLoading()
  195. }, 500)
  196. },
  197. saveRequirement(needGoBack = false) {
  198. uni.showLoading({ title: '保存中...' })
  199. // TODO: 调用后端接口
  200. setTimeout(() => {
  201. uni.hideLoading()
  202. uni.showToast({
  203. title: '保存成功',
  204. icon: 'success'
  205. })
  206. this.isEditing = false
  207. if (needGoBack) {
  208. setTimeout(() => {
  209. uni.navigateBack()
  210. }, 1000)
  211. }
  212. }, 500)
  213. },
  214. // 获取文本方法
  215. getGenderText() {
  216. const option = this.genderOptions.find(item => item.value === this.requirement.gender)
  217. return option ? option.label : '不限'
  218. },
  219. getAgeRangeText() {
  220. if (!this.requirement.minAge && !this.requirement.maxAge) return '不限'
  221. if (this.requirement.minAge && !this.requirement.maxAge) return this.requirement.minAge + '岁以上'
  222. if (!this.requirement.minAge && this.requirement.maxAge) return this.requirement.maxAge + '岁以下'
  223. return this.requirement.minAge + '-' + this.requirement.maxAge + '岁'
  224. },
  225. getHeightRangeText() {
  226. if (!this.requirement.minHeight && !this.requirement.maxHeight) return '不限'
  227. if (this.requirement.minHeight && !this.requirement.maxHeight) return this.requirement.minHeight + 'cm以上'
  228. if (!this.requirement.minHeight && this.requirement.maxHeight) return this.requirement.maxHeight + 'cm以下'
  229. return this.requirement.minHeight + '-' + this.requirement.maxHeight + 'cm'
  230. },
  231. getEducationText() {
  232. if (this.requirement.educationLevel === null || this.requirement.educationLevel === undefined) return '不限'
  233. return this.educationOptions[this.requirement.educationLevel] || '不限'
  234. },
  235. getSalaryText() {
  236. if (this.requirement.salaryRange === null || this.requirement.salaryRange === undefined) return '不限'
  237. return this.salaryOptions[this.requirement.salaryRange] || '不限'
  238. },
  239. getHouseText() {
  240. const option = this.houseOptions.find(item => item.value === this.requirement.house)
  241. return option ? option.label : '不限'
  242. },
  243. getCarText() {
  244. const option = this.carOptions.find(item => item.value === this.requirement.car)
  245. return option ? option.label : '不限'
  246. },
  247. getMaritalText() {
  248. if (this.requirement.maritalStatus === null || this.requirement.maritalStatus === undefined) return '不限'
  249. return this.maritalOptions[this.requirement.maritalStatus] || '不限'
  250. },
  251. // 获取索引方法
  252. getGenderIndex() {
  253. const index = this.genderOptions.findIndex(item => item.value === this.requirement.gender)
  254. return Math.max(0, index)
  255. },
  256. getEducationIndex() {
  257. return this.requirement.educationLevel || 0
  258. },
  259. getSalaryIndex() {
  260. return this.requirement.salaryRange || 0
  261. },
  262. getHouseIndex() {
  263. const index = this.houseOptions.findIndex(item => item.value === this.requirement.house)
  264. return Math.max(0, index)
  265. },
  266. getCarIndex() {
  267. const index = this.carOptions.findIndex(item => item.value === this.requirement.car)
  268. return Math.max(0, index)
  269. },
  270. getMaritalIndex() {
  271. return this.requirement.maritalStatus || 0
  272. },
  273. // 选择器变更方法
  274. onGenderChange(e) {
  275. this.requirement.gender = this.genderOptions[parseInt(e.detail.value)].value
  276. },
  277. onEducationChange(e) {
  278. this.requirement.educationLevel = parseInt(e.detail.value)
  279. },
  280. onSalaryChange(e) {
  281. this.requirement.salaryRange = parseInt(e.detail.value)
  282. },
  283. onHouseChange(e) {
  284. this.requirement.house = this.houseOptions[parseInt(e.detail.value)].value
  285. },
  286. onCarChange(e) {
  287. this.requirement.car = this.carOptions[parseInt(e.detail.value)].value
  288. },
  289. onMaritalChange(e) {
  290. this.requirement.maritalStatus = parseInt(e.detail.value)
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. * {
  297. box-sizing: border-box;
  298. }
  299. .requirement-page {
  300. min-height: 100vh;
  301. background: linear-gradient(180deg, #FF8A9B 0%, #FFB4C0 25%, #FFF0F2 50%, #F8F8F8 100%);
  302. display: flex;
  303. flex-direction: column;
  304. }
  305. /* 顶部导航栏 */
  306. .header {
  307. display: flex;
  308. align-items: center;
  309. justify-content: space-between;
  310. padding: 25rpx 30rpx;
  311. padding-top: calc(25rpx + env(safe-area-inset-top));
  312. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  313. box-shadow: 0 4rpx 20rpx rgba(255, 138, 155, 0.2);
  314. .back-btn {
  315. width: 70rpx;
  316. height: 70rpx;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. background: rgba(255, 255, 255, 0.2);
  321. border-radius: 50%;
  322. .back-icon {
  323. font-size: 44rpx;
  324. color: #FFFFFF;
  325. font-weight: bold;
  326. }
  327. }
  328. .header-title {
  329. font-size: 38rpx;
  330. font-weight: bold;
  331. color: #FFFFFF;
  332. }
  333. .edit-btn {
  334. padding: 12rpx 30rpx;
  335. background: rgba(255, 255, 255, 0.3);
  336. border-radius: 35rpx;
  337. .edit-text {
  338. font-size: 28rpx;
  339. color: #FFFFFF;
  340. font-weight: 500;
  341. }
  342. }
  343. }
  344. .content {
  345. flex: 1;
  346. padding: 20rpx 0rpx;
  347. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  348. }
  349. /* 提示区域 */
  350. .tips-section {
  351. background: linear-gradient(135deg, #E8F5E8 0%, #D4EDDA 100%);
  352. border-radius: 15rpx;
  353. padding: 20rpx 25rpx;
  354. margin-bottom: 25rpx;
  355. display: flex;
  356. align-items: center;
  357. border-left: 6rpx solid #28A745;
  358. .tips-icon {
  359. font-size: 32rpx;
  360. margin-right: 15rpx;
  361. flex-shrink: 0;
  362. }
  363. .tips-text {
  364. font-size: 26rpx;
  365. color: #28A745;
  366. line-height: 1.5;
  367. }
  368. }
  369. /* 区块样式 */
  370. .section {
  371. background: #FFFFFF;
  372. border-radius: 20rpx;
  373. padding: 30rpx 0;
  374. margin-bottom: 25rpx;
  375. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  376. .section-title {
  377. font-size: 32rpx;
  378. font-weight: bold;
  379. color: #333333;
  380. margin-bottom: 25rpx;
  381. padding: 0 30rpx;
  382. }
  383. .item-row {
  384. display: flex;
  385. align-items: center;
  386. padding: 25rpx 30rpx 25rpx 30rpx;
  387. border-bottom: 1rpx solid #F5F5F5;
  388. &:last-child {
  389. border-bottom: none;
  390. }
  391. .label {
  392. font-size: 28rpx;
  393. color: #333333;
  394. font-weight: 500;
  395. flex: 1;
  396. }
  397. .value,
  398. .picker-value {
  399. text-align: right;
  400. font-size: 28rpx;
  401. color: #666666;
  402. min-width: 120rpx;
  403. flex-shrink: 0;
  404. }
  405. .input {
  406. text-align: right;
  407. font-size: 28rpx;
  408. color: #333333;
  409. min-width: 200rpx;
  410. flex-shrink: 0;
  411. }
  412. .range-input {
  413. flex: 1;
  414. display: flex;
  415. align-items: center;
  416. justify-content: flex-end;
  417. .range-value {
  418. width: 100rpx;
  419. height: 60rpx;
  420. text-align: center;
  421. border: 1rpx solid #E0E0E0;
  422. border-radius: 8rpx;
  423. font-size: 26rpx;
  424. background: #FAFAFA;
  425. box-sizing: border-box;
  426. }
  427. .range-divider {
  428. margin: 0 10rpx;
  429. color: #999999;
  430. font-size: 24rpx;
  431. }
  432. .range-unit {
  433. margin-left: 10rpx;
  434. font-size: 24rpx;
  435. color: #999999;
  436. width: 40rpx;
  437. }
  438. }
  439. }
  440. .item-column {
  441. padding: 25rpx 30rpx 25rpx 30rpx;
  442. .label {
  443. display: block;
  444. font-size: 28rpx;
  445. color: #333333;
  446. font-weight: 500;
  447. margin-bottom: 20rpx;
  448. }
  449. .textarea {
  450. width: 100%;
  451. min-height: 160rpx;
  452. padding: 20rpx;
  453. border: 1rpx solid #E0E0E0;
  454. border-radius: 10rpx;
  455. font-size: 26rpx;
  456. line-height: 1.6;
  457. background: #FAFAFA;
  458. box-sizing: border-box;
  459. }
  460. .value {
  461. font-size: 26rpx;
  462. color: #666666;
  463. &.multi-line {
  464. display: block;
  465. line-height: 1.8;
  466. }
  467. }
  468. }
  469. }
  470. </style>