addExpectation.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <template>
  2. <view class="add-expectation">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar" :style="{ paddingTop: (12 + statusBarHeight) + 'px' }">
  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">{{id==""||id==0?'添加':'编辑'}}求职期望</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 class="footer">
  95. <u-button
  96. type="primary"
  97. @click="saveWorkExperience"
  98. :customStyle="{
  99. height: '90rpx',
  100. fontSize: '32rpx',
  101. borderRadius: '45rpx',
  102. margin: '40rpx 0',
  103. }"
  104. >提交</u-button
  105. >
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. export default {
  111. data() {
  112. return {
  113. statusBarHeight: 0, // 状态栏高度
  114. id:0,
  115. jobId:0,
  116. jobTitle: '',
  117. city: '',
  118. minSalary: '8000',
  119. maxSalary: '10000',
  120. jobType: 'fulltime',
  121. industry: '',
  122. // 范围滑块相关数据
  123. minValue: 8000,
  124. maxValue: 10000,
  125. sliderMin: 5000,
  126. sliderMax: 50000,
  127. step: 1000,
  128. trackWidth: 0,
  129. draggingThumb: null, // 'left' 或 'right' 或 null
  130. startX: 0,
  131. startValue: 0,
  132. isWork:false
  133. }
  134. },
  135. computed: {
  136. // 左侧滑块位置百分比
  137. leftPercent() {
  138. return ((this.minValue - this.sliderMin) / (this.sliderMax - this.sliderMin)) * 100
  139. },
  140. // 右侧滑块位置百分比
  141. rightPercent() {
  142. return ((this.maxValue - this.sliderMin) / (this.sliderMax - this.sliderMin)) * 100
  143. },
  144. // 进度条样式
  145. progressStyle() {
  146. return {
  147. left: this.leftPercent + '%',
  148. width: (this.rightPercent - this.leftPercent) + '%'
  149. }
  150. },
  151. // 左侧滑块样式
  152. leftThumbStyle() {
  153. return {
  154. left: this.leftPercent + '%'
  155. }
  156. },
  157. // 右侧滑块样式
  158. rightThumbStyle() {
  159. return {
  160. left: this.rightPercent + '%'
  161. }
  162. }
  163. },
  164. methods: {
  165. getData(){
  166. var that=this
  167. this.$Request.getT("/app/intention/getIntentionInfo", {intentionId:this.id}).then((res) => {
  168. if (res.code == 0) {
  169. res=res.data
  170. that.jobId=res.ruleClassifyId
  171. that.jobTitle=res.ruleClassifyName
  172. that.jobType=res.postType=='全职'?'fulltime':'parttime'
  173. that.city=res.citys
  174. that.industry=res.industry
  175. var salaryRange=res.salaryRange.split('-')
  176. that.minValue=salaryRange[0]?parseInt(salaryRange[0]):0
  177. that.maxValue=salaryRange[1]?parseInt(salaryRange[1]):0
  178. that.minSalary=salaryRange[0]?salaryRange[0]:0
  179. that.maxSalary=salaryRange[1]?salaryRange[1]:0
  180. } else {
  181. uni.showToast({
  182. title: res.msg,
  183. icon: "none",
  184. });
  185. }
  186. });
  187. },
  188. goBack() {
  189. uni.navigateBack()
  190. },
  191. selectJob() {
  192. uni.navigateTo({
  193. url: '/package/jobIntention/jobList'
  194. })
  195. },
  196. selectCity() {
  197. uni.navigateTo({
  198. url: '/package/jobIntention/city'
  199. })
  200. },
  201. selectIndustry() {
  202. if(this.jobId==''||this.jobId==0)
  203. return this.$queue.showToast('请先选择岗位')
  204. uni.navigateTo({
  205. url: '/package/jobIntention/preferenceSetting?jobId='+this.jobId+'&jobTitle='+this.jobTitle+'&selectedPreferences='+encodeURIComponent(JSON.stringify(this.industry==''||this.industry==null?[]:this.industry.split('/')))
  206. })
  207. },
  208. selectJobType(type) {
  209. this.jobType = type
  210. },
  211. // 获取滑块轨道宽度
  212. getTrackWidth() {
  213. uni.createSelectorQuery().in(this).select('.range-slider-track').boundingClientRect(data => {
  214. this.trackWidth = data.width
  215. }).exec()
  216. },
  217. // 将像素位置转换为数值
  218. pixelToValue(pixel) {
  219. const percent = (pixel / this.trackWidth) * 100
  220. const value = this.sliderMin + (percent / 100) * (this.sliderMax - this.sliderMin)
  221. return Math.round(value / this.step) * this.step
  222. },
  223. // 左侧滑块开始拖拽
  224. onLeftThumbStart(e) {
  225. this.draggingThumb = 'left'
  226. this.startX = e.touches[0].clientX
  227. this.startValue = this.minValue
  228. e.preventDefault()
  229. },
  230. // 左侧滑块拖拽中
  231. onLeftThumbMove(e) {
  232. if (this.draggingThumb !== 'left') return
  233. const deltaX = e.touches[0].clientX - this.startX
  234. const deltaPercent = (deltaX / this.trackWidth) * 100
  235. const deltaValue = (deltaPercent / 100) * (this.sliderMax - this.sliderMin)
  236. let newValue = this.startValue + deltaValue
  237. // 限制范围
  238. newValue = Math.max(this.sliderMin, Math.min(newValue, this.maxValue - this.step))
  239. newValue = Math.round(newValue / this.step) * this.step
  240. this.minValue = newValue
  241. this.minSalary = newValue.toString()
  242. e.preventDefault()
  243. },
  244. // 左侧滑块结束拖拽
  245. onLeftThumbEnd(e) {
  246. this.draggingThumb = null
  247. e.preventDefault()
  248. },
  249. // 右侧滑块开始拖拽
  250. onRightThumbStart(e) {
  251. this.draggingThumb = 'right'
  252. this.startX = e.touches[0].clientX
  253. this.startValue = this.maxValue
  254. e.preventDefault()
  255. },
  256. // 右侧滑块拖拽中
  257. onRightThumbMove(e) {
  258. if (this.draggingThumb !== 'right') return
  259. const deltaX = e.touches[0].clientX - this.startX
  260. const deltaPercent = (deltaX / this.trackWidth) * 100
  261. const deltaValue = (deltaPercent / 100) * (this.sliderMax - this.sliderMin)
  262. let newValue = this.startValue + deltaValue
  263. // 限制范围
  264. newValue = Math.max(this.minValue + this.step, Math.min(newValue, this.sliderMax))
  265. newValue = Math.round(newValue / this.step) * this.step
  266. this.maxValue = newValue
  267. this.maxSalary = newValue.toString()
  268. e.preventDefault()
  269. },
  270. // 右侧滑块结束拖拽
  271. onRightThumbEnd(e) {
  272. this.draggingThumb = null
  273. e.preventDefault()
  274. },
  275. // 点击轨道
  276. onTrackClick(e) {
  277. if (this.draggingThumb) return
  278. const rect = e.currentTarget.getBoundingClientRect()
  279. const clickX = e.detail.x - rect.left
  280. const clickPercent = (clickX / rect.width) * 100
  281. const clickValue = this.sliderMin + (clickPercent / 100) * (this.sliderMax - this.sliderMin)
  282. // 判断点击位置更靠近哪个滑块
  283. const distanceToLeft = Math.abs(clickValue - this.minValue)
  284. const distanceToRight = Math.abs(clickValue - this.maxValue)
  285. if (distanceToLeft < distanceToRight) {
  286. // 更靠近左侧滑块
  287. let newValue = Math.round(clickValue / this.step) * this.step
  288. newValue = Math.max(this.sliderMin, Math.min(newValue, this.maxValue - this.step))
  289. this.minValue = newValue
  290. this.minSalary = newValue.toString()
  291. } else {
  292. // 更靠近右侧滑块
  293. let newValue = Math.round(clickValue / this.step) * this.step
  294. newValue = Math.max(this.minValue + this.step, Math.min(newValue, this.sliderMax))
  295. this.maxValue = newValue
  296. this.maxSalary = newValue.toString()
  297. }
  298. },
  299. saveWorkExperience() {
  300. if (!this.jobId) {
  301. uni.showToast({ title: "请选择工作职位", icon: "none" });
  302. return;
  303. }
  304. if (!this.city) {
  305. uni.showToast({ title: "请选择城市", icon: "none" });
  306. return;
  307. }
  308. if (!this.industry) {
  309. uni.showToast({ title: "请选择从事方向", icon: "none" });
  310. return;
  311. }
  312. if(this.isWork)
  313. return
  314. this.isWork=true
  315. let data={
  316. intentionId:this.id,
  317. ruleClassifyId:this.jobId,
  318. ruleClassifyName:this.jobTitle,
  319. citys:this.city,
  320. salaryRange:this.minSalary+'-'+this.maxSalary,
  321. postType:this.jobType === 'fulltime'?'全职':'兼职',
  322. industry:this.industry,
  323. "createTime": "",
  324. "industryId": 201,
  325. "industryOneId": 200,
  326. "classifyOneId": 0,
  327. "classifyTwoId": 0,
  328. "isDefault": 1
  329. }
  330. uni.showLoading({ title: "提交中..." });
  331. this.$Request.postJson("/app/intention/saveUpdate", data).then((res) => {
  332. this.isWork=false
  333. this.industry=''
  334. uni.hideLoading();
  335. if (res.code == 0) {
  336. uni.showToast({ title: "保存成功", icon: "none" });
  337. // 实际开发中可以在这里添加跳转逻辑
  338. uni.$emit('updateResume')
  339. setTimeout(() => {
  340. uni.navigateBack()
  341. }, 1000);
  342. } else {
  343. uni.showToast({
  344. title: res.msg,
  345. icon: "none",
  346. });
  347. }
  348. });
  349. },
  350. },
  351. mounted() {
  352. // 初始化滑块轨道宽度
  353. this.$nextTick(() => {
  354. this.getTrackWidth()
  355. })
  356. },
  357. onLoad(options) {
  358. // 获取状态栏高度
  359. let systemInfo = uni.getSystemInfoSync();
  360. this.statusBarHeight = systemInfo.statusBarHeight || 0;
  361. this.id=options&&options.id?options.id:""
  362. // 监听选择结果
  363. uni.$on('jobs', (data) => {
  364. this.jobTitle = data.ruleClassifyName
  365. this.jobId = data.ruleClassifyId
  366. })
  367. uni.$on('city', (data) => {
  368. console.log(data)
  369. this.city = data.city
  370. })
  371. /* uni.$on('industry', (data) => {
  372. this.industry = data.industry
  373. }) */
  374. // 监听技能设置更新
  375. uni.$on('preferenceUpdated', (data) => {
  376. this.industry=data.preferences.join('/')
  377. })
  378. if(this.id!=0&&this.id!='')
  379. this.getData()
  380. },
  381. onUnload() {
  382. // 移除监听
  383. uni.$off('jobs')
  384. uni.$off('city')
  385. /* uni.$off('industry') */
  386. uni.$off('preferenceUpdated')
  387. }
  388. }
  389. </script>
  390. <style lang="scss" scoped>
  391. .add-expectation {
  392. min-height: 100vh;
  393. padding: 0 40rpx 40rpx 40rpx;
  394. }
  395. .nav-bar {
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-between;
  399. margin-bottom: 30rpx;
  400. .nav-left {
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. }
  405. .nav-title {
  406. color: rgba(51, 51, 51, 1);
  407. font-family: DM Sans;
  408. font-size: 32rpx;
  409. font-weight: 700;
  410. line-height: 26px;
  411. text-align: center;
  412. }
  413. }
  414. .form-container {
  415. background: #ffffff;
  416. border-radius: 20rpx;
  417. margin-top: 30rpx;
  418. }
  419. .form-item {
  420. margin-bottom: 40rpx;
  421. &:last-child {
  422. margin-bottom: 0;
  423. }
  424. .form-label {
  425. color: rgba(58, 57, 67, 1);
  426. font-family: DM Sans;
  427. font-size: 36rpx;
  428. font-weight: 500;
  429. line-height: 24px;
  430. letter-spacing: 0px;
  431. text-align: left;
  432. }
  433. .form-input {
  434. height: 100rpx;
  435. display: flex;
  436. justify-content: space-between;
  437. align-items: center;
  438. padding: 24rpx 20rpx;
  439. border-radius: 12rpx;
  440. box-shadow: 0px 8px 150px 0px rgba(0, 0, 0, 0.06);
  441. background: rgba(255, 255, 255, 1);
  442. margin-top: 20rpx;
  443. .input-text {
  444. color: rgba(97, 110, 124, 1);
  445. font-family: DM Sans;
  446. font-weight: 400;
  447. line-height: 20px;
  448. letter-spacing: 0px;
  449. text-align: left;
  450. font-size: 28rpx;
  451. }
  452. }
  453. }
  454. .salary-container {
  455. .salary-inputs {
  456. display: flex;
  457. align-items: center;
  458. margin: 20rpx 0 30rpx 0;
  459. gap: 50rpx;
  460. .salary-input {
  461. display: flex;
  462. align-items: center;
  463. flex: 1;
  464. padding: 20rpx;
  465. border-radius: 12rpx;
  466. box-shadow: 0px 8px 150px 0px rgba(0, 0, 0, 0.06);
  467. background: rgba(255, 255, 255, 1);
  468. .currency, .salary-field {
  469. color: rgba(97, 110, 124, 1);
  470. font-family: DM Sans;
  471. font-weight: 400;
  472. line-height: 20px;
  473. letter-spacing: 0px;
  474. text-align: left;
  475. font-size: 28rpx;
  476. }
  477. }
  478. .salary-separator {
  479. margin: 0 20rpx;
  480. color: rgba(153, 153, 153, 1);
  481. font-size: 28rpx;
  482. }
  483. }
  484. .range-slider-container {
  485. padding: 20rpx 10rpx;
  486. }
  487. .range-slider-track {
  488. position: relative;
  489. height: 6rpx;
  490. background-color: #E5E5EA;
  491. border-radius: 3rpx;
  492. cursor: pointer;
  493. }
  494. .range-slider-progress {
  495. position: absolute;
  496. top: 0;
  497. height: 100%;
  498. background-color: #007AFF;
  499. border-radius: 3rpx;
  500. transition: all 0.1s ease;
  501. }
  502. .range-slider-thumb {
  503. position: absolute;
  504. top: 50%;
  505. width: 40rpx;
  506. height: 40rpx;
  507. background-color: #007AFF;
  508. border-radius: 50%;
  509. border: 4rpx solid #ffffff;
  510. box-shadow: 0 2rpx 8rpx rgba(0, 122, 255, 0.3);
  511. transform: translate(-50%, -50%);
  512. cursor: pointer;
  513. transition: all 0.1s ease;
  514. }
  515. .range-slider-thumb:active {
  516. transform: translate(-50%, -50%) scale(1.1);
  517. box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.4);
  518. }
  519. }
  520. .job-type-container {
  521. display: flex;
  522. gap: 50rpx;
  523. margin-top: 20rpx;
  524. .job-type-btn {
  525. flex: 1;
  526. padding: 24rpx 20rpx;
  527. border: 1rpx solid #E5E5EA;
  528. border-radius: 42rpx;
  529. text-align: center;
  530. text {
  531. color: rgba(97, 110, 124, 1);
  532. font-size: 28rpx;
  533. }
  534. &.active {
  535. background: #016BF6;
  536. text {
  537. color: #FFFFFF;
  538. font-weight: 400;
  539. }
  540. }
  541. }
  542. }
  543. </style>