addExpectation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <view class="add-expectation">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar">
  5. <view class="nav-left" @click="goBack">
  6. <u-icon name="arrow-leftward" color="rgba(51, 51, 51, 1)" style="font-size: 38rpx;"></u-icon>
  7. </view>
  8. <view class="nav-title">添加求职期望</view>
  9. <view class="nav-right"></view>
  10. </view>
  11. <!-- 表单内容 -->
  12. <view class="form-container">
  13. <!-- 工作职位 -->
  14. <view class="form-item">
  15. <text class="form-label">工作职位</text>
  16. <view class="form-input" @click="selectJob">
  17. <text class="input-text">{{ jobTitle || '请选择' }}</text>
  18. <u-icon name="arrow-right" color="#999" size="24"></u-icon>
  19. </view>
  20. </view>
  21. <!-- 工作城市 -->
  22. <view class="form-item">
  23. <text class="form-label">工作城市</text>
  24. <view class="form-input" @click="selectCity">
  25. <text class="input-text">{{ city || '请选择' }}</text>
  26. <u-icon name="arrow-right" color="#999" size="24"></u-icon>
  27. </view>
  28. </view>
  29. <!-- 期望薪酬 -->
  30. <view class="form-item">
  31. <text class="form-label">期望薪酬</text>
  32. <view class="salary-container">
  33. <view class="salary-inputs">
  34. <view class="salary-input">
  35. <text class="currency">¥</text>
  36. <input v-model="minSalary" type="number" placeholder="8000" class="salary-field" />
  37. </view>
  38. <view class="salary-input">
  39. <text class="currency">¥</text>
  40. <input v-model="maxSalary" type="number" placeholder="10000" class="salary-field" />
  41. </view>
  42. </view>
  43. <!-- 范围滑块 -->
  44. <view class="range-slider-container">
  45. <view class="range-slider-track" @click="onTrackClick">
  46. <view class="range-slider-progress" :style="progressStyle"></view>
  47. <view
  48. class="range-slider-thumb range-slider-thumb-left"
  49. :style="leftThumbStyle"
  50. @touchstart="onLeftThumbStart"
  51. @touchmove="onLeftThumbMove"
  52. @touchend="onLeftThumbEnd"
  53. ></view>
  54. <view
  55. class="range-slider-thumb range-slider-thumb-right"
  56. :style="rightThumbStyle"
  57. @touchstart="onRightThumbStart"
  58. @touchmove="onRightThumbMove"
  59. @touchend="onRightThumbEnd"
  60. ></view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <!-- 工作类型 -->
  66. <view class="form-item">
  67. <text class="form-label">工作类型</text>
  68. <view class="job-type-container">
  69. <view
  70. class="job-type-btn"
  71. :class="{ active: jobType === 'fulltime' }"
  72. @click="selectJobType('fulltime')"
  73. >
  74. <text>全职</text>
  75. </view>
  76. <view
  77. class="job-type-btn"
  78. :class="{ active: jobType === 'parttime' }"
  79. @click="selectJobType('parttime')"
  80. >
  81. <text>兼职</text>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 从事方向 -->
  86. <view class="form-item">
  87. <text class="form-label">从事方向</text>
  88. <view class="form-input" @click="selectIndustry">
  89. <text class="input-text">{{ industry || '请选择' }}</text>
  90. <u-icon name="arrow-right" color="#999" size="24"></u-icon>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. export default {
  98. data() {
  99. return {
  100. jobTitle: '',
  101. city: '',
  102. minSalary: '8000',
  103. maxSalary: '10000',
  104. jobType: 'fulltime',
  105. industry: '',
  106. // 范围滑块相关数据
  107. minValue: 8000,
  108. maxValue: 10000,
  109. sliderMin: 5000,
  110. sliderMax: 50000,
  111. step: 1000,
  112. trackWidth: 0,
  113. draggingThumb: null, // 'left' 或 'right' 或 null
  114. startX: 0,
  115. startValue: 0
  116. }
  117. },
  118. computed: {
  119. // 左侧滑块位置百分比
  120. leftPercent() {
  121. return ((this.minValue - this.sliderMin) / (this.sliderMax - this.sliderMin)) * 100
  122. },
  123. // 右侧滑块位置百分比
  124. rightPercent() {
  125. return ((this.maxValue - this.sliderMin) / (this.sliderMax - this.sliderMin)) * 100
  126. },
  127. // 进度条样式
  128. progressStyle() {
  129. return {
  130. left: this.leftPercent + '%',
  131. width: (this.rightPercent - this.leftPercent) + '%'
  132. }
  133. },
  134. // 左侧滑块样式
  135. leftThumbStyle() {
  136. return {
  137. left: this.leftPercent + '%'
  138. }
  139. },
  140. // 右侧滑块样式
  141. rightThumbStyle() {
  142. return {
  143. left: this.rightPercent + '%'
  144. }
  145. }
  146. },
  147. methods: {
  148. goBack() {
  149. uni.navigateBack()
  150. },
  151. selectJob() {
  152. uni.navigateTo({
  153. url: '/package/jobIntention/jobList'
  154. })
  155. },
  156. selectCity() {
  157. uni.navigateTo({
  158. url: '/package/jobIntention/city'
  159. })
  160. },
  161. selectIndustry() {
  162. uni.navigateTo({
  163. url: '/package/jobIntention/industry'
  164. })
  165. },
  166. selectJobType(type) {
  167. this.jobType = type
  168. },
  169. // 获取滑块轨道宽度
  170. getTrackWidth() {
  171. uni.createSelectorQuery().in(this).select('.range-slider-track').boundingClientRect(data => {
  172. this.trackWidth = data.width
  173. }).exec()
  174. },
  175. // 将像素位置转换为数值
  176. pixelToValue(pixel) {
  177. const percent = (pixel / this.trackWidth) * 100
  178. const value = this.sliderMin + (percent / 100) * (this.sliderMax - this.sliderMin)
  179. return Math.round(value / this.step) * this.step
  180. },
  181. // 左侧滑块开始拖拽
  182. onLeftThumbStart(e) {
  183. this.draggingThumb = 'left'
  184. this.startX = e.touches[0].clientX
  185. this.startValue = this.minValue
  186. e.preventDefault()
  187. },
  188. // 左侧滑块拖拽中
  189. onLeftThumbMove(e) {
  190. if (this.draggingThumb !== 'left') return
  191. const deltaX = e.touches[0].clientX - this.startX
  192. const deltaPercent = (deltaX / this.trackWidth) * 100
  193. const deltaValue = (deltaPercent / 100) * (this.sliderMax - this.sliderMin)
  194. let newValue = this.startValue + deltaValue
  195. // 限制范围
  196. newValue = Math.max(this.sliderMin, Math.min(newValue, this.maxValue - this.step))
  197. newValue = Math.round(newValue / this.step) * this.step
  198. this.minValue = newValue
  199. this.minSalary = newValue.toString()
  200. e.preventDefault()
  201. },
  202. // 左侧滑块结束拖拽
  203. onLeftThumbEnd(e) {
  204. this.draggingThumb = null
  205. e.preventDefault()
  206. },
  207. // 右侧滑块开始拖拽
  208. onRightThumbStart(e) {
  209. this.draggingThumb = 'right'
  210. this.startX = e.touches[0].clientX
  211. this.startValue = this.maxValue
  212. e.preventDefault()
  213. },
  214. // 右侧滑块拖拽中
  215. onRightThumbMove(e) {
  216. if (this.draggingThumb !== 'right') return
  217. const deltaX = e.touches[0].clientX - this.startX
  218. const deltaPercent = (deltaX / this.trackWidth) * 100
  219. const deltaValue = (deltaPercent / 100) * (this.sliderMax - this.sliderMin)
  220. let newValue = this.startValue + deltaValue
  221. // 限制范围
  222. newValue = Math.max(this.minValue + this.step, Math.min(newValue, this.sliderMax))
  223. newValue = Math.round(newValue / this.step) * this.step
  224. this.maxValue = newValue
  225. this.maxSalary = newValue.toString()
  226. e.preventDefault()
  227. },
  228. // 右侧滑块结束拖拽
  229. onRightThumbEnd(e) {
  230. this.draggingThumb = null
  231. e.preventDefault()
  232. },
  233. // 点击轨道
  234. onTrackClick(e) {
  235. if (this.draggingThumb) return
  236. const rect = e.currentTarget.getBoundingClientRect()
  237. const clickX = e.detail.x - rect.left
  238. const clickPercent = (clickX / rect.width) * 100
  239. const clickValue = this.sliderMin + (clickPercent / 100) * (this.sliderMax - this.sliderMin)
  240. // 判断点击位置更靠近哪个滑块
  241. const distanceToLeft = Math.abs(clickValue - this.minValue)
  242. const distanceToRight = Math.abs(clickValue - this.maxValue)
  243. if (distanceToLeft < distanceToRight) {
  244. // 更靠近左侧滑块
  245. let newValue = Math.round(clickValue / this.step) * this.step
  246. newValue = Math.max(this.sliderMin, Math.min(newValue, this.maxValue - this.step))
  247. this.minValue = newValue
  248. this.minSalary = newValue.toString()
  249. } else {
  250. // 更靠近右侧滑块
  251. let newValue = Math.round(clickValue / this.step) * this.step
  252. newValue = Math.max(this.minValue + this.step, Math.min(newValue, this.sliderMax))
  253. this.maxValue = newValue
  254. this.maxSalary = newValue.toString()
  255. }
  256. }
  257. },
  258. mounted() {
  259. // 初始化滑块轨道宽度
  260. this.$nextTick(() => {
  261. this.getTrackWidth()
  262. })
  263. },
  264. onShow() {
  265. // 监听选择结果
  266. uni.$on('jobSelected', (data) => {
  267. this.jobTitle = data.name
  268. })
  269. uni.$on('citySelected', (data) => {
  270. this.city = data.name
  271. })
  272. uni.$on('industrySelected', (data) => {
  273. this.industry = data.name
  274. })
  275. },
  276. onUnload() {
  277. // 移除监听
  278. uni.$off('jobSelected')
  279. uni.$off('citySelected')
  280. uni.$off('industrySelected')
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. .add-expectation {
  286. min-height: 100vh;
  287. padding: 88rpx 40rpx 40rpx 40rpx;
  288. }
  289. .nav-bar {
  290. display: flex;
  291. align-items: center;
  292. justify-content: space-between;
  293. padding: 20rpx 0;
  294. .nav-left {
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. }
  299. .nav-title {
  300. color: rgba(51, 51, 51, 1);
  301. font-family: DM Sans;
  302. font-size: 32rpx;
  303. font-weight: 700;
  304. line-height: 26px;
  305. text-align: center;
  306. }
  307. }
  308. .form-container {
  309. background: #ffffff;
  310. border-radius: 20rpx;
  311. margin-top: 30rpx;
  312. }
  313. .form-item {
  314. margin-bottom: 40rpx;
  315. &:last-child {
  316. margin-bottom: 0;
  317. }
  318. .form-label {
  319. color: rgba(58, 57, 67, 1);
  320. font-family: DM Sans;
  321. font-size: 36rpx;
  322. font-weight: 500;
  323. line-height: 24px;
  324. letter-spacing: 0px;
  325. text-align: left;
  326. }
  327. .form-input {
  328. height: 100rpx;
  329. display: flex;
  330. justify-content: space-between;
  331. align-items: center;
  332. padding: 24rpx 20rpx;
  333. border-radius: 12rpx;
  334. box-shadow: 0px 8px 150px 0px rgba(0, 0, 0, 0.06);
  335. background: rgba(255, 255, 255, 1);
  336. margin-top: 20rpx;
  337. .input-text {
  338. color: rgba(97, 110, 124, 1);
  339. font-family: DM Sans;
  340. font-weight: 400;
  341. line-height: 20px;
  342. letter-spacing: 0px;
  343. text-align: left;
  344. font-size: 28rpx;
  345. }
  346. }
  347. }
  348. .salary-container {
  349. .salary-inputs {
  350. display: flex;
  351. align-items: center;
  352. margin: 20rpx 0 30rpx 0;
  353. gap: 50rpx;
  354. .salary-input {
  355. display: flex;
  356. align-items: center;
  357. flex: 1;
  358. padding: 20rpx;
  359. border-radius: 12rpx;
  360. box-shadow: 0px 8px 150px 0px rgba(0, 0, 0, 0.06);
  361. background: rgba(255, 255, 255, 1);
  362. .currency, .salary-field {
  363. color: rgba(97, 110, 124, 1);
  364. font-family: DM Sans;
  365. font-weight: 400;
  366. line-height: 20px;
  367. letter-spacing: 0px;
  368. text-align: left;
  369. font-size: 28rpx;
  370. }
  371. }
  372. .salary-separator {
  373. margin: 0 20rpx;
  374. color: rgba(153, 153, 153, 1);
  375. font-size: 28rpx;
  376. }
  377. }
  378. .range-slider-container {
  379. padding: 20rpx 10rpx;
  380. }
  381. .range-slider-track {
  382. position: relative;
  383. height: 6rpx;
  384. background-color: #E5E5EA;
  385. border-radius: 3rpx;
  386. cursor: pointer;
  387. }
  388. .range-slider-progress {
  389. position: absolute;
  390. top: 0;
  391. height: 100%;
  392. background-color: #007AFF;
  393. border-radius: 3rpx;
  394. transition: all 0.1s ease;
  395. }
  396. .range-slider-thumb {
  397. position: absolute;
  398. top: 50%;
  399. width: 40rpx;
  400. height: 40rpx;
  401. background-color: #007AFF;
  402. border-radius: 50%;
  403. border: 4rpx solid #ffffff;
  404. box-shadow: 0 2rpx 8rpx rgba(0, 122, 255, 0.3);
  405. transform: translate(-50%, -50%);
  406. cursor: pointer;
  407. transition: all 0.1s ease;
  408. }
  409. .range-slider-thumb:active {
  410. transform: translate(-50%, -50%) scale(1.1);
  411. box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.4);
  412. }
  413. }
  414. .job-type-container {
  415. display: flex;
  416. gap: 50rpx;
  417. margin-top: 20rpx;
  418. .job-type-btn {
  419. flex: 1;
  420. padding: 24rpx 20rpx;
  421. border: 1rpx solid #E5E5EA;
  422. border-radius: 42rpx;
  423. text-align: center;
  424. text {
  425. color: rgba(97, 110, 124, 1);
  426. font-size: 28rpx;
  427. }
  428. &.active {
  429. background: #016BF6;
  430. text {
  431. color: #FFFFFF;
  432. font-weight: 400;
  433. }
  434. }
  435. }
  436. }
  437. </style>