search.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view>
  3. <!-- 头部背景和搜索 -->
  4. <view>
  5. <image :src="appConfig.mobile_top_bg" class="top-image" id="top-image" mode="widthFix" @load="topImageLoad">
  6. </image>
  7. </view>
  8. <!-- 搜索 -->
  9. <router-link to="/pages/search/search" style="position: absolute; width: 100%; padding: 0 98rpx;height: 70rpx;"
  10. :style="{top: searchTop + 'rpx'}">
  11. <u-search wrap-bg-color="transparent" bg-color="#ffffff" :disabled="false" :height="62" shape="square"
  12. :show-action="false"></u-search>
  13. </router-link>
  14. <!-- 筛选 -->
  15. <view class="flex row-right bg-white p-l-30 p-r-30 p-b-20 p-t-20" @click="show = true">
  16. <u-icon name="list-dot" size="28"></u-icon>
  17. <view class="m-l-10">筛选</view>
  18. </view>
  19. <!-- 筛选弹出 -->
  20. <u-popup v-model="show" mode="right" width="80%" :closeable="true">
  21. <view class="p-20">
  22. <view v-for="(item, index) in categoryList">
  23. <view>{{ item.description }}</view>
  24. <!-- 标签 -->
  25. <view class="flex flex-wrap">
  26. <view class="tag-item" :class="{ 'tat-active': item.activeIndex == null }"
  27. @tap="changeTag(null, index)">
  28. 全部
  29. </view>
  30. <view class="tag-item" :class="{ 'tat-active': item.activeIndex == tagIndex }"
  31. v-for="(tag, tagIndex) in item.data" :key="tagIndex" @tap="changeTag(tagIndex, index)">
  32. {{ tag.name }}
  33. </view>
  34. </view>
  35. </view>
  36. <view class="confrim-btn flex w-full row-center">
  37. <button class="btn reset lg" @click="resetForm">重置</button>
  38. <button class="white btn lg" @click="refresh">确定</button>
  39. </view>
  40. </view>
  41. </u-popup>
  42. <!-- 政策列表 -->
  43. <view id="main">
  44. <mescroll-uni ref="mescrollRef" :top="top" @init="mescrollInit" @down="downCallback" @up="upCallback"
  45. :down="downOption" :up="upOption" style="left: 100px;">
  46. <view class="p-24">
  47. <view class="item" v-for="(item, index) in policyList" :key="index" @tap="goDetail(item)">
  48. <view class="font-size-28">{{item.title}}</view>
  49. <!-- <view class="flex m-t-20">
  50. <view class="flex-1">阅读次数: 1072次</view>
  51. <view class="flex-1">状态: 有效</view>
  52. </view>
  53. <view class="flex m-t-10">
  54. <view class="flex-1">支持方式: 其他</view>
  55. <view class="flex-1">支持产业: 所有产业</view>
  56. </view>
  57. <view class="flex m-t-10">
  58. <view class="flex-1">发文单位: 科技部火炬中心</view>
  59. </view> -->
  60. <view class="u-border-bottom m-t-20"></view>
  61. <view class="flex row-between p-t-20">
  62. <view class="flex primary">
  63. <u-icon name="star-fill" size="28"></u-icon>
  64. <view class="m-l-10">{{item.author}}</view>
  65. </view>
  66. <view>{{timeFormat(item.created_at)}}</view>
  67. </view>
  68. </view>
  69. </view>
  70. <loading-view v-if="showLoading" background-color="transparent" :size="50"></loading-view>
  71. </mescroll-uni>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  77. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  78. import {
  79. mapGetters,
  80. mapActions
  81. } from 'vuex'
  82. import {
  83. policyCategory,
  84. policyList
  85. } from '@/api/app'
  86. import {
  87. pxToRpx
  88. } from '@/utils/tools'
  89. import {
  90. timeFormat
  91. } from '@/utils/date'
  92. const app = getApp()
  93. const homeItem = {
  94. name: '首页'
  95. }
  96. export default {
  97. mixins: [MescrollMixin, MescrollMoreItemMixin],
  98. data() {
  99. return {
  100. statusBarHeight: 0,
  101. keyword: '',
  102. top: 0,
  103. searchTop: 0,
  104. show: false,
  105. activeIndex: 0,
  106. categoryList: [],
  107. policyList: [],
  108. downOption: {
  109. // use: false,
  110. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  111. },
  112. upOption: {
  113. auto: true, // 不自动加载
  114. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  115. empty: {
  116. icon: '/static/images/order_null.png',
  117. tip: '暂无数据~', // 提示
  118. fixed: true,
  119. top: '100rpx'
  120. }
  121. },
  122. showLoading: false
  123. }
  124. },
  125. created() {
  126. uni.getSystemInfo({
  127. success: (res) => {
  128. this.statusBarHeight = res.statusBarHeight;
  129. }
  130. });
  131. },
  132. updated: function() {
  133. this.$nextTick(() => {
  134. // 仅在整个视图都被重新渲染之后才会运行的代码
  135. setTimeout(() => {
  136. uni.createSelectorQuery().in(this).select('#main')
  137. .boundingClientRect(data => {
  138. console.log("得到布局位置信息" + JSON.stringify(data));
  139. this.top = pxToRpx(data.top)
  140. }).exec();
  141. }, 30)
  142. });
  143. },
  144. onLoad() {
  145. this.getCategoryFun()
  146. },
  147. onHide() {},
  148. onPullDownRefresh() {},
  149. methods: {
  150. refresh() {
  151. this.show = false
  152. this.mescroll.resetUpScroll()
  153. },
  154. //筛选条件
  155. async getCategoryFun() {
  156. const {
  157. status,
  158. data
  159. } = await policyCategory({});
  160. if (status == 1) {
  161. this.categoryList = data
  162. console.log(this.categoryList)
  163. }
  164. },
  165. changeTag(tagIndex, index) {
  166. this.categoryList[index].activeIndex = tagIndex
  167. this.$forceUpdate();
  168. },
  169. resetForm() {
  170. this.categoryList = this.categoryList.map((item, index) => {
  171. item.activeIndex = null
  172. return item
  173. })
  174. },
  175. topImageLoad(e) {
  176. setTimeout(() => {
  177. uni.createSelectorQuery().in(this).select('#top-image').boundingClientRect(data => {
  178. console.log("得到布局位置信息" + JSON.stringify(data));
  179. this.searchTop = pxToRpx(data.height) - 100
  180. }).exec();
  181. }, 30)
  182. },
  183. searchTalents() {
  184. let {
  185. keyword
  186. } = this;
  187. if (!keyword) {
  188. this.$toast({
  189. title: '请输入关键字'
  190. })
  191. return;
  192. }
  193. uni.navigateTo({
  194. url: '/pages/talents/talents?keyword=' + this.keyword
  195. })
  196. },
  197. upCallback(page) {
  198. let pageNum = page.num; // 页码, 默认从1开始
  199. let pageSize = page.size; // 页长, 默认每页10条
  200. let params = {
  201. page_size: pageSize,
  202. page_no: pageNum
  203. }
  204. this.categoryList.forEach((item, index) => {
  205. if (item.activeIndex != null) {
  206. if (item.name != 'cengci') {
  207. params[item.name] = item.data[item.activeIndex].value
  208. } else {
  209. params[item.name] = item.data[item.activeIndex].name
  210. }
  211. }
  212. })
  213. console.log(this.categoryList)
  214. policyList(params).then(({
  215. data,
  216. _meta
  217. }) => {
  218. let curPageData = data;
  219. let curPageLen = curPageData.length;
  220. let hasNext = _meta.pageCount > _meta.currentPage;
  221. if (page.num == 1) this.policyList = [];
  222. this.policyList = this.policyList.concat(curPageData);
  223. this.mescroll.endSuccess(curPageLen, hasNext);
  224. })
  225. },
  226. timeFormat(time) {
  227. return timeFormat(time)
  228. },
  229. goDetail(item) {
  230. // uni.setStorageSync('policyDetail', item);
  231. uni.navigateTo({
  232. url: '/pages/policy/detail?id=' + item.id + '&title=' + item.title,
  233. })
  234. },
  235. },
  236. computed: {
  237. ...mapGetters(['appConfig']),
  238. positionTop() {
  239. return this.top
  240. },
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. page {
  246. padding: 0;
  247. }
  248. .top-image {
  249. width: 100%;
  250. }
  251. .index-header {
  252. background-color: #E8B175;
  253. color: #fff;
  254. .header-text {
  255. min-height: 100rpx;
  256. text-align: justify;
  257. }
  258. .header-border {
  259. border-top: 1px dashed #fff;
  260. }
  261. }
  262. .item {
  263. background: #FFFFFF;
  264. box-shadow: 0px 8rpx 16rpx 2rpx rgba(0, 0, 0, 0.03);
  265. border-radius: 12rpx;
  266. opacity: 1;
  267. padding: 24rpx 34rpx;
  268. margin-bottom: 16rpx;
  269. }
  270. .tag-item {
  271. margin: 8rpx;
  272. padding: 8rpx 28rpx;
  273. background: #F7F8FA;
  274. border-radius: 8rpx 8rpx 8rpx 8rpx;
  275. opacity: 1;
  276. }
  277. .tat-active {
  278. color: #FFFFFF;
  279. background: #FEEFF5;
  280. color: #DD4250;
  281. border: 2rpx solid #DD4250;
  282. }
  283. .class-list {
  284. background-color: #fff;
  285. color: $-color-primary;
  286. .class-list-item {
  287. padding: 30rpx;
  288. .item-img {
  289. width: 50rpx;
  290. height: 50rpx;
  291. // padding: 9rpx;
  292. // background-color: #E8B175;
  293. border-radius: 8rpx;
  294. image {
  295. width: 100%;
  296. }
  297. }
  298. }
  299. }
  300. .count {
  301. border-bottom: $-solid-border;
  302. }
  303. .confrim-btn {
  304. position: fixed;
  305. bottom: 100rpx;
  306. .btn {
  307. padding: 0 80rpx;
  308. height: 84rpx;
  309. line-height: 84rpx;
  310. background-color: $-color-primary;
  311. box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(243, 113, 113, 0.39);
  312. border-radius: 18rpx 18rpx 18rpx 18rpx;
  313. }
  314. .reset {
  315. background-color: #F2F2F2;
  316. color: #858585;
  317. }
  318. }
  319. </style>