matters.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <!-- pages/me.wxml -->
  3. <view class="container">
  4. <uni-search-bar :focus="true" v-model="searchValue" @input="search"
  5. style="width: 100%;"
  6. @cancel="cancel">
  7. </uni-search-bar>
  8. <!-- <view style="width: 100%;display: flex;">
  9. <uni-search-bar :focus="true" v-model="searchValue" @input="search"
  10. style="width: 70%;"
  11. @cancel="cancel">
  12. </uni-search-bar>
  13. <uni-data-select
  14. style="width: 30%;margin: auto;"
  15. v-model="value"
  16. placeholder="请选择排序"
  17. :localdata="range"
  18. @change="getList(value)"
  19. ></uni-data-select>
  20. </view> -->
  21. <view class="rnwdList">
  22. <view class="list" @tap="goDetails(item)" v-for="(item, index1) in qbwd" :key="index1">
  23. <span class="listTitle">{{ item.title }}</span>
  24. <view class="onePic">
  25. <image :src="loadImgSrc(item.picture)">
  26. </image>
  27. </view>
  28. </view>
  29. <uni-fab ref="fab" horizontal="right" style="position: fixed;bottom: 1%;right: 1%;z-index: 200;"
  30. @fabClick="fabClick()"/>
  31. </view>
  32. <!-- 新增资讯按钮 -->
  33. <!-- <button class="addInfomarionBtn" @click="addInfomation()"></button> -->
  34. </view>
  35. </template>
  36. <script>
  37. import { getMattersList } from '@/api/me/matters/matters.js'
  38. // pages/me.js
  39. export default {
  40. data() {
  41. return {
  42. qbwd:[],
  43. listParams:{
  44. pageNum: 1,
  45. pageSize: 7,
  46. title: '',
  47. isTop:0,
  48. type: 11,
  49. flag:''
  50. },
  51. topList:[],
  52. total:0,
  53. searchValue:'',
  54. favoriteList:[],
  55. value: 1,
  56. range: [
  57. { value: 'watch', text: "热度" },
  58. { value: 'like', text: "点赞" },
  59. { value: '', text: "最新" },
  60. ],
  61. };
  62. },
  63. created(){
  64. this.getList()
  65. },
  66. onReachBottom(){
  67. let pageNum = this.listParams.pageNum
  68. let pageSize = this.listParams.pageSize
  69. let total = this.total
  70. if(pageNum * pageSize >= total){
  71. uni.showToast({
  72. title:'暂无更多数据'
  73. })
  74. return
  75. } else {
  76. this.listParams.pageNum += 1;
  77. this.getList(null,'dropDown')
  78. }
  79. },
  80. methods:{
  81. currentFavoriteCount(e){
  82. if(this.favoriteList.includes(e.id)){
  83. return e.likeNum + 1
  84. } else {
  85. return e.likeNum
  86. }
  87. },
  88. addFavorite(e){
  89. if(this.favoriteList.includes(e.id)) return
  90. likeServer({
  91. id:e.id,
  92. type:11
  93. }).then(e => {
  94. })
  95. this.favoriteList.push(e.id)
  96. return
  97. if(this.favoriteList.includes(e.id)){
  98. // 取消点赞
  99. likeServer({
  100. id:e.id,
  101. type:12
  102. })
  103. let deleteIdx = this.favoriteList.findIndex((v => v == e.id))
  104. this.favoriteList.splice(deleteIdx,1)
  105. } else {
  106. likeServer({
  107. id:e.id,
  108. type:12
  109. })
  110. this.favoriteList.push(e.id)
  111. }
  112. },
  113. cancel(){
  114. this.listParams.title = ''
  115. },
  116. fabClick(){
  117. uni.navigateTo({
  118. url: `../mattersAdd/mattersAdd`
  119. })
  120. },
  121. search(){
  122. this.listParams.title = this.searchValue
  123. this.getList()
  124. },
  125. getList(val = null,type){
  126. this.listParams.flag = val || ''
  127. switch(type){
  128. case 'dropDown':
  129. // 上拉
  130. getMattersList(this.listParams).then(res => {
  131. this.qbwd = [...this.qbwd,...res.rows]
  132. this.total = res.total
  133. })
  134. break;
  135. default:
  136. this.qbwd = this.topList
  137. getMattersList(this.listParams).then(res => {
  138. this.qbwd = [...this.qbwd,...res.rows]
  139. this.total = res.total
  140. })
  141. break;
  142. }
  143. },
  144. goDetails(e) {
  145. let id = e.id || ''
  146. let type = 11
  147. uni.navigateTo({
  148. url: `../mattersDetail/mattersDetail?id=${id}`
  149. });
  150. },
  151. // 新增资讯
  152. addInfomation(){
  153. uni.navigateTo({
  154. url: `../informationAdd/informationAdd`
  155. });
  156. }
  157. },
  158. /**
  159. * 生命周期函数--监听页面加载
  160. */
  161. onLoad(options) {},
  162. /**
  163. * 生命周期函数--监听页面初次渲染完成
  164. */
  165. onReady() {},
  166. /**
  167. * 生命周期函数--监听页面显示
  168. */
  169. onShow() {},
  170. /**
  171. * 生命周期函数--监听页面隐藏
  172. */
  173. onHide() {},
  174. /**
  175. * 生命周期函数--监听页面卸载
  176. */
  177. onUnload() {},
  178. /**
  179. * 页面相关事件处理函数--监听用户下拉动作
  180. */
  181. onPullDownRefresh() {},
  182. /**
  183. * 用户点击右上角分享
  184. */
  185. onShareAppMessage() {},
  186. };
  187. </script>
  188. <style lang="scss">
  189. @import './matters.css';
  190. .container{
  191. height: 100%;
  192. }
  193. .container{
  194. height: 100%;
  195. content: '\e633';
  196. }
  197. .favorite{
  198. .icon-shoucang:before{
  199. color: red;
  200. }
  201. }
  202. .not-favorite{
  203. }
  204. </style>