newsSquare.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. isLogin: false
  65. };
  66. },
  67. onShow() {
  68. let user = null;
  69. try {
  70. user = JSON.parse(uni.getStorageSync('userInfo'));
  71. } catch (e) {
  72. //TODO handle the exception
  73. }
  74. if (!user) return
  75. this.isLogin = true
  76. },
  77. methods: {
  78. toPublishPage() {
  79. if (!this.isLogin) {
  80. uni.navigateTo({
  81. url: '/pages/Login/Login?choose=1'
  82. });
  83. return
  84. }
  85. uni.navigateTo({
  86. url: '../publishNews/publishNews'
  87. })
  88. },
  89. toMyNews() {
  90. uni.navigateTo({
  91. url: '/pages/myNews/myNews'
  92. })
  93. },
  94. clearHistory() {
  95. uni.removeStorageSync('historySearch');
  96. this.historySearch = []
  97. },
  98. inputConfirm(e) {
  99. this.title = e
  100. let historyArr = JSON.parse(JSON.stringify(this.historySearch))
  101. if (historyArr.length >= 8) {
  102. historyArr.pop(1)
  103. }
  104. historyArr.unshift(e)
  105. historyArr = [...new Set(historyArr)]
  106. this.historySearch = historyArr
  107. this.$nextTick(() => {
  108. this.onRefresh()
  109. })
  110. uni.setStorageSync('historySearch', JSON.stringify(this.historySearch));
  111. this.closeSearchModal()
  112. },
  113. searchKey(e) {
  114. this.title = e
  115. this.keyword = e
  116. this.$nextTick(() => {
  117. this.onRefresh()
  118. })
  119. this.closeSearchModal()
  120. },
  121. inputFocus() {
  122. try {
  123. let searchStr = uni.getStorageSync('historySearch')
  124. this.historySearch = searchStr ? JSON.parse(searchStr) : []
  125. } catch (e) {
  126. this.historySearch = []
  127. }
  128. this.searchModal = true
  129. },
  130. closeSearchModal() {
  131. this.searchModal = false
  132. },
  133. //tabs通知swiper切换
  134. tabsChange(index) {
  135. this._setCurrent(index);
  136. },
  137. //下拉刷新时,通知当前显示的列表进行reload操作
  138. onRefresh() {
  139. this.$refs.swiperList[this.current].reload(() => {
  140. this.$refs.paging.complete([]);
  141. });
  142. },
  143. //当滚动到底部时,通知当前显示的列表加载更多
  144. scrolltolower() {
  145. this.$refs.swiperList[this.current].doLoadMore();
  146. },
  147. // swiper滑动结束
  148. animationfinish(e) {
  149. let current = e.detail.current;
  150. this._setCurrent(current);
  151. },
  152. //设置swiper的高度
  153. heightChanged(height) {
  154. if (height === 0) {
  155. //默认swiper高度为屏幕可用高度-tabsView高度-slot="top"内view的高度
  156. height = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
  157. }
  158. this.swiperHeight = height;
  159. },
  160. _setCurrent(current) {
  161. if (current !== this.current) {
  162. //切换tab时,将上一个tab的数据清空
  163. this.$refs.swiperList[this.current].clear();
  164. }
  165. this.current = current;
  166. }
  167. }
  168. };
  169. </script>
  170. <style scoped lang="scss">
  171. .loadingBox {
  172. width: 100%;
  173. height: 100%;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. background-color: red;
  178. }
  179. .addNewsBtn {
  180. position: fixed;
  181. width: 56px;
  182. height: 56px;
  183. right: 15px;
  184. border-radius: 50%;
  185. background-color: #3466EB;
  186. color: #FFFFFF;
  187. display: flex;
  188. flex-direction: column;
  189. align-items: center;
  190. bottom: 150px;
  191. // background-image: url('../../static/image/addNews.png');
  192. // background-position: center;
  193. // background-repeat: no-repeat;
  194. // background-size: 120%;
  195. z-index: 150;
  196. .addIcon {
  197. font-size: 30px;
  198. line-height: 30px;
  199. }
  200. .addText {
  201. font-size: 12px;
  202. }
  203. }
  204. .searchModal {
  205. position: absolute;
  206. top: 44px;
  207. right: 0;
  208. bottom: 0;
  209. left: 0;
  210. z-index: 200;
  211. background-color: #fff;
  212. box-sizing: border-box;
  213. padding: 0 15px;
  214. .textTips {
  215. display: flex;
  216. align-items: center;
  217. justify-content: space-between;
  218. margin-top: 15px;
  219. .del {
  220. width: 32rpx;
  221. height: 32rpx;
  222. }
  223. }
  224. .serachBox {
  225. display: flex;
  226. flex-wrap: wrap;
  227. .serachItem {
  228. margin-top: 20px;
  229. padding: 8rpx 16rpx;
  230. max-width: 100%;
  231. overflow: hidden;
  232. text-overflow: ellipsis;
  233. }
  234. }
  235. }
  236. .header {
  237. width: 100%;
  238. display: flex;
  239. justify-content: space-between;
  240. align-items: center;
  241. box-sizing: border-box;
  242. padding: 0 15px;
  243. height: 44px;
  244. position: sticky;
  245. z-index: 100;
  246. background-color: #FFFFFF;
  247. top: 0;
  248. .myNews {}
  249. .closeModalBox {
  250. position: absolute;
  251. right: 15px;
  252. width: 150rpx;
  253. background-color: #fff;
  254. height: 44px;
  255. line-height: 44px;
  256. text-align: right;
  257. }
  258. .input {
  259. width: 526rpx;
  260. }
  261. }
  262. .banner-view {
  263. background-color: #007aff;
  264. color: white;
  265. display: flex;
  266. flex-direction: column;
  267. align-items: center;
  268. justify-content: center;
  269. }
  270. .paging-content {
  271. flex: 1;
  272. display: flex;
  273. flex-direction: column;
  274. }
  275. .swiper {
  276. height: 1000px;
  277. }
  278. </style>