comment.vue 18 KB

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