toLegal.vue 5.5 KB

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