comment.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <view>
  3. <mescroll-body style="background-color: #fff;" @init="mescrollInit" top="0" bottom="200" :down="downOption" :up="upOption" @down="downCallback"
  4. @up="upCallback" @emptyclick="emptyClick">
  5. <view class="es-bc-white es-br-20" style="margin-top: 0;">
  6. <view class="es-view-w-x1 es-mt-25">
  7. <view v-for="(item, index) in dataList" :key="index" class="es es-mt-20">
  8. <view class="es-icon-80 es-br">
  9. <image :src="$isEmpty(item.avatar)?defHeadImg:item.avatar"></image>
  10. </view>
  11. <view class="es-f1 es-ml-21 es-pb-20">
  12. <view class="es-fs-28 es-fw">{{item.nickName}}</view>
  13. <view class="es-c-99 es-fs-22 es-mt-4">{{ utils.formatDate(item.createTime) }}</view>
  14. <view class="es-fs-26 es-fw-500 es-pt-24 es-pb-25">{{item.content}}</view>
  15. <view class="es es-c-99">
  16. <view class="es es-ac" @tap="doLike(item)">
  17. <view class="es-icon-28" :class="item.liked?'es-icon-course-like2-ac':'es-icon-course-like2'" ></view>
  18. <view class="es-ml-11 es-fs-26">{{item.likes}}</view>
  19. </view>
  20. <view class="es es-ac es-ml-23" @tap="openReplyPop(item)">
  21. <view class="es-icon-28 es-icon-course-comment"></view>
  22. <view class="es-ml-11 es-fs-26">{{item.replyCount}}</view>
  23. </view>
  24. <view class="es-f1"></view>
  25. <view class="es es-ac es-pc es-icon-33" v-if="isMySend(item)" @tap="delComment(item,0)">
  26. <view class="es-w-33 es-h-9 es-icon es-icon-course-point"></view>
  27. </view>
  28. </view>
  29. <view v-if="item.replyList && item.replyList.length>0" class="es-br-20 es-pt-10 es-pb-10 es-view-w-x es-mt-25" style="background-color: #F6F9F8;">
  30. <view class="es es-pt-20 es-pb-20 comment-reply-item" v-for="(cItem,idx) in item.replyList" :key="idx">
  31. <view class="es-icon-60 es-br">
  32. <image :src="$isEmpty(cItem.avatar)?defHeadImg:cItem.avatar"></image>
  33. </view>
  34. <view class="es-f1 es-ml-11">
  35. <view class="es-fs-24 es-fw-600">{{cItem.nickName}}</view>
  36. <view class="es-fs-22 es-c-99 es-mt-10 es-mb-10">{{ utils.formatDate(cItem.createTime) }}</view>
  37. <view class="es-fs-24 es-fw-500 es-pt-8 es-pb-14">{{cItem.content}}</view>
  38. <view class="es es-c-99">
  39. <view class="es es-ac" @tap="doReplyLike(cItem)">
  40. <view class="es-icon-28" :class="cItem.liked?'es-icon-course-like2-ac':'es-icon-course-like2'" ></view>
  41. <view class="es-ml-11 es-fs-26">{{cItem.likes}}</view>
  42. </view>
  43. <view class="es-f1"></view>
  44. <view class="es es-ac es-pc es-icon-33" v-if="isMySend(cItem)" @tap="delComment(cItem,1)">
  45. <view class="es-w-33 es-h-9 es-icon es-icon-course-point"></view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <view @tap="replayClick(item,index)" v-if="item.showReplyBtn" class="es es-ac es-mt-20 es-pb-20">
  52. <text class="es es-ac es-fs-24 es es-ac es-pc es-pt-10 es-pb-10 es-c-99">
  53. ——展开更多回复
  54. </text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </mescroll-body>
  61. <view :style="'height:'+(KeyHight)+'px'" v-if="KeyHight" ></view>
  62. <view class="es-h-120 es-auto-bottom" v-else></view>
  63. <view class="es-fix-bottom es-bc-white es-b-t" v-if="showBoottom">
  64. <view class="es-h-120 es-view-w-x es es-ac">
  65. <view class="es-f1 es-ipt es-f1 es-br es-icon-auto es-icon-course-bg2">
  66. <input ref="txtPing" v-model="pingContent" :focus="isInputFocus" @blur="onblur" :placeholder="placeholder" placeholder-class="es-c" />
  67. </view>
  68. <view class="es-fs-30 es-fw-600 es-ml-20 es-c" :adjust-position="false"
  69. :always-system="true" @tap="commentSend()">发布</view>
  70. </view>
  71. <view class="es-auto-bottom" v-if="!KeyHight"></view>
  72. </view>
  73. <!-- 回复弹出框 -->
  74. <uni-popup ref="popup" background-color="#fff" >
  75. <view class="popup-content">
  76. <view class="es-h-150 es-view-w-x es es-ac">
  77. <!-- <input ref="txtPing" v-model="pingContent" :focus="isInputFocus" @blur="onblur" :placeholder="placeholder" placeholder-class="es-c" /> -->
  78. <textarea name="replyPing" v-model="replyContent" style="background-color: #f7f7f7;" :placeholder="rPlaceholder" :focus="isRInputFocus" @blur="onReplyBlur" placeholder-class="place-hold"></textarea>
  79. <view class="es-fs-30 es-fw-600 es-ml-20 es-c" :adjust-position="false"
  80. :always-system="true" @tap="replySend">发布</view>
  81. </view>
  82. </view>
  83. </uni-popup>
  84. </view>
  85. </template>
  86. <script>
  87. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  88. import { getComments,getReplies,addComment,doLikeComment,deleteComment } from '@/api/shortvideo.js'
  89. export default {
  90. mixins: [MescrollMixin], // 使用mixin
  91. props: {
  92. videoId: {
  93. type: [String, Number],
  94. default: 0
  95. },
  96. smsNum: {
  97. type: [String, Number],
  98. default: 0
  99. }
  100. },
  101. data() {
  102. return {
  103. pingContent: '',
  104. KeyHight:0,
  105. cateId:0,
  106. courseId:5,
  107. totalNum:0,
  108. viewHeight:400,
  109. courseData:{},
  110. pageHei:400,
  111. downOption: {
  112. auto: false ,// 不自动加载 (mixin已处理第一个tab触发downCallback)
  113. use:true
  114. },
  115. upOption: {
  116. auto: false, // 不自动加载
  117. page: {
  118. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  119. size: 10 // 每页数据的数量
  120. },
  121. empty:{
  122. tip: '~ 暂无数据 ~', // 提示
  123. btnText: '去看看',
  124. icon:"/static/image/nodata.png"
  125. },
  126. textNoMore:"已经到底了",
  127. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  128. use:true,
  129. },
  130. pingType:1,//1:评论 2:回复
  131. dataList: [], //列表数据
  132. replyParentId:null,
  133. isLastPage:false,
  134. txtPing:null,
  135. sortType:1,
  136. isRInputFocus:false,
  137. isInputFocus:false,
  138. showBoottom:false,
  139. placeholder:"发布一条友善的评论",
  140. canShowReply:false,
  141. defHeadImg:"/static/image/course/defHead.png",
  142. rpyPageNum:0,
  143. replyContent:"",
  144. rPlaceholder:"",
  145. delCommentId:null,
  146. myUserInfo:{userId:0},
  147. isAnimaStart:true
  148. }
  149. },
  150. mounted() {
  151. try {
  152. const res = uni.getSystemInfoSync();
  153. let navigationBarHeight=88,tabHei=120;
  154. let tempHei=res.windowHeight-uni.upx2px(navigationBarHeight+tabHei);
  155. console.log("qxj tempHei:"+tempHei);
  156. this.pageHei=tempHei+"px";
  157. this.checkUser();
  158. let that=this;
  159. uni.$on('reachBottom', (data) => {
  160. if(!that.isLastPage){
  161. that.mescroll.triggerUpScroll();
  162. }
  163. });
  164. // this.txtPing = this.$refs["txtPing"];
  165. // uni.onKeyboardHeightChange(this.boardHeightChange);
  166. } catch (e) {
  167. }
  168. },
  169. onLoad(options) {
  170. //this.refreshPage();
  171. this.txtPing = this.$refs["txtPing"];
  172. uni.onKeyboardHeightChange(this.boardHeightChange);
  173. },
  174. onUnload: function() {
  175. uni.offKeyboardHeightChange(this.boardHeightChange);
  176. },
  177. methods: {
  178. downCallback() {
  179. // 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  180. this.mescroll.resetUpScroll(true);
  181. },
  182. upCallback(page) {
  183. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  184. const params={"videoId":this.videoId};
  185. //uni.showLoading({title:""});
  186. getComments(params,page.num).then(res => {
  187. //uni.hideLoading();
  188. if(res.code==200){
  189. setTimeout(()=>{
  190. this.mescroll.endByPage(res.data.list.length, res.data.pages);
  191. this.isLastPage=res.data.isLastPage;
  192. if(this.isLastPage){
  193. this.mescroll.showNoMore()
  194. }
  195. if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
  196. let dataList=res.data.list;
  197. dataList.forEach((item, index) => {
  198. if(item.replyCount>0){
  199. item.showReplyBtn=true;
  200. item.isLastReplyPage=false;
  201. }else{
  202. item.showReplyBtn=false;
  203. item.isLastReplyPage=true;
  204. }
  205. item.rpyPageNum=1;
  206. });
  207. this.dataList=this.dataList.concat(dataList); //追加新数据
  208. },100);
  209. }
  210. },
  211. rej => {}
  212. ).catch(()=>{
  213. //联网失败, 结束加载
  214. this.mescroll.endErr();
  215. });
  216. },
  217. refreshPage(){
  218. //this.mescroll.hideTopBtn();
  219. this.mescroll.resetUpScroll();
  220. },
  221. tapCommentType(type){
  222. this.sortType=type;
  223. this.refreshPage();
  224. },
  225. doLike(item){
  226. if(!this.$checkToken()){
  227. this.$showLoginPage();
  228. return;
  229. }
  230. const params={"commentId":item.commentId};
  231. uni.showLoading({title:""});
  232. doLikeComment(params).then(res => {
  233. uni.hideLoading();
  234. if(res.code==200){
  235. if(item.liked==0){
  236. item.likes+=1;
  237. item.liked=1;
  238. }else{
  239. item.likes-=1;
  240. item.liked=0;
  241. }
  242. this.dataList[index]=item;
  243. this.$forceUpdate();
  244. uni.showToast({title: '操作成功',icon: 'none',position:'bottom'});
  245. }else{
  246. uni.showToast({title: res.msg,icon: 'none'});
  247. }
  248. },
  249. rej => {}
  250. );
  251. },
  252. doReplyLike(item){
  253. if(!this.$checkToken()){
  254. this.$showLoginPage();
  255. return;
  256. }
  257. const params={"commentId":item.commentId};
  258. uni.showLoading({title:""});
  259. doLikeComment(params).then(res => {
  260. uni.hideLoading();
  261. if(res.code==200){
  262. if(item.liked==0){
  263. item.likes+=1;
  264. item.liked=1;
  265. }else{
  266. item.likes-=1;
  267. item.liked=0;
  268. }
  269. // this.dataList[index]=item;
  270. // this.$forceUpdate();
  271. uni.showToast({title: '操作成功',icon: 'none',position:'bottom'});
  272. }else{
  273. uni.showToast({title: res.msg,icon: 'none'});
  274. }
  275. },
  276. rej => {}
  277. );
  278. },
  279. replayClick(item,index){
  280. const params={"videoId":this.videoId,"parentId":item.commentId};
  281. uni.showLoading({title:""});
  282. getReplies(params,item.rpyPageNum).then(res => {
  283. uni.hideLoading();
  284. if(res.code==200){
  285. if(item.rpyPageNum == 1) item.replyList = []; //如果是第一页需手动制空列表
  286. item.replyList=item.replyList.concat(res.data.list); //追加新数据
  287. if(res.data.isLastPage){
  288. item.showReplyBtn=false;
  289. item.isLastReplyPage=true;
  290. }else{
  291. item.rpyPageNum+=1;
  292. item.showReplyBtn=true;
  293. item.isLastReplyPage=false;
  294. }
  295. this.dataList[index]=item;
  296. this.$forceUpdate();
  297. }
  298. },
  299. rej => {}
  300. ).catch(()=>{
  301. //联网失败, 结束加载
  302. this.refreshing = false;
  303. this.refreshText = '加载完成',
  304. this.reqDataCode=-1;
  305. });
  306. },
  307. /*打开回复弹框*/
  308. openReplyPop(item){
  309. this.rPlaceholder="回复"+item.nickName;
  310. this.$refs.popup.open("bottom")
  311. this.replyParentId=item.commentId;
  312. this.$nextTick(()=>{
  313. this.replyContent='';
  314. this.isRInputFocus=true;
  315. });
  316. },
  317. //点击评论发送按钮
  318. commentSend(){
  319. this.replyParentId=null;
  320. if(this.$isEmpty(this.pingContent)){
  321. uni.showToast({title: '评论内容不能为空',icon: 'none',position:'bottom'});
  322. return;
  323. }
  324. if(!this.$checkToken()){
  325. this.$showLoginPage();
  326. return;
  327. }
  328. let params={"videoId":this.videoId,"content":this.pingContent};
  329. this.postComment(params);
  330. },
  331. //点击回复发送按钮
  332. replySend(){
  333. if(this.$isEmpty(this.replyContent)){
  334. uni.showToast({title: '回复内容不能为空',icon: 'none',position:'bottom'});
  335. return;
  336. }
  337. if(!this.$checkToken()){
  338. this.$showLoginPage();
  339. return;
  340. }
  341. let params={"videoId":this.videoId,"content":this.replyContent,"parentId":this.replyParentId};
  342. this.postComment(params);
  343. },
  344. //提交评论请求
  345. postComment(params){
  346. let that=this;
  347. uni.showLoading({title:""});
  348. addComment(params).then(res => {
  349. uni.hideLoading();
  350. if(res.code==200){
  351. this.pingContent="";
  352. this.replyContent="";
  353. this.sendNotify(this.totalNum++);
  354. if(!this.replyParentId){
  355. uni.showToast({title: '添加评论成功',icon: 'none',position:'bottom'});
  356. }else{
  357. uni.showToast({title: '添加回复成功',icon: 'none',position:'bottom'});
  358. }
  359. }else{
  360. uni.showToast({title: res.msg,icon: 'none'});
  361. }
  362. this.placeholder="发布一条友善的评论";
  363. this.pingContent='';
  364. this.refreshPage();
  365. },
  366. rej => {}
  367. );
  368. },
  369. delComment(item,type){
  370. if(!this.$checkToken()){
  371. this.$showLoginPage();
  372. return;
  373. }
  374. let that = this;
  375. uni.showModal({
  376. title: '系统提示',
  377. content: '确定删除吗',
  378. success: function (res) {
  379. if (res.confirm) {
  380. console.log("qxj confirm");
  381. that.delCommentAct(item,type);
  382. } else if (res.cancel) {
  383. }
  384. }
  385. });
  386. },
  387. delCommentAct(item,type){
  388. this.delCommentId=item.commentId;
  389. let params={"commentId":this.delCommentId,"videoId":this.videoId};
  390. if(type==1){
  391. params["parentId"]=item.parentId;
  392. }
  393. this.delCommentRequest(params);
  394. },
  395. delCommentRequest(params){
  396. let that=this;
  397. uni.showLoading({title:""});
  398. deleteComment(params).then(res => {
  399. uni.hideLoading();
  400. if(res.code==200){
  401. uni.showToast({title: '操作成功',icon: 'none'});
  402. this.sendNotify(this.totalNum-1);
  403. setTimeout(function(){
  404. that.refreshPage();
  405. },1000)
  406. }else{
  407. uni.showToast({title: res.msg,icon: 'none'});
  408. }
  409. },
  410. rej => {}
  411. );
  412. },
  413. isMySend(item){
  414. if(this.myUserInfo!=null && this.myUserInfo.userId==item.userId){
  415. return true;
  416. }
  417. return false;
  418. },
  419. onblur(){
  420. this.isInputFocus=false;
  421. this.placeholder="发布一条友善的评论";
  422. //this.replyParentId=null;
  423. },
  424. onReplyBlur(){
  425. this.isRInputFocus=false;
  426. //this.rPlaceholder="发布一条友善的评论";
  427. },
  428. //点击空布局按钮的回调
  429. emptyClick(){
  430. this.mescroll.resetUpScroll();
  431. },
  432. boardHeightChange:function(res){
  433. console.log('changeHeight', res.height);
  434. //转化为rpx
  435. this.KeyHight = res.height;
  436. },
  437. showBotBar(smsNum){
  438. this.showBoottom=true;
  439. this.totalNum=smsNum;
  440. console.log("qxj showBotBar smsNum:"+smsNum);
  441. this.checkUser();
  442. setTimeout(()=>{
  443. this.refreshPage();
  444. },500);
  445. },
  446. hideBotBar(){
  447. this.showBoottom=false;
  448. },
  449. sendNotify(num){
  450. uni.$emit('refreshTitle',num);
  451. },
  452. checkUser(){
  453. if(this.$checkToken()){
  454. let useInfo=uni.getStorageSync('userInfo');
  455. if(!!useInfo && useInfo!=null){
  456. this.myUserInfo=JSON.parse(useInfo);
  457. }
  458. }
  459. },
  460. }
  461. }
  462. </script>
  463. <style scoped>
  464. page {
  465. background-color: white;
  466. }
  467. .es-view-w-x1{
  468. padding-left: 20rpx;
  469. padding-right: 20rpx;
  470. position: relative;
  471. }
  472. .content1{
  473. position: relative;
  474. }
  475. .topbox{
  476. position: absolute;
  477. left: 10px;
  478. top: -30px;
  479. right: 20px;
  480. height: 40px;
  481. display: flex;
  482. }
  483. .banner {
  484. height: 430rpx;
  485. }
  486. .es-icon-course-bg {
  487. background-image: url(/static/images/course/bg.png);
  488. }
  489. .es-icon-course-icon-1 {
  490. background-image: url(/static/images/course/icon-1.png);
  491. }
  492. .es-icon-course-icon-2 {
  493. background-image: url(/static/images/course/icon-2.png);
  494. }
  495. .es-icon-course-icon-3 {
  496. background-image: url(/static/images/course/icon-3.png);
  497. }
  498. .es-icon-course-close {
  499. background-image: url(/static/images/course/close.png);
  500. }
  501. .es-icon-course-info {
  502. background-image: url(/static/images/course/info.png);
  503. }
  504. .es-icon-course-bg2 {
  505. background-image: url(/static/images/course/bg2.png);
  506. }
  507. .es-icon-course-bg3 {
  508. background-image: url(/static/images/course/bg3.png);
  509. }
  510. .es-icon-course-comment {
  511. background-image: url(/static/images/hall/pingjia_icon.png);
  512. }
  513. .es-icon-course-nav-bg,
  514. .nav {
  515. background-image: url(/static/images/course/nav-bg.png);
  516. }
  517. .es-icon-course-nav-bg-ac,
  518. .nav.ac {
  519. background-image: url(/static/images/course/nav-bg-ac.png);
  520. }
  521. .es-icon-course-point {
  522. background-image: url(/static/images/hall/more_icon16.png);
  523. }
  524. .es-icon-course-share {
  525. background-image: url(/static/images/course/share.png);
  526. }
  527. .es-icon-course-like2 {
  528. background-image: url(/static/images/hall/dianzan_icon.png);
  529. }
  530. .es-icon-course-like2-ac {
  531. background-image: url(/static/images/hall/dianzan_on_icon.png);
  532. }
  533. .item {
  534. width: calc(33.33% - 14rpx);
  535. }
  536. .nav {
  537. width: 216rpx;
  538. height: 60rpx;
  539. }
  540. .comment-reply-item {
  541. border-bottom: 1px #fff solid;
  542. }
  543. .es-ipt input {
  544. padding-left: 43rpx;
  545. }
  546. .es-ipt,
  547. .es-ipt input {
  548. background-color: inherit;
  549. }
  550. textarea{
  551. width: 100%;
  552. font-size: 28upx;
  553. font-family: PingFang SC;
  554. font-weight: 500;
  555. height: 140upx;
  556. line-height: 1.6;
  557. text-indent: 0.5em;
  558. color: #666666;
  559. }
  560. .place-hold{
  561. font-size: 28upx;
  562. font-family: PingFang SC;
  563. font-weight: 500;
  564. color: #999999;
  565. padding:10rpx 0rpx;
  566. }
  567. </style>