comment.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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="/static/images/no_commen.png"></image>
  53. <text>暂无评论,快去抢沙发吧~</text>
  54. </view>
  55. </scroll-view>
  56. </view>
  57. </view>
  58. <view class="release_bar">
  59. <view class="input_count">
  60. <input type="text" :placeholder="placeholder" placeholder-style="color: #999999; font-size: 26rpx;" v-model="content" :focus="focus" confirm-type="search">
  61. </view>
  62. <button class="send" @click.stop="submitComment">发送</button>
  63. </view>
  64. </view>
  65. <view class='mask' catchtouchmove="true" :hidden='isShow==false' @tap="close"></view>
  66. </view>
  67. </template>
  68. <script>
  69. import { replyLstApi, starCommentApi, replyCreateApi } from '@/api/community.js';
  70. import Loading from '@/components/Loading/index.vue';
  71. import { mapGetters } from "vuex";
  72. export default {
  73. props:{
  74. isShow: {
  75. type: Boolean,
  76. default: false
  77. }
  78. },
  79. components: {
  80. Loading
  81. },
  82. computed: mapGetters(['viewColor']),
  83. data() {
  84. return {
  85. content: '',
  86. id: "",
  87. list: [],
  88. loaded: false,
  89. loading: false,
  90. where: {
  91. page: 1,
  92. limit: 10
  93. },
  94. reply_id: "",
  95. placeholder: "快来说点儿什么吧...",
  96. isChild: false,
  97. index: 0,
  98. listIndex: 0,
  99. focus: false,
  100. all: 0
  101. };
  102. },
  103. methods: {
  104. // 点击关闭按钮
  105. close() {
  106. this.$emit('close');
  107. },
  108. onTouchmove(e){
  109. if (this.loadend || this.loading) return;
  110. const query = uni.createSelectorQuery().in(this);
  111. query.select('#reply').boundingClientRect(data => {
  112. console.log(data)
  113. if(data.bottom < 1500 && data.top < 0) {
  114. this.getList();
  115. }
  116. }).exec();
  117. // 模拟触底刷新
  118. },
  119. getData(item,index){
  120. this.id = item.community_id
  121. this.loading = this.loaded = false
  122. this.where.page = 1
  123. this.list = []
  124. this.getList()
  125. this.listIndex = index
  126. },
  127. getList(){
  128. let that = this;
  129. if(that.loading || that.loaded) return;
  130. that.loading = true;
  131. replyLstApi(that.id,that.where).then(res => {
  132. that.loading = false;
  133. that.all = res.data.all;
  134. that.loaded = res.data.list.length < that.where.limit;
  135. that.list.push.apply(that.list, res.data.list);
  136. that.where.page = that.where.page + 1;
  137. },
  138. error => {
  139. that.$util.Tips({
  140. title: error.msg
  141. })
  142. }
  143. );
  144. },
  145. /*发表评论*/
  146. submitComment(){
  147. let that = this;
  148. let reply_id = that.reply_id ? that.reply_id : 0
  149. replyCreateApi(that.id,{content: that.content,reply_id: reply_id}).then(res => {
  150. that.$util.Tips({
  151. title: res.message
  152. });
  153. if(that.isChild){
  154. if(that.list[that.index]['children']){
  155. that.list[that.index]['children'].push(res.data)
  156. }else{
  157. that.list[that.index]['children'] = [res.data]
  158. }
  159. }else{
  160. that.list.unshift(res.data)
  161. }
  162. that.all++
  163. that.content = ""
  164. that.$util.Tips({
  165. title: res.message
  166. });
  167. that.$emit('successFul',that.listIndex);
  168. that.loseFocus()
  169. });
  170. },
  171. toReply(item,index){
  172. this.content = ""
  173. this.placeholder = '回复:'+item.author.nickname
  174. this.reply_id = item.reply_id
  175. this.isChild = true
  176. this.index = index;
  177. this.focus = true;
  178. },
  179. loseFocus(){
  180. this.focus = false;
  181. this.reply_id = 0;
  182. this.placeholder = "快来说点儿什么吧..."
  183. this.isChild = false
  184. // this.content = ""
  185. },
  186. /*点赞评论*/
  187. starComment(item){
  188. let that = this;
  189. let status = item.relevance_id ? 0 : 1
  190. starCommentApi(item.reply_id,{status: status}).then(res => {
  191. if (res.status === 200) {
  192. if(item.relevance_id){
  193. item.count_start--;
  194. item.count_start = item.count_start == 0 ? 0 : item.count_start
  195. item.relevance_id = false
  196. }else{
  197. item.count_start++;
  198. item.relevance_id = true
  199. }
  200. }
  201. that.$util.Tips({
  202. title: res.message
  203. });
  204. }).catch(err => {
  205. uni.showToast({
  206. title: err,
  207. icon: 'none'
  208. })
  209. });
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. .container{
  216. background: #ffffff;
  217. border-radius: 16rpx 16rpx 0 0;
  218. position: relative;
  219. position: fixed;
  220. bottom: 0;
  221. width: 100%;
  222. left: 0;
  223. background-color: #f5f5f5;
  224. z-index: 1000;
  225. border-radius: 16rpx 16rpx 0 0;
  226. transform: translate3d(0, 100%, 0);
  227. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  228. &.on {
  229. transform: translate3d(0, 0, 0);
  230. }
  231. .main_content{
  232. padding: 24rpx 30rpx 0;
  233. border-bottom: 1rpx solid #F5F5F5;
  234. margin-bottom: 100rpx;
  235. }
  236. .header{
  237. position: relative;
  238. text-align: center;
  239. .title{
  240. color: #282828;
  241. font-size: 36rpx;
  242. font-weight: bold;
  243. }
  244. .iconfont{
  245. color: #8A8A8A;
  246. font-size: 36rpx;
  247. position: absolute;
  248. top: 4rpx;
  249. right: 0;
  250. }
  251. }
  252. }
  253. scroll-view{
  254. height: 60vh;
  255. }
  256. .main{
  257. margin-top: 60rpx;
  258. padding-bottom: 20rpx;
  259. .common_list{
  260. position: relative;
  261. padding-left: 94rpx;
  262. margin-bottom: 20rpx;
  263. .commen_one{
  264. position: absolute;
  265. top: 0;
  266. left: 0;
  267. .image,uni-image{
  268. width: 74rpx;
  269. height: 74rpx;
  270. border-radius: 100%;
  271. }
  272. }
  273. .info{
  274. position: relative;
  275. padding-right: 90rpx;
  276. }
  277. .name,.name_two{
  278. color: #999999;
  279. font-size: 26rpx;
  280. }
  281. .desc,.desc_two{
  282. color: #282828;
  283. font-size: 28rpx;
  284. margin-top: 10rpx;
  285. }
  286. .desc_two{
  287. font-size: 26rpx;
  288. .reply_user{
  289. font-size: 24rpx;
  290. color: #4A8AC9;
  291. margin: 0 6rpx;
  292. }
  293. }
  294. .time,.time_two{
  295. color: #BBBBBB;
  296. font-size: 22rpx;
  297. margin-top: 15rpx;
  298. }
  299. .like,.like_two{
  300. color: #999999;
  301. font-size: 26rpx;
  302. text-align: center;
  303. position: absolute;
  304. top: 0;
  305. right: 0;
  306. width: 75rpx;
  307. .icon-yidianzan{
  308. color: var(--view-theme);
  309. }
  310. }
  311. .reply_list{
  312. margin-top: 20rpx;
  313. .item{
  314. padding-right: 140rpx;
  315. position: relative;
  316. }
  317. .item_count{
  318. position: relative;
  319. padding-left: 56rpx;
  320. .image,un-image{
  321. width: 36rpx;
  322. height: 36rpx;
  323. border-radius: 100%;
  324. position: absolute;
  325. top: 0;
  326. left: 0;
  327. }
  328. }
  329. }
  330. }
  331. .end{
  332. margin-top: 50rpx;
  333. text-align: center;
  334. text{
  335. color: #999999;
  336. font-size: 22rpx;
  337. position: relative;
  338. &::before,&::after{
  339. content: "";
  340. display: inline-block;
  341. width: 22rpx;
  342. height: 1rpx;
  343. background: #999999;
  344. position: absolute;
  345. top: 18rpx;
  346. opacity: .5;
  347. }
  348. &::before{
  349. left: -30rpx;
  350. }
  351. &::after{
  352. right: -30rpx;
  353. }
  354. }
  355. }
  356. }
  357. .release_bar{
  358. position: fixed;
  359. width: 100%;
  360. bottom: 0;
  361. left: 0;
  362. background: #ffffff;
  363. display: flex;
  364. align-items: center;
  365. justify-content: space-between;
  366. padding: 15rpx 30rpx;
  367. border-top: 1rpx solid #F5F5F5;
  368. .avatar,image,uni-image{
  369. width: 54rpx;
  370. height: 54rpx;
  371. border-radius: 100%;
  372. }
  373. .input_count{
  374. width: 550rpx;
  375. background: #F7F7F7;
  376. border-radius: 31rpx;
  377. padding: 12rpx 30rpx;
  378. }
  379. .send{
  380. font-size: 26rpx;
  381. color: #ffffff;
  382. padding: 12rpx 30rpx;
  383. background-image: linear-gradient(126deg, var(--view-bntColor21) 0%, var(--view-bntColor22) 100%);
  384. border-radius: 30rpx;
  385. text-align: center;
  386. }
  387. }
  388. .empty{
  389. margin: 130rpx 0 150rpx;
  390. text-align: center;
  391. image,uni-image{
  392. display: inline-block;
  393. width: 414rpx;
  394. height: 305rpx;
  395. }
  396. text{
  397. display: block;
  398. color: #999999;
  399. font-size: 26rpx;
  400. }
  401. }
  402. </style>