search.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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" @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" @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></disclaimer>
  40. </view>
  41. </u-scroll-view>
  42. </view>
  43. </template>
  44. <script>
  45. import NavBar from '@/components/layout/nav-bar'
  46. import UTabs from '@/components/common/u-tabs'
  47. import UScrollView from '@/components/common/u-scroll-view'
  48. import USearch from '@/components/common/u-search'
  49. import ExhibitItem from '@/pages/exhibitor/components/exhibit-item.vue'
  50. import ExhibitorItem from '@/pages/exhibitor/components/exhibitor-item.vue'
  51. import NewsItem from '@/pages/news/components/news-item.vue'
  52. import ActivityItem from '@/pages/activity/components/activity-item.vue'
  53. import disclaimer from '@/components/disclaimer-text/index.vue'
  54. import { globalSearch, mettingList, exhibitorsList, exhibitorsProductList, exhibitorsNewsList, exhibitorsBoothActivityList } from '@/api/exhibitor'
  55. export default {
  56. options: {
  57. styleIsolation: 'shared'
  58. },
  59. components: {
  60. NavBar,
  61. UScrollView,
  62. UTabs,
  63. USearch,
  64. ExhibitItem,
  65. ExhibitorItem,
  66. NewsItem,
  67. ActivityItem,
  68. disclaimer
  69. },
  70. data() {
  71. return {
  72. searchKeyword: '',
  73. tabActive: 1,
  74. isEmpty: false,
  75. defaultTabs: [{
  76. label: '展商',
  77. value: 1
  78. }, {
  79. label: '展品',
  80. value: 2
  81. }, {
  82. label: '展商新闻',
  83. value: 3
  84. }, {
  85. label: '展商活动',
  86. value: 4
  87. }, {
  88. label: '同期活动',
  89. value: 5
  90. }],
  91. tabs: [],
  92. exhibitorList: [],
  93. exhibitorListLoading: false,
  94. exhibitorListLastPage: 1,
  95. exhibitorListParams: {
  96. page: 1,
  97. page_size: 10,
  98. keyword: ''
  99. },
  100. exhibitList: [],
  101. exhibitListLoading: false,
  102. exhibitListLastPage: 1,
  103. exhibitListParams: {
  104. page: 1,
  105. page_size: 10,
  106. keyword: ''
  107. },
  108. newsList: [],
  109. newsListLoading: false,
  110. newsListLastPage: 1,
  111. newsListParams: {
  112. page: 1,
  113. page_size: 10,
  114. keyword: ''
  115. },
  116. activityList: [],
  117. activityListLoading: false,
  118. activityListLastPage: 1,
  119. activityListParams: {
  120. page: 1,
  121. page_size: 10,
  122. keyword: ''
  123. },
  124. mettingList: [],
  125. mettingListLoading: false,
  126. mettingListLastPage: 1,
  127. mettingListParams: {
  128. page: 1,
  129. page_size: 10,
  130. keyword: ''
  131. },
  132. listParams: {
  133. page: 1,
  134. page_size: 10,
  135. keyword: ''
  136. }
  137. }
  138. },
  139. onLoad(options) {
  140. console.log('options')
  141. console.log(options.query)
  142. this.searchKeyword = options.query
  143. this.onClickSearch()
  144. },
  145. created() {},
  146. methods: {
  147. tabChange() {
  148. },
  149. onClickSearch() {
  150. this.listParams.page = 1
  151. this.listParams.keyword = this.searchKeyword
  152. this.exhibitorListParams = {...this.listParams}
  153. this.exhibitListParams = {...this.listParams}
  154. this.newsListParams = {...this.listParams}
  155. this.activityListParams = {...this.listParams}
  156. this.mettingListParams = {...this.listParams}
  157. this.tabs = [...this.defaultTabs]
  158. this.getGlobalSearch()
  159. this.getMettingList()
  160. },
  161. getGlobalSearch() { // 全局搜索
  162. globalSearch(this.listParams).then(res => {
  163. if (res.code === 0) {
  164. this.exhibitorList = res.data.exhibitors_list.data ?? []
  165. this.exhibitorListLastPage = res.data.exhibitors_list.last_page ?? 1
  166. this.exhibitList = res.data.product_list.data ?? []
  167. this.exhibitListLastPage = res.data.product_list.last_page ?? 0
  168. this.newsList = res.data.news_list.data ?? []
  169. this.newsListLastPage = res.data.news_list.last_page ?? 0
  170. this.activityList = res.data.booth_activity_list.data ?? []
  171. this.activityListLastPage = res.data.booth_activity_list.last_page ?? 0
  172. if (this.exhibitorList.length === 0) {
  173. this.tabs = this.tabs.filter(item => item.value !== 1);
  174. }
  175. if (this.exhibitList.length === 0) {
  176. this.tabs = this.tabs.filter(item => item.value !== 2);
  177. }
  178. if (this.newsList.length === 0) {
  179. this.tabs = this.tabs.filter(item => item.value !== 3);
  180. }
  181. if (this.activityList.length === 0) {
  182. this.tabs = this.tabs.filter(item => item.value !== 4);
  183. }
  184. }
  185. })
  186. },
  187. getExhibitorsList() { // 展商
  188. this.exhibitorListLoading = true
  189. exhibitorsList(this.exhibitorListParams).then(res => {
  190. if (res.data.data) {
  191. if (this.exhibitorListParams.page > 1) {
  192. this.exhibitorList = [...this.exhibitorList, ...res.data.data]
  193. } else {
  194. this.exhibitorList = res.data.data
  195. this.exhibitorListLastPage = res.data.last_page
  196. }
  197. } else {
  198. this.showToast('系统繁忙,稍候再试')
  199. }
  200. this.exhibitorListLoading = false
  201. })
  202. },
  203. getExhibitList() { // 展品
  204. this.exhibitListLoading = true
  205. exhibitorsProductList(this.exhibitListParams).then(res => {
  206. if (res.data.data) {
  207. if (this.exhibitListParams.page > 1) {
  208. this.exhibitList = [...this.exhibitList, ...res.data.data]
  209. } else {
  210. this.exhibitList = res.data.data
  211. this.exhibitListLastPage = res.data.last_page
  212. }
  213. } else {
  214. this.showToast('系统繁忙,稍候再试')
  215. }
  216. this.exhibitListLoading = false
  217. })
  218. },
  219. getExhibitorsNewsList() { // 展商新闻
  220. this.newsListLoading = true
  221. exhibitorsNewsList(this.newsListParams).then(res => {
  222. if (res.data.data) {
  223. if (this.newsListParams.page > 1) {
  224. this.newsList = [...this.newsList, ...res.data.data]
  225. } else {
  226. this.newsList = res.data.data
  227. this.newsListLastPage = res.data.last_page
  228. }
  229. } else {
  230. this.showToast('系统繁忙,稍候再试')
  231. }
  232. this.newsListLoading = false
  233. })
  234. },
  235. getActivityList() { // 展台活动
  236. this.activityListLoading = true
  237. exhibitorsBoothActivityList(this.activityListParams).then(res => {
  238. if (res.data.data) {
  239. if (this.activityListParams.page > 1) {
  240. this.activityList = [...this.activityList, ...res.data.data]
  241. } else {
  242. this.activityList = res.data.data
  243. this.activityListLastPage = res.data.last_page
  244. }
  245. } else {
  246. this.showToast('系统繁忙,稍候再试')
  247. }
  248. this.activityListLoading = false
  249. })
  250. },
  251. getMettingList() { // 同期活动
  252. this.mettingListLoading = true
  253. mettingList(this.mettingListParams).then(res => {
  254. if (res.data.data) {
  255. if (this.mettingListParams.page > 1) {
  256. this.mettingList = [...this.mettingList, ...res.data.data]
  257. } else {
  258. this.mettingList = res.data.data
  259. this.mettingListLastPage = res.data.last_page
  260. }
  261. if (this.mettingListParams.page === 1 && this.mettingList.length === 0) {
  262. this.tabs = this.tabs.filter(item => item.value !== 5);
  263. }
  264. } else {
  265. this.showToast('系统繁忙,稍候再试')
  266. }
  267. this.mettingListLoading = false
  268. })
  269. },
  270. onScrollToLower(e) {
  271. if (this.tabActive === 1) {
  272. if (this.exhibitorListLastPage === this.exhibitorListParams.page) return
  273. if (this.exhibitorListLoading === true) return
  274. this.exhibitorListLoading = true
  275. this.exhibitorListParams.page = this.exhibitorListParams.page+1
  276. this.getExhibitorsList()
  277. } else if (this.tabActive === 2) {
  278. if (this.exhibitListLastPage === this.exhibitListParams.page) return
  279. if (this.exhibitListLoading === true) return
  280. this.exhibitListLoading = true
  281. this.exhibitListParams.page = this.exhibitListParams.page+1
  282. this.getExhibitList()
  283. } else if (this.tabActive === 3) {
  284. if (this.newsListLastPage === this.newsListParams.page) return
  285. if (this.newsListLoading === true) return
  286. this.newsListLoading = true
  287. this.newsListParams.page = this.newsListParams.page+1
  288. this.getExhibitorsNewsList()
  289. } else if (this.tabActive === 4) {
  290. if (this.activityListLastPage === this.activityListParams.page) return
  291. if (this.activityListLoading === true) return
  292. this.activityListLoading = true
  293. this.activityListParams.page = this.activityListParams.page+1
  294. this.getActivityList()
  295. } else if (this.tabActive === 5) {
  296. if (this.mettingListLastPage === this.mettingListParams.page) return
  297. if (this.mettingListLoading === true) return
  298. this.mettingListLoading = true
  299. this.mettingListParams.page = this.mettingListParams.page+1
  300. this.getMettingList()
  301. }
  302. },
  303. updateItemValue(e) {
  304. if (this.tabActive === 1) {
  305. this.exhibitorList.forEach((item) => {
  306. if (item.id === e.id) {
  307. item[e.key] = e.value
  308. }
  309. })
  310. } else if (this.tabActive === 2) {
  311. this.exhibitList.forEach((item) => {
  312. if (item.id === e.id) {
  313. item[e.key] = e.value
  314. }
  315. })
  316. } else if (this.tabActive === 4) {
  317. this.activityList.forEach((item) => {
  318. if (item.id === e.id) {
  319. item[e.key] = e.value
  320. }
  321. })
  322. } else if (this.tabActive === 5) {
  323. this.mettingList.forEach((item) => {
  324. if (item.id === e.id) {
  325. item[e.key] = e.value
  326. }
  327. })
  328. }
  329. }
  330. }
  331. }
  332. </script>
  333. <style lang="scss">
  334. .search-result-text{
  335. margin: 33rpx 0;
  336. display: block;
  337. font-size: $fontSize3;
  338. color: #000000;
  339. }
  340. .search-result-list{
  341. display: grid;
  342. grid-template-columns: 1fr;
  343. grid-row-gap: 28rpx;
  344. margin-top: 32rpx;
  345. }
  346. </style>