search.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view class="search-index">
  3. <nav-bar title="搜索" @init="onInitNavbar"></nav-bar>
  4. <u-scroll-view :tabbar-conflict="false" @scroll-near-lower="onScrollToLower">
  5. <view class="main-container">
  6. <u-search v-model="searchKeyword" placeholder="搜索展商 / 展品名称 / 会议" @search="onClickSearch"/>
  7. <view class="search-result-text">搜索结果</view>
  8. <template v-if="isEmpty">
  9. <van-empty description="暂无数据" />
  10. </template>
  11. <template v-else>
  12. <u-tabs :active.sync="tabActive" :tabs="tabs" tab-style="default" @change="tabChange"/>
  13. <view v-if="tabActive === 1" class="search-result-list exhibit-list">
  14. <template v-for="(item, index) in exhibitorList">
  15. <exhibitor-item :item="item" :key="index" :pollShow="pollShow.exhibitors_poll_show" @share="onShare()" @updateItemValue="updateItemValue()"/>
  16. </template>
  17. </view>
  18. <view v-else-if="tabActive === 2" class="search-result-list exhibit-list">
  19. <template v-for="(item, index) in exhibitList">
  20. <exhibit-item :item="item" :key="index" :pollShow="pollShow.product_poll_show" @share="onShare()" @updateItemValue="updateItemValue()"/>
  21. </template>
  22. </view>
  23. <view v-else-if="tabActive === 3" class="search-result-list exhibit-list">
  24. <template v-for="(item, index) in newsList">
  25. <news-item :item="item" :key="index" />
  26. </template>
  27. </view>
  28. <view v-else-if="tabActive === 4" class="search-result-list exhibit-list">
  29. <template v-for="(item, index) in activityList">
  30. <activity-item :item="item" :key="index" @updateItemValue="updateItemValue()"/>
  31. </template>
  32. </view>
  33. <view v-else-if="tabActive === 5" class="search-result-list exhibit-list">
  34. <template v-for="(item, index) in mettingList">
  35. <activity-item :item="item" :key="index" platform="metting" @updateItemValue="updateItemValue()"/>
  36. </template>
  37. </view>
  38. </template>
  39. <disclaimer-text></disclaimer-text>
  40. </view>
  41. </u-scroll-view>
  42. <u-share-action-sheet :show.sync="showShare" :show-info="shareInfo" />
  43. </view>
  44. </template>
  45. <script>
  46. import NavBar from '@/components/layout/nav-bar'
  47. import UTabs from '@/components/common/u-tabs'
  48. import UScrollView from '@/components/common/u-scroll-view'
  49. import UShareActionSheet from '@/components/common/u-share-action-sheet'
  50. import USearch from '@/components/common/u-search'
  51. import ExhibitItem from '@/pages/exhibitor/components/exhibit-item.vue'
  52. import ExhibitorItem from '@/pages/exhibitor/components/exhibitor-item.vue'
  53. import NewsItem from '@/pages/news/components/news-item.vue'
  54. import ActivityItem from '@/pages/activity/components/activity-item.vue'
  55. import { globalSearch, mettingList, exhibitorsList, exhibitorsProductList, exhibitorsNewsList, exhibitorsBoothActivityList, globalPollShow } from '@/api/exhibitor'
  56. import DisclaimerText from '@/components/disclaimer-text/index.vue'
  57. export default {
  58. options: {
  59. styleIsolation: 'shared'
  60. },
  61. components: {
  62. NavBar,
  63. UScrollView,
  64. UTabs,
  65. USearch,
  66. ExhibitItem,
  67. ExhibitorItem,
  68. NewsItem,
  69. ActivityItem,
  70. DisclaimerText,
  71. UShareActionSheet
  72. },
  73. data() {
  74. return {
  75. searchKeyword: '',
  76. tabActive: 1,
  77. isEmpty: false,
  78. defaultTabs: [{
  79. label: '展商',
  80. value: 1
  81. }, {
  82. label: '展品',
  83. value: 2
  84. }, {
  85. label: '展商新闻',
  86. value: 3
  87. }, {
  88. label: '展商活动',
  89. value: 4
  90. }, {
  91. label: '同期活动',
  92. value: 5
  93. }],
  94. tabs: [],
  95. exhibitorList: [],
  96. exhibitorListLoading: false,
  97. exhibitorListLastPage: 1,
  98. exhibitorListParams: {
  99. page: 1,
  100. page_size: 10,
  101. keyword: ''
  102. },
  103. exhibitList: [],
  104. exhibitListLoading: false,
  105. exhibitListLastPage: 1,
  106. exhibitListParams: {
  107. page: 1,
  108. page_size: 10,
  109. keyword: ''
  110. },
  111. newsList: [],
  112. newsListLoading: false,
  113. newsListLastPage: 1,
  114. newsListParams: {
  115. page: 1,
  116. page_size: 10,
  117. keyword: ''
  118. },
  119. activityList: [],
  120. activityListLoading: false,
  121. activityListLastPage: 1,
  122. activityListParams: {
  123. page: 1,
  124. page_size: 10,
  125. keyword: ''
  126. },
  127. mettingList: [],
  128. mettingListLoading: false,
  129. mettingListLastPage: 1,
  130. mettingListParams: {
  131. page: 1,
  132. page_size: 10,
  133. keyword: ''
  134. },
  135. listParams: {
  136. page: 1,
  137. page_size: 10,
  138. keyword: ''
  139. },
  140. pollShow: {
  141. exhibitors_poll_show: 0,
  142. product_poll_show: 0
  143. },
  144. showShare: false,
  145. shareInfo: null,
  146. }
  147. },
  148. onLoad(options) {
  149. console.log('options')
  150. console.log(options.query)
  151. this.searchKeyword = options.query
  152. this.onClickSearch()
  153. },
  154. created() {
  155. this.getGlobalPollShow()
  156. },
  157. methods: {
  158. tabChange() {
  159. },
  160. onClickSearch() {
  161. this.listParams.page = 1
  162. this.listParams.keyword = this.searchKeyword
  163. this.exhibitorListParams = {...this.listParams}
  164. this.exhibitListParams = {...this.listParams}
  165. this.newsListParams = {...this.listParams}
  166. this.activityListParams = {...this.listParams}
  167. this.mettingListParams = {...this.listParams}
  168. this.tabs = [...this.defaultTabs]
  169. this.getGlobalSearch()
  170. this.getMettingList()
  171. },
  172. getGlobalSearch() { // 全局搜索
  173. globalSearch(this.listParams).then(res => {
  174. if (res.code === 0) {
  175. this.exhibitorList = res.data.exhibitors_list.data ?? []
  176. this.exhibitorListLastPage = res.data.exhibitors_list.last_page ?? 1
  177. this.exhibitList = res.data.product_list.data ?? []
  178. this.exhibitListLastPage = res.data.product_list.last_page ?? 0
  179. this.newsList = res.data.news_list.data ?? []
  180. this.newsListLastPage = res.data.news_list.last_page ?? 0
  181. this.activityList = res.data.booth_activity_list.data ?? []
  182. this.activityListLastPage = res.data.booth_activity_list.last_page ?? 0
  183. if (this.exhibitorList.length === 0) {
  184. this.tabs = this.tabs.filter(item => item.value !== 1);
  185. }
  186. if (this.exhibitList.length === 0) {
  187. this.tabs = this.tabs.filter(item => item.value !== 2);
  188. }
  189. if (this.newsList.length === 0) {
  190. this.tabs = this.tabs.filter(item => item.value !== 3);
  191. }
  192. if (this.activityList.length === 0) {
  193. this.tabs = this.tabs.filter(item => item.value !== 4);
  194. }
  195. }
  196. })
  197. },
  198. getExhibitorsList() { // 展商
  199. this.exhibitorListLoading = true
  200. exhibitorsList(this.exhibitorListParams).then(res => {
  201. if (res.data.data) {
  202. if (this.exhibitorListParams.page > 1) {
  203. this.exhibitorList = [...this.exhibitorList, ...res.data.data]
  204. } else {
  205. this.exhibitorList = res.data.data
  206. this.exhibitorListLastPage = res.data.last_page
  207. }
  208. } else {
  209. this.showToast('系统繁忙,稍候再试')
  210. }
  211. this.exhibitorListLoading = false
  212. })
  213. },
  214. getExhibitList() { // 展品
  215. this.exhibitListLoading = true
  216. exhibitorsProductList(this.exhibitListParams).then(res => {
  217. if (res.data.data) {
  218. if (this.exhibitListParams.page > 1) {
  219. this.exhibitList = [...this.exhibitList, ...res.data.data]
  220. } else {
  221. this.exhibitList = res.data.data
  222. this.exhibitListLastPage = res.data.last_page
  223. }
  224. } else {
  225. this.showToast('系统繁忙,稍候再试')
  226. }
  227. this.exhibitListLoading = false
  228. })
  229. },
  230. getExhibitorsNewsList() { // 展商新闻
  231. this.newsListLoading = true
  232. exhibitorsNewsList(this.newsListParams).then(res => {
  233. if (res.data.data) {
  234. if (this.newsListParams.page > 1) {
  235. this.newsList = [...this.newsList, ...res.data.data]
  236. } else {
  237. this.newsList = res.data.data
  238. this.newsListLastPage = res.data.last_page
  239. }
  240. } else {
  241. this.showToast('系统繁忙,稍候再试')
  242. }
  243. this.newsListLoading = false
  244. })
  245. },
  246. getActivityList() { // 展台活动
  247. this.activityListLoading = true
  248. exhibitorsBoothActivityList(this.activityListParams).then(res => {
  249. if (res.data.data) {
  250. if (this.activityListParams.page > 1) {
  251. this.activityList = [...this.activityList, ...res.data.data]
  252. } else {
  253. this.activityList = res.data.data
  254. this.activityListLastPage = res.data.last_page
  255. }
  256. } else {
  257. this.showToast('系统繁忙,稍候再试')
  258. }
  259. this.activityListLoading = false
  260. })
  261. },
  262. getMettingList() { // 同期活动
  263. this.mettingListLoading = true
  264. mettingList(this.mettingListParams).then(res => {
  265. if (res.data.data) {
  266. if (this.mettingListParams.page > 1) {
  267. this.mettingList = [...this.mettingList, ...res.data.data]
  268. } else {
  269. this.mettingList = res.data.data
  270. this.mettingListLastPage = res.data.last_page
  271. }
  272. if (this.mettingListParams.page === 1 && this.mettingList.length === 0) {
  273. this.tabs = this.tabs.filter(item => item.value !== 5);
  274. }
  275. } else {
  276. this.showToast('系统繁忙,稍候再试')
  277. }
  278. this.mettingListLoading = false
  279. })
  280. },
  281. onScrollToLower(e) {
  282. if (this.tabActive === 1) {
  283. if (this.exhibitorListLastPage === this.exhibitorListParams.page) return
  284. if (this.exhibitorListLoading === true) return
  285. this.exhibitorListLoading = true
  286. this.exhibitorListParams.page = this.exhibitorListParams.page+1
  287. this.getExhibitorsList()
  288. } else if (this.tabActive === 2) {
  289. if (this.exhibitListLastPage === this.exhibitListParams.page) return
  290. if (this.exhibitListLoading === true) return
  291. this.exhibitListLoading = true
  292. this.exhibitListParams.page = this.exhibitListParams.page+1
  293. this.getExhibitList()
  294. } else if (this.tabActive === 3) {
  295. if (this.newsListLastPage === this.newsListParams.page) return
  296. if (this.newsListLoading === true) return
  297. this.newsListLoading = true
  298. this.newsListParams.page = this.newsListParams.page+1
  299. this.getExhibitorsNewsList()
  300. } else if (this.tabActive === 4) {
  301. if (this.activityListLastPage === this.activityListParams.page) return
  302. if (this.activityListLoading === true) return
  303. this.activityListLoading = true
  304. this.activityListParams.page = this.activityListParams.page+1
  305. this.getActivityList()
  306. } else if (this.tabActive === 5) {
  307. if (this.mettingListLastPage === this.mettingListParams.page) return
  308. if (this.mettingListLoading === true) return
  309. this.mettingListLoading = true
  310. this.mettingListParams.page = this.mettingListParams.page+1
  311. this.getMettingList()
  312. }
  313. },
  314. updateItemValue(e) {
  315. if (this.tabActive === 1) {
  316. this.exhibitorList.forEach((item) => {
  317. if (item.id === e.id) {
  318. item[e.key] = e.value
  319. }
  320. })
  321. } else if (this.tabActive === 2) {
  322. this.exhibitList.forEach((item) => {
  323. if (item.id === e.id) {
  324. item[e.key] = e.value
  325. }
  326. })
  327. } else if (this.tabActive === 4) {
  328. this.activityList.forEach((item) => {
  329. if (item.id === e.id) {
  330. item[e.key] = e.value
  331. }
  332. })
  333. } else if (this.tabActive === 5) {
  334. this.mettingList.forEach((item) => {
  335. if (item.id === e.id) {
  336. item[e.key] = e.value
  337. }
  338. })
  339. }
  340. },
  341. getGlobalPollShow() {
  342. globalPollShow().then(res => {
  343. this.pollShow = res.data
  344. })
  345. },
  346. onShare(e) {
  347. this.shareInfo = e.detail
  348. this.showShare = true
  349. },
  350. onShareAppMessage: function (res) {
  351. if (res.from === 'button') {
  352. if (this.shareInfo) {
  353. return this.shareInfo
  354. }
  355. }
  356. this.shareInfo = null
  357. this.showShare = false
  358. return {
  359. title: '慕尼黑上海电子生产设备展',
  360. path: '/pages/index/index',
  361. imageUrl: 'https://oss.starify.cn/prod/starify/up/0001018678/20241108/672da5a7dd374.png?x-oss-process=image/resize,w_600,h_600,limit_0,m_pad'
  362. }
  363. }
  364. }
  365. }
  366. </script>
  367. <style lang="scss">
  368. .search-result-text{
  369. margin: 33rpx 0;
  370. display: block;
  371. font-size: $fontSize3;
  372. color: #000000;
  373. }
  374. .search-result-list{
  375. display: grid;
  376. grid-template-columns: 1fr;
  377. grid-row-gap: 28rpx;
  378. margin-top: 32rpx;
  379. }
  380. </style>