commentN.nvue 19 KB

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