comment.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <view :style="viewColor">
  3. <view class="container" :class="isShow==true?'on':''" @click.stop="loseFocus">
  4. <view class="main_content">
  5. <view class="header">
  6. <text class="title">评论 {{all}}</text>
  7. <text class="iconfont icon-guanbi5" @click="close"></text>
  8. </view>
  9. <view class="main">
  10. <scroll-view scroll-y="true">
  11. <view v-if="list.length > 0" @touchmove="onTouchmove" id="reply">
  12. <view class="common_list" v-for="(item, index) in list" :key="index">
  13. <view class="commen_one">
  14. <image :src="(item.author&&item.author.avatar) || '/static/images/f.png'" class="image"></image>
  15. </view>
  16. <view class="info_count">
  17. <view class="info">
  18. <view class="message" @click.stop="toReply(item,index)">
  19. <view v-if="item.author" class="name">{{item.author.nickname}}</view>
  20. <view class="desc">{{item.content}}</view>
  21. <view class="time">{{item.create_time}}</view>
  22. </view>
  23. <view class="like" @click.stop="starComment(item)">
  24. <view class="iconfont":class="item.relevance_id ? 'icon-yidianzan' : 'icon-dianzan1'"></view>
  25. {{item.count_start}}
  26. </view>
  27. </view>
  28. <view v-if="item.children && item.children.length > 0" class="reply_count">
  29. <view v-for="(itemn,indexn) in item.children" :key="indexn" class="reply_list">
  30. <view class="item">
  31. <view class="item_count" @click.stop="toReply(itemn,index)">
  32. <image class="image" :src="itemn.author && itemn.author.avatar || '/static/images/f.png'"></image>
  33. <view v-if="itemn.author" class="name_two">{{itemn.author.nickname}}</view>
  34. <view class="desc_two">
  35. <text class="reply_user" v-if="itemn.reply">回复 @{{itemn.reply.nickname}} </text> {{itemn.content}}
  36. </view>
  37. <view class="time_two">{{itemn.create_time}}</view>
  38. </view>
  39. <view class="like_two" @click.stop="starComment(itemn)">
  40. <view class="iconfont":class="itemn.relevance_id ? 'icon-yidianzan' : 'icon-dianzan1'"></view>
  41. {{itemn.count_start}}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="end"><text>到底了</text></view>
  49. </view>
  50. <Loading :loaded="loaded" :loading="loading"></Loading>
  51. <view v-if="list.length == 0 && !loading" class="empty">
  52. <image :src="`${domain}/static/images/no_commen.png`"></image>
  53. <text>暂无评论,快去抢沙发吧~</text>
  54. </view>
  55. </scroll-view>
  56. </view>
  57. </view>
  58. <view class="release_bar" :style="'bottom:'+bottom+'rpx;'">
  59. <image class="image" :src="userInfo.avatar || '/static/images/f.png'"></image>
  60. <view class="input_count" @click.stop="">
  61. <input ref="myInput" type="text" :placeholder="placeholder" placeholder-style="color: #999999; font-size: 26rpx;" v-model="content" confirm-type="search">
  62. </view>
  63. <button class="send" @click.stop="submitComment">发送</button>
  64. </view>
  65. </view>
  66. <!-- 绑定手机号 -->
  67. <uni-popup ref="bindmobile" type="bottom">
  68. <bindmobile @close="closepoup" :isCommuity="true"></bindmobile>
  69. </uni-popup>
  70. <view class='mask' catchtouchmove="true" :hidden='isShow==false' @tap="close"></view>
  71. </view>
  72. </template>
  73. <script>
  74. // +----------------------------------------------------------------------
  75. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  76. // +----------------------------------------------------------------------
  77. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  78. // +----------------------------------------------------------------------
  79. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  80. // +----------------------------------------------------------------------
  81. // | Author: CRMEB Team <admin@crmeb.com>
  82. // +----------------------------------------------------------------------
  83. import { replyLstApi, starCommentApi, replyCreateApi } from '@/api/community.js';
  84. import Loading from '@/components/Loading/index.vue';
  85. import bindmobile from '@/components/bindmobile.vue';
  86. import { getUserInfo } from '@/api/user.js';
  87. import { mapGetters } from "vuex";
  88. import { configMap } from '@/utils';
  89. import { HTTP_REQUEST_URL } from '@/config/app';
  90. import { toLogin } from '@/libs/login.js';
  91. export default {
  92. props:{
  93. isShow: {
  94. type: Boolean,
  95. default: false
  96. },
  97. bottom: {
  98. type: Number,
  99. default: 0
  100. },
  101. userInfo: {
  102. type: Object,
  103. default: () => {uid:0;avatar:""}
  104. }
  105. },
  106. components: {
  107. Loading,bindmobile
  108. },
  109. computed: configMap({community_reply_auth:0},mapGetters(['isLogin', 'viewColor'])),
  110. data() {
  111. return {
  112. domain: HTTP_REQUEST_URL,
  113. content: '',
  114. id: "",
  115. list: [],
  116. loaded: false,
  117. loading: false,
  118. where: {
  119. page: 1,
  120. limit: 10
  121. },
  122. reply_id: "",
  123. placeholder: "快来说点儿什么吧...",
  124. isChild: false,
  125. index: 0,
  126. listIndex: 0,
  127. focus: false,
  128. all: 0,
  129. };
  130. },
  131. methods: {
  132. // 点击关闭按钮
  133. close() {
  134. this.$emit('close');
  135. },
  136. onTouchmove(e){
  137. if (this.loadend || this.loading) return;
  138. const query = uni.createSelectorQuery().in(this);
  139. query.select('#reply').boundingClientRect(data => {
  140. console.log(data)
  141. if(data.bottom < 1500 && data.top < 0) {
  142. this.getList();
  143. }
  144. }).exec();
  145. // 模拟触底刷新
  146. },
  147. getData(item,index){
  148. this.id = item.community_id
  149. this.loading = this.loaded = false
  150. this.where.page = 1
  151. this.list = []
  152. this.getList()
  153. this.listIndex = index
  154. },
  155. getList(){
  156. let that = this;
  157. if(that.loading || that.loaded) return;
  158. that.loading = true;
  159. replyLstApi(that.id,that.where).then(res => {
  160. that.loading = false;
  161. that.all = res.data.all;
  162. that.loaded = res.data.list.length < that.where.limit;
  163. that.list.push.apply(that.list, res.data.list);
  164. that.where.page = that.where.page + 1;
  165. },
  166. error => {
  167. that.$util.Tips({
  168. title: error.msg
  169. })
  170. }
  171. );
  172. },
  173. /*发表评论*/
  174. submitComment(){
  175. let that = this;
  176. if (that.isLogin === false) {
  177. toLogin()
  178. }else{
  179. that.getUserInfo();
  180. }
  181. },
  182. /**
  183. * 获取个人用户信息
  184. */
  185. getUserInfo: function() {
  186. let that = this;
  187. getUserInfo().then(res => {
  188. /*判断是否绑定手机号*/
  189. if(res.data.phone || that.community_reply_auth == 0){
  190. that.createReply()
  191. }else{
  192. that.$refs.bindmobile.open()
  193. }
  194. });
  195. },
  196. createReply() {
  197. let that = this;
  198. let reply_id = that.reply_id ? that.reply_id : 0
  199. replyCreateApi(that.id,{content: that.content,reply_id: reply_id}).then(res => {
  200. that.$util.Tips({
  201. title: res.message
  202. });
  203. if(res.data.status == 1){
  204. if(that.isChild){
  205. if(that.list[that.index]['children']){
  206. that.list[that.index]['children'].push(res.data)
  207. }else{
  208. that.list[that.index]['children'] = [res.data]
  209. }
  210. }else{
  211. that.list.unshift(res.data)
  212. }
  213. that.all++
  214. }
  215. that.content = ""
  216. that.$util.Tips({
  217. title: res.message
  218. });
  219. that.$emit('successFul',that.listIndex);
  220. that.loseFocus()
  221. }).catch(err => {
  222. uni.showToast({
  223. title: err,
  224. icon: 'none'
  225. })
  226. });
  227. },
  228. toReply(item,index){
  229. this.focus = true;
  230. // this.$refs.myInput.focus();
  231. this.content = ""
  232. this.placeholder = '回复:'+item.author.nickname
  233. this.reply_id = item.reply_id
  234. this.isChild = true
  235. this.index = index;
  236. // this.focus = true;
  237. },
  238. loseFocus(){
  239. this.focus = false;
  240. this.reply_id = 0;
  241. this.placeholder = "快来说点儿什么吧..."
  242. this.isChild = false
  243. },
  244. /*点赞评论*/
  245. starComment(item){
  246. let that = this;
  247. let status = item.relevance_id ? 0 : 1
  248. starCommentApi(item.reply_id,{status: status}).then(res => {
  249. if (res.status === 200) {
  250. if(item.relevance_id){
  251. item.count_start--;
  252. item.count_start = item.count_start == 0 ? 0 : item.count_start
  253. item.relevance_id = false
  254. }else{
  255. item.count_start++;
  256. item.relevance_id = true
  257. }
  258. }
  259. that.$util.Tips({
  260. title: res.message
  261. });
  262. }).catch(err => {
  263. uni.showToast({
  264. title: err,
  265. icon: 'none'
  266. })
  267. });
  268. },
  269. closepoup(){
  270. this.$refs.bindmobile.close()
  271. },
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .container{
  277. display: block;
  278. background: #ffffff;
  279. border-radius: 16rpx 16rpx 0 0;
  280. position: relative;
  281. position: fixed;
  282. bottom: 0;
  283. padding-bottom: calc(0rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  284. padding-bottom: calc(0rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  285. width: 100%;
  286. left: 0;
  287. background-color: #f5f5f5;
  288. z-index: 40;
  289. border-radius: 16rpx 16rpx 0 0;
  290. transform: translate3d(0, 100%, 0);
  291. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  292. &.on {
  293. transform: translate3d(0, 0, 0);
  294. }
  295. .main_content{
  296. padding: 24rpx 30rpx;
  297. border-bottom: 1px solid #F5F5F5;
  298. position: relative;
  299. }
  300. .header{
  301. position: relative;
  302. text-align: center;
  303. .title{
  304. color: #282828;
  305. font-size: 36rpx;
  306. font-weight: bold;
  307. }
  308. .iconfont{
  309. color: #8A8A8A;
  310. font-size: 36rpx;
  311. position: absolute;
  312. top: 4rpx;
  313. right: 0;
  314. }
  315. }
  316. }
  317. scroll-view{
  318. max-height: 60vh;
  319. }
  320. .main{
  321. margin-top: 60rpx;
  322. padding-bottom: 20rpx;
  323. position: static;
  324. .common_list{
  325. position: relative;
  326. padding-left: 94rpx;
  327. margin-bottom: 20rpx;
  328. .commen_one{
  329. position: absolute;
  330. top: 0;
  331. left: 0;
  332. .image,uni-image{
  333. width: 74rpx;
  334. height: 74rpx;
  335. border-radius: 100%;
  336. }
  337. }
  338. .info{
  339. position: relative;
  340. padding-right: 90rpx;
  341. }
  342. .name,.name_two{
  343. color: #999999;
  344. font-size: 26rpx;
  345. }
  346. .desc,.desc_two{
  347. color: #282828;
  348. font-size: 28rpx;
  349. margin-top: 10rpx;
  350. }
  351. .desc_two{
  352. font-size: 26rpx;
  353. .reply_user{
  354. font-size: 24rpx;
  355. color: #4A8AC9;
  356. margin: 0 6rpx;
  357. }
  358. }
  359. .time,.time_two{
  360. color: #BBBBBB;
  361. font-size: 22rpx;
  362. margin-top: 15rpx;
  363. }
  364. .like,.like_two{
  365. color: #999999;
  366. font-size: 26rpx;
  367. text-align: center;
  368. position: absolute;
  369. top: 0;
  370. right: 0;
  371. width: 75rpx;
  372. .icon-yidianzan{
  373. color: var(--view-theme);
  374. }
  375. }
  376. .reply_list{
  377. margin-top: 20rpx;
  378. .item{
  379. padding-right: 140rpx;
  380. position: relative;
  381. }
  382. .item_count{
  383. position: relative;
  384. padding-left: 56rpx;
  385. .image,un-image{
  386. width: 36rpx;
  387. height: 36rpx;
  388. border-radius: 100%;
  389. position: absolute;
  390. top: 0;
  391. left: 0;
  392. }
  393. }
  394. }
  395. }
  396. .end{
  397. margin-top: 50rpx;
  398. text-align: center;
  399. text{
  400. color: #999999;
  401. font-size: 22rpx;
  402. position: relative;
  403. &::before,&::after{
  404. content: "";
  405. display: inline-block;
  406. width: 22rpx;
  407. height: 1rpx;
  408. background: #999999;
  409. position: absolute;
  410. top: 18rpx;
  411. opacity: .5;
  412. }
  413. &::before{
  414. left: -30rpx;
  415. }
  416. &::after{
  417. right: -30rpx;
  418. }
  419. }
  420. }
  421. }
  422. .release_bar{
  423. // position: absolute;
  424. width: 100%;
  425. left: 0;
  426. /*#ifndef MP*/
  427. bottom: 0;
  428. /*#endif*/
  429. /*#ifdef MP*/
  430. bottom: 10rpx;
  431. /*#endif*/
  432. background: #ffffff;
  433. display: flex;
  434. align-items: center;
  435. justify-content: space-between;
  436. padding: 15rpx 30rpx;
  437. border-top: 1px solid #F5F5F5;
  438. flex-direction: row;
  439. .avatar,image,uni-image{
  440. width: 54rpx;
  441. height: 54rpx;
  442. border-radius: 100%;
  443. }
  444. .input_count{
  445. width: 480rpx;
  446. background: #F7F7F7;
  447. border-radius: 31rpx;
  448. padding: 12rpx 30rpx;
  449. }
  450. .send{
  451. font-size: 26rpx;
  452. color: #ffffff;
  453. padding: 12rpx 30rpx;
  454. background-image: linear-gradient(126deg, var(--view-bntColor21) 0%, var(--view-bntColor22) 100%);
  455. border-radius: 30rpx;
  456. text-align: center;
  457. }
  458. }
  459. .empty{
  460. display: block;
  461. margin: 130rpx 0 150rpx;
  462. text-align: center;
  463. image,uni-image{
  464. display: inline-block;
  465. width: 414rpx;
  466. height: 305rpx;
  467. }
  468. text{
  469. display: block;
  470. color: #999999;
  471. font-size: 26rpx;
  472. }
  473. }
  474. </style>