toGovernmentList.vue 6.1 KB

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