search.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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) {
  206. params[item.name] = item.data[item.activeIndex].value
  207. }
  208. })
  209. policyList(params).then(({
  210. data,
  211. _meta
  212. }) => {
  213. let curPageData = data;
  214. let curPageLen = curPageData.length;
  215. let hasNext = _meta.pageCount > _meta.currentPage;
  216. if (page.num == 1) this.policyList = [];
  217. this.policyList = this.policyList.concat(curPageData);
  218. this.mescroll.endSuccess(curPageLen, hasNext);
  219. })
  220. },
  221. timeFormat(time) {
  222. return timeFormat(time)
  223. },
  224. goDetail(item){
  225. // uni.setStorageSync('policyDetail', item);
  226. uni.navigateTo({
  227. url: '/pages/policy/detail?id=' + item.id+ '&title=' + item.title,
  228. })
  229. },
  230. },
  231. computed: {
  232. ...mapGetters(['appConfig']),
  233. positionTop() {
  234. return this.top
  235. },
  236. }
  237. }
  238. </script>
  239. <style lang="scss">
  240. page {
  241. padding: 0;
  242. }
  243. .top-image {
  244. width: 100%;
  245. }
  246. .index-header {
  247. background-color: #E8B175;
  248. color: #fff;
  249. .header-text {
  250. min-height: 100rpx;
  251. text-align: justify;
  252. }
  253. .header-border {
  254. border-top: 1px dashed #fff;
  255. }
  256. }
  257. .item {
  258. background: #FFFFFF;
  259. box-shadow: 0px 8rpx 16rpx 2rpx rgba(0, 0, 0, 0.03);
  260. border-radius: 12rpx;
  261. opacity: 1;
  262. padding: 24rpx 34rpx;
  263. margin-bottom: 16rpx;
  264. }
  265. .tag-item {
  266. margin: 8rpx;
  267. padding: 8rpx 28rpx;
  268. background: #F7F8FA;
  269. border-radius: 8rpx 8rpx 8rpx 8rpx;
  270. opacity: 1;
  271. }
  272. .tat-active {
  273. color: #FFFFFF;
  274. background: #FEEFF5;
  275. color: #DD4250;
  276. border: 2rpx solid #DD4250;
  277. }
  278. .class-list {
  279. background-color: #fff;
  280. color: $-color-primary;
  281. .class-list-item {
  282. padding: 30rpx;
  283. .item-img {
  284. width: 50rpx;
  285. height: 50rpx;
  286. // padding: 9rpx;
  287. // background-color: #E8B175;
  288. border-radius: 8rpx;
  289. image {
  290. width: 100%;
  291. }
  292. }
  293. }
  294. }
  295. .count {
  296. border-bottom: $-solid-border;
  297. }
  298. .confrim-btn {
  299. position: fixed;
  300. bottom: 100rpx;
  301. .btn {
  302. padding: 0 80rpx;
  303. height: 84rpx;
  304. line-height: 84rpx;
  305. background-color: $-color-primary;
  306. box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(243, 113, 113, 0.39);
  307. border-radius: 18rpx 18rpx 18rpx 18rpx;
  308. }
  309. .reset {
  310. background-color: #F2F2F2;
  311. color: #858585;
  312. }
  313. }
  314. </style>