filter.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 selectedDistrict = ref('');
  141. const onRegionChange = (e) => {
  142. selectedRegion.value = e.detail.value;
  143. selectedCity.value = e.detail.value[1]; // 取城市名作为核心过滤条件
  144. selectedDistrict.value = e.detail.value[2]; // 取区名
  145. };
  146. const loadDictionaries = () => {
  147. getDicts('main_position_type').then(res => {
  148. if (res.data) {
  149. jobTypes.value = res.data;
  150. }
  151. });
  152. getDicts('main_experience').then(res => {
  153. if (res.data) {
  154. experiences.value = res.data;
  155. }
  156. });
  157. getDicts('main_education').then(res => {
  158. if (res.data) {
  159. educations.value = res.data;
  160. }
  161. });
  162. };
  163. onMounted(() => {
  164. // 加载搜索历史
  165. const historyStr = uni.getStorageSync('search_history');
  166. if (historyStr) {
  167. try {
  168. historyList.value = JSON.parse(historyStr);
  169. } catch(e){}
  170. }
  171. loadDictionaries();
  172. // 延迟一小会儿,确保 DOM 已经挂载好
  173. setTimeout(() => {
  174. uni.createSelectorQuery().select('.slider-track-area').boundingClientRect(res => {
  175. if (res && res.width) {
  176. const thumbW = uni.upx2px(40);
  177. thumbHalf.value = thumbW / 2;
  178. sliderWidth.value = res.width - thumbW;
  179. updateThumbPositions();
  180. }
  181. }).exec();
  182. }, 300);
  183. });
  184. // 计算位置同步到界面
  185. const updateThumbPositions = () => {
  186. if (sliderWidth.value > 0) {
  187. minX.value = (minSalary.value / MAX_SALARY) * sliderWidth.value;
  188. maxX.value = (maxSalary.value / MAX_SALARY) * sliderWidth.value;
  189. }
  190. };
  191. const onMinMove = (e) => {
  192. if (e.detail.source === 'touch') {
  193. let newX = e.detail.x;
  194. if (newX > maxX.value) newX = maxX.value;
  195. minX.value = newX;
  196. minSalary.value = Math.round((newX / sliderWidth.value) * MAX_SALARY);
  197. }
  198. };
  199. const onMaxMove = (e) => {
  200. if (e.detail.source === 'touch') {
  201. let newX = e.detail.x;
  202. if (newX < minX.value) newX = minX.value;
  203. maxX.value = newX;
  204. maxSalary.value = Math.round((newX / sliderWidth.value) * MAX_SALARY);
  205. }
  206. };
  207. // 清除历史记录
  208. const clearHistory = () => {
  209. uni.showModal({
  210. title: '提示',
  211. content: '确认清空历史搜索?',
  212. success: (res) => {
  213. if (res.confirm) {
  214. historyList.value = [];
  215. selectedHistory.value = '';
  216. uni.removeStorageSync('search_history');
  217. }
  218. }
  219. });
  220. };
  221. // 确定筛选项
  222. const confirmFilters = () => {
  223. // 匹配选中的字典标签,若包含“不限”则重置为空字符串传给后端
  224. const expItem = experiences.value.find(i => i.dictValue === selectedExperience.value);
  225. const userExp = (expItem && expItem.dictLabel && expItem.dictLabel.includes('不限')) ? '' : selectedExperience.value;
  226. const eduItem = educations.value.find(i => i.dictValue === selectedEducation.value);
  227. const userEdu = (eduItem && eduItem.dictLabel && eduItem.dictLabel.includes('不限')) ? '' : selectedEducation.value;
  228. // 发送给岗位列表页面进行筛选
  229. const filterParams = {
  230. keyword: selectedHistory.value,
  231. jobType: selectedJobType.value,
  232. minSalary: minSalary.value,
  233. maxSalary: maxSalary.value,
  234. experience: userExp,
  235. education: userEdu,
  236. workCity: selectedCity.value,
  237. workProvince: selectedRegion.value[0],
  238. workDistrict: selectedDistrict.value
  239. };
  240. uni.$emit('updateFilters', filterParams);
  241. uni.showToast({
  242. title: '筛选已应用',
  243. icon: 'success'
  244. });
  245. setTimeout(() => {
  246. uni.navigateBack();
  247. }, 800);
  248. };
  249. // 重置过滤器
  250. const resetFilters = () => {
  251. selectedHistory.value = '';
  252. selectedJobType.value = '';
  253. minSalary.value = 0;
  254. maxSalary.value = 50;
  255. updateThumbPositions();
  256. selectedExperience.value = '';
  257. selectedEducation.value = '不限';
  258. selectedRegion.value = ['', '', ''];
  259. selectedCity.value = '';
  260. selectedDistrict.value = '';
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .container {
  265. width: 100%;
  266. height: 100vh;
  267. background-color: #FFFFFF;
  268. display: flex;
  269. flex-direction: column;
  270. }
  271. .scroll-body {
  272. flex: 1;
  273. overflow-y: auto;
  274. padding: 24rpx 40rpx;
  275. box-sizing: border-box;
  276. }
  277. .section {
  278. margin-bottom: 40rpx;
  279. .section-header {
  280. display: flex;
  281. justify-content: space-between;
  282. align-items: center;
  283. margin-bottom: 24rpx;
  284. .title {
  285. font-size: 28rpx;
  286. font-weight: bold;
  287. color: #1A1A1A;
  288. }
  289. .delete-icon {
  290. width: 32rpx;
  291. height: 32rpx;
  292. opacity: 0.4;
  293. padding: 10rpx;
  294. }
  295. }
  296. .tags-row {
  297. display: flex;
  298. flex-wrap: wrap;
  299. gap: 16rpx;
  300. .tag {
  301. background-color: #FFFFFF;
  302. color: #555555;
  303. font-size: 24rpx;
  304. padding: 12rpx 30rpx;
  305. border-radius: 100rpx;
  306. border: 2rpx solid #E4E7ED;
  307. min-width: 130rpx;
  308. text-align: center;
  309. box-sizing: border-box;
  310. &.active {
  311. background-color: #1F6CFF;
  312. color: #FFFFFF;
  313. border-color: #1F6CFF;
  314. }
  315. }
  316. }
  317. }
  318. .location-picker {
  319. display: flex;
  320. justify-content: space-between;
  321. align-items: center;
  322. background-color: #F8F9FB;
  323. padding: 24rpx 30rpx;
  324. border-radius: 12rpx;
  325. border: 2rpx solid #E4E7ED;
  326. .location-text {
  327. font-size: 26rpx;
  328. color: #1A1A1A;
  329. &.placeholder {
  330. color: #BBBBBB;
  331. }
  332. }
  333. .arrow-icon {
  334. width: 24rpx;
  335. height: 24rpx;
  336. opacity: 0.3;
  337. }
  338. }
  339. .salary-display {
  340. text-align: center;
  341. font-size: 28rpx;
  342. color: #1F6CFF;
  343. margin-bottom: 24rpx;
  344. font-weight: bold;
  345. }
  346. .range-slider-wrap {
  347. width: 100%;
  348. height: 60rpx;
  349. padding: 0 20rpx;
  350. box-sizing: border-box;
  351. }
  352. .slider-track-area {
  353. width: 100%;
  354. height: 100%;
  355. position: relative;
  356. }
  357. .slider-bg {
  358. position: absolute;
  359. top: 50%;
  360. left: 0;
  361. right: 0;
  362. height: 8rpx;
  363. background-color: #F0F2F5;
  364. transform: translateY(-50%);
  365. border-radius: 4rpx;
  366. }
  367. .slider-active {
  368. position: absolute;
  369. top: 50%;
  370. height: 8rpx;
  371. background-color: #1F6CFF;
  372. transform: translateY(-50%);
  373. border-radius: 4rpx;
  374. }
  375. .slider-thumb {
  376. width: 40rpx;
  377. height: 40rpx;
  378. background-color: #FFFFFF;
  379. border-radius: 50%;
  380. border: 4rpx solid #1F6CFF;
  381. box-shadow: 0 2rpx 6rpx rgba(31, 108, 255, 0.2);
  382. top: 50%;
  383. margin-top: -20rpx;
  384. box-sizing: border-box;
  385. }
  386. .bottom-bar {
  387. position: fixed;
  388. left: 0;
  389. right: 0;
  390. bottom: 0;
  391. height: 110rpx;
  392. background-color: #FFFFFF;
  393. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
  394. display: flex;
  395. align-items: center;
  396. padding: 0 40rpx;
  397. padding-bottom: env(safe-area-inset-bottom);
  398. gap: 30rpx;
  399. z-index: 100;
  400. .btn {
  401. flex: 1;
  402. display: flex;
  403. align-items: center;
  404. justify-content: center;
  405. font-size: 28rpx;
  406. height: 72rpx;
  407. border-radius: 100rpx;
  408. font-weight: 500;
  409. }
  410. .reset-btn {
  411. background-color: #FFFFFF;
  412. color: #666666;
  413. border: 2rpx solid #E4E7ED;
  414. box-sizing: border-box;
  415. }
  416. .confirm-btn {
  417. background-color: #1F6CFF;
  418. color: #FFFFFF;
  419. }
  420. }
  421. </style>