toGovernmentList.vue 5.6 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="loadImgSrc(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="loadImgSrc(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="loadImgSrc(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.updateTime || item.createTime }}
  36. <!-- <em class="iconfont icon-jifen"></em> -->
  37. </span>
  38. <view class="ck">
  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. type: 10,
  71. flag:'',
  72. isTop:null
  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. onReachBottom(){
  89. let pageNum = this.listParams.pageNum
  90. let pageSize = this.listParams.pageSize
  91. let total = this.total
  92. if(pageNum * pageSize >= total){
  93. uni.showToast({
  94. title:'暂无更多数据'
  95. })
  96. return
  97. } else {
  98. this.listParams.pageNum += 1;
  99. this.getList()
  100. }
  101. },
  102. methods:{
  103. currentFavoriteCount(e){
  104. if(this.favoriteList.includes(e.id)){
  105. return e.likeNum + 1
  106. } else {
  107. return e.likeNum
  108. }
  109. },
  110. addFavorite(e){
  111. if(this.favoriteList.includes(e.id)) return
  112. likeServer({
  113. id:e.id,
  114. type:12
  115. }).then(e => {
  116. })
  117. this.favoriteList.push(e.id)
  118. return
  119. if(this.favoriteList.includes(e.id)){
  120. // 取消点赞
  121. likeServer({
  122. id:e.id,
  123. type:10
  124. })
  125. let deleteIdx = this.favoriteList.findIndex((v => v == e.id))
  126. this.favoriteList.splice(deleteIdx,1)
  127. } else {
  128. likeServer({
  129. id:e.id,
  130. type:10
  131. })
  132. this.favoriteList.push(e.id)
  133. }
  134. },
  135. cancel(){
  136. this.listParams.titleName = ''
  137. },
  138. search(){
  139. this.listParams.titleName = this.searchValue
  140. this.getList()
  141. },
  142. getList(val = null){
  143. this.listParams.flag = val || ''
  144. this.qbwd = this.topList
  145. listWxs(this.listParams).then(res => {
  146. this.qbwd = [...this.qbwd,...res.rows]
  147. this.total = res.total
  148. })
  149. },
  150. goDetails(e) {
  151. let id = e.id || ''
  152. let type = 10
  153. uni.navigateTo({
  154. url: `../informationDetail/informationDetail?id=${id}&type=${type}`
  155. });
  156. },
  157. // 新增资讯
  158. addInfomation(){
  159. uni.navigateTo({
  160. url: `../informationAdd/informationAdd`
  161. });
  162. }
  163. },
  164. /**
  165. * 生命周期函数--监听页面加载
  166. */
  167. onLoad(options) {
  168. if(options.type!=null){
  169. this.listParams.type = options.type
  170. }
  171. if(options.type==null){
  172. this.listParams.isGovernment = 1
  173. }
  174. // 查置顶
  175. listWx({
  176. type:10,
  177. isTop:1
  178. }).then(e => {
  179. this.topList = e.data
  180. this.qbwd = this.topList
  181. this.getList()
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady() {},
  188. /**
  189. * 生命周期函数--监听页面显示
  190. */
  191. onShow() {},
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide() {},
  196. /**
  197. * 生命周期函数--监听页面卸载
  198. */
  199. onUnload() {},
  200. /**
  201. * 页面相关事件处理函数--监听用户下拉动作
  202. */
  203. onPullDownRefresh() {},
  204. /**
  205. * 用户点击右上角分享
  206. */
  207. onShareAppMessage() {},
  208. };
  209. </script>
  210. <style lang="scss">
  211. @import './index.css';
  212. .container{
  213. height: 100%;
  214. content: '\e633';
  215. }
  216. .favorite{
  217. .icon-shoucang:before{
  218. color: red;
  219. }
  220. }
  221. .not-favorite{
  222. }
  223. </style>