commentN.nvue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <template>
  2. <view class="es content es-bc-white" style="position:relative;flex-direction: column;" @touchmove.stop>
  3. <view class="comtentBox es-bc-white es-pb-40 es-br-20 flex" >
  4. <view class="es es-h-60" >
  5. <view class="es es-ac es-view-w-x es-h-44 es-mt-25" >
  6. <image class="es-w-35 es-h-31" src="/static/images/course/comment2.png"></image>
  7. <text class="es-ml-20 es-fs-28 es-fw-600 es-f1">评论</text>
  8. <text class="es-ml-1 es-fs-30 es-c-99">({{totalNum}})</text>
  9. </view>
  10. <image @tap="closePopup()" style="position: absolute;right:30rpx;top:20rpx" class="es-w-40 es-h-40" src="/static/images/close40.png"></image>
  11. </view>
  12. <view class="es-view-w-x es-mt-15" >
  13. <view class="es es-ac es-mt-25 es-c" style="border-bottom: 1px #FAFAFA solid;">
  14. <view class="es-on-act nav es-icon-auto es es-ac es-pc x-c es-br-10" :class="sortType==1?'ac':'br'" @tap="tapCommentType(1)">
  15. <image src="/static/images/course/icon-2.png" class="es-icon-20"></image>
  16. <text class="es-ml-19 es-fs-28 es-c" :class="1?'es-fw-600':''">热度</text>
  17. </view>
  18. <view class="es-on-act nav es-icon-auto es es-ac es-pc es-br-10 es-ml-14" :class="sortType==2?'ac':'br'" @tap="tapCommentType(2)">
  19. <image src="/static/images/course/icon-2.png" class="es-icon-20"></image>
  20. <text class="es-ml-19 es-fs-28 es-c" :class="0?'es-fw-600':''">时间</text>
  21. </view>
  22. </view>
  23. <list loadmoreoffset="100" @loadmore="loadmore" :style="{'height':listHei+'px'}" >
  24. <refresh @pullingdown='onpullingdown' @refresh="onrefresh" :display=" refreshing ? 'show' : 'hide' " class="refresh x-c ">
  25. <loading-indicator style="width: 22px;height: 22px;color:#999;"></loading-indicator>
  26. <text class="es-fs-32 es-ml-8">{{refreshText}}</text>
  27. </refresh>
  28. <cell v-for="(item, index) in dataList" :key="index">
  29. <view class="es es-mt-30" >
  30. <image class="es-icon-80 es-br" :src="isEmpty(item.avatar)?defHeadImg:item.avatar"></image>
  31. <view class="es-f1 es-ml-21" style="display:flex;flex:1;">
  32. <text class="es-fs-28 es-fw">{{ isEmpty(item.nickName)?"暂无昵称":item.nickName }}</text>
  33. <text class="es-c-99 es-fs-22 es-mt-4">{{ formatDate(item.createTime) }}</text>
  34. <text class="es-fs-26 es-fw-500 es-pt-24 es-pb-25">{{item.content}}</text>
  35. <view class="es es-c-99 es-pb-10">
  36. <view class="es es-ac" @tap="doLike(item,index)">
  37. <image class="es-icon-28" :src="item.isLike?'/static/images/course/dianzan_on_icon.png':'/static/images/course/dianzan_icon.png'"></image>
  38. <text class="es-ml-11 es-fs-26">{{item.likes}}</text>
  39. </view>
  40. <view class="es es-ac es-ml-23" @tap="doReply(item)">
  41. <image class="es-icon-28" src="/static/images/course/pingjia_icon.png"></image>
  42. <text class="es-ml-11 es-fs-26">{{item.replyCount}}</text>
  43. </view>
  44. <view class="es-f1"></view>
  45. <view class="es es-ac es-pc es-icon-33" style="position:absolute;right:20rpx;" v-if="isMySend(item)" @tap="delComment(item)">
  46. <image src="/static/images/course/more_icon16.png" class="es-w-32 es-h-32"></image>
  47. </view>
  48. </view>
  49. <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"
  50. style="background-color: #F5F7FA;">
  51. <view class="es es-pt-20 es-pb-20" :class="cIndex<item.replyList.length-1?'comment-reply-item':''" v-for="(cItem,cIndex) in item.replyList" :key="cIndex">
  52. <image class="es-icon-60 es-br" :src="isEmpty(cItem.avatar)?defHeadImg:cItem.avatar"></image>
  53. <view class="es-f1 es-ml-11" style="display:flex;flex:1;">
  54. <text class="es-fs-24 es-fw-600">{{cItem.nickName || '暂无昵称'}}</text>
  55. <text class="es-fs-22 es-c-99 es-mt-10 es-mb-10">{{ formatDate(cItem.createTime) }}</text>
  56. <text class="es-fs-24 es-fw-500 es-pb-20">{{cItem.content}}</text>
  57. <view class="es-f1 es-c-99">
  58. <view class="es es-ac" @tap="doLike(cItem,index,cIndex,1)">
  59. <image class="es-icon-28" :src="cItem.isLike?'/static/images/course/dianzan_on_icon.png':'/static/images/course/dianzan_icon.png'"></image>
  60. <text class="es-ml-11 es-fs-26">{{cItem.likes}}</text>
  61. </view>
  62. <view class="es es-ac es-pc es-icon-33" style="position:absolute;right:0" v-if="isMySend(cItem)" @tap="delComment(cItem)">
  63. <image src="/static/images/course/more_icon16.png" class="es-w-32 es-h-32"></image>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view @tap="replayClick(item,index)" v-if="item.replyList && item.replyList.length>3" class="es es-ac es-mt-20 es-pb-20">
  69. <view class="es-f1"></view>
  70. <text v-if="item.expand==undefined" class="es es-ac es-fs-22 es es-ac es-pc es-view-w-x es-pt-10 es-pb-10 es-br es-brc es-c">
  71. {{item.replyList.length-3}}条回复>
  72. </text>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </cell>
  78. <cell v-if="showLoadMore || dataList.length > 4">
  79. <view class="loading-more">
  80. <text class="loading-more-text">{{loadMoreText}}</text>
  81. </view>
  82. </cell>
  83. <cell>
  84. <view v-if="totalNum==0 && reqDataCode!=0" class="y-f" style="height: 300px;padding-top: 200rpx;" >
  85. <image @tap="refreshPage()" class="es-w-124 es-h-80" style="width:187rpx;height:120rpx;" src="/static/image/nodata.png"></image>
  86. <text @tap="refreshPage()" class="es-c-33">{{reqDataCode==1?'暂无数据':'请求超时'}}</text>
  87. </view>
  88. </cell>
  89. </list>
  90. </view>
  91. </view>
  92. <view :style="'height:'+(KeyHight)+'px'" style="background-color: red;" v-if="KeyHight>0"></view>
  93. <view class="es-h-120 es-auto-bottom" v-else></view>
  94. <cover-view class="fix-bottom es-b-t" >
  95. <view class="es-h-120 es-view-w-x es es-ac flex" >
  96. <view class="es-f1 es-br es-ipt flex ac es-h-70 es-pl-20 es-pr-20 es-pt-10" >
  97. <input style="width:100%;font-size: 28rpx;" ref="txtPing" v-model="pingContent" :focus="isInputFocus"
  98. @blur="onblur" :placeholder="placeholder" placeholder-class="es-c" />
  99. </view>
  100. <text class="es-w-120 es-h-60 es-fs-30 es-fw-600 es-ml-20 es-c " style="text-align: center;line-height: 60rpx;" :adjust-position="false"
  101. :always-system="true" @tap="doSend">发布</text>
  102. </view>
  103. <view class="es-auto-bottom" v-if="!KeyHight"></view>
  104. </cover-view>
  105. </view>
  106. </template>
  107. <script>
  108. import { getCourseById,getCommentList,addComment,updateComment,commentDoLike,deleteComment } from '@/api/course'
  109. import { isLogin,isEmpty } from '@/utils/common'
  110. import { showLoginPage } from '@/utils/login'
  111. import dayjs from 'dayjs';
  112. export default {
  113. data() {
  114. return {
  115. pingContent: '',
  116. KeyHight:0,
  117. cateId:5,
  118. courseId:0,
  119. totalNum:0,
  120. courseData:{},
  121. pageHei:400,
  122. downOption: {
  123. auto: false ,// 不自动加载 (mixin已处理第一个tab触发downCallback)
  124. use:true
  125. },
  126. upOption: {
  127. use:true,
  128. auto: false, // 不自动加载
  129. page: {
  130. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  131. size: 10 // 每页数据的数量
  132. },
  133. empty:{
  134. tip: '~ 暂无数据 ~', // 提示
  135. btnText: '去看看'
  136. },
  137. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  138. },
  139. pingType:1,//1:评论 2:回复
  140. dataList: [], //列表数据
  141. replyParentId:null,
  142. txtPing:null,
  143. sortType:1,
  144. isInputFocus:false,
  145. showBoottom:true,
  146. placeholder:"发布一条友善的评论",
  147. defHeadImg:"/static/images/hall/my_heads_icon.png",
  148. myUserInfo:{userId:0},
  149. delCommentId:null,
  150. mescroll:null,
  151. adpid: '',
  152. loadMoreText:"加载中...",
  153. showLoadMore:false,
  154. isLastPage:false,
  155. refreshing: false,
  156. refreshText: '下拉刷新',
  157. pageNum:1,
  158. listHei:0,
  159. reqDataCode:0 //1:正常加载 -1 请求超时
  160. }
  161. },
  162. mounted() {
  163. try {
  164. console.log("qxj commentN mounted");
  165. let that=this;
  166. this.subNVue= uni.getSubNVueById('commentN');
  167. uni.$on('comment', (data) => {
  168. that.videoId=data.videoId;
  169. that.courseId=data.courseId;
  170. that.getCourseInfo();
  171. that.upCallback();
  172. });
  173. const res = uni.getSystemInfoSync();
  174. // this.listHei=res.windowHeight*1;
  175. // this.listHei=uni.upx2px(1150 - 240);
  176. this.listHei= res.windowHeight*0.85 - uni.upx2px(324);
  177. this.txtPing = this.$refs["txtPing"];
  178. uni.onKeyboardHeightChange(this.boardHeightChange);
  179. if(this.isLogin()){
  180. let useInfo=uni.getStorageSync('userInfo');
  181. if(!!useInfo && useInfo!=null){
  182. this.myUserInfo=JSON.parse(useInfo);
  183. }
  184. }
  185. } catch (e) {
  186. }
  187. },
  188. onUnload() {
  189. console.log("qxj commentN onUnload");
  190. uni.offKeyboardHeightChange(this.boardHeightChange);
  191. uni.$off("comment");
  192. },
  193. methods: {
  194. getCourseInfo(){
  195. getCourseById(this.courseId).then(res => {
  196. if(res.code==200){
  197. this.courseData=res.data;
  198. }
  199. },
  200. rej => {}
  201. );
  202. },
  203. onpullingdown(e) {
  204. if (this.refreshing) return;
  205. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  206. this.refreshText = '下拉更新'
  207. } else {
  208. this.refreshText = '释放更新'
  209. }
  210. },
  211. onrefresh(e) {
  212. console.log('onRefreshing...');
  213. this.refreshing = true;
  214. this.pageNum=1;
  215. this.upCallback();
  216. if (this.refreshing) return;
  217. },
  218. loadmore(){
  219. if(this.isLastPage){
  220. return;
  221. }
  222. console.log("loadmore");
  223. this.pageNum++;
  224. this.showLoadMore = true;
  225. setTimeout(() => {
  226. this.upCallback();
  227. }, 300);
  228. },
  229. /*下拉刷新的回调 */
  230. upCallback() {
  231. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  232. const params={"courseId":this.courseId,"sortType":this.sortType};
  233. uni.showLoading({title:""});
  234. getCommentList(params,this.pageNum).then(res => {
  235. uni.hideLoading();
  236. if(res.code==200){
  237. setTimeout(()=>{
  238. //this.mescroll.endByPage(res.data.list.length, res.data.pages);
  239. if(this.pageNum == 1) this.dataList = []; //如果是第一页需手动制空列表
  240. this.dataList=this.dataList.concat(res.data.list); //追加新数据
  241. this.totalNum=res.data.total;
  242. this.reqDataCode=1;
  243. this.refreshing = false;
  244. this.isLastPage=res.data.isLastPage;
  245. if(this.isLastPage){
  246. this.refreshText = '加载完成'
  247. }
  248. if(res.data.isLastPage){
  249. this.loadMoreText = "";
  250. this.showLoadMore=false;
  251. }
  252. },200);
  253. }else{
  254. this.refreshing = false;
  255. this.refreshText = '加载完成';
  256. this.reqDataCode=-1;
  257. }
  258. },
  259. rej => {}
  260. ).catch(()=>{
  261. //联网失败, 结束加载
  262. this.refreshing = false;
  263. this.refreshText = '加载完成';
  264. this.reqDataCode=-1;
  265. });
  266. },
  267. closePopup() {
  268. const subNVue = uni.getSubNVueById('commentN');
  269. subNVue.hide('slide-out-bottom');
  270. },
  271. refreshPage(){
  272. this.pageNum=1;
  273. this.upCallback();
  274. },
  275. tapCommentType(type){
  276. this.sortType=type;
  277. this.refreshPage();
  278. },
  279. isMySend(item){
  280. if(this.myUserInfo!=null && this.myUserInfo.userId==item.userId){
  281. return true;
  282. }
  283. return false;
  284. },
  285. doSend(){
  286. if(this.isEmpty(this.pingContent)){
  287. uni.showToast({title: '评论内容不能为空',icon: 'none'});
  288. return;
  289. }
  290. if(!isLogin()){
  291. showLoginPage();
  292. return;
  293. }
  294. let params={"courseId":this.courseId,"content":this.pingContent,"type":this.pingType};
  295. if(!!this.replyParentId){
  296. params["parentId"]=this.replyParentId;
  297. }
  298. uni.showLoading({title:""});
  299. addComment(params).then(res => {
  300. uni.hideLoading();
  301. if(res.code==200){
  302. uni.showToast({title: '添加评论成功',icon: 'none'});
  303. }else{
  304. uni.showToast({title: res.msg,icon: 'none'});
  305. }
  306. this.placeholder="发布一条友善的评论";
  307. this.pingType=1;
  308. this.pingContent='';
  309. this.refreshPage();
  310. },
  311. rej => {}
  312. );
  313. },
  314. doReply(item){
  315. this.replyParentId=item.commentId;
  316. this.pingType=2;
  317. let placeHolder=this.isEmpty(item.nickName)?"回复":"回复"+item.nickName;
  318. this.placeholder=placeHolder;
  319. this.pingContent='';
  320. //this.isInputFocus=true;
  321. this.$nextTick(()=>{
  322. this.$refs.txtPing.focus();
  323. });
  324. },
  325. replayClick(item,index){
  326. item.expand=true;
  327. this.dataList[index]=item;
  328. this.$forceUpdate(); // 如果你需要强制刷新,可以调用 $forceUpdate()
  329. },
  330. expandReplyAct(item,idx){
  331. return true
  332. },
  333. onblur(){
  334. console.log("qxj onblur");
  335. },
  336. doLike(item,index,childIdx,type){
  337. if(!this.isLogin()){
  338. showLoginPage();
  339. return;
  340. }
  341. const params={"commentId":item.commentId};
  342. uni.showLoading({title:""});
  343. commentDoLike(params).then(res => {
  344. uni.hideLoading();
  345. if(res.code==200){
  346. if(item.isLike==0){
  347. item.likes+=1;
  348. item.isLike=1;
  349. }else{
  350. item.likes=1;
  351. item.isLike=0;
  352. }
  353. // this.dataList[index]=item;
  354. // this.$forceUpdate();
  355. uni.showToast({title: '操作成功',icon: 'none'});
  356. }else{
  357. uni.showToast({title: res.msg,icon: 'none'});
  358. }
  359. },
  360. rej => {}
  361. );
  362. },
  363. delComment(item){
  364. this.delCommentId=item.commentId;
  365. let that = this;
  366. uni.showModal({
  367. title: '系统提示',
  368. content: '确定删除吗',
  369. success: function (res) {
  370. if (res.confirm) {
  371. console.log("qxj confirm");
  372. that.delCommentAct();
  373. } else if (res.cancel) {
  374. console.log("qxj cancel");
  375. }
  376. }
  377. });
  378. },
  379. delCommentAct(){
  380. if(!this.isLogin()){
  381. showLoginPage();
  382. return;
  383. }
  384. uni.showLoading({title:""});
  385. deleteComment(this.delCommentId).then(res => {
  386. uni.hideLoading();
  387. if(res.code==200){
  388. uni.showToast({title: '操作成功',icon: 'none'});
  389. }else{
  390. uni.showToast({title: res.msg,icon: 'none'});
  391. }
  392. this.refreshPage();
  393. },
  394. rej => {}
  395. );
  396. },
  397. boardHeightChange:function(res){
  398. console.log('changeHeight', res.height);
  399. if(res.height==0){
  400. this.placeholder="发布一条友善的评论";
  401. //this.pingContent='';
  402. this.isInputFocus=false;
  403. }else{
  404. this.isInputFocus=true;
  405. }
  406. this.KeyHight = res.height;
  407. },
  408. isLogin() {
  409. let obj=uni.getStorageSync("AppToken");
  410. return !!obj;
  411. },
  412. isEmpty(obj) {
  413. if (typeof obj == "undefined" || obj == null || obj == "") {
  414. return true;
  415. } else {
  416. return false;
  417. }
  418. },
  419. formatDate(dateStr) {
  420. let formatStr = "";
  421. let formatDate;
  422. if(dateStr==null){
  423. return formatStr;
  424. }
  425. let date = dayjs(dateStr,'YYYY-MM-DD HH:mm:ss');
  426. let today = dayjs();
  427. if (date.year() != today.year()) {
  428. formatDate = date.format('YYYY-MM-DD HH:mm');
  429. }
  430. else if (date.month() === today.month()) {
  431. switch (date.date() - today.date()) {
  432. case 0:
  433. formatDate = date.format('今天 HH:mm');
  434. break;
  435. case -1:
  436. formatDate = date.format('昨天 HH:mm');
  437. break;
  438. case 1:
  439. formatDate = date.format('明天 HH:mm');
  440. break;
  441. default:
  442. formatDate = date.format('MM-DD HH:mm');
  443. break;
  444. }
  445. }
  446. else if (date.month() - today.month() === 0 && date.date() === 1) {
  447. formatDate = date.format('明天 HH:mm');
  448. }
  449. else {
  450. formatDate = date.format('MM-DD HH:mm');
  451. }
  452. return formatDate;
  453. }
  454. },
  455. onHide() {
  456. console.log("qxj commentN onHide");
  457. },
  458. onClose() {
  459. console.log("qxj commentN onClose");
  460. },
  461. beforeDestroy() {
  462. console.log("qxj commentN beforeDestroy");
  463. uni.$off('comment');
  464. },
  465. destroyed() {
  466. console.log("qxj commentN destroyed");
  467. // 注销全局配置监听
  468. uni.$off("comment");
  469. }
  470. }
  471. </script>
  472. <style scoped>
  473. page {
  474. background-color: white;
  475. }
  476. .fl-row{
  477. display: flex;
  478. flex-direction: row;
  479. }
  480. .comtentBox{
  481. background-color:#171a1d;
  482. box-sizing: border-box;
  483. }
  484. .banner {
  485. height: 430rpx;
  486. }
  487. .es-icon-course-bg {
  488. background-image: url(/static/images/course/bg.png);
  489. }
  490. .es-icon-course-icon-1 {
  491. background-image: url(/static/images/course/icon-1.png);
  492. }
  493. .es-icon-course-icon-2 {
  494. background-image: url(/static/images/course/icon-2.png);
  495. }
  496. .es-icon-course-icon-3 {
  497. background-image: url(/static/images/course/icon-3.png);
  498. }
  499. .es-icon-course-close {
  500. background-image: url(/static/images/course/close.png);
  501. }
  502. .es-icon-course-info {
  503. background-image: url(/static/images/course/info.png);
  504. }
  505. .es-icon-course-bg2 {
  506. background-image: url(/static/images/course/bg2.png);
  507. }
  508. .es-icon-course-bg3 {
  509. background-image: url(/static/images/course/bg3.png);
  510. }
  511. .es-icon-course-comment {
  512. background-image: url(/static/images/course/comment.png);
  513. }
  514. .es-icon-course-comment2 {
  515. background-image: url(/static/images/course/comment2.png);
  516. }
  517. .es-icon-course-nav-bg,
  518. .nav {
  519. background-image: url(/static/images/course/nav-bg.png);
  520. }
  521. .es-icon-course-nav-bg-ac,.ac {
  522. background-color: #ffd8c4;
  523. }
  524. .es-icon-course-point {
  525. background-image: url(/static/images/course/point.png);
  526. }
  527. .es-icon-course-share {
  528. background-image: url(/static/images/course/share.png);
  529. }
  530. .es-icon-course-like2 {
  531. background-image: url(/static/images/course/like2.png);
  532. }
  533. .es-icon-course-like2-ac {
  534. background-image: url(/static/images/course/like2-ac.png);
  535. }
  536. .item {
  537. width: calc(33.33% - 14rpx);
  538. }
  539. .nav {
  540. width: 216rpx;
  541. height: 60rpx;
  542. }
  543. .comment-reply-item {
  544. /* border-bottom: 1px #fff solid; */
  545. }
  546. .br{
  547. border: 1px solid #FF5C03;
  548. }
  549. .fix-bottom{
  550. position: fixed;
  551. left: 0;
  552. right: 0;
  553. bottom: 0;
  554. /* width: 100%; */
  555. z-index: 999;
  556. background-color: white;
  557. }
  558. .refresh {
  559. display: flex;
  560. flex-direction: row;
  561. justify-content: center;
  562. height: 50px;
  563. }
  564. .loading-more {
  565. align-items: center;
  566. justify-content: center;
  567. padding-top: 14px;
  568. padding-bottom: 14px;
  569. text-align: center;
  570. }
  571. .loading-more-text {
  572. font-size: 28rpx;
  573. color: #999;
  574. }
  575. </style>