commentN.nvue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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-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/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?'../../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?'../../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. <view :style="'height:'+(KeyHight)+'px'" 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 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/image/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. comWidth: 300,
  161. replyWidth: 200
  162. }
  163. },
  164. mounted() {
  165. try {
  166. console.log("qxj commentN mounted");
  167. let that=this;
  168. this.subNVue= uni.getSubNVueById('commentN');
  169. uni.$on('comment', (data) => {
  170. that.videoId=data.videoId;
  171. that.courseId=data.courseId;
  172. that.getCourseInfo();
  173. that.upCallback();
  174. });
  175. const res = uni.getSystemInfoSync();
  176. // this.listHei=res.windowHeight*1;
  177. // this.listHei=uni.upx2px(1150 - 240);
  178. this.listHei= res.windowHeight*0.85 - uni.upx2px(324);
  179. this.comWidth = res.screenWidth - uni.upx2px(182)
  180. this.replyWidth = res.screenWidth - uni.upx2px(312)
  181. this.txtPing = this.$refs["txtPing"];
  182. uni.onKeyboardHeightChange(this.boardHeightChange);
  183. if(this.isLogin()){
  184. let useInfo=uni.getStorageSync('userInfo');
  185. if(!!useInfo && useInfo!=null){
  186. this.myUserInfo=JSON.parse(useInfo);
  187. }
  188. }
  189. } catch (e) {
  190. }
  191. },
  192. onUnload() {
  193. console.log("qxj commentN onUnload");
  194. uni.offKeyboardHeightChange(this.boardHeightChange);
  195. uni.$off("comment");
  196. },
  197. methods: {
  198. getCourseInfo(){
  199. getCourseById(this.courseId).then(res => {
  200. if(res.code==200){
  201. this.courseData=res.data;
  202. }
  203. },
  204. rej => {}
  205. );
  206. },
  207. onpullingdown(e) {
  208. if (this.refreshing) return;
  209. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  210. this.refreshText = '下拉更新'
  211. } else {
  212. this.refreshText = '释放更新'
  213. }
  214. },
  215. onrefresh(e) {
  216. console.log('onRefreshing...');
  217. this.refreshing = true;
  218. this.pageNum=1;
  219. this.upCallback();
  220. if (this.refreshing) return;
  221. },
  222. loadmore(){
  223. if(this.isLastPage){
  224. return;
  225. }
  226. console.log("loadmore");
  227. this.pageNum++;
  228. this.showLoadMore = true;
  229. setTimeout(() => {
  230. this.upCallback();
  231. }, 300);
  232. },
  233. /*下拉刷新的回调 */
  234. upCallback() {
  235. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  236. const params={"courseId":this.courseId,"sortType":this.sortType};
  237. uni.showLoading({title:""});
  238. getCommentList(params,this.pageNum).then(res => {
  239. uni.hideLoading();
  240. if(res.code==200){
  241. setTimeout(()=>{
  242. //this.mescroll.endByPage(res.data.list.length, res.data.pages);
  243. if(this.pageNum == 1) this.dataList = []; //如果是第一页需手动制空列表
  244. this.dataList=this.dataList.concat(res.data.list); //追加新数据
  245. this.totalNum=res.data.total;
  246. this.reqDataCode=1;
  247. this.refreshing = false;
  248. this.isLastPage=res.data.isLastPage;
  249. if(this.isLastPage){
  250. this.refreshText = '加载完成'
  251. }
  252. if(res.data.isLastPage){
  253. this.loadMoreText = "";
  254. this.showLoadMore=false;
  255. }
  256. },200);
  257. }else{
  258. this.refreshing = false;
  259. this.refreshText = '加载完成';
  260. this.reqDataCode=-1;
  261. }
  262. },
  263. rej => {}
  264. ).catch(()=>{
  265. //联网失败, 结束加载
  266. this.refreshing = false;
  267. this.refreshText = '加载完成';
  268. this.reqDataCode=-1;
  269. });
  270. },
  271. closePopup() {
  272. const subNVue = uni.getSubNVueById('commentN');
  273. subNVue.hide('slide-out-bottom');
  274. },
  275. refreshPage(){
  276. this.pageNum=1;
  277. this.upCallback();
  278. },
  279. tapCommentType(type){
  280. this.sortType=type;
  281. this.refreshPage();
  282. },
  283. isMySend(item){
  284. if(this.myUserInfo!=null && this.myUserInfo.userId==item.userId){
  285. return true;
  286. }
  287. return false;
  288. },
  289. doSend(){
  290. if(this.isEmpty(this.pingContent)){
  291. uni.showToast({title: '评论内容不能为空',icon: 'none'});
  292. return;
  293. }
  294. if(!isLogin()){
  295. showLoginPage();
  296. return;
  297. }
  298. let params={"courseId":this.courseId,"content":this.pingContent,"type":this.pingType};
  299. if(this.pingType==2){
  300. params["parentId"]=this.replyParentId;
  301. }
  302. uni.showLoading({title:""});
  303. addComment(params).then(res => {
  304. uni.hideLoading();
  305. if(res.code==200){
  306. uni.showToast({title: '添加评论成功',icon: 'none'});
  307. }else{
  308. uni.showToast({title: res.msg,icon: 'none'});
  309. }
  310. this.placeholder="发布一条友善的评论";
  311. this.pingType=1;
  312. this.pingContent='';
  313. this.refreshPage();
  314. },
  315. rej => {}
  316. );
  317. },
  318. doReply(item){
  319. this.replyParentId=item.commentId;
  320. this.pingType=2;
  321. let placeHolder=this.isEmpty(item.nickName)?"回复":"回复"+item.nickName;
  322. this.placeholder=placeHolder;
  323. this.pingContent='';
  324. //this.isInputFocus=true;
  325. this.$nextTick(()=>{
  326. this.$refs.txtPing.focus();
  327. });
  328. },
  329. replayClick(item,index){
  330. item.expand=true;
  331. this.dataList[index]=item;
  332. this.$forceUpdate(); // 如果你需要强制刷新,可以调用 $forceUpdate()
  333. },
  334. expandReplyAct(item,idx){
  335. return true
  336. },
  337. onblur(){
  338. console.log("qxj onblur");
  339. },
  340. doLike(item,index,childIdx,type){
  341. if(!this.isLogin()){
  342. showLoginPage();
  343. return;
  344. }
  345. const params={"commentId":item.commentId};
  346. uni.showLoading({title:""});
  347. commentDoLike(params).then(res => {
  348. uni.hideLoading();
  349. if(res.code==200){
  350. if(item.isLike==0){
  351. item.likes+=1;
  352. item.isLike=1;
  353. }else{
  354. item.likes=1;
  355. item.isLike=0;
  356. }
  357. // this.dataList[index]=item;
  358. // this.$forceUpdate();
  359. uni.showToast({title: '操作成功',icon: 'none'});
  360. }else{
  361. uni.showToast({title: res.msg,icon: 'none'});
  362. }
  363. },
  364. rej => {}
  365. );
  366. },
  367. delComment(item){
  368. this.delCommentId=item.commentId;
  369. let that = this;
  370. uni.showModal({
  371. title: '系统提示',
  372. content: '确定删除吗',
  373. success: function (res) {
  374. if (res.confirm) {
  375. console.log("qxj confirm");
  376. that.delCommentAct();
  377. } else if (res.cancel) {
  378. console.log("qxj cancel");
  379. }
  380. }
  381. });
  382. },
  383. delCommentAct(){
  384. if(!this.isLogin()){
  385. showLoginPage();
  386. return;
  387. }
  388. uni.showLoading({title:""});
  389. deleteComment(this.delCommentId).then(res => {
  390. uni.hideLoading();
  391. if(res.code==200){
  392. uni.showToast({title: '操作成功',icon: 'none'});
  393. }else{
  394. uni.showToast({title: res.msg,icon: 'none'});
  395. }
  396. this.refreshPage();
  397. },
  398. rej => {}
  399. );
  400. },
  401. boardHeightChange:function(res){
  402. // console.log('changeHeight', res.height);
  403. if(res.height==0){
  404. this.placeholder="发布一条友善的评论";
  405. //this.pingContent='';
  406. this.isInputFocus=false;
  407. }else{
  408. this.isInputFocus=true;
  409. }
  410. this.KeyHight = res.height;
  411. },
  412. isLogin() {
  413. let obj=uni.getStorageSync("AppToken");
  414. return !!obj;
  415. },
  416. isEmpty(obj) {
  417. if (typeof obj == "undefined" || obj == null || obj == "") {
  418. return true;
  419. } else {
  420. return false;
  421. }
  422. },
  423. formatDate(dateStr) {
  424. let formatStr = "";
  425. let formatDate;
  426. if(dateStr==null){
  427. return formatStr;
  428. }
  429. let date = dayjs(dateStr,'YYYY-MM-DD HH:mm:ss');
  430. let today = dayjs();
  431. if (date.year() != today.year()) {
  432. formatDate = date.format('YYYY-MM-DD HH:mm');
  433. }
  434. else if (date.month() === today.month()) {
  435. switch (date.date() - today.date()) {
  436. case 0:
  437. formatDate = date.format('今天 HH:mm');
  438. break;
  439. case -1:
  440. formatDate = date.format('昨天 HH:mm');
  441. break;
  442. case 1:
  443. formatDate = date.format('明天 HH:mm');
  444. break;
  445. default:
  446. formatDate = date.format('MM-DD HH:mm');
  447. break;
  448. }
  449. }
  450. else if (date.month() - today.month() === 0 && date.date() === 1) {
  451. formatDate = date.format('明天 HH:mm');
  452. }
  453. else {
  454. formatDate = date.format('MM-DD HH:mm');
  455. }
  456. return formatDate;
  457. }
  458. },
  459. onHide() {
  460. console.log("qxj commentN onHide");
  461. },
  462. onClose() {
  463. console.log("qxj commentN onClose");
  464. },
  465. beforeDestroy() {
  466. console.log("qxj commentN beforeDestroy");
  467. uni.$off('comment');
  468. },
  469. destroyed() {
  470. console.log("qxj commentN destroyed");
  471. // 注销全局配置监听
  472. uni.$off("comment");
  473. }
  474. }
  475. </script>
  476. <style>
  477. .content {
  478. background-color: white;
  479. }
  480. .fl-row{
  481. display: flex;
  482. flex-direction: row;
  483. }
  484. .comtentBox{
  485. background-color:#171a1d;
  486. /* box-sizing: border-box; */
  487. display: flex;
  488. }
  489. .banner {
  490. height: 430rpx;
  491. }
  492. .es-icon-course-bg {
  493. background-image: url(../../static/images/other/course/bg.png);
  494. }
  495. .es-icon-course-icon-1 {
  496. background-image: url(../../static/images/other/course/icon-1.png);
  497. }
  498. .es-icon-course-icon-2 {
  499. background-image: url(../../static/images/other/course/icon-2.png);
  500. }
  501. .es-icon-course-icon-3 {
  502. background-image: url(../../static/images/other/course/icon-3.png);
  503. }
  504. .es-icon-course-close {
  505. background-image: url(../../static/images/other/course/close.png);
  506. }
  507. .es-icon-course-info {
  508. background-image: url(../../static/images/other/course/info.png);
  509. }
  510. .es-icon-course-bg2 {
  511. background-image: url(../../static/images/other/course/bg2.png);
  512. }
  513. .es-icon-course-bg3 {
  514. background-image: url(../../static/images/other/course/bg3.png);
  515. }
  516. .es-icon-course-comment {
  517. background-image: url(../../static/images/other/course/comment.png);
  518. }
  519. .es-icon-course-comment2 {
  520. background-image: url(../../static/images/other/course/comment2.png);
  521. }
  522. .es-icon-course-nav-bg,
  523. .nav {
  524. background-image: url(../../static/images/other/course/nav-bg.png);
  525. }
  526. .es-icon-course-nav-bg-ac,.ac {
  527. background-color: #ffd8c4;
  528. }
  529. .es-icon-course-point {
  530. background-image: url(../../static/images/other/course/point.png);
  531. }
  532. .es-icon-course-share {
  533. background-image: url(../../static/images/other/course/share.png);
  534. }
  535. .es-icon-course-like2 {
  536. background-image: url(../../static/images/other/course/like2.png);
  537. }
  538. .es-icon-course-like2-ac {
  539. background-image: url(../../static/images/other/course/like2-ac.png);
  540. }
  541. .item {
  542. width: calc(33.33% - 7px);
  543. }
  544. .nav {
  545. width: 216rpx;
  546. height: 60rpx;
  547. }
  548. .comment-reply-item {
  549. /* border-bottom: 1px #fff solid; */
  550. }
  551. .br{
  552. border: 1px solid #2583EB;
  553. }
  554. .fix-bottom{
  555. position: fixed;
  556. left: 0;
  557. right: 0;
  558. bottom: 0;
  559. /* width: 100%; */
  560. z-index: 999;
  561. background-color: white;
  562. }
  563. .refresh {
  564. display: flex;
  565. flex-direction: row;
  566. justify-content: center;
  567. height: 50px;
  568. }
  569. .loading-more {
  570. align-items: center;
  571. justify-content: center;
  572. padding-top: 14px;
  573. padding-bottom: 14px;
  574. text-align: center;
  575. }
  576. .loading-more-text {
  577. font-size: 28rpx;
  578. color: #999;
  579. }
  580. </style>