newssqdetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <view class="ndetail " @click="getComflag">
  3. <image :src="nonews" v-if="datainfo.status==2" class="noimg"></image>
  4. <block v-else>
  5. <!-- 详情 -->
  6. <view class="ndbox mb12">
  7. <view class="plr15">
  8. <view class="tit">{{datainfo.communityTitle}}</view>
  9. <view class="time mb12">{{datainfo.publishTime}}</view>
  10. <view class="rich">
  11. <rich-text :nodes="communityContent" style="word-break: break-all;"></rich-text>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="ndbox mb12 plr15">
  16. <view class="flext mb15">
  17. <view class="pltit flex0">评论<text>({{commenttotal||0}})</text></view>
  18. <view class="flex1"></view>
  19. <view class="pltitnum"><text>{{datainfo.userLikes}}</text>赞<text class="line">|</text><text>{{datainfo.userShare}}</text> 分享</view>
  20. </view>
  21. <!-- 评论列表 -->
  22. <box-list :datainfo="commentlist" type="comment" @getZhanFn="getZhanFn" @getShouFn="getShouFn" @getDzFn="getplDzFn" @getHfFn="getplHfFn" @getDelFn="getDelFn"></box-list>
  23. </view>
  24. <!-- 评论 -->
  25. <view class="pjfbtn" @click.stop="btns" :style="{bottom: `${bottom}px`}">
  26. <view class="mb10 plr20">
  27. <view class="flexc pjfbox ">
  28. <textarea :placeholder="placeholder" :adjust-position="adjustpos" :focus="isfocus" v-model="text" :auto-height="autoHeight" :cursor-spacing='curspac' fixed="true" :show-confirm-bar="confirmBar" ></textarea>
  29. <view class="btns" @click.stop="getPinLunFn">发送</view>
  30. </view>
  31. </view>
  32. <view class="ndbfox flexc">
  33. <view class="flexcc ndbflist" @click.stop="getshareFn">
  34. <image :src="share"></image>
  35. <view>{{datainfo.userShare}}</view>
  36. </view>
  37. <view class="flexcc ndbflist" @click.stop="getHfFna">
  38. <image :src="nicona"></image>
  39. <view>{{commenttotal||0}}</view>
  40. </view>
  41. <view class="flexcc ndbflist" @click.stop="getDzFn('1')">
  42. <image :src="nicond" v-if="datainfo.isLike=='Y'"></image>
  43. <image :src="niconb" v-else></image>
  44. <view>{{datainfo.userLikes}}</view>
  45. </view>
  46. <view class="flexcc ndbflist" @click.stop="getScFn('1')">
  47. <image :src="starb" v-if="datainfo.isStar=='Y'"></image>
  48. <image :src="niconc" v-else></image>
  49. <view>{{datainfo.userStars}}</view>
  50. </view>
  51. </view>
  52. </view>
  53. </block>
  54. <loading></loading>
  55. </view>
  56. </template>
  57. <script>
  58. import config from '@/config'
  59. const baseUrl = config.baseUrl
  60. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  61. import boxList from "@/manage/components/car/list.vue"
  62. import {getRootComment,getParentComment,commentIndex,giveTheThumbs,getStars,commentContentPut,deletepl,newsDet,setShare} from "@/api/work/manage.js"
  63. export default{
  64. components:{boxList},
  65. data(){
  66. return{
  67. nicona:require('@/manage/static/news/nicona.png'),
  68. niconb:require('@/manage/static/news/niconb.png'),
  69. niconc:require('@/manage/static/news/niconc.png'),
  70. nicond:require('@/manage/static/news/nicond.png'),
  71. nicone:require('@/manage/static/news/nicone.png'),
  72. head:require('@/manage/static/news/head.png'),
  73. starb:require('@/manage/static/news/starb.png'),
  74. nonews:require('@/manage/static/news/nonews.png'),
  75. share:require('@/manage/static/news/share.png'),
  76. baseUrl:config.baseUrl,
  77. autoHeight:true,
  78. confirmBar:false,
  79. adrfixed:true,
  80. adjustpos:false,
  81. curspac:0,//光标和键盘距离
  82. placeholder:'发表我的评论',
  83. datainfo:{
  84. },
  85. communityContent:'',
  86. text:'',
  87. id:"",
  88. commentlist:[],//评论列表
  89. commenttotal:"0",
  90. pageSize: 10,
  91. pageNum: 1,
  92. userId:this.$store.state.user.userId,
  93. nickName:this.$store.state.user.nickName,
  94. avatar:this.$store.state.user.avatar,
  95. isRoot:'1',//isRoot,根评论id 1:根评论 2:子评论
  96. isfocus:false,
  97. plinfo:'',//二级评论信息
  98. bottom:0,
  99. tenantId:this.$store.state.user.tenantId,
  100. }
  101. },
  102. onLoad: function(e) {
  103. this.id=e.id;
  104. this.getDetailFn();
  105. this.getRootComment();
  106. // #ifndef H5
  107. uni.onKeyboardHeightChange(res=> { //监听键盘高度变化
  108. const res_keyboard = uni.getSystemInfoSync();
  109. // let key_height = res.height - (res_keyboard.screenHeight - res_keyboard.windowHeight)
  110. this.bottom = `${ res.height>0 ? res.height : 0}`;
  111. // if(this.bottom==0){
  112. // this.isfocus=false;
  113. // }
  114. })
  115. // #endif
  116. },
  117. // 上拉触底加载更多触发事件
  118. onReachBottom() {
  119. if (this.reachflag) {
  120. this.pageNum++
  121. this.getDataFn()
  122. }
  123. },
  124. onPageScroll(e) {
  125. this.isfocus=false;
  126. },
  127. methods:{
  128. checkPermi, checkRole,
  129. //评论
  130. getComflag(){
  131. if(this.isfocus){
  132. this.isfocus=false;
  133. this.placeholder="发表我的评论"
  134. this.isRoot='1'
  135. }
  136. },
  137. // 分享
  138. getshareFn(){
  139. var params={
  140. communityId:this.id,
  141. tenantId:this.tenantId
  142. }
  143. setShare(params).then(res=>{
  144. if(res.code==200){
  145. this.$toast("分享成功")
  146. this.datainfo.userShare++
  147. }
  148. })
  149. },
  150. btns(){
  151. },
  152. getDetailFn(){
  153. newsDet(this.id).then(res=>{
  154. if(res.code==200){
  155. this.datainfo=res.data;
  156. var data=JSON.parse(JSON.stringify(res.data))
  157. if(data.communityContent){
  158. this.communityContent=this.formatRichText(data.communityContent)
  159. }
  160. }
  161. })
  162. },
  163. // 删除
  164. getDelFn(id){
  165. var that=this;
  166. // var info=JSON.parse(JSON.stringify(data))
  167. // var type=info.type;
  168. // var pid=info.pid;
  169. deletepl(id).then(res=>{
  170. if(res.code==200){
  171. this.$toast("删除成功");
  172. uni.$emit('partyNewsList')
  173. setTimeout(function(){
  174. // 删除数据
  175. that.getRootComment()
  176. },1500)
  177. }
  178. })
  179. },
  180. getZhanFn(obj){
  181. // 获取自己
  182. var obj=JSON.parse(JSON.stringify(obj));
  183. var idx=obj.idx;
  184. var list=JSON.parse(JSON.stringify(this.commentlist))[idx]
  185. var params={
  186. parentId:list.id,
  187. pageSize:list.pageSize,
  188. pageNum: list.pageNum,
  189. tenantId:this.tenantId
  190. }
  191. getParentComment(params).then(res=>{
  192. if(res.code==200){
  193. var reachflag=true;
  194. if (res.rows.length < obj.pageSize) {
  195. list.reachflag = false
  196. } else {
  197. var num = parseInt(res.rows.length) + parseInt(obj.pageSize) * parseInt(obj.pageNum - 1)
  198. if (num < obj.childrenListCount) {
  199. list.reachflag = true
  200. } else {
  201. list.reachflag = false
  202. }
  203. }
  204. list.childrenList=list.childrenList.concat(res.rows)
  205. list.pageNum=obj.pageNum++
  206. this.commentlist.splice(idx,1,list)
  207. }
  208. })
  209. },
  210. // 点赞
  211. getDzFn(type,info){
  212. var params={
  213. userId:this.userId,
  214. nickName:this.nickName,
  215. avatar:this.avatar,
  216. targetType:type,
  217. communityId:this.id,
  218. tenantId:this.tenantId
  219. }
  220. if(type==1){
  221. params.targetId=this.id;
  222. params.targetTitle=this.datainfo.communityTitle;
  223. }else {
  224. params.targetId=info.id;
  225. params.targetTitle=info.content;
  226. }
  227. giveTheThumbs(params).then(res=>{
  228. if(res.code==200){
  229. uni.$emit('partyNewsList')
  230. if(type==1){
  231. if(this.datainfo.isLike=='Y'){
  232. this.$toast("取消点赞成功");
  233. this.datainfo.isLike='N';
  234. this.datainfo.userLikes--;
  235. }else{
  236. this.$toast("点赞成功");
  237. this.datainfo.isLike='Y';
  238. this.datainfo.userLikes++;
  239. }
  240. }else{
  241. var idx=info.idx;
  242. var aidx=info.aidx;
  243. var atype=info.atype;
  244. var obj=JSON.parse(JSON.stringify(this.commentlist))[idx];
  245. if(atype&&atype=='ejdz'){
  246. var erobj=obj.childrenList[aidx];
  247. if(erobj.isLike=='Y'){
  248. this.$toast("取消点赞成功");
  249. erobj.isLike='N';
  250. erobj.likeCount--;
  251. }else{
  252. this.$toast("点赞成功");
  253. erobj.isLike='Y';
  254. erobj.likeCount++;
  255. }
  256. obj.childrenList[aidx]=JSON.parse(JSON.stringify(erobj))
  257. this.commentlist.splice(idx,1,obj)
  258. }else{
  259. if(obj.isLike=='Y'){
  260. this.$toast("取消点赞成功");
  261. obj.isLike='N';
  262. obj.likeCount--;
  263. }else{
  264. this.$toast("点赞成功");
  265. obj.isLike='Y';
  266. obj.likeCount++;
  267. }
  268. this.commentlist.splice(idx,1,obj)
  269. }
  270. }
  271. }
  272. })
  273. },
  274. getplDzFn(data){
  275. var info=JSON.parse(JSON.stringify(data))
  276. this.getDzFn('2',info)
  277. },
  278. // 收藏
  279. getScFn(type){
  280. var params={
  281. userId:this.userId,
  282. nickName:this.nickName,
  283. avatar:this.avatar,
  284. targetType:'1',//目标类型(1:社区 2:党建 )
  285. tenantId:this.tenantId
  286. }
  287. params.targetId=this.id;
  288. params.targetTitle=this.datainfo.communityTitle;
  289. getStars(params).then(res=>{
  290. if(res.code==200){
  291. uni.$emit('partyNewsList')
  292. if(this.datainfo.isStar=='Y'){
  293. this.$toast("取消收藏成功");
  294. this.datainfo.isStar='N';
  295. this.datainfo.userStars--;
  296. }else{
  297. this.$toast("收藏成功");
  298. this.datainfo.isStar='Y';
  299. this.datainfo.userStars++
  300. }
  301. }
  302. })
  303. },
  304. // 评论回复
  305. getHfFna(data){
  306. var that=this;
  307. this.isRoot='1';
  308. this.placeholder='发表我的评论'
  309. this.isfocus=true;
  310. },
  311. getplHfFn(data){
  312. this.isfocus=false;
  313. var that=this;
  314. this.plinfo=JSON.parse(JSON.stringify(data))
  315. this.placeholder='回复:'+data.toNickName
  316. this.isRoot='2';
  317. this.isfocus=true;
  318. },
  319. getPinLunFn(){
  320. var params={
  321. userId:this.userId,
  322. nickName:this.nickName,
  323. avatar:this.avatar,
  324. isRoot:this.isRoot,
  325. communityId:this.id,
  326. communityType:this.datainfo.communityType,
  327. communityTitle:this.datainfo.communityTitle,
  328. commentContent:this.text,
  329. tenantId:this.tenantId
  330. }
  331. if(this.isRoot==2){
  332. var info=JSON.parse(JSON.stringify(this.plinfo))
  333. if(info.type=='ejhf'){
  334. params.toRoot='Y';
  335. }
  336. params.parentId=info.parentId;
  337. params.toUserId=info.toUserId;
  338. params.toNickName=info.toNickName;
  339. params.toAvatar=info.toAvatar;
  340. }
  341. commentIndex(params).then(res=>{
  342. if(res.code==200){
  343. this.$toast('评论成功,等待审核')
  344. this.text='';
  345. this.isfocus=false;
  346. }
  347. })
  348. },
  349. getShouFn(idx){
  350. var list=JSON.parse(JSON.stringify(this.commentlist))[idx];
  351. list.childrenList=[];
  352. list.pageNum=1;
  353. list.reachflag=true;
  354. this.commentlist.splice(idx,1,list)
  355. },
  356. getRootComment(){
  357. var that=this;
  358. var params={
  359. communityId:this.id,
  360. pageSize:this.pageSize,
  361. pageNum: this.pageNum,
  362. tenantId:this.tenantId
  363. }
  364. // userid,头像,nickname,标题(或者评论对象的内容) 点赞收藏评论,
  365. getRootComment(params).then(res=>{
  366. if(res.code==200){
  367. this.commenttotal=res.total;
  368. if (res.rows.length < this.pageSize) {
  369. this.reachflag = false
  370. this.wtdt = '到底了~';
  371. } else {
  372. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  373. if (num < res.total) {
  374. this.reachflag = true
  375. this.wtdt = ''
  376. } else {
  377. this.reachflag = false
  378. this.wtdt = '到底了~';
  379. }
  380. }
  381. var newArr=JSON.parse(JSON.stringify(res.rows))
  382. newArr.forEach(ite=>{
  383. ite.pageSize=1
  384. ite.pageNum=10
  385. ite.reachflag=true
  386. })
  387. if (this.pageNum == 1) {
  388. this.commentlist = newArr;
  389. } else {
  390. this.commentlist = this.list.concat(newArr)
  391. }
  392. }
  393. })
  394. },
  395. //解析富文本方法
  396. formatRichText(html) {
  397. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  398. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  399. // match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  400. // match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  401. return match;
  402. });
  403. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  404. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  405. return match;
  406. });
  407. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  408. newContent = newContent.replace(/\<img src="/gi,
  409. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +baseUrl);
  410. return newContent;
  411. },
  412. }
  413. }
  414. </script>
  415. <style>
  416. page{background: #F3F3F0;}
  417. </style>
  418. <style lang="scss" scoped>
  419. .ndetail{
  420. min-height: 100vh;padding: 20rpx 18rpx 260rpx;
  421. .ndbox{background: #FFFFFF;border-radius: 20rpx;padding-top: 30rpx;padding-bottom: 20rpx;
  422. .tit{font-weight: bold;font-size: 32rpx;color: #272727;margin-bottom: 14rpx;text-align: center;padding-top: 4rpx;}
  423. .time{font-weight: 500;font-size: 24rpx;color: #AAAAAA;text-align: center;}
  424. .rich{padding: 28rpx 0;}
  425. //border-top: 2rpx solid #E5E5E5;
  426. }
  427. }
  428. .pltitnum{font-weight: 500;font-size: 26rpx;color: #AAAAAA;
  429. text{display: inline-block;margin-right:10rpx;
  430. &.line{margin: 0 12rpx;}
  431. }
  432. }
  433. .pltit{font-weight: bold;font-size: 30rpx;color: #272727;
  434. text{margin-left: 24rpx;font-size: 24rpx;color: #666666;}
  435. }
  436. .plr20{padding: 0 40rpx;}
  437. .pjfbtn{background: #FFFFFF;position: fixed;bottom: 0;left: 0;right: 0;padding:26rpx 0rpx 20rpx;box-shadow: 0px 0px 18rpx 0px rgba(159,159,159,0.47);
  438. .pjfbox{background: #E6E6E6;border-radius: 10rpx;
  439. textarea{flex: 1;font-size: 26rpx;color: #222327;min-height: 100rpx;font-size: 26rpx;margin: 0;background: #E6E6E6;box-sizing: border-box;padding: 10rpx 0 10rpx 36rpx;border-radius:10rpx 0 0 10rpx;}
  440. .btns{nt-weight: bold;padding: 0 34rpx;height: 60rpx;line-height: 60rpx;flex: 0 0 auto;
  441. font-size: 26rpx;
  442. }
  443. color: #314081;}
  444. }
  445. .ndbfox{
  446. // border-top: 2rpx solid #E5E5E5;
  447. .ndbflist{width: 33.3%;padding: 20rpx 0;box-sizing: border-box;
  448. image{width: 26rpx;height: 26rpx;margin-right: 26rpx;}
  449. view{font-weight: 500;font-size: 26rpx;color: #666666;}
  450. }
  451. }
  452. // .pjfbtn /deep/ .uni-easyinput{flex: 1;font-size: 26rpx;color: #222327;}
  453. // .pjfbtn /deep/ .uni-textarea-textarea{min-height: 40rpx;font-size: 26rpx;margin: 0;background: #E6E6E6;box-sizing: border-box;padding: 10rpx 0 10rpx 36rpx;border-radius:10rpx 0 0 10rpx;}
  454. </style>