newsSquare.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view class="content">
  3. <view class="addNewsBtn" @click="toPublishPage()">
  4. <view class="addIcon">
  5. +
  6. </view>
  7. <view class="addText">
  8. 帮忙
  9. </view>
  10. </view>
  11. <view class="searchModal" v-show="searchModal">
  12. <div class="textTips">
  13. <text>搜索历史</text>
  14. <image src="../../static/image/del.png" class="del" @click="clearHistory()"></image>
  15. </div>
  16. <div class="serachBox">
  17. <div class="serachItem" @click="searchKey(item)" v-for="(item,index) in historySearch" :key="index">
  18. {{ item }}
  19. </div>
  20. </div>
  21. </view>
  22. <z-paging ref="paging" refresher-only @onRefresh="onRefresh" :refresher-status.sync="refresherStatus"
  23. @scrolltolower="scrolltolower" :auto-hide-loading-after-first-loaded="false" :loading-full-fixed="true"
  24. :auto-clean-list-when-reload="false">
  25. <view slot="loading">
  26. </view>
  27. <!-- 自定义下拉刷新view -->
  28. <!-- <custom-refresher slot="refresher" :status="refresherStatus"></custom-refresher> -->
  29. <view class="header">
  30. <uni-easyinput class="input" prefixIcon="search" placeholder="请输入关键字查询" @focus="inputFocus()"
  31. @confirm="inputConfirm()" v-model="keyword" :clearable="false"></uni-easyinput>
  32. <view class="myNews" @click="toMyNews">我的求助</view>
  33. <view class="closeModalBox" @click="closeSearchModal" v-show="searchModal">
  34. 取消
  35. </view>
  36. </view>
  37. <view>
  38. <view style="z-index: 100;position: sticky;top :44px;">
  39. <tabs-view @change="tabsChange" :current="current" :items="tabList"></tabs-view>
  40. </view>
  41. <swiper class="swiper" :style="[{ height: swiperHeight + 'px' }]" :current="current"
  42. @animationfinish="animationfinish">
  43. <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
  44. <news-list ref="swiperList" :tabIndex="index" :currentIndex="current" :title="title"
  45. @heightChanged="heightChanged"></news-list>
  46. </swiper-item>
  47. </swiper>
  48. </view>
  49. </z-paging>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. refresherStatus: 0,
  57. swiperHeight: 0,
  58. tabList: ['发布', '热线', '嗨享'],
  59. current: 0, // tabs组件的current值,表示当前活动的tab选项
  60. searchModal: false,
  61. historySearch: [],
  62. title: '',
  63. keyword: ''
  64. };
  65. },
  66. methods: {
  67. toPublishPage() {
  68. uni.navigateTo({
  69. url: '../publishNews/publishNews'
  70. })
  71. },
  72. toMyNews() {
  73. uni.navigateTo({
  74. url: '/pages/myNews/myNews'
  75. })
  76. },
  77. clearHistory() {
  78. uni.removeStorageSync('historySearch');
  79. this.historySearch = []
  80. },
  81. inputConfirm(e) {
  82. this.title = e
  83. let historyArr = JSON.parse(JSON.stringify(this.historySearch))
  84. if (historyArr.length >= 8) {
  85. historyArr.pop(1)
  86. }
  87. historyArr.unshift(e)
  88. historyArr = [...new Set(historyArr)]
  89. this.historySearch = historyArr
  90. this.$nextTick(() => {
  91. this.onRefresh()
  92. })
  93. uni.setStorageSync('historySearch', JSON.stringify(this.historySearch));
  94. this.closeSearchModal()
  95. },
  96. searchKey(e) {
  97. this.title = e
  98. this.keyword = e
  99. this.$nextTick(() => {
  100. this.onRefresh()
  101. })
  102. this.closeSearchModal()
  103. },
  104. inputFocus() {
  105. try {
  106. let searchStr = uni.getStorageSync('historySearch')
  107. this.historySearch = searchStr ? JSON.parse(searchStr) : []
  108. } catch (e) {
  109. this.historySearch = []
  110. }
  111. this.searchModal = true
  112. },
  113. closeSearchModal() {
  114. this.searchModal = false
  115. },
  116. //tabs通知swiper切换
  117. tabsChange(index) {
  118. this._setCurrent(index);
  119. },
  120. //下拉刷新时,通知当前显示的列表进行reload操作
  121. onRefresh() {
  122. this.$refs.swiperList[this.current].reload(() => {
  123. this.$refs.paging.complete([]);
  124. });
  125. },
  126. //当滚动到底部时,通知当前显示的列表加载更多
  127. scrolltolower() {
  128. this.$refs.swiperList[this.current].doLoadMore();
  129. },
  130. // swiper滑动结束
  131. animationfinish(e) {
  132. let current = e.detail.current;
  133. this._setCurrent(current);
  134. },
  135. //设置swiper的高度
  136. heightChanged(height) {
  137. if (height === 0) {
  138. //默认swiper高度为屏幕可用高度-tabsView高度-slot="top"内view的高度
  139. height = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
  140. }
  141. this.swiperHeight = height;
  142. },
  143. _setCurrent(current) {
  144. if (current !== this.current) {
  145. //切换tab时,将上一个tab的数据清空
  146. this.$refs.swiperList[this.current].clear();
  147. }
  148. this.current = current;
  149. }
  150. }
  151. };
  152. </script>
  153. <style scoped lang="scss">
  154. .loadingBox {
  155. width: 100%;
  156. height: 100%;
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. background-color: red;
  161. }
  162. .addNewsBtn {
  163. position: fixed;
  164. width: 56px;
  165. height: 56px;
  166. right: 15px;
  167. border-radius: 50%;
  168. background-color: #3466EB;
  169. color: #FFFFFF;
  170. display: flex;
  171. flex-direction: column;
  172. align-items: center;
  173. bottom: 150px;
  174. // background-image: url('../../static/image/addNews.png');
  175. // background-position: center;
  176. // background-repeat: no-repeat;
  177. // background-size: 120%;
  178. z-index: 150;
  179. .addIcon {
  180. font-size: 30px;
  181. line-height: 30px;
  182. }
  183. .addText {
  184. font-size: 12px;
  185. }
  186. }
  187. .searchModal {
  188. position: absolute;
  189. top: 44px;
  190. right: 0;
  191. bottom: 0;
  192. left: 0;
  193. z-index: 200;
  194. background-color: #fff;
  195. box-sizing: border-box;
  196. padding: 0 15px;
  197. .textTips {
  198. display: flex;
  199. align-items: center;
  200. justify-content: space-between;
  201. margin-top: 15px;
  202. .del {
  203. width: 32rpx;
  204. height: 32rpx;
  205. }
  206. }
  207. .serachBox {
  208. display: flex;
  209. flex-wrap: wrap;
  210. .serachItem {
  211. margin-top: 20px;
  212. padding: 8rpx 16rpx;
  213. max-width: 100%;
  214. overflow: hidden;
  215. text-overflow: ellipsis;
  216. }
  217. }
  218. }
  219. .header {
  220. width: 100%;
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. box-sizing: border-box;
  225. padding: 0 15px;
  226. height: 44px;
  227. position: sticky;
  228. z-index: 100;
  229. background-color: #FFFFFF;
  230. top: 0;
  231. .myNews {}
  232. .closeModalBox {
  233. position: absolute;
  234. right: 15px;
  235. width: 150rpx;
  236. background-color: #fff;
  237. height: 44px;
  238. line-height: 44px;
  239. text-align: right;
  240. }
  241. .input {
  242. width: 526rpx;
  243. }
  244. }
  245. .banner-view {
  246. background-color: #007aff;
  247. color: white;
  248. display: flex;
  249. flex-direction: column;
  250. align-items: center;
  251. justify-content: center;
  252. }
  253. .paging-content {
  254. flex: 1;
  255. display: flex;
  256. flex-direction: column;
  257. }
  258. .swiper {
  259. height: 1000px;
  260. }
  261. </style>