comment.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <template>
  2. <view>
  3. <view class="es es-ac es-mt-25 es-pb-30 es-fs-22 es-c" style="border-bottom: 1px #FAFAFA solid;">
  4. <view class="es-on-act nav es-icon-auto es es-ac es-pc" :class="sortType==1?'ac':''" @tap="tapCommentType(1)">
  5. <view class="es-icon-20 es-icon-course-icon-2"></view>
  6. <view class="es-ml-19" :class="1?'es-fw-600':''">热度</view>
  7. </view>
  8. <view class="es-on-act nav es-icon-auto es es-ac es-pc es-ml-14" :class="sortType==2?'ac':''" @tap="tapCommentType(2)">
  9. <view class="es-icon-20 es-icon-course-icon-2"></view>
  10. <view class="es-ml-19" :class="0?'es-fw-600':''">时间</view>
  11. </view>
  12. </view>
  13. <mescroll-body @init="mescrollInit" top="0" :down="downOption" :up="upOption" @down="downCallback" @up="upCallback" @emptyclick="emptyClick">
  14. <view class="es-bc-white es-br-20">
  15. <view class="es-view-w-x1 es-mt-25">
  16. <view v-for="(item, index) in dataList" :key="index" class="es es-mt-20">
  17. <view class="es-icon-80 es-br">
  18. <image :src="$isEmpty(item.avatar)?defHeadImg:item.avatar"></image>
  19. </view>
  20. <view class="es-f1 es-ml-21">
  21. <view class="es-fs-28 es-fw">{{item.nickName || '暂无昵称'}}</view>
  22. <view class="es-c-99 es-fs-22 es-mt-4">{{ utils.formatDate(item.createTime) }}</view>
  23. <view class="es-fs-26 es-fw-500 es-pt-24 es-pb-25">
  24. {{item.content}}
  25. </view>
  26. <view class="es es-c-99">
  27. <view class="es es-ac" @tap="doLike(item)">
  28. <view class="es-icon-28" :class="item.isLike?'es-icon-course-like2-ac':'es-icon-course-like2'" ></view>
  29. <view class="es-ml-11 es-fs-26">{{item.likes}}</view>
  30. </view>
  31. <view class="es es-ac es-ml-23" @tap="openReplyPop(item)">
  32. <view class="es-icon-28 es-icon-course-comment"></view>
  33. <view class="es-ml-11 es-fs-26">{{item.replyCount}}</view>
  34. </view>
  35. <view class="es-f1"></view>
  36. <view class="es es-ac es-pc es-icon-33" v-if="isMySend(item)" @tap="delComment(item)">
  37. <image src="/static/images/hall/more_icon16.png" class="es-w-32 es-h-32"></image>
  38. </view>
  39. </view>
  40. <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;">
  41. <view class="es es-pt-20 es-pb-20" v-for="(cItem,idx) in item.replyList" :key="idx">
  42. <view class="es-icon-60 es-br">
  43. <image :src="$isEmpty(cItem.avatar)?defHeadImg:cItem.avatar"></image>
  44. </view>
  45. <view class="es-f1 es-ml-11">
  46. <view class="es-fs-24 es-fw-600">{{cItem.nickName || '暂无昵称'}}</view>
  47. <view class="es-fs-22 es-c-99 es-mt-10 es-mb-10">{{ utils.formatDate(cItem.createTime) }}</view>
  48. <view class="es-fs-24 es-fw-500 es-pt-8 es-pb-14">{{cItem.content}}</view>
  49. <view class="es es-c-99">
  50. <view class="es es-ac" @tap="doReplyLike(cItem)">
  51. <view class="es-icon-28" :class="cItem.liked?'es-icon-course-like2-ac':'es-icon-course-like2'" ></view>
  52. <view class="es-ml-11 es-fs-26">{{cItem.likes}}</view>
  53. </view>
  54. <view class="es es-ac es-pc es-icon-33" v-if="isMySend(cItem)" @tap="delComment(cItem)">
  55. <image src="/static/images/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. </view>
  95. </template>
  96. <script>
  97. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  98. import { getCourseById,getCommentList,addComment,updateComment,commentDoLike,deleteComment } from '@/api/course'
  99. export default {
  100. mixins: [MescrollMixin],
  101. props: {
  102. courseId: {
  103. type: [String, Number],
  104. default: 0
  105. }
  106. },
  107. data() {
  108. return {
  109. pingContent: '',
  110. KeyHight:0,
  111. cateId:5,
  112. courseId1:0,
  113. totalNum:0,
  114. courseData:{},
  115. pageHei:400,
  116. downOption: {
  117. auto: false ,// 不自动加载 (mixin已处理第一个tab触发downCallback)
  118. use:true
  119. },
  120. upOption: {
  121. auto: false, // 不自动加载
  122. page: {
  123. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  124. size: 10 // 每页数据的数量
  125. },
  126. empty:{
  127. tip: '~ 暂无数据 ~', // 提示
  128. btnText: '去看看',
  129. icon:"/static/image/nodata.png"
  130. },
  131. textNoMore:"已经到底了",
  132. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  133. use:true,
  134. },
  135. pingType:1,//1:评论 2:回复
  136. dataList: [], //列表数据
  137. replyParentId:null,
  138. txtPing:null,
  139. sortType:1,
  140. isInputFocus:false,
  141. showBoottom:false,
  142. placeholder:"发布一条友善的评论",
  143. defHeadImg:"/static/images/hall/my_heads_icon.png",
  144. myUserInfo:{userId:0},
  145. rpyPageNum:0,
  146. replyContent:"",
  147. rPlaceholder:"",
  148. delCommentId:null,
  149. isLastPage:false,
  150. isRInputFocus:false,
  151. }
  152. },
  153. mounted() {
  154. try {
  155. console.log("qxj comment mounted");
  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. } catch (e) {
  169. }
  170. },
  171. onLoad(options) {
  172. console.log("qxj comment onLoad");
  173. this.txtPing = this.$refs["txtPing"];
  174. uni.onKeyboardHeightChange(this.boardHeightChange);
  175. },
  176. onUnload: function() {
  177. uni.offKeyboardHeightChange(this.boardHeightChange);
  178. },
  179. methods: {
  180. onReplyBlur(){
  181. this.isRInputFocus=false;
  182. //this.rPlaceholder="发布一条友善的评论";
  183. },
  184. getCourseInfo(){
  185. getCourseById(this.courseId).then(res => {
  186. if(res.code==200){
  187. this.courseData=res.data;
  188. }
  189. },
  190. rej => {}
  191. );
  192. },
  193. upCallback(page) {
  194. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  195. const params={"courseId":this.courseId,"sortType":this.sortType};
  196. //uni.showLoading({title:""});
  197. getCommentList(params,page.num).then(res => {
  198. //uni.hideLoading();
  199. if(res.code==200){
  200. setTimeout(()=>{
  201. this.mescroll.endByPage(res.data.list.length, res.data.pages);
  202. this.isLastPage=res.data.isLastPage;
  203. if(this.isLastPage){
  204. this.mescroll.showNoMore()
  205. }
  206. if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
  207. let dataList=res.data.list;
  208. // dataList.forEach((item, index) => {
  209. // if(item.replyCount>0){
  210. // item.showReplyBtn=true;
  211. // item.isLastReplyPage=false;
  212. // }else{
  213. // item.showReplyBtn=false;
  214. // item.isLastReplyPage=true;
  215. // }
  216. // item.rpyPageNum=1;
  217. // });
  218. this.dataList=this.dataList.concat(dataList); //追加新数据
  219. },100);
  220. }
  221. },
  222. rej => {}
  223. ).catch(()=>{
  224. //联网失败, 结束加载
  225. this.mescroll.endErr();
  226. });
  227. },
  228. refreshPage(){
  229. this.mescroll.hideTopBtn();
  230. this.mescroll.resetUpScroll();
  231. },
  232. tapCommentType(type){
  233. this.sortType=type;
  234. this.refreshPage();
  235. },
  236. isMySend(item){
  237. if(this.myUserInfo!=null && this.myUserInfo.userId==item.userId){
  238. return true;
  239. }
  240. return false;
  241. },
  242. doReply(item){
  243. this.replyParentId=item.commentId;
  244. this.pingType=2;
  245. this.placeholder="回复"+item.nickName;
  246. this.$nextTick(()=>{
  247. this.pingContent='';
  248. this.isInputFocus=true;
  249. });
  250. // this.txtPing.placeholder="回复";
  251. },
  252. replayClick(item,index){
  253. item.expand=true;
  254. this.dataList[index]=item;
  255. this.$forceUpdate(); // 如果你需要强制刷新,可以调用 $forceUpdate()
  256. },
  257. onblur(){
  258. this.isInputFocus=false;
  259. this.placeholder="发布一条友善的评论";
  260. },
  261. doLike(item){
  262. if(!this.$checkToken()){
  263. this.$showLoginPage();
  264. return;
  265. }
  266. const params={"commentId":item.commentId};
  267. uni.showLoading({title:""});
  268. commentDoLike(params).then(res => {
  269. uni.hideLoading();
  270. if(res.code==200){
  271. uni.showToast({title: '操作成功',icon: 'none'});
  272. }else{
  273. uni.showToast({title: res.msg,icon: 'none'});
  274. }
  275. this.refreshPage();
  276. },
  277. rej => {}
  278. );
  279. },
  280. doReplyLike(item){
  281. if(!this.$checkToken()){
  282. this.$showLoginPage();
  283. return;
  284. }
  285. const params={"commentId":item.commentId};
  286. uni.showLoading({title:""});
  287. commentDoLike(params).then(res => {
  288. uni.hideLoading();
  289. if(res.code==200){
  290. if(item.liked==0){
  291. item.likes+=1;
  292. item.liked=1;
  293. }else{
  294. item.likes-=1;
  295. item.liked=0;
  296. }
  297. // this.dataList[index]=item;
  298. // this.$forceUpdate();
  299. uni.showToast({title: '操作成功',icon: 'none',position:'bottom'});
  300. }else{
  301. uni.showToast({title: res.msg,icon: 'none'});
  302. }
  303. },
  304. rej => {}
  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={"courseId":this.courseId,"content":this.pingContent,"type":this.pingType};
  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={"courseId":this.courseId,"content":this.replyContent,"parentId":this.replyParentId,"type":this.pingType};
  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. uni.$emit('refreshTitle',that.totalNum++);
  352. this.pingContent="";
  353. this.replyContent="";
  354. this.sendNotify(this.totalNum++);
  355. if(!this.replyParentId){
  356. uni.showToast({title: '添加评论成功',icon: 'none',position:'bottom'});
  357. }else{
  358. uni.showToast({title: '添加回复成功',icon: 'none',position:'bottom'});
  359. }
  360. }else{
  361. uni.showToast({title: res.msg,icon: 'none'});
  362. }
  363. this.placeholder="发布一条友善的评论";
  364. this.pingType=1;
  365. this.pingContent='';
  366. this.refreshPage();
  367. },
  368. rej => {}
  369. );
  370. },
  371. delComment(item){
  372. if(!this.$checkToken()){
  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);
  384. } else if (res.cancel) {
  385. }
  386. }
  387. });
  388. },
  389. delCommentAct(item){
  390. this.delCommentId=item.commentId;
  391. this.delCommentRequest(this.delCommentId);
  392. },
  393. delCommentRequest(params){
  394. let that=this;
  395. uni.showLoading({title:""});
  396. deleteComment(params).then(res => {
  397. uni.hideLoading();
  398. if(res.code==200){
  399. uni.showToast({title: '操作成功',icon: 'none'});
  400. this.sendNotify(this.totalNum-1);
  401. setTimeout(function(){
  402. that.refreshPage();
  403. },1000)
  404. }else{
  405. uni.showToast({title: res.msg,icon: 'none'});
  406. }
  407. },
  408. rej => {}
  409. );
  410. },
  411. //点击空布局按钮的回调
  412. emptyClick(){
  413. this.mescroll.resetUpScroll(true);
  414. },
  415. boardHeightChange:function(res){
  416. console.log('changeHeight', res.height);
  417. //转化为rpx
  418. this.KeyHight = res.height;
  419. },
  420. showBotBar(smsNum){
  421. this.showBoottom=true;
  422. this.totalNum=smsNum;
  423. console.log("qxj showBotBar smsNum:"+smsNum);
  424. this.checkUser();
  425. setTimeout(()=>{
  426. this.refreshPage();
  427. },500);
  428. },
  429. hideBotBar(){
  430. this.showBoottom=false;
  431. },
  432. sendNotify(num){
  433. uni.$emit('refreshTitle',num);
  434. },
  435. checkUser(){
  436. if(this.$checkToken()){
  437. let useInfo=uni.getStorageSync('userInfo');
  438. if(!!useInfo && useInfo!=null){
  439. this.myUserInfo=JSON.parse(useInfo);
  440. }
  441. }
  442. },
  443. }
  444. }
  445. </script>
  446. <style>
  447. page {
  448. background-color: white;
  449. }
  450. .es-view-w-x1{
  451. padding-left: 20rpx;
  452. padding-right: 20rpx;
  453. position: relative;
  454. }
  455. .banner {
  456. height: 430rpx;
  457. }
  458. .es-icon-course-bg {
  459. background-image: url(/static/images/course/bg.png);
  460. }
  461. .es-icon-course-icon-1 {
  462. background-image: url(/static/images/course/icon-1.png);
  463. }
  464. .es-icon-course-icon-2 {
  465. background-image: url(/static/images/course/icon-2.png);
  466. }
  467. .es-icon-course-icon-3 {
  468. background-image: url(/static/images/course/icon-3.png);
  469. }
  470. .es-icon-course-close {
  471. background-image: url(/static/images/course/close.png);
  472. }
  473. .es-icon-course-info {
  474. background-image: url(/static/images/course/info.png);
  475. }
  476. .es-icon-course-bg2 {
  477. background-image: url(/static/images/course/bg2.png);
  478. }
  479. .es-icon-course-bg3 {
  480. background-image: url(/static/images/course/bg3.png);
  481. }
  482. .es-icon-course-comment {
  483. background-image: url(/static/images/hall/pingjia_icon.png);
  484. }
  485. .es-icon-course-nav-bg,
  486. .nav {
  487. background-image: url(/static/images/course/nav-bg.png);
  488. }
  489. .es-icon-course-nav-bg-ac,
  490. .nav.ac {
  491. background-image: url(/static/images/course/nav-bg-ac.png);
  492. }
  493. .es-icon-course-point {
  494. background-image: url(/static/images/hall/more_icon16.png);
  495. }
  496. .es-icon-course-share {
  497. background-image: url(/static/images/course/share.png);
  498. }
  499. .es-icon-course-like2 {
  500. background-image: url(/static/images/hall/dianzan_icon.png);
  501. }
  502. .es-icon-course-like2-ac {
  503. background-image: url(/static/images/hall/dianzan_on_icon.png);
  504. }
  505. .item {
  506. width: calc(33.33% - 14rpx);
  507. }
  508. .nav {
  509. width: 216rpx;
  510. height: 60rpx;
  511. }
  512. .es-ipt input {
  513. padding-left: 43rpx;
  514. }
  515. .es-ipt,.es-ipt input {
  516. }
  517. textarea{
  518. width: 100%;
  519. font-size: 28upx;
  520. font-family: PingFang SC;
  521. font-weight: 500;
  522. height: 140upx;
  523. line-height: 1.6;
  524. text-indent: 0.5em;
  525. color: #666666;
  526. }
  527. .place-hold{
  528. font-size: 28upx;
  529. font-family: PingFang SC;
  530. font-weight: 500;
  531. color: #999999;
  532. padding:10rpx 0rpx;
  533. }
  534. </style>