newsdj.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="car">
  3. <view class="cartop">
  4. <view class="toptit" v-if="checkPermi(['wuYe:residentInfo:count'])">
  5. <image :src="djtop"></image>本社区党员共<text>{{count}}</text>人
  6. </view>
  7. <view class="tabtop flexc">
  8. <view class="tabt" :class="tabval==ite.dictValue?'act':''" v-for="(ite,idx) in tablist" :key="idx" @click="getTabFn(ite.dictValue)">{{ite.dictLabel}}</view>
  9. </view>
  10. </view>
  11. <!-- 列表 -->
  12. <view class="carlists">
  13. <view v-if="checkPermi(['wuYe:residentInfo:count'])" style="height: 70rpx;"></view>
  14. <car-list :datainfo="list" :wzlxList="wzlxList" :wtdt="wtdt" type='newsdj' @getDetail="getDetail" @getScFn="getScFn" @getDelFn="getDelFn"></car-list>
  15. </view>
  16. <block v-if="checkPermi(['wuYe:partyNews:add'])">
  17. <view style="height: 100rpx;"></view>
  18. <view class="rfbtn" @click="getAddFn" >发布</view>
  19. </block>
  20. <loading></loading>
  21. </view>
  22. </template>
  23. <script>
  24. import config from '@/config'
  25. // const baseUrl = config.baseUrl,
  26. import carList from "@/manage/components/car/list.vue"
  27. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  28. import {getDictionaryFn} from "@/api/system/user.js"
  29. import {partyNewsList,partyNewsDel,partyNewsCount,getStarsDj} from "@/api/work/manage.js"
  30. export default{
  31. components:{carList},
  32. data(){
  33. return{
  34. djtop:require('@/manage/static/community/djtop.png'),
  35. cxrq:"",
  36. text:'',
  37. list:[],
  38. pageSize: 10,
  39. pageNum: 1,
  40. reachflag: true,
  41. wtdt:'',
  42. tabval:'',
  43. tablist:[{dictLabel:"已停用",dictValue:'yty'}],
  44. wzlxList:[],
  45. baseUrl:config.baseUrl,
  46. count:0,
  47. userId:this.$store.state.user.userId,
  48. nickName:this.$store.state.user.nickName,
  49. avatar:this.$store.state.user.avatar,
  50. tenantId:this.$store.state.user.tenantId
  51. }
  52. },
  53. onUnload() {
  54. uni.$off('partyNewsList')
  55. },
  56. onLoad: function() {
  57. uni.$on('partyNewsList',(res)=>{
  58. this.getrefreshData()
  59. })
  60. this.init()
  61. },
  62. // 上拉触底加载更多触发事件
  63. onReachBottom() {
  64. if (this.reachflag) {
  65. this.pageNum++
  66. this.getDataFn()
  67. }
  68. },
  69. methods:{
  70. checkPermi, checkRole,
  71. init(){
  72. // 文章类型
  73. getDictionaryFn('article_type').then(res=>{
  74. if(res.code==200){
  75. if(res.data){
  76. this.tabval=res.data[0].dictValue;
  77. this.wzlxList = res.data.map(v => {
  78. return {
  79. dictLabel: v.dictLabel,
  80. dictValue: v.dictValue
  81. }
  82. })
  83. var newArr=JSON.parse(JSON.stringify(this.tablist))
  84. this.tablist=this.wzlxList.concat(newArr)
  85. this.getDataFn()
  86. }
  87. }
  88. })
  89. if(checkPermi(['wuYe:residentInfo:count'])){
  90. var params={
  91. residentAppearance:"2"
  92. }
  93. partyNewsCount(params).then(res=>{
  94. if(res.code==200){
  95. this.count=res.data;
  96. }
  97. })
  98. }
  99. },
  100. getAddFn(){
  101. this.$tab.navigateTo("/manage/pages/community/newsadddj?tabval="+this.tabval)
  102. },
  103. getDetail(id){
  104. this.$tab.navigateTo("/manage/pages/community/djdetail?id="+id)
  105. },
  106. getrefreshData(){
  107. this.pageNum=1;
  108. this.list=[];
  109. this.reachflag=true;
  110. this.getDataFn()
  111. },
  112. getTabFn(val){
  113. this.tabval=val;
  114. this.getrefreshData()
  115. },
  116. getDelFn(data){
  117. var that=this;
  118. partyNewsDel(data).then(res=>{
  119. if(res.code==200){
  120. this.$toast("删除成功");
  121. setTimeout(function(){
  122. that.getrefreshData()
  123. },1500)
  124. }
  125. })
  126. },
  127. formatRichText(html) {
  128. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  129. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  130. // match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  131. // match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  132. return match;
  133. });
  134. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  135. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  136. return match;
  137. });
  138. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  139. newContent = newContent.replace(/\<img src="/gi,
  140. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +this.baseUrl);
  141. return newContent;
  142. },
  143. // 收藏
  144. getScFn(ite){
  145. var data=JSON.parse(JSON.stringify(ite))
  146. var info=data.ite;
  147. var idx=data.idx;
  148. var params={
  149. userId:this.userId,
  150. nickName:this.nickName,
  151. avatar:this.avatar,
  152. targetTitle:info.partyTitle,
  153. targetId:info.partyId,
  154. targetType:'2',//目标类型(1:社区 2:党建 )
  155. tenantId:this.tenantId
  156. }
  157. getStarsDj(params).then(res=>{
  158. if(res.code==200){
  159. if(info.isStars=='Y'){
  160. this.$toast("取消收藏成功");
  161. this.list[idx].isStars='N';
  162. this.list[idx].starsCount--;
  163. // this.datainfo.isStar='N';
  164. // this.datainfo.userStars--;
  165. }else{
  166. this.$toast("收藏成功");
  167. this.list[idx].isStars='Y';
  168. this.list[idx].starsCount++;
  169. }
  170. }
  171. })
  172. },
  173. getDataFn(){
  174. var params={
  175. pageSize:this.pageSize,
  176. pageNum: this.pageNum,
  177. }
  178. if(this.tabval=='yty'){
  179. params.status='1'
  180. }else{
  181. params.partyType=this.tabval;
  182. params.status='0'
  183. }
  184. partyNewsList(params).then(res=>{
  185. if(res.code==200){
  186. if (res.rows.length < this.pageSize) {
  187. this.reachflag = false
  188. this.wtdt = '到底了~';
  189. } else {
  190. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  191. if (num < res.total) {
  192. this.reachflag = true
  193. this.wtdt = ''
  194. } else {
  195. this.reachflag = false
  196. this.wtdt = '到底了~';
  197. }
  198. }
  199. var newArr=JSON.parse(JSON.stringify(res.rows))
  200. newArr.forEach(ite=>{
  201. if(ite.partyContent){
  202. ite.partyContent=this.formatRichText(ite.partyContent)
  203. }
  204. ite.right=0;
  205. })
  206. if (this.pageNum == 1) {
  207. this.list = newArr;
  208. } else {
  209. this.list = this.list.concat(newArr)
  210. }
  211. }else{
  212. this.$toast(res.msg)
  213. }
  214. })
  215. },
  216. }
  217. }
  218. </script>
  219. <style>
  220. page{background: #F3F3F0;}
  221. </style>
  222. <style lang="scss" scoped>
  223. .car{padding: 130rpx 0 10rpx;}
  224. .cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
  225. .toptit{display: flex;justify-content: center;font-weight: 500;font-size: 26rpx;color: #8592AA;height: 70rpx;align-items: center;
  226. background: #E4EDFF;
  227. text{font-size: 32rpx;color: #0156FE;padding: 0 10rpx;}
  228. image{width: 28rpx;height: 26rpx;flex: 0 0 auto;margin-right: 12rpx;}
  229. }
  230. .tabtop{padding-bottom: 40rpx;padding-top: 14rpx;overflow: auto;
  231. .tabt{font-weight: 500;font-size: 32rpx;color: #666666;position: relative;line-height: 56rpx;flex: 0 0 auto;text-align: center;min-width: 140rpx;margin: 0 20rpx;
  232. &.act{font-weight: bold;font-size: 32rpx;color: #272727;
  233. &::after{content: '';width: 40rpx;height: 10rpx;background: #0156FE;border-radius: 6rpx;position: absolute;left: 50%;margin-left: -20rpx;bottom: -10rpx;}
  234. }
  235. }
  236. }
  237. }
  238. .carlists{padding: 0 18rpx;}
  239. </style>