index.vue 14 KB

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