newsSquare.vue 6.3 KB

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