comment.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <app-layout>
  3. <view class="comment">
  4. <view class="navigator dir-left-nowrap">
  5. <view @click="setActiveNav(3)">
  6. <text :class="{'active-nav': score === 3}">好评</text>
  7. </view>
  8. <view @click="setActiveNav(2)">
  9. <text :class="{'active-nav': score === 2}">中评</text>
  10. </view>
  11. <view @click="setActiveNav(1)">
  12. <text :class="{'active-nav': score === 1}">差评</text>
  13. </view>
  14. </view>
  15. <view class="replyStatus dir-left-nowrap main-center cross-center">
  16. <view @click="setActiveReply(2)" :class="{'active-reply': is_reply === 2}">未回复</view>
  17. <view @click="setActiveReply(1)" :class="{'active-reply': is_reply === 1}">已回复</view>
  18. </view>
  19. <view class="tip" v-if="list.length === 0">
  20. <image src="https://v4test.zjhejiang.com/web/statics/img/app/app_admin/no-comment.png"></image>
  21. <view>没有任何评论哦~</view>
  22. </view>
  23. <view class="content">
  24. <view class="item dir-top-nowrap" v-for="(item, index) in list" :key="index"
  25. :class="{'is-top-box-bg': item.is_top === 1}">
  26. <view class="top dir-left-nowrap">
  27. <image :src="item.cover_pic" lazy-load class="image"></image>
  28. <view class="text" :class="{'is-top-center-bg': item.is_top === 1}">
  29. <view class="name">
  30. {{item.name}}
  31. </view>
  32. <view class="from">
  33. 来自用户 {{item.nickname}}
  34. </view>
  35. </view>
  36. </view>
  37. <view class="bottom dir-left-nowrap main-between">
  38. <view class="performed dir-left-nowrap cross-center">
  39. <image class="icon"
  40. :src="`${item.score === 3 ? '../image/praise.png' : item.score === 2 ? '../image/average.png' : '../image/bad-review.png'}`"/>
  41. <view class="evaluation">{{item.score === 3 ? '好评' : item.score === 2 ? '中评' : item.score
  42. === 1 ? '差评' : ''}}
  43. </view>
  44. <view class="show" v-if="0 && item.is_show === 0">已隐藏</view>
  45. </view>
  46. <view class="button dir-left-nowrap">
  47. <view>
  48. <view @click="isTop(item,index)">
  49. <view class="reply">
  50. {{item.is_top === 1 ? '取消置顶' : '置顶'}}
  51. </view>
  52. </view>
  53. </view>
  54. <view>
  55. <view @click="isShow(item)" style="margin-left:16rpx">
  56. <view class="show-button">
  57. {{item.is_show === 1 ? '隐藏评论' : '取消隐藏'}}
  58. </view>
  59. </view>
  60. </view>
  61. <view>
  62. <app-jump-button form
  63. :url="`/pages/app_admin/comment-detail/comment-detail?id=${item.id}`">
  64. <view class="reply">
  65. {{item.reply_content === '' ? '回复' : '修改回复'}}
  66. </view>
  67. </app-jump-button>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </app-layout>
  75. </template>
  76. <script>
  77. export default {
  78. name: 'comment',
  79. data() {
  80. return {
  81. list: [],
  82. over: false,
  83. page: 1,
  84. is_reply: 2,
  85. score: 3,
  86. }
  87. },
  88. onLoad() {
  89. this.$request({
  90. url: this.$api.app_admin.comments,
  91. data: {
  92. score: 3,
  93. is_reply: 2,
  94. page: 1,
  95. }
  96. }).then(response => {
  97. if (response.code === 0) {
  98. this.list = response.data.list;
  99. }
  100. })
  101. },
  102. onReachBottom() {
  103. if (!this.over) {
  104. this.page++;
  105. this.request();
  106. }
  107. },
  108. methods: {
  109. setActiveNav(data) {
  110. this.page = 1;
  111. this.score = data;
  112. this.is_reply = 2;
  113. this.over = false;
  114. uni.pageScrollTo({
  115. scrollTop: 0
  116. });
  117. this.$request({
  118. url: this.$api.app_admin.comments,
  119. data: {
  120. score: this.score,
  121. is_reply: this.is_reply,
  122. page: this.page,
  123. }
  124. }).then(response => {
  125. if (response.code === 0) {
  126. this.list = response.data.list;
  127. }
  128. })
  129. },
  130. setActiveReply(data) {
  131. this.page = 1;
  132. this.is_reply = data;
  133. this.over = false;
  134. this.$request({
  135. url: this.$api.app_admin.comments,
  136. data: {
  137. score: this.score,
  138. is_reply: this.is_reply,
  139. page: this.page,
  140. }
  141. }).then(response => {
  142. if (response.code === 0) {
  143. this.list = response.data.list;
  144. }
  145. });
  146. },
  147. request() {
  148. this.$request({
  149. url: this.$api.app_admin.comments,
  150. data: {
  151. score: this.score,
  152. is_reply: this.is_reply,
  153. page: this.page,
  154. }
  155. }).then(response => {
  156. if (response.code === 0) {
  157. if (response.data.list.length > 0) {
  158. this.list = [...this.list, ...response.data.list];
  159. } else {
  160. this.over = true;
  161. }
  162. }
  163. })
  164. },
  165. isTop(data, index) {
  166. const self = this;
  167. const is_top = data.is_top == 1 ? 0 : 1;
  168. self.$request({
  169. url: self.$api.app_admin.comments_top,
  170. method: 'POST',
  171. data: {
  172. status: is_top,
  173. id: data.id
  174. }
  175. }).then(info => {
  176. if (info.code === 0) {
  177. data.is_top = is_top;
  178. self.list.splice(index, 1, data);
  179. uni.showToast({title: info.msg, icon: 'none'});
  180. }
  181. })
  182. },
  183. isShow(data) {
  184. if (data.is_show === 0) {
  185. this.$request({
  186. url: this.$api.app_admin.comments_show,
  187. method: 'POST',
  188. data: {
  189. is_show: 1,
  190. id: data.id,
  191. }
  192. }).then(response => {
  193. if (response.code === 0) {
  194. for (let i = 0; i < this.list.length; i++) {
  195. if (data.id === this.list[i].id) {
  196. this.list[i].is_show = 1;
  197. }
  198. }
  199. }
  200. })
  201. } else {
  202. this.$request({
  203. url: this.$api.app_admin.comments_show,
  204. method: 'POST',
  205. data: {
  206. is_show: 0,
  207. id: data.id,
  208. }
  209. }).then(response => {
  210. if (response.code === 0) {
  211. for (let i = 0; i < this.list.length; i++) {
  212. if (data.id === this.list[i].id) {
  213. this.list[i].is_show = 0;
  214. }
  215. }
  216. }
  217. })
  218. }
  219. }
  220. },
  221. }
  222. </script>
  223. <style scoped lang="scss">
  224. @import "./comment.scss";
  225. </style>