comment.vue 16 KB

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