position.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view>
  3. <Navbar :showLogo="true"></Navbar>
  4. <view class="box defaultBgc">
  5. <scroll-view class="scrollBox" :scroll-y="true" :scroll-top="scrollTop" @scrolltolower="loadingMore" @scroll="onScroll" style="position:relative;">
  6. <view>
  7. <view class="commonBackground">
  8. <SwiperAd v-if="swiperAdList.length" margin="0 10px 10px 10px" padding="10px 0 0 0" :list="swiperAdList" imgUrlKey="img" :strType="false" @click="handleToDetails"></SwiperAd>
  9. </view>
  10. <!-- 五宫格菜单 -->
  11. <view>
  12. <uni-grid :column="5" @change="handleGrid" :showBorder="false">
  13. <uni-grid-item v-for="(val, index) in gridList" :index="index" :key="index">
  14. <view class="d-flex align-center flex-column justify-center" style="width: 100%; height: 100%; border: none;">
  15. <image :src="val.icon" style="width: 45px; height: 45px;"></image>
  16. <text class="grid-item-text MiSans-Normal">{{ val.label }}</text>
  17. </view>
  18. </uni-grid-item>
  19. </uni-grid>
  20. </view>
  21. <!-- 搜索条 -->
  22. <view class="whiteBgc stick">
  23. <view style="position: relative;">
  24. <uni-search-bar
  25. v-model="query.content"
  26. placeholder="输入职位/公司关键字"
  27. cancelButton="none"
  28. :focus="false"
  29. bgColor="#fbfffe"
  30. @confirm="onSearch($event.value)"
  31. @clear="query.content = ''; onSearch()"
  32. >
  33. <template v-slot:searchIcon>
  34. <uni-icons color="#0E100F" size="18" type="search" />
  35. </template>
  36. </uni-search-bar>
  37. <button class="search-btn MiSans-Medium" @tap.stop="onSearch">搜索</button>
  38. </view>
  39. </view>
  40. <view class="px-10 stickFilter ss-p-b-10">
  41. <FilterList :list="filterList" idValue="label" @change="handleSearch"></FilterList>
  42. </view>
  43. <view style="background-color: #fff;">
  44. <PositionList v-if="positionListData?.length || more !== 'loading'" :list="positionListData" :noMore="false"></PositionList>
  45. <uni-load-more :status="more" />
  46. </view>
  47. </view>
  48. </scroll-view>
  49. <AdvertisePop v-if="showAdvertisePop" />
  50. </view>
  51. </view>
  52. </template>
  53. <script setup>
  54. import { ref, reactive, nextTick } from 'vue'
  55. import SwiperAd from '@/components/SwiperAd'
  56. import FilterList from '@/components/FilterList'
  57. import PositionList from '@/components/PositionList'
  58. import AdvertisePop from '@/components/Advertisement'
  59. import { dealDictObjData } from '@/utils/position'
  60. import { getJobAdvertisedSearch, getPromotedPosition } from '@/api/position'
  61. import { onShow, onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  62. import Navbar from '@/components/Navbar'
  63. import { getRewardEventList } from '@/utils/eventList'
  64. import { getMorningNewsArticle } from '@/api/content'
  65. import { getWebContent } from '@/api/common'
  66. onLoad(() => {
  67. wx.showShareMenu({
  68. withShareTicket: true,
  69. menus: ['shareAppMessage', 'shareTimeline']
  70. })
  71. onShareAppMessage(() => {
  72. return {
  73. title: '门墩儿 专注顶尖招聘',
  74. path: '/pages/index/position',
  75. imageUrl: '../../static/img/share-poster.jpg'
  76. }
  77. })
  78. onShareTimeline(() => {
  79. return {
  80. title: '门墩儿 专注顶尖招聘',
  81. path: '/pages/index/position',
  82. imageUrl: '../../static/img/share-poster.jpg'
  83. }
  84. })
  85. if (!uni.getStorageSync('token')) getRewardEventList()
  86. })
  87. const more = ref('more')
  88. // 轮播图-优选集团信息
  89. const preferredGroup = ref({})
  90. // 获取轮播图
  91. const showAdvertisePop = ref(false)
  92. const swiperAdList = ref([])
  93. const getSystemWebContent = async () => {
  94. const { data } = await getWebContent()
  95. swiperAdList.value = data?.appHomeCarousel || []
  96. // 是否展示弹窗广告
  97. // showAdvertisePop.value = data && data.appAdvertisement && data.appAdvertisement.length ? true : false
  98. // 优选集团
  99. preferredGroup.value = data?.appPreferredGroup || {}
  100. }
  101. const filterList = ref([
  102. { label: '城市', multiple: true, dictType: 'areaTreeData', key: 'areaIds', map: { text: 'name', value: 'id' } },
  103. { label: '职位', dictType: 'positionTreeData',key: 'positionId', map: { text: 'nameCn', value: 'id' } },
  104. { label: '求职类型', dictType: 'menduner_job_type', key: 'jobType' },
  105. { label: '薪资待遇', dictType: 'menduner_pay_scope', key: 'payScope' },
  106. ])
  107. const gridList = [
  108. { label: '门墩儿猎头', icon: '/static/img/headhunting.png', path: '/pagesB/headhunting/index' },
  109. { label: '精选企业', icon: '/static/img/enterprise.png', path: '/pagesB/recommendEnterprise/index' },
  110. { label: '酒店英语', icon: '/static/img/group.png', weiXinPublicUrl: 'https://mp.weixin.qq.com/s/zta8NvNaJOFhPxq9NAE9pw' },
  111. // { label: '早报资讯', icon: '/static/img/information.png', id: 'morningNews' },
  112. { label: '招聘会', icon: '/static/img/information.png', path: '/pages/index/jobFair' },
  113. { label: '了解门墩儿', icon: '/static/img/contact.png', path: '/pagesB/about/index' }
  114. ]
  115. // 轮播图链接跳转
  116. const handleToDetails = ({ link, title }) => {
  117. if (!link) return
  118. // 公众号链接跳转
  119. if (link.includes('http')) uni.navigateTo({ url: `/pages/addWebView/index?url=${link}&title=${title || '门墩儿 专注顶尖招聘'}` })
  120. else {
  121. // 优选集团
  122. if (preferredGroup.value && Object.keys(preferredGroup.value).length > 0 && preferredGroup.value[link]) uni.navigateTo({ url: `/pagesB/preferredGroup/index?id=${link}` })
  123. // 企业详情
  124. else uni.navigateTo({ url: `/pagesB/companyDetail/index?id=${link}` })
  125. }
  126. }
  127. const handleGrid = async (e) => {
  128. const index = e.detail.index
  129. const obj = gridList[index]
  130. // 早报资讯
  131. if (obj?.id === 'morningNews') {
  132. try {
  133. const { data } = await getMorningNewsArticle()
  134. if (data && Object.keys(data).length && data.url) {
  135. uni.navigateTo({
  136. url: `/pages/addWebView/index?url=${data.url}&title=门墩儿早报`
  137. })
  138. } else uni.showToast({ icon: 'none', title: '暂无早报资讯内容' })
  139. } catch (err) {
  140. uni.showToast({ icon: 'none', title: err.msg })
  141. }
  142. }
  143. if (obj?.path) {
  144. if (obj?.path === '/pages/index/jobFair') {
  145. uni.switchTab({
  146. url: obj?.path
  147. })
  148. return
  149. }
  150. uni.navigateTo({
  151. url: obj.path
  152. })
  153. }
  154. if (obj?.weiXinPublicUrl) {
  155. uni.navigateTo({ url: `/pages/addWebView/index?url=${obj?.weiXinPublicUrl}&title=${obj?.title || obj.label}` })
  156. }
  157. }
  158. const checkValue = (obj) => {
  159. return Object.values(obj).some(value => {
  160. return value !== null && value !== undefined && value !== '' && (Array.isArray(value) ? value.length > 0 : true)
  161. })
  162. }
  163. const type = ref('recommend')
  164. const positionListData = ref([])
  165. const query = reactive({
  166. pageSize: 20,
  167. pageNo: 1,
  168. hire: false,
  169. content: '',
  170. positionId: '',
  171. areaIds: [],
  172. industryIds: [],
  173. jobType: [],
  174. payScope: ''
  175. })
  176. const getData = async () => {
  177. // 效验是否有带搜索条件
  178. const { content, areaIds, industryIds, jobType, payScope, positionId } = query
  179. const hasValue = checkValue({ content, areaIds, industryIds, jobType, payScope, positionId })
  180. // 当前接口为推荐列表时,带查询条件需返回到列表顶部
  181. if (hasValue && type.value === 'recommend') {
  182. scrollTop.value = old.value.scrollTop
  183. nextTick(() => {
  184. type.value = 'position'
  185. scrollTop.value = 0
  186. })
  187. }
  188. // 当前接口为只为列表时,清除查询条件需返回到列表顶部
  189. if (!hasValue && type.value === 'position') {
  190. scrollTop.value = old.value.scrollTop
  191. nextTick(() => {
  192. type.value = 'recommend'
  193. scrollTop.value = 0
  194. })
  195. }
  196. // 带搜索条件(除分页外)用职位搜索接口,无条件则用推荐接口
  197. const api = hasValue ? getJobAdvertisedSearch : getPromotedPosition
  198. const _query = Object.keys(query).reduce((acc, cur) => {
  199. if (!query[cur]) {
  200. return acc
  201. }
  202. acc[cur] = query[cur]
  203. return acc
  204. }, {})
  205. const params = hasValue ? _query : { pageSize: query.pageSize, pageNo: query.pageNo, hire: 0 }
  206. if (params.pageNo === 1) positionListData.value = []
  207. if (params.pageNo <= 0) return
  208. type.value = hasValue ? 'position' : 'recommend'
  209. try {
  210. more.value = 'loading'
  211. const res = await api(params)
  212. const arr = res?.data?.list || []
  213. if (!arr?.length) {
  214. more.value = 'noMore'
  215. return
  216. }
  217. // 推荐接口返回数据需要拼接
  218. const list = !hasValue ? arr.map(e => {
  219. const { anotherName, logoUrl, scale, industryId, enterpriseId, enterpriseName, ...job } = e
  220. return { job, enterprise: { anotherName, logoUrl, scale, industryId, enterpriseId, name: enterpriseName } }
  221. }) : arr
  222. positionListData.value.push(...list.map(e => {
  223. if (!e) {
  224. return e
  225. }
  226. e.job = { ...e.job, ...dealDictObjData({}, e.job) }
  227. e.enterprise = { ...e.enterprise, ...dealDictObjData({}, e.enterprise)}
  228. return e
  229. }))
  230. if (positionListData.value.length === +res.data.total) {
  231. more.value = 'noMore'
  232. return
  233. }
  234. } catch (error) {
  235. query.pageNo--
  236. more.value = 'more'
  237. }
  238. }
  239. // 设置自定义tabbar选中值
  240. onShow(() => {
  241. const currentPage = getCurrentPages()[0]; // 获取当前页面实例
  242. const currentTabBar = currentPage?.getTabBar?.();
  243. // 设置当前tab页的下标index
  244. currentTabBar?.setData({ selected: 0 });
  245. getSystemWebContent()
  246. getData()
  247. })
  248. const scrollTop = ref(0)
  249. const old = ref({
  250. scrollTop: 0
  251. })
  252. const onScroll = (e) =>{
  253. old.value.scrollTop = e.detail.scrollTop
  254. }
  255. const handleSearch = (key, value) => {
  256. query[key] = value
  257. // if (key === 'positionId' || key === 'payScope') {
  258. // query[key] = value || null
  259. // } else {
  260. // query[key] = value ? [value] : []
  261. // }
  262. onSearch()
  263. }
  264. const onSearch = () => {
  265. query.pageNo = 1
  266. positionListData.value = []
  267. getData()
  268. }
  269. // 加载更多
  270. const loadingMore = () => {
  271. more.value = 'loading'
  272. query.pageNo++
  273. getData()
  274. }
  275. </script>
  276. <style scoped lang="scss">
  277. .stick {
  278. z-index: 1;
  279. position: sticky;
  280. top: 0;
  281. }
  282. .stickFilter {
  283. z-index: 1;
  284. position: sticky;
  285. box-shadow: 0px 10rpx 12rpx 0px rgba(195, 195, 195, .25);
  286. top: 110rpx;
  287. background-color: #fff;
  288. }
  289. .px-0 { padding-left: 0 !important; padding-right: 0 !important; }
  290. .pb-10 {
  291. padding-bottom: 10px;
  292. }
  293. .pb-20 { padding-bottom: 20px; }
  294. .px-5 { padding-left: 5px; padding-right: 5px; }
  295. .px-10 { padding-left: 10px; padding-right: 10px; }
  296. .mx-10 { margin-left: 10px; margin-right: 10px }
  297. .mx-20 { margin-left: 20px; margin-right: 20px; }
  298. .mb-10 { margin-bottom: 10px; }
  299. .box {
  300. height: 100vh;
  301. overflow: hidden;
  302. padding-bottom: 120rpx;
  303. box-sizing: border-box;
  304. display: flex;
  305. flex-direction: column;
  306. }
  307. .grid-item-text {
  308. font-family: MiSans, MiSans;
  309. font-weight: 400;
  310. font-size: 24rpx;
  311. color: #0E100F;
  312. font-style: normal;
  313. text-transform: none;
  314. }
  315. .scrollBox{
  316. flex: 1;
  317. height: 0 !important;
  318. padding-bottom: 24rpx;
  319. box-sizing: border-box;
  320. }
  321. :deep(.uni-searchbar__box) {
  322. width: 100%;
  323. height: 80rpx !important;
  324. border: 1px solid #00B760;
  325. border-radius: 20rpx;
  326. flex: none;
  327. }
  328. .search-btn {
  329. position: absolute;
  330. right: 30rpx;
  331. top: 50%;
  332. transform: translateY(-50%);
  333. width: 100rxp;
  334. height: 60rpx;
  335. font-size: 24rpx;
  336. background-color: #00B760;
  337. color: #fff;
  338. border-radius: 20rpx;
  339. z-index: 9;
  340. }
  341. :deep(.picker-view) {
  342. padding-bottom: 80px !important;
  343. }
  344. </style>