comment.vue 18 KB

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