comment.nvue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. <template>
  2. <view class="container">
  3. <view class="main_content">
  4. <text class="title">评论 {{noteDetail.replyNum?noteDetail.replyNum:0}}</text>
  5. <image @click="close" class="closeBnt" :src="urlDomain +'crmebimage/presets/close.png'" mode=""></image>
  6. <!-- 评论列表 -->
  7. <view class="main">
  8. <scroll-view class="scroll-view" scroll-y="true" @scroll="followScroll" @scrolltolower="onTouchmove">
  9. <view class="container">
  10. <view v-if="list.length > 0" id="reply">
  11. <view class="common_list" v-for="(item, index) in list" :key="index">
  12. <view class="commen_one">
  13. <image :src="item.avatar || urlDomain+'crmebimage/presets/morenT.png'"
  14. class="image"></image>
  15. </view>
  16. <view class="info_count">
  17. <view class="info">
  18. <view class="message" @click.stop="toReply(item,index)">
  19. <text v-if="item.nickname" class="name">{{item.nickname}}</text>
  20. <view class="desc acea-row row-middle">
  21. <rich-text :nodes="nodes(item)" class="text"></rich-text>
  22. </view>
  23. <view class="timeBox">
  24. <text
  25. class="time">{{item.createTime?getDateDiff(item.createTime):''}}</text>
  26. <text @click.stop="onDel(item, index)" v-if="item.uid == uid"
  27. class="del">删除</text>
  28. </view>
  29. </view>
  30. <view v-if="item.auditStatus!==0" class="like" @click.stop="starComment(item)">
  31. <image v-if="item.isLike" class="dianzan"
  32. :src="`${urlDomain}crmebimage/presets/zan1.png`"></image>
  33. <image v-else class="dianzan"
  34. :src="`${urlDomain}crmebimage/presets/zan.png`"></image>
  35. <text class="like-text">{{item.countStart?item.countStart:0}}</text>
  36. </view>
  37. </view>
  38. <view v-if="item.replyList && item.replyList.length > 0" class="reply_count">
  39. <view v-for="(itemn,indexn) in item.replyList" :key="indexn" class="reply_list">
  40. <view class="item">
  41. <view class="item_count" @click.stop="toReply(itemn,index)">
  42. <image class="image"
  43. :src="itemn.avatar || '/static/images/morenT.png'">
  44. </image>
  45. <text v-if="itemn.nickname" class="name_two">{{itemn.nickname}}
  46. </text>
  47. <view class="desc acea-row row-middle">
  48. <view class="centent">
  49. <rich-text :nodes="nodes(itemn)"
  50. class="reply_text"></rich-text>
  51. </view>
  52. </view>
  53. <view class="timeBox">
  54. <text
  55. class="time_two">{{ getDateDiff(itemn.createTime) }}</text>
  56. <text @click.stop="onDel(itemn, index)" v-if="itemn.uid == uid"
  57. class="del">删除</text>
  58. </view>
  59. </view>
  60. <view v-if="itemn.auditStatus!==0" class="like_two"
  61. @click.stop="starComment(itemn)">
  62. <view class="iconfont"
  63. :class="itemn.isLike ? 'icon-yidianzan' : 'icon-dianzan1'">
  64. </view>
  65. {{itemn.countStart ? itemn.countStart : 0}}
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <view class="end">
  73. <text class="text">到底了</text>
  74. </view>
  75. </view>
  76. <view :hidden="!loading" class="acea-row row-center-wrapper loadingicon">
  77. <text class="iconfont icon-jiazai loading"></text>
  78. </view>
  79. <view v-if="list.length == 0 && !loading" class="empty-box">
  80. <image :src="urlDomain+'crmebimage/presets/noEvaluate.png'"></image>
  81. <text class="txt">暂无评论,快去抢沙发吧~</text>
  82. </view>
  83. </view>
  84. </scroll-view>
  85. </view>
  86. <!-- 评论框 -->
  87. <view @click="parentPinglun" class="release_bar">
  88. <image class="image" :src="userInfo.avatar || urlDomain+'crmebimage/presets/morenT.png'"></image>
  89. <text class="lang">{{placeholder}}</text>
  90. </view>
  91. <!-- 真实评论弹窗 -->
  92. <uni-popup type="bottom" ref="comment" @touchmove.stop.prevent="moveHandle">
  93. <view class="release_bar no-border" style="padding: 20rpx 24rpx;">
  94. <image class="image" :src="userInfo.avatar || urlDomain+'crmebimage/presets/morenT.png'"></image>
  95. <textarea :placeholder="placeholder" placeholder-style="color: #999999; font-size: 12px;"
  96. v-model="content" :cursor-spacing="cursorSpacing" confirm-hold
  97. :style="' height: 20px; margin-bottom: 20upx; font-size: 15px; color: #000000; margin-top: 20upx; margin-left: 30upx;'"
  98. :show-confirm-bar="false" class="input_count" :focus="autoFocus"
  99. :adjust-position="adjustPosition" auto-height />
  100. <text class="send" @click.stop="submitComment">发送</text>
  101. </view>
  102. </uni-popup>
  103. </view>
  104. </view>
  105. </template>
  106. <script>
  107. import Cache from '@/utils/cache'
  108. import {
  109. mapGetters
  110. } from "vuex";
  111. import {
  112. discoverNoteLike
  113. } from '@/libs/follow.js';
  114. import {
  115. replyListApi,
  116. noteReplyAddApi,
  117. noteReplyLikeApi,
  118. replyDeleteApi
  119. } from '@/api/discover.js';
  120. import {
  121. toLogin
  122. } from '@/libs/login.js';
  123. import {
  124. Debounce
  125. } from '@/utils/validate.js'
  126. let app = getApp();
  127. export default {
  128. computed: mapGetters(['isLogin', 'userInfo', 'uid']),
  129. watch: {
  130. noteId: {
  131. handler: function(newV, oldV) {
  132. if (newV) {
  133. this.getList();
  134. }
  135. },
  136. deep: true
  137. },
  138. noteDetails: {
  139. handler: function(newV, oldV) {
  140. if (newV) {
  141. this.noteDetail = newV
  142. }
  143. },
  144. deep: true
  145. }
  146. },
  147. props: {
  148. /* 哪里引用,detail详情中引用 */
  149. fromTo: {
  150. type: String,
  151. default: ''
  152. },
  153. /* 内容id */
  154. noteId: {
  155. type: Number,
  156. default: 0
  157. },
  158. /* 内容详情 */
  159. noteDetails: {
  160. type: Object,
  161. default: function() {
  162. return {};
  163. },
  164. },
  165. },
  166. data() {
  167. return {
  168. nodes(data) {
  169. return [{
  170. children: [{
  171. type: 'text',
  172. attrs: {
  173. class: 'audit-status',
  174. style: 'color:#FE960F;margin-right: 8rpx;border: 1px solid #FE960F;'
  175. },
  176. text: data.auditStatus === 0 ? '审核中- ' : ''
  177. },
  178. {
  179. type: 'text',
  180. attrs: {
  181. class: 'reply_user',
  182. style: 'color:#4A8AC9'
  183. },
  184. text: data.reviewUserNickname ? `回复@${data.reviewUserNickname}` : ''
  185. }, {
  186. type: 'text',
  187. attrs: {
  188. class: 'reply_text'
  189. },
  190. text: data.content
  191. }
  192. ]
  193. }]
  194. },
  195. urlDomain: Cache.get("imgHost"),
  196. cursorSpacing: 20, //键盘距离输入框的距离
  197. adjustPosition: true, //默认
  198. autoFocus: false,
  199. noteDetail: this.noteDetails,
  200. theme: app.globalData.theme,
  201. content: '',
  202. isShowComment: false, //真实评论弹窗显示隐藏
  203. placeholder: "快来说点儿什么吧...",
  204. loadTitle: '加载更多',
  205. where: {
  206. page: 1,
  207. limit: 10,
  208. noteId: ''
  209. },
  210. list: [],
  211. loading: false,
  212. replyId: 0,
  213. focus: false,
  214. index: 0,
  215. isChild: false,
  216. bottomVal: 0
  217. }
  218. },
  219. mounted() {
  220. this.getList();
  221. },
  222. methods: {
  223. getDateDiff(data) {
  224. let datas = data;
  225. // 传进来的data必须是日期格式,不能是时间戳
  226. //var str = data;
  227. //将字符串转换成时间格式
  228. var timePublish = new Date(data);
  229. var timeNow = new Date();
  230. var minute = 1000 * 60;
  231. var hour = minute * 60;
  232. var day = hour * 24;
  233. var month = day * 30;
  234. var result = "2";
  235. var diffValue = timeNow - timePublish;
  236. var diffMonth = diffValue / month;
  237. var diffWeek = diffValue / (7 * day);
  238. var diffDay = diffValue / day;
  239. var diffHour = diffValue / hour;
  240. var diffMinute = diffValue / minute;
  241. if (diffValue < 0) {} else if (diffMonth > 3) {
  242. result = timePublish.getFullYear() + "-";
  243. result += timePublish.getMonth() + "-";
  244. result += timePublish.getDate();
  245. } else if (diffMonth > 1) {
  246. result = parseInt(diffMonth) + "月前";
  247. } else if (diffWeek > 1) {
  248. result = parseInt(diffWeek) + "周前";
  249. } else if (diffDay > 1) {
  250. result = parseInt(diffDay) + "天前";
  251. } else if (diffHour > 1) {
  252. result = parseInt(diffHour) + "小时前";
  253. } else if (diffMinute > 1) {
  254. result = parseInt(diffMinute) + "分钟前";
  255. } else {
  256. result = "刚刚";
  257. }
  258. return result;
  259. },
  260. //删除自己的评论
  261. onDel(item, i) {
  262. uni.showModal({
  263. title: '提示',
  264. content: '确认删除评论吗?',
  265. success: res => {
  266. if (res.confirm) {
  267. this.onSub(item, i);
  268. } else if (res.cancel) {
  269. console.log('用户点击取消');
  270. }
  271. }
  272. });
  273. },
  274. onSub(item, i) {
  275. uni.showLoading({
  276. title: '删除中...'
  277. });
  278. replyDeleteApi(item.id).then(res => {
  279. this.list.splice(i, 1)
  280. uni.showToast({
  281. title: '删除成功',
  282. icon: 'none'
  283. })
  284. this.noteDetail.replyNum--
  285. this.$emit('getReplyNum', this.noteDetail.replyNum)
  286. }).catch(err => {
  287. uni.showToast({
  288. title: err,
  289. icon: 'none'
  290. })
  291. });
  292. },
  293. /*点赞评论*/
  294. starComment: Debounce(function(item) {
  295. let that = this;
  296. noteReplyLikeApi(item.id).then(res => {
  297. this.$set(item, 'isLike', !item.isLike);
  298. if (!item.isLike) {
  299. item.countStart--;
  300. item.countStart = item.countStart == 0 ? 0 : item.countStart
  301. } else {
  302. item.countStart++;
  303. }
  304. }).catch(err => {
  305. uni.showToast({
  306. title: err,
  307. icon: 'none'
  308. })
  309. });
  310. }),
  311. // 模拟触底刷新
  312. onTouchmove(e) {
  313. if (this.loadend || this.loading) return;
  314. this.getList();
  315. },
  316. /**
  317. *
  318. */
  319. followScroll() {
  320. uni.$emit('scroll');
  321. },
  322. close() {
  323. this.$emit('close');
  324. },
  325. //点赞
  326. likeToggle: Debounce(function(item) {
  327. if (this.isLogin) {
  328. discoverNoteLike(item.id).then(() => {
  329. this.$set(item, 'userIsLike', !item.userIsLike);
  330. if (!item.userIsLike) {
  331. item.likeNum--;
  332. item.likeNum = item.likeNum == 0 ? 0 : item.likeNum
  333. } else {
  334. item.likeNum++;
  335. }
  336. });
  337. } else {
  338. toLogin();
  339. }
  340. }),
  341. //回复
  342. toReply(item, index) {
  343. this.placeholder = '回复:' + item.nickname
  344. this.replyId = item.id
  345. this.isChild = true
  346. this.index = index
  347. this.focus = true
  348. this.content = ""
  349. },
  350. clickTextarea() {
  351. this.isopen = false;
  352. if (uni.getSystemInfoSync().platform == 'ios') {
  353. this.autoFocus = false;
  354. setTimeout(() => {
  355. this.autoFocus = true;
  356. }, 200)
  357. }
  358. },
  359. linechange(event) {
  360. this.lineheight = event.detail.height
  361. },
  362. //真实评论弹窗 关闭
  363. closeComment() {
  364. this.autoFocus = false;
  365. this.placeholder = "快来说点儿什么吧...";
  366. this.content = ""
  367. this.isChild = false
  368. this.focus = false
  369. this.bottomVal = 0
  370. this.isShowComment = false;
  371. },
  372. oninput() {
  373. if (Number(this.noteDetail.replyStatus) > 1) {
  374. return this.$util.Tips({
  375. title: '该内容禁止评论'
  376. });
  377. } else {
  378. this.isShowComment = true
  379. }
  380. },
  381. parentPinglun() {
  382. if (!this.isLogin) {
  383. toLogin();
  384. } else {
  385. if (Number(this.noteDetail.replyStatus) > 1) {
  386. return this.$util.Tips({
  387. title: '该内容禁止评论'
  388. });
  389. } else {
  390. this.$refs.comment.open('bottom')
  391. this.autoFocus = false;
  392. setTimeout(() => {
  393. this.autoFocus = true;
  394. this.isShowComment = true
  395. }, 50)
  396. }
  397. }
  398. },
  399. //评论发送提交
  400. submitComment() {
  401. if (!this.content) return;
  402. noteReplyAddApi({
  403. content: this.content,
  404. noteId: this.noteId,
  405. replyId: this.replyId
  406. }).then(res => {
  407. this.$refs.comment.close();
  408. this.isShowComment = false;
  409. this.autoFocus = false;
  410. if (this.isChild) {
  411. if (this.list[this.index]['replyList']) {
  412. this.list[this.index]['replyList'].push(res.data)
  413. } else {
  414. this.list[this.index]['replyList'] = [res.data]
  415. }
  416. } else {
  417. this.list.unshift(res.data)
  418. }
  419. if (res.data.auditStatus == 1) this.noteDetail.replyNum++
  420. this.$emit('getReplyNum', this.noteDetail.replyNum)
  421. this.closeComment();
  422. this.$util.Tips({
  423. title: res.message
  424. });
  425. }).catch(err => {
  426. this.isShowComment = false
  427. uni.showToast({
  428. title: err,
  429. icon: 'none'
  430. })
  431. });
  432. },
  433. getList() {
  434. let that = this;
  435. if (that.loading || that.loaded) return;
  436. that.loading = true;
  437. that.where.noteId = this.noteId;
  438. replyListApi(that.where).then(res => {
  439. that.loading = false;
  440. that.all = res.data.all;
  441. that.loaded = res.data.list.length < that.where.limit;
  442. that.loadTitle = that.loadend ? '没有了' : '加载更多';
  443. that.list.push.apply(that.list, res.data.list);
  444. that.where.page = that.where.page + 1;
  445. },
  446. error => {
  447. that.loading = false;
  448. that.$util.Tips({
  449. title: error.msg
  450. })
  451. }
  452. );
  453. },
  454. }
  455. }
  456. </script>
  457. <style lang="scss" scoped>
  458. .timeBox {
  459. flex-direction: row;
  460. .time {
  461. color: #BBBBBB;
  462. font-size: 22rpx;
  463. margin-top: 16rpx;
  464. }
  465. .del {
  466. font-size: 24rpx;
  467. color: #4A8AC9;
  468. margin-top: 15rpx;
  469. display: inline-block;
  470. }
  471. }
  472. .audit-status {
  473. font-size: 18rpx !important;
  474. border-radius: 2px;
  475. opacity: 1;
  476. border: 1px solid #FE960F;
  477. color: #FE960F;
  478. height: 32rpx;
  479. padding: 0 4rpx;
  480. line-height: 32rpx;
  481. margin-right: 8rpx;
  482. }
  483. .mt10 {
  484. margin-top: 10rpx;
  485. }
  486. .empty-box {
  487. display: flex;
  488. flex-direction: column;
  489. justify-content: center;
  490. align-items: center;
  491. padding-bottom: 60rpx;
  492. image {
  493. width: 414rpx;
  494. height: 305rpx;
  495. }
  496. .txt,
  497. text {
  498. font-size: 26rpx;
  499. color: #999;
  500. }
  501. }
  502. .lang {
  503. width: 616rpx !important;
  504. height: 32px;
  505. line-height: 32px;
  506. margin-left: 30rpx;
  507. padding-left: 30rpx;
  508. background-color: #eee;
  509. border-radius: 50px;
  510. display: flex;
  511. flex-direction: row;
  512. font-size: 13px;
  513. color: #999;
  514. }
  515. .main_content {
  516. padding: 12px 15rpx;
  517. border-bottom: 2px solid #F5F5F5;
  518. position: relative;
  519. bottom: 0;
  520. }
  521. .header {
  522. width: 750rpx;
  523. position: relative;
  524. text-align: center;
  525. }
  526. .title {
  527. text-align: center;
  528. flex-direction: row;
  529. color: #282828;
  530. font-size: 36rpx;
  531. font-weight: bold;
  532. }
  533. .closeBnt {
  534. position: absolute;
  535. right: 30rpx;
  536. top: 30rpx;
  537. width: 15px;
  538. height: 15px;
  539. }
  540. .scroll-view {
  541. height: 600px;
  542. padding-bottom: 240px;
  543. }
  544. .main {
  545. margin-top: 30px;
  546. padding-bottom: 10px;
  547. // position: sticky;
  548. .common_list {
  549. position: relative;
  550. padding-left: 50px;
  551. margin-bottom: 15px;
  552. .commen_one {
  553. position: absolute;
  554. top: 0;
  555. left: 0;
  556. .image {
  557. width: 74rpx;
  558. height: 74rpx;
  559. border-radius: 100%;
  560. }
  561. }
  562. .info {
  563. position: relative;
  564. //padding-right: 90rpx;
  565. width: 630rpx;
  566. }
  567. .name,
  568. .name_two {
  569. color: #999999;
  570. font-size: 26rpx;
  571. }
  572. .text {
  573. color: #282828;
  574. font-size: 28rpx;
  575. }
  576. .desc_two,
  577. .content {
  578. width: 400rpx;
  579. }
  580. .desc {
  581. width: 600rpx;
  582. // display: flex;
  583. // flex-direction: row;
  584. // flex-wrap: wrap;
  585. color: #282828;
  586. font-size: 28rpx;
  587. margin-top: 10rpx;
  588. }
  589. .desc_two {
  590. // display: flex;
  591. // flex-direction: row;
  592. // flex-wrap: wrap;
  593. color: #282828;
  594. font-size: 28rpx;
  595. margin-top: 10rpx;
  596. }
  597. .reply_text {
  598. font-size: 26rpx;
  599. color: #282828;
  600. }
  601. .desc_two {
  602. .reply_user {
  603. font-size: 24rpx;
  604. color: #4A8AC9;
  605. margin: 0 6rpx;
  606. }
  607. }
  608. .time,
  609. .time_two {
  610. color: #BBBBBB;
  611. font-size: 22rpx;
  612. margin-top: 15rpx;
  613. margin-right: 20rpx;
  614. }
  615. .like,
  616. .like_two {
  617. text-align: center;
  618. position: absolute;
  619. top: 0;
  620. right: 0;
  621. width: 75rpx;
  622. .like-text {
  623. color: #999999;
  624. font-size: 13px;
  625. margin-top: 2px;
  626. }
  627. .dianzan {
  628. width: 13px;
  629. height: 13px;
  630. }
  631. }
  632. .reply_list {
  633. margin-top: 20rpx;
  634. .item {
  635. //padding-right: 140rpx;
  636. position: relative;
  637. }
  638. .item_count {
  639. position: relative;
  640. padding-left: 56rpx;
  641. .image {
  642. width: 36rpx;
  643. height: 36rpx;
  644. border-radius: 100%;
  645. position: absolute;
  646. top: 0;
  647. left: 0;
  648. }
  649. }
  650. }
  651. }
  652. .end {
  653. margin: 50rpx 0;
  654. text-align: center;
  655. display: flex;
  656. flex-direction: column;
  657. align-items: center;
  658. .text {
  659. color: #999999;
  660. font-size: 22rpx;
  661. position: relative;
  662. .before,
  663. .after {
  664. display: flex;
  665. width: 22rpx;
  666. height: 1rpx;
  667. background: #999999;
  668. position: absolute;
  669. top: 18rpx;
  670. opacity: .5;
  671. }
  672. .before {
  673. left: -30rpx;
  674. }
  675. .after {
  676. right: -30rpx;
  677. }
  678. }
  679. }
  680. }
  681. .release_bar {
  682. bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  683. bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  684. bottom: 0;
  685. position: fixed;
  686. width: 750rpx;
  687. left: 0;
  688. background: #ffffff;
  689. display: flex;
  690. align-items: center;
  691. justify-content: space-between;
  692. padding: 15rpx 30rpx;
  693. border-top: 1rpx solid #F5F5F5;
  694. flex-direction: row;
  695. .image {
  696. width: 54rpx;
  697. height: 54rpx;
  698. border-radius: 100%;
  699. }
  700. .input_count {
  701. width: 480rpx;
  702. background: #F7F7F7;
  703. border-radius: 31rpx;
  704. padding: 12rpx 30rpx;
  705. line-height: 32px;
  706. }
  707. .send {
  708. font-size: 26rpx;
  709. color: #ffffff;
  710. padding: 12rpx 30rpx;
  711. background: #E93323;
  712. border-radius: 30rpx;
  713. text-align: center;
  714. }
  715. }
  716. .empty {
  717. display: flex;
  718. margin: 130rpx 0 150rpx;
  719. text-align: center;
  720. align-items: center;
  721. // flex-direction: row;
  722. .image {
  723. display: flex;
  724. width: 414rpx;
  725. height: 305rpx;
  726. }
  727. .text {
  728. display: flex;
  729. color: #999999;
  730. font-size: 26rpx;
  731. }
  732. }
  733. </style>