community.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框区域 -->
  4. <view class="content">
  5. <uv-row custom-style="margin: 10px 0px" gutter="10">
  6. <picker @change="bindPickerChange" range-key="name" :value="placeIndex" :range="placeList">
  7. <view class="address">
  8. <view class="address_text">{{ placeList[placeIndex].name }}</view>
  9. <img src="../../static/index/bottom.png" />
  10. </view>
  11. </picker>
  12. <view class="search">
  13. <view class="add">
  14. <image class="img" src="../../static/index/search.png" mode="aspectFit"></image>
  15. </view>
  16. <input class="inp" type="text" v-model="keywords" placeholder="请输入关键字搜索" />
  17. <view class="btnSearch" @click="searchHandler">搜索</view>
  18. </view>
  19. </uv-row>
  20. </view>
  21. <!-- 分段器区域 -->
  22. <view class="control">
  23. <uni-segmented-control :current="current" :values="items" style-type="text" active-color="#096562" @clickItem="onClickItem" />
  24. </view>
  25. <!-- 数据列表区域 -->
  26. <scroll-view v-if="list.length" class="body" scroll-y @scrolltolower="handleTolower">
  27. <uv-waterfall ref="waterfall" v-model="list" :add-time="80" :left-gap="0" :right-gap="0" :column-gap="8" @changeList="changeList">
  28. <!-- 第一列数据 -->
  29. <template v-slot:list1>
  30. <!-- 为了磨平部分平台的BUG,必须套一层view -->
  31. <view>
  32. <view v-for="(item, index) in list1" :key="item.id" class="waterfall_item" @click="goPageDetail(item)">
  33. <img v-if="item.image" mode="aspectFill" class="item_cover" :src="item.image[0]" />
  34. <video v-if="item.video" class="item_cover" :src="item.video" :show-center-play-btn="false" :show-fullscreen-btn="false" :show-play-btn="false"></video>
  35. <view class="item_town" v-if="item.townName">{{ item.townName }}</view>
  36. <img v-if="item.video" class="item_play" src="../../static/index/video.png" />
  37. <view class="item_desc">{{ item.title }}</view>
  38. <view class="item_info">
  39. <img mode="aspectFill" :src="item.userPhoto" />
  40. <view class="text">{{ item.userName }}</view>
  41. <img
  42. class="img"
  43. :src="item.isCollect === 1 ? '../../static/index/like-active.png' : '../../static/index/like.png'"
  44. @click.stop="handleClickLike(item)"
  45. />
  46. <view class="count">{{ item.collectNum }}</view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <!-- 第二列数据 -->
  52. <template v-slot:list2>
  53. <!-- 为了磨平部分平台的BUG,必须套一层view -->
  54. <view>
  55. <view v-for="(item, index) in list2" :key="item.id" class="waterfall_item" @click="goPageDetail(item)">
  56. <img v-if="item.image" mode="aspectFill" class="item_cover" :src="item.image[0]" />
  57. <video v-if="item.video" class="item_cover" :src="item.video" :show-center-play-btn="false" :show-fullscreen-btn="false" :show-play-btn="false"></video>
  58. <view class="item_town" v-if="item.townName">{{ item.townName }}</view>
  59. <img v-if="item.video" class="item_play" src="../../static/index/video.png" />
  60. <view class="item_desc">{{ item.title }}</view>
  61. <view class="item_info">
  62. <img mode="aspectFill" :src="item.userPhoto" />
  63. <view class="text">{{ item.userName }}</view>
  64. <img
  65. class="img"
  66. :src="item.isCollect === 1 ? '../../static/index/like-active.png' : '../../static/index/like.png'"
  67. @click.stop="handleClickLike(item)"
  68. />
  69. <view class="count">{{ item.collectNum }}</view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. </uv-waterfall>
  75. </scroll-view>
  76. <!-- 没有数据时展示的区域 -->
  77. <view class="noData" v-if="!list.length">
  78. <img src="../../static/images/noData.png" />
  79. 暂无数据
  80. </view>
  81. <!-- 悬浮按钮区域 -->
  82. <uni-fab :pattern="pattern" horizontal="right" @fabClick="handleClickBtn"></uni-fab>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. // 悬浮按钮样式
  90. pattern: {
  91. buttonColor: '#096562'
  92. },
  93. keywords: '',
  94. // 当前选择地区索引
  95. placeIndex: 0,
  96. // 当前选择地区的id
  97. placeId: '',
  98. // 地区数组
  99. placeList: [
  100. {
  101. name: '靖安县'
  102. }
  103. ],
  104. // 分段器数组
  105. items: ['发现', '关注', '收藏'],
  106. // 当前索引
  107. current: 0,
  108. // 当前页
  109. page: 1,
  110. // 每页多少条
  111. rows: 6,
  112. // 总条数
  113. total: null,
  114. // 瀑布流全部数据
  115. list: [],
  116. // 瀑布流第一列数据
  117. list1: [],
  118. // 瀑布流第二列数据
  119. list2: []
  120. }
  121. },
  122. onShow() {
  123. let userInfo = uni.getStorageSync('userInfo')
  124. let tokenId = uni.getStorageSync('tokenId')
  125. if (!userInfo || !tokenId) {
  126. uni.showModal({
  127. title: '提示',
  128. content: '您当前未登录,请授权登录查看社区信息',
  129. showCancel: false,
  130. success: (res) => {
  131. if (res.confirm) {
  132. uni.navigateTo({
  133. url: '/pages/login/login'
  134. })
  135. }
  136. }
  137. })
  138. } else {
  139. this.placeList = [
  140. {
  141. name: '靖安县'
  142. }
  143. ]
  144. this.list = []
  145. this.list1 = []
  146. this.list2 = []
  147. this.page = 1
  148. this.getTownList()
  149. this.getHotelList()
  150. }
  151. },
  152. methods: {
  153. // 获取乡镇列表数组
  154. async getTownList() {
  155. const res = await this.$myRequest({
  156. url: '/mhotel/articletownShips.action'
  157. })
  158. // console.log(res)
  159. if (res.code === 200) {
  160. this.placeList = [...this.placeList, ...res.data]
  161. }
  162. },
  163. // 获取推文列表数组
  164. async getHotelList() {
  165. const res = await this.$myRequest({
  166. url: '/mhotel/articlequeryArticlePage.action',
  167. data: {
  168. page: this.page,
  169. rows: this.rows,
  170. townId: this.placeId,
  171. type: this.current,
  172. keyWord: this.keywords,
  173. userId: uni.getStorageSync('userInfo').id
  174. }
  175. })
  176. // console.log(res)
  177. if (res.code === 200) {
  178. this.list = [...this.list, ...res.data.pageList]
  179. this.total = res.data.total
  180. }
  181. },
  182. changeList(e) {
  183. if (e.name === 'list1') {
  184. this.list1.push(e.value)
  185. } else {
  186. this.list2.push(e.value)
  187. }
  188. },
  189. // 点击爱心回调
  190. async handleClickLike(item) {
  191. const res = await this.$myRequest({
  192. url: '/mhotel/articlecollectArticle.action',
  193. data: {
  194. id: item.id,
  195. userId: uni.getStorageSync('userInfo').id
  196. }
  197. })
  198. // console.log(res)
  199. if (res.code === 200) {
  200. item.isCollect === 1 ? ((item.isCollect = 0), (item.collectNum -= 1)) : ((item.isCollect = 1), (item.collectNum += 1))
  201. }
  202. },
  203. // 点击悬浮按钮回调
  204. handleClickBtn() {
  205. uni.navigateTo({
  206. url: '/pagesSub/send/send'
  207. })
  208. },
  209. // 搜索按钮点击回调
  210. searchHandler() {
  211. this.list = []
  212. this.$refs.waterfall.clear()
  213. this.list1 = []
  214. this.list2 = []
  215. this.page = 1
  216. this.getHotelList()
  217. },
  218. // 选择地区时的回调
  219. bindPickerChange(e) {
  220. this.placeIndex = e.detail.value
  221. this.placeId = this.placeList[this.placeIndex].id || ''
  222. this.searchHandler()
  223. },
  224. // 分段器切换回调
  225. onClickItem(e) {
  226. this.current = e.currentIndex
  227. this.searchHandler()
  228. },
  229. // 页面触底回调
  230. handleTolower() {
  231. if (this.total > this.list.length) {
  232. this.page++
  233. this.getHotelList()
  234. } else {
  235. uni.showToast({
  236. title: '没有更多数据了',
  237. icon: 'none',
  238. maks: true
  239. })
  240. }
  241. },
  242. // 点击每一个推文回调
  243. goPageDetail(item) {
  244. uni.navigateTo({
  245. url: `/pagesSub/tweetDetail/tweetDetail?id=${item.id}&townId=${item.townId}`
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="scss" scoped>
  252. .container {
  253. display: flex;
  254. flex-direction: column;
  255. align-items: center;
  256. height: 100vh;
  257. overflow: hidden;
  258. background-color: #f7f7f7;
  259. .content {
  260. background-color: #f7f7f7;
  261. .address {
  262. display: flex;
  263. width: 152rpx;
  264. font-size: 28rpx;
  265. .address_text {
  266. width: 104rpx;
  267. text-align: center;
  268. overflow: hidden;
  269. white-space: nowrap;
  270. text-overflow: ellipsis;
  271. }
  272. img {
  273. width: 48rpx;
  274. height: 48rpx;
  275. }
  276. }
  277. .search {
  278. display: flex;
  279. justify-content: space-between;
  280. align-items: center;
  281. width: 538rpx;
  282. height: 80rpx;
  283. opacity: 1;
  284. border-radius: 70px;
  285. background-color: #fff;
  286. .add {
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. margin-left: 10rpx;
  291. width: 60rpx;
  292. font-size: 50rpx;
  293. height: 60rpx;
  294. line-height: 60rpx;
  295. color: rgba(30, 125, 251, 1);
  296. .img {
  297. width: 30rpx;
  298. height: 30rpx;
  299. }
  300. }
  301. .inp {
  302. height: 60rpx;
  303. line-height: 60rpx;
  304. flex-grow: 1;
  305. font-size: 28rpx;
  306. }
  307. .btnSearch {
  308. width: 100rpx;
  309. text-align: center;
  310. margin-right: 10rpx;
  311. height: 60rpx;
  312. line-height: 60rpx;
  313. opacity: 1;
  314. font-size: 28rpx;
  315. font-weight: 400;
  316. height: 2rem;
  317. color: #096562;
  318. }
  319. }
  320. }
  321. .control {
  322. margin: 0 auto 20rpx;
  323. padding-bottom: 10rpx;
  324. width: 690rpx;
  325. height: 90rpx;
  326. border-radius: 8rpx;
  327. background-color: #fff;
  328. }
  329. .body {
  330. margin: auto;
  331. width: 690rpx;
  332. height: calc(100vh - 220rpx);
  333. .waterfall_item {
  334. position: relative;
  335. overflow: hidden;
  336. margin-bottom: 20rpx;
  337. width: 335rpx;
  338. border-radius: 10rpx;
  339. background-color: #fff;
  340. .item_cover {
  341. width: 335rpx;
  342. height: 463rpx;
  343. border: 10rpx 10rpx 0 0;
  344. }
  345. .item_town {
  346. position: absolute;
  347. top: 404rpx;
  348. left: 22rpx;
  349. padding: 0 20rpx;
  350. line-height: 43rpx;
  351. text-align: center;
  352. font-size: 20rpx;
  353. color: #fff;
  354. border-radius: 42rpx;
  355. background-color: rgba(0, 0, 0, 0.5);
  356. }
  357. .item_play {
  358. position: absolute;
  359. top: 20rpx;
  360. right: 20rpx;
  361. width: 50rpx;
  362. height: 50rpx;
  363. }
  364. .item_desc {
  365. padding: 0 22rpx;
  366. font-size: 28rpx;
  367. font-weight: bold;
  368. }
  369. .item_info {
  370. padding: 15rpx 22rpx;
  371. display: flex;
  372. // align-items: center;
  373. color: #666666;
  374. font-size: 20rpx;
  375. img {
  376. width: 30rpx;
  377. height: 30rpx;
  378. border-radius: 50%;
  379. }
  380. .text {
  381. margin-left: 12rpx;
  382. width: 150rpx;
  383. overflow: hidden;
  384. text-overflow: ellipsis;
  385. white-space: nowrap;
  386. }
  387. .img {
  388. margin-left: auto;
  389. }
  390. .count {
  391. margin-left: 5rpx;
  392. }
  393. }
  394. }
  395. }
  396. .noData {
  397. display: flex;
  398. flex-direction: column;
  399. justify-content: center;
  400. align-items: center;
  401. padding-bottom: 65rpx;
  402. img {
  403. margin-top: 80rpx;
  404. width: 600rpx;
  405. height: 600rpx;
  406. }
  407. }
  408. }
  409. </style>