detail.vue 14 KB

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