newssqdetail.vue 13 KB

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