articleDetails.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view>
  3. <u-navbar :isBack="back" ></u-navbar>
  4. <share-server ref="share" ></share-server>
  5. <!-- 新闻内容 -->
  6. <view class="content">
  7. <view class="title">
  8. {{info.title}}
  9. </view>
  10. <view class="infos">
  11. <view class="date">
  12. {{info.createTime}}
  13. </view>
  14. <view class="pageview" >
  15. <view class="icon">
  16. <u-icon name="eye" size="32"></u-icon>
  17. </view>
  18. <view class="number">
  19. {{info.hits}}
  20. </view>
  21. </view>
  22. </view>
  23. <view class="text news-content" v-html="info.content">
  24. </view>
  25. </view>
  26. <!-- 评论 -->
  27. <template v-if="typeNameBl">
  28. <view class="comment" v-if="info.title&&infolistComment&&infolistComment.length" >
  29. <view class="title">
  30. 精华评论
  31. </view>
  32. <view class="comment-item" v-for="(item,i) in infolistComment" :key="i" >
  33. <view class="photo">
  34. <img v-if="item.headImg" :src="item.headImg" alt="">
  35. <u-avatar v-else size="80" ></u-avatar>
  36. </view>
  37. <view class="details">
  38. <view class="name-date">
  39. <view class="name" :class="{
  40. red:!item.userName
  41. }" >
  42. {{item.userName?item.userName:'用户异常'}}
  43. </view>
  44. <view class="date">
  45. {{item.date}}
  46. </view>
  47. </view>
  48. <view class="comment-content">
  49. {{item.content}}
  50. <view class="mine" v-if="userInfo&&(item.userId==userInfo.id)">
  51. <view class="my-comment">
  52. 我的评论<span style="color:red;margin-left: 2px;" v-if="item.status==0">[审批中]</span>
  53. </view>
  54. <view class="delete" @click="newsCommentsdelete(item.id)">
  55. 删除
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <u-divider style="margin-top: 20px;" v-if="infolistComment.length==recordsTotal" >已经到底了,欢迎留下你的评论</u-divider>
  62. </view>
  63. <view class="bottom" v-if="userInfo" >
  64. <view class="input" @click="showMessage=true">
  65. <view class="inputT">发表评论</view>
  66. </view>
  67. <view class="like" :class="{
  68. red:info.iLike
  69. }" @click="changeLikes()">
  70. <view class="icon">
  71. <u-icon name="thumb-up" size="32"></u-icon>
  72. </view>
  73. <view class="number">
  74. {{info.likesNum}}
  75. </view>
  76. </view>
  77. </view>
  78. <view class="bottom" v-else >
  79. <view class="input" @click="issueMethod()">
  80. <view class="inputT">未登录,前往登录</view>
  81. </view>
  82. <view class="like" :class="{
  83. red:info.iLike
  84. }" >
  85. <view class="icon">
  86. <u-icon name="thumb-up" size="32"></u-icon>
  87. </view>
  88. <view class="number">
  89. {{info.likesNum}}
  90. </view>
  91. </view>
  92. </view>
  93. </template>
  94. <u-popup v-model="showMessage" border-radius="34" mode="bottom" >
  95. <view class="showMessage">
  96. <view class="showMessage1"><h3>发表评论({{content.length}}/50)</h3></view>
  97. <view class="showMessage2">
  98. <textarea name="" id="" style=" width:100%"
  99. v-model="content" maxlength="50"
  100. cols="30" rows="5" placeholder="填写内容"></textarea>
  101. </view>
  102. <view class="showMessage3">
  103. <u-button type="primary" @click="submitMessage()">提交</u-button>
  104. </view>
  105. </view>
  106. </u-popup>
  107. </view>
  108. </template>
  109. <script>
  110. import * as API from '@/apis/pagejs/news.js'
  111. import ShareServer from '@/components/ShareServer.vue'
  112. export default {
  113. components: {
  114. ShareServer
  115. },
  116. data() {
  117. return {
  118. id:"",
  119. content:"",
  120. info:{},
  121. showMessage:false,
  122. userInfo:null,
  123. list:[],
  124. infolistComment:[],
  125. listForm:{
  126. pageIndex:1,
  127. newsId:"",
  128. queryStatus:0,
  129. pageSize:10,
  130. },
  131. back:true,
  132. recordsTotal:0,
  133. getNewsCommentsListBl:true,
  134. }
  135. },
  136. onLoad(op){
  137. if(op.back&&op.back=="share"){
  138. this.back=false
  139. }
  140. this.id=op.id
  141. this.listForm.newsId=this.id;
  142. this.userInfo=this.carhelp.getPersonInfo()
  143. this.getInfo(true)
  144. },
  145. computed:{
  146. typeNameBl(){
  147. if(this.info&&(this.info.typeName=='图片新闻'||this.info.typeName=='政务动态')){
  148. return true
  149. }else{
  150. return false
  151. }
  152. }
  153. },
  154. methods: {
  155. onReachBottom() {
  156. if (this.infolistComment.length < this.recordsTotal&&this.getNewsCommentsListBl) {
  157. this.myLoadmore();
  158. }
  159. },
  160. myLoadmore(){
  161. this.listForm.pageIndex += 1;
  162. this.getNewsCommentsList();
  163. },
  164. issueMethod(){
  165. uni.showModal({
  166. title:"提示",
  167. content:"未登录,登录后参与评论",
  168. confirmText:"前往登录",
  169. showCancel:true,
  170. success: function (res) {
  171. if(res.confirm){
  172. uni.navigateTo({
  173. url:'/pages/login/index'
  174. })
  175. }
  176. }
  177. })
  178. },
  179. newsCommentsdelete(id){
  180. uni.showModal({
  181. title: '提示',
  182. content: '是否删除评论?',
  183. success: res=>{
  184. if (res.confirm) {
  185. this.newsCommentsdeletemethods(id)
  186. } else if (res.cancel) {
  187. //('用户点击取消');
  188. }
  189. }
  190. });
  191. },
  192. newsCommentsdeletemethods(id){
  193. uni.showLoading({
  194. title: "加载中",
  195. mask: true,
  196. })
  197. API.newsCommentsdelete(id).then((res) => {
  198. uni.showToast({
  199. title: "删除成功",
  200. icon: "none"
  201. })
  202. //this.getInfo();
  203. this.getNewsCommentsList(true)
  204. }).catch(error => {
  205. uni.showToast({
  206. title: error,
  207. icon: "none"
  208. })
  209. })
  210. },
  211. submitMessage(){
  212. if(!this.content){
  213. uni.showToast({
  214. title: "请填写内容",
  215. icon: "none"
  216. })
  217. return
  218. }
  219. uni.showLoading({
  220. title: "加载中",
  221. mask: true,
  222. })
  223. API.commentNews({
  224. newsId:this.id,
  225. content:this.content,
  226. }).then((res) => {
  227. this.content=""
  228. uni.showToast({
  229. title: "提交成功",
  230. icon: "none"
  231. })
  232. this.showMessage=false
  233. //this.getInfo();
  234. this.getNewsCommentsList(true)
  235. }).catch(error => {
  236. uni.showToast({
  237. title: error,
  238. icon: "none"
  239. })
  240. })
  241. },
  242. changeLikes(){
  243. if(!this.info.iLike){
  244. uni.showLoading({
  245. title: "加载中",
  246. mask: true,
  247. })
  248. API.changeLikes({
  249. newsId:this.id
  250. }).then((res) => {
  251. this.info.iLike=true;
  252. this.info.likesNum++;
  253. uni.hideLoading();
  254. //this.getInfo(true)
  255. }).catch(error => {
  256. uni.showToast({
  257. title: error,
  258. icon: "none"
  259. })
  260. })
  261. }else{
  262. uni.showToast({
  263. title: "您已经点过赞了",
  264. icon: "none"
  265. })
  266. }
  267. },
  268. getNewsCommentsList(bl){
  269. if(this.typeNameBl){
  270. }else{
  271. return
  272. }
  273. if(bl){
  274. this.listForm.pageIndex=1;
  275. this.infolistComment=[];
  276. this.getNewsCommentsListBl=false
  277. }
  278. uni.showLoading({
  279. title: "加载中",
  280. mask: true,
  281. })
  282. if(this.userInfo){
  283. this.listForm.queryStatus =1
  284. }
  285. API.newsCommentsList(this.listForm).then((res) => {
  286. uni.hideLoading();
  287. this.infolistComment = [
  288. ...this.infolistComment,
  289. ...res.data.data
  290. ];
  291. this.recordsTotal = res.data.recordsTotal;
  292. this.$nextTick(()=>{
  293. this.getNewsCommentsListBl=true
  294. })
  295. }).catch(error => {
  296. uni.showToast({
  297. title: error,
  298. icon: "none"
  299. })
  300. })
  301. },
  302. getInfo(bl){
  303. if(bl){
  304. uni.showLoading({
  305. title: "加载中",
  306. mask: true,
  307. })
  308. }
  309. var userId=null
  310. if(this.userInfo){
  311. userId=this.userInfo.id
  312. }
  313. API.detail({
  314. id:this.id,
  315. userId:userId
  316. }).then((res) => {
  317. if(bl){
  318. uni.hideLoading();
  319. }
  320. this.info=res.data;
  321. if(this.$refs.share){
  322. this.$refs.share.setUrl("/pages/news/articleDetails?back=share&id="+this.id);
  323. this.$refs.share.setTitle(this.info.title,this.id);
  324. }
  325. this.$nextTick(()=>{
  326. var list =document.getElementsByClassName("news-content")[0].getElementsByTagName("img");
  327. for(var i=0;i<list.length;i++){
  328. list[i].style='width: 100%;height: 100%;'
  329. }
  330. })
  331. this.getNewsCommentsList();
  332. }).catch(error => {
  333. uni.showToast({
  334. title: error,
  335. icon: "none"
  336. })
  337. })
  338. }
  339. }
  340. }
  341. </script>
  342. <style>
  343. </style>
  344. <style lang="scss" scoped>
  345. .showPointsRuleClass{
  346. padding: 10px 30px;
  347. }
  348. page{
  349. border-top: 1px solid #f1f1f1;
  350. padding-bottom:100px;
  351. font-family: 'Regular';
  352. }
  353. // 新闻内容
  354. .content{
  355. padding: 32rpx 32rpx 48rpx 32rpx;
  356. background-color: #fff;
  357. .title{
  358. color: rgba(16, 16, 16, 1);
  359. font-size: 20px;
  360. text-align: justify;
  361. font-weight: 550;
  362. font-family: 'SemiBold';
  363. }
  364. .infos{
  365. display: flex;
  366. justify-content: space-between;
  367. padding: 24rpx 0 32rpx 0;
  368. border-bottom: 1px solid rgba(241, 241, 241, 1);
  369. color: rgba(119, 119, 119, 1);
  370. font-size: 12px;
  371. .pageview{
  372. display: flex;
  373. }
  374. .icon{
  375. margin-right:8rpx ;
  376. }
  377. }
  378. .text{
  379. margin-top: 40rpx;
  380. line-height: 28px;
  381. color: rgba(51, 51, 51, 1);
  382. }
  383. .picture{
  384. margin-top: 40rpx;
  385. img{
  386. width: 100%;
  387. height: 155px;
  388. }
  389. .pic-title{
  390. margin-top: 7px;
  391. color: rgba(119, 119, 119, 1);
  392. font-size: 12px;
  393. text-align: center;
  394. }
  395. }
  396. }
  397. .showMessage{
  398. padding: 60rpx 50rpx ;
  399. .showMessage2{
  400. background-color: #E5E7EA;
  401. margin: 40rpx 0;
  402. textarea{
  403. padding: 8rpx;
  404. border-radius:34px;
  405. }
  406. }
  407. }
  408. // 评论
  409. .comment{
  410. margin-top:24rpx;
  411. background-color: #fff;
  412. padding: 32rpx 32rpx 48rpx 32rpx;
  413. .title{
  414. color: rgba(51, 51, 51, 1);
  415. font-size: 18px;
  416. }
  417. .comment-item:last-of-type{
  418. .comment-content{
  419. border: none;
  420. }
  421. }
  422. .comment-item{
  423. display: flex;
  424. padding-top: 58rpx;
  425. .photo{
  426. margin-top: -12px;
  427. img{
  428. width: 80rpx;
  429. height: 80rpx;
  430. border-radius: 50px;
  431. }
  432. }
  433. .details{
  434. margin-left: 24rpx;
  435. width: 100%;
  436. .name-date{
  437. display: flex;
  438. justify-content: space-between;
  439. .name{
  440. color: rgba(51, 51, 51, 1);
  441. font-size: 16px;
  442. }
  443. .date{
  444. color: rgba(119, 119, 119, 1);
  445. font-size: 12px;
  446. }
  447. }
  448. }
  449. .comment-content{
  450. margin-top: 16rpx;
  451. color: rgba(51, 51, 51, 1);
  452. line-height: 20px;
  453. border-bottom: 1px solid rgba(232, 232, 232, 1);
  454. padding-bottom: 40rpx;
  455. .mine{
  456. margin-top: 16rpx;
  457. display: flex;
  458. justify-content: space-between;
  459. line-height: 20px;
  460. .my-comment{
  461. color: rgba(119, 119, 119, 1);
  462. font-size: 12px;
  463. border: 1px solid rgba(153, 153, 153, 1);
  464. padding: 0rpx 12rpx;
  465. border-radius: 4px;
  466. }
  467. .delete{
  468. color: rgba(119, 119, 119, 1);
  469. font-size: 12px;
  470. }
  471. }
  472. }
  473. }
  474. }
  475. .red{
  476. color: red !important;
  477. }
  478. .bottom{
  479. position: fixed;
  480. left: 0;
  481. right: 0;
  482. bottom: 0;
  483. background-color: #fff;
  484. padding: 16rpx 32rpx;
  485. display: flex;
  486. justify-content: space-between;
  487. align-items: center;
  488. .input{
  489. background-color: rgba(229, 231, 234, 1);
  490. height: 32px;
  491. line-height: 32px;
  492. border-radius: 8rpx;
  493. width: 520rpx;
  494. padding-left: 16rpx;
  495. }
  496. /deep/.uni-input-placeholder{
  497. text-indent: 28rpx;
  498. }
  499. /deep/.uni-input-input{
  500. text-indent: 28rpx;
  501. }
  502. .like{
  503. display: flex;
  504. .number{
  505. margin-left: 16rpx;
  506. }
  507. }
  508. }
  509. </style>