addExpectation.vue 14 KB

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