filter.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-y class="scroll-body">
  4. <!-- 历史搜索 -->
  5. <view class="section" v-if="historyList.length > 0">
  6. <view class="section-header">
  7. <text class="title">历史搜索</text>
  8. <image src="/static/icons/icon-delete.svg" class="delete-icon" mode="aspectFit" @click="clearHistory"></image>
  9. </view>
  10. <view class="tags-row">
  11. <view
  12. class="tag"
  13. :class="{ active: selectedHistory === item }"
  14. v-for="(item, index) in historyList"
  15. :key="index"
  16. @click="selectedHistory = item"
  17. >
  18. {{ item }}
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 岗位类型 -->
  23. <view class="section">
  24. <view class="section-header">
  25. <text class="title">岗位类型</text>
  26. </view>
  27. <view class="tags-row">
  28. <view
  29. class="tag"
  30. :class="{ active: selectedJobType === item.dictValue }"
  31. v-for="(item, index) in jobTypes"
  32. :key="index"
  33. @click="selectedJobType = item.dictValue"
  34. >
  35. {{ item.dictLabel }}
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 期望薪资 -->
  40. <view class="section">
  41. <view class="section-header">
  42. <text class="title">期望薪资 (K)</text>
  43. </view>
  44. <view class="salary-display">
  45. <text>{{ minSalary }} - {{ maxSalary }}K</text>
  46. </view>
  47. <view class="range-slider-wrap">
  48. <movable-area class="slider-track-area">
  49. <view class="slider-bg"></view>
  50. <view class="slider-active" :style="{ left: (minX + thumbHalf) + 'px', width: (maxX - minX) + 'px' }"></view>
  51. <movable-view class="slider-thumb" direction="horizontal" :x="minX" @change="onMinMove" :animation="false"></movable-view>
  52. <movable-view class="slider-thumb" direction="horizontal" :x="maxX" @change="onMaxMove" :animation="false"></movable-view>
  53. </movable-area>
  54. </view>
  55. </view>
  56. <!-- 工作经验 -->
  57. <view class="section">
  58. <view class="section-header">
  59. <text class="title">工作经验</text>
  60. </view>
  61. <view class="tags-row">
  62. <view
  63. class="tag"
  64. :class="{ active: selectedExperience === item.dictValue }"
  65. v-for="(item, index) in experiences"
  66. :key="index"
  67. @click="selectedExperience = item.dictValue"
  68. >
  69. {{ item.dictLabel }}
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 工作地点 -->
  74. <view class="section">
  75. <view class="section-header">
  76. <text class="title">工作地点</text>
  77. </view>
  78. <picker mode="region" @change="onRegionChange" :value="selectedRegion">
  79. <view class="location-picker">
  80. <text class="location-text" :class="{ 'placeholder': !selectedCity }">
  81. {{ selectedCity ? (selectedRegion[0] + ' ' + selectedRegion[1] + ' ' + selectedRegion[2]) : '请选择工作地点' }}
  82. </text>
  83. <image src="/static/icons/chevron-right.svg" class="arrow-icon" mode="aspectFit"></image>
  84. </view>
  85. </picker>
  86. </view>
  87. <!-- 学历要求 -->
  88. <view class="section">
  89. <view class="section-header">
  90. <text class="title">学历要求</text>
  91. </view>
  92. <view class="tags-row">
  93. <view
  94. class="tag"
  95. :class="{ active: selectedEducation === item.dictValue }"
  96. v-for="(item, index) in educations"
  97. :key="index"
  98. @click="selectedEducation = item.dictValue"
  99. >
  100. {{ item.dictLabel }}
  101. </view>
  102. </view>
  103. </view>
  104. <!-- 底部安全距离 -->
  105. <view style="height: 160rpx;"></view>
  106. </scroll-view>
  107. <!-- 底部操作栏 -->
  108. <view class="bottom-bar">
  109. <view class="btn reset-btn" @click="resetFilters">重置</view>
  110. <view class="btn confirm-btn" @click="confirmFilters">确定</view>
  111. </view>
  112. </view>
  113. </template>
  114. <script setup lang="js">
  115. import { ref, onMounted } from 'vue';
  116. import { getDicts } from '../../api/dict.js';
  117. // 历史搜索数据
  118. const historyList = ref([]);
  119. const selectedHistory = ref('');
  120. // 岗位类型
  121. const jobTypes = ref([]);
  122. const selectedJobType = ref('');
  123. // 期望薪资滑块状态
  124. const minSalary = ref(0);
  125. const maxSalary = ref(50);
  126. const minX = ref(0);
  127. const maxX = ref(0);
  128. const sliderWidth = ref(0);
  129. const thumbHalf = ref(0);
  130. const MAX_SALARY = 50; // 上限 50K
  131. // 工作经验
  132. const experiences = ref([]);
  133. const selectedExperience = ref('');
  134. // 学历要求
  135. const educations = ref([]);
  136. const selectedEducation = ref('');
  137. // 地理位置
  138. const selectedRegion = ref(['', '', '']);
  139. const selectedCity = ref('');
  140. const onRegionChange = (e) => {
  141. selectedRegion.value = e.detail.value;
  142. selectedCity.value = e.detail.value[1]; // 取城市名作为核心过滤条件
  143. };
  144. const loadDictionaries = () => {
  145. getDicts('main_position_type').then(res => {
  146. if (res.data) {
  147. jobTypes.value = res.data;
  148. }
  149. });
  150. getDicts('main_experience').then(res => {
  151. if (res.data) {
  152. experiences.value = res.data;
  153. }
  154. });
  155. getDicts('main_education').then(res => {
  156. if (res.data) {
  157. educations.value = res.data;
  158. }
  159. });
  160. };
  161. onMounted(() => {
  162. // 加载搜索历史
  163. const historyStr = uni.getStorageSync('search_history');
  164. if (historyStr) {
  165. try {
  166. historyList.value = JSON.parse(historyStr);
  167. } catch(e){}
  168. }
  169. loadDictionaries();
  170. // 延迟一小会儿,确保 DOM 已经挂载好
  171. setTimeout(() => {
  172. uni.createSelectorQuery().select('.slider-track-area').boundingClientRect(res => {
  173. if (res && res.width) {
  174. const thumbW = uni.upx2px(40);
  175. thumbHalf.value = thumbW / 2;
  176. sliderWidth.value = res.width - thumbW;
  177. updateThumbPositions();
  178. }
  179. }).exec();
  180. }, 300);
  181. });
  182. // 计算位置同步到界面
  183. const updateThumbPositions = () => {
  184. if (sliderWidth.value > 0) {
  185. minX.value = (minSalary.value / MAX_SALARY) * sliderWidth.value;
  186. maxX.value = (maxSalary.value / MAX_SALARY) * sliderWidth.value;
  187. }
  188. };
  189. const onMinMove = (e) => {
  190. if (e.detail.source === 'touch') {
  191. let newX = e.detail.x;
  192. if (newX > maxX.value) newX = maxX.value;
  193. minX.value = newX;
  194. minSalary.value = Math.round((newX / sliderWidth.value) * MAX_SALARY);
  195. }
  196. };
  197. const onMaxMove = (e) => {
  198. if (e.detail.source === 'touch') {
  199. let newX = e.detail.x;
  200. if (newX < minX.value) newX = minX.value;
  201. maxX.value = newX;
  202. maxSalary.value = Math.round((newX / sliderWidth.value) * MAX_SALARY);
  203. }
  204. };
  205. // 清除历史记录
  206. const clearHistory = () => {
  207. uni.showModal({
  208. title: '提示',
  209. content: '确认清空历史搜索?',
  210. success: (res) => {
  211. if (res.confirm) {
  212. historyList.value = [];
  213. selectedHistory.value = '';
  214. uni.removeStorageSync('search_history');
  215. }
  216. }
  217. });
  218. };
  219. // 确定筛选项
  220. const confirmFilters = () => {
  221. // 匹配选中的字典标签,若包含“不限”则重置为空字符串传给后端
  222. const expItem = experiences.value.find(i => i.dictValue === selectedExperience.value);
  223. const userExp = (expItem && expItem.dictLabel && expItem.dictLabel.includes('不限')) ? '' : selectedExperience.value;
  224. const eduItem = educations.value.find(i => i.dictValue === selectedEducation.value);
  225. const userEdu = (eduItem && eduItem.dictLabel && eduItem.dictLabel.includes('不限')) ? '' : selectedEducation.value;
  226. // 发送给岗位列表页面进行筛选
  227. const filterParams = {
  228. keyword: selectedHistory.value,
  229. jobType: selectedJobType.value,
  230. minSalary: minSalary.value,
  231. maxSalary: maxSalary.value,
  232. experience: userExp,
  233. education: userEdu,
  234. workCity: selectedCity.value,
  235. workProvince: selectedRegion.value[0]
  236. };
  237. uni.$emit('updateFilters', filterParams);
  238. uni.showToast({
  239. title: '筛选已应用',
  240. icon: 'success'
  241. });
  242. setTimeout(() => {
  243. uni.navigateBack();
  244. }, 800);
  245. };
  246. // 重置过滤器
  247. const resetFilters = () => {
  248. selectedHistory.value = '';
  249. selectedJobType.value = '';
  250. minSalary.value = 0;
  251. maxSalary.value = 50;
  252. updateThumbPositions();
  253. selectedExperience.value = '';
  254. selectedEducation.value = '不限';
  255. selectedRegion.value = ['', '', ''];
  256. selectedCity.value = '';
  257. };
  258. </script>
  259. <style lang="scss" scoped>
  260. .container {
  261. width: 100%;
  262. height: 100vh;
  263. background-color: #FFFFFF;
  264. display: flex;
  265. flex-direction: column;
  266. }
  267. .scroll-body {
  268. flex: 1;
  269. overflow-y: auto;
  270. padding: 24rpx 40rpx;
  271. box-sizing: border-box;
  272. }
  273. .section {
  274. margin-bottom: 40rpx;
  275. .section-header {
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. margin-bottom: 24rpx;
  280. .title {
  281. font-size: 28rpx;
  282. font-weight: bold;
  283. color: #1A1A1A;
  284. }
  285. .delete-icon {
  286. width: 32rpx;
  287. height: 32rpx;
  288. opacity: 0.4;
  289. padding: 10rpx;
  290. }
  291. }
  292. .tags-row {
  293. display: flex;
  294. flex-wrap: wrap;
  295. gap: 16rpx;
  296. .tag {
  297. background-color: #FFFFFF;
  298. color: #555555;
  299. font-size: 24rpx;
  300. padding: 12rpx 30rpx;
  301. border-radius: 100rpx;
  302. border: 2rpx solid #E4E7ED;
  303. min-width: 130rpx;
  304. text-align: center;
  305. box-sizing: border-box;
  306. &.active {
  307. background-color: #1F6CFF;
  308. color: #FFFFFF;
  309. border-color: #1F6CFF;
  310. }
  311. }
  312. }
  313. }
  314. .location-picker {
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. background-color: #F8F9FB;
  319. padding: 24rpx 30rpx;
  320. border-radius: 12rpx;
  321. border: 2rpx solid #E4E7ED;
  322. .location-text {
  323. font-size: 26rpx;
  324. color: #1A1A1A;
  325. &.placeholder {
  326. color: #BBBBBB;
  327. }
  328. }
  329. .arrow-icon {
  330. width: 24rpx;
  331. height: 24rpx;
  332. opacity: 0.3;
  333. }
  334. }
  335. .salary-display {
  336. text-align: center;
  337. font-size: 28rpx;
  338. color: #1F6CFF;
  339. margin-bottom: 24rpx;
  340. font-weight: bold;
  341. }
  342. .range-slider-wrap {
  343. width: 100%;
  344. height: 60rpx;
  345. padding: 0 20rpx;
  346. box-sizing: border-box;
  347. }
  348. .slider-track-area {
  349. width: 100%;
  350. height: 100%;
  351. position: relative;
  352. }
  353. .slider-bg {
  354. position: absolute;
  355. top: 50%;
  356. left: 0;
  357. right: 0;
  358. height: 8rpx;
  359. background-color: #F0F2F5;
  360. transform: translateY(-50%);
  361. border-radius: 4rpx;
  362. }
  363. .slider-active {
  364. position: absolute;
  365. top: 50%;
  366. height: 8rpx;
  367. background-color: #1F6CFF;
  368. transform: translateY(-50%);
  369. border-radius: 4rpx;
  370. }
  371. .slider-thumb {
  372. width: 40rpx;
  373. height: 40rpx;
  374. background-color: #FFFFFF;
  375. border-radius: 50%;
  376. border: 4rpx solid #1F6CFF;
  377. box-shadow: 0 2rpx 6rpx rgba(31, 108, 255, 0.2);
  378. top: 50%;
  379. margin-top: -20rpx;
  380. box-sizing: border-box;
  381. }
  382. .bottom-bar {
  383. position: fixed;
  384. left: 0;
  385. right: 0;
  386. bottom: 0;
  387. height: 110rpx;
  388. background-color: #FFFFFF;
  389. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
  390. display: flex;
  391. align-items: center;
  392. padding: 0 40rpx;
  393. padding-bottom: env(safe-area-inset-bottom);
  394. gap: 30rpx;
  395. z-index: 100;
  396. .btn {
  397. flex: 1;
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. font-size: 28rpx;
  402. height: 72rpx;
  403. border-radius: 100rpx;
  404. font-weight: 500;
  405. }
  406. .reset-btn {
  407. background-color: #FFFFFF;
  408. color: #666666;
  409. border: 2rpx solid #E4E7ED;
  410. box-sizing: border-box;
  411. }
  412. .confirm-btn {
  413. background-color: #1F6CFF;
  414. color: #FFFFFF;
  415. }
  416. }
  417. </style>