comment.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 class="reply" @click="isTop(item,index)">
  48. {{item.is_top === 1 ? '取消置顶' : '置顶'}}
  49. </view>
  50. <view @click="isShow(item)" class="show-button" style="margin-left:16rpx">
  51. {{item.is_show === 1 ? '隐藏评论' : '取消隐藏'}}
  52. </view>
  53. <app-jump-button form
  54. :url="`/pages/app_admin/comment-detail/comment-detail?id=${item.id}`">
  55. <view class="reply">
  56. {{item.reply_content === '' ? '回复' : '修改回复'}}
  57. </view>
  58. </app-jump-button>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </app-layout>
  65. </template>
  66. <script>
  67. export default {
  68. name: 'comment',
  69. data() {
  70. return {
  71. list: [],
  72. over: false,
  73. page: 1,
  74. is_reply: 2,
  75. score: 3,
  76. first: true,
  77. }
  78. },
  79. onLoad() {
  80. this.$showLoading({
  81. type: 'global',
  82. text: '加载中...'
  83. });
  84. this.$request({
  85. url: this.$api.app_admin.comments,
  86. data: {
  87. score: 3,
  88. is_reply: 2,
  89. page: 1,
  90. }
  91. }).then(response => {
  92. this.$hideLoading();
  93. if (response.code === 0) {
  94. this.first = false;
  95. this.list = response.data.list;
  96. }
  97. })
  98. },
  99. onReachBottom() {
  100. if (!this.over) {
  101. this.page++;
  102. this.request();
  103. }
  104. },
  105. onShow() {
  106. if(this.first) {
  107. return false
  108. }
  109. this.$request({
  110. url: this.$api.app_admin.comments,
  111. data: {
  112. score: this.score,
  113. is_reply: this.is_reply,
  114. page: this.page,
  115. }
  116. }).then(response => {
  117. if (response.code === 0) {
  118. for(let i in response.data.list) {
  119. for(let j in this.list) {
  120. this.list = response.data.list;
  121. }
  122. }
  123. }
  124. })
  125. },
  126. methods: {
  127. setActiveNav(data) {
  128. this.page = 1;
  129. this.score = data;
  130. this.is_reply = 2;
  131. this.over = false;
  132. uni.pageScrollTo({
  133. scrollTop: 0
  134. });
  135. this.$request({
  136. url: this.$api.app_admin.comments,
  137. data: {
  138. score: this.score,
  139. is_reply: this.is_reply,
  140. page: this.page,
  141. }
  142. }).then(response => {
  143. if (response.code === 0) {
  144. this.list = response.data.list;
  145. }
  146. })
  147. },
  148. setActiveReply(data) {
  149. this.page = 1;
  150. this.is_reply = data;
  151. this.over = false;
  152. this.$request({
  153. url: this.$api.app_admin.comments,
  154. data: {
  155. score: this.score,
  156. is_reply: this.is_reply,
  157. page: this.page,
  158. }
  159. }).then(response => {
  160. if (response.code === 0) {
  161. this.list = response.data.list;
  162. }
  163. });
  164. },
  165. request() {
  166. this.$request({
  167. url: this.$api.app_admin.comments,
  168. data: {
  169. score: this.score,
  170. is_reply: this.is_reply,
  171. page: this.page,
  172. }
  173. }).then(response => {
  174. if (response.code === 0) {
  175. if (response.data.list.length > 0) {
  176. this.list = [...this.list, ...response.data.list];
  177. } else {
  178. this.over = true;
  179. }
  180. }
  181. })
  182. },
  183. isTop(data, index) {
  184. const self = this;
  185. const is_top = data.is_top == 1 ? 0 : 1;
  186. self.$request({
  187. url: self.$api.app_admin.comments_top,
  188. method: 'POST',
  189. data: {
  190. status: is_top,
  191. id: data.id
  192. }
  193. }).then(info => {
  194. if (info.code === 0) {
  195. data.is_top = is_top;
  196. self.list.splice(index, 1, data);
  197. uni.showToast({title: info.msg, icon: 'none'});
  198. }
  199. })
  200. },
  201. isShow(data) {
  202. if (data.is_show === 0) {
  203. this.$request({
  204. url: this.$api.app_admin.comments_show,
  205. method: 'POST',
  206. data: {
  207. is_show: 1,
  208. id: data.id,
  209. }
  210. }).then(response => {
  211. if (response.code === 0) {
  212. for (let i = 0; i < this.list.length; i++) {
  213. if (data.id === this.list[i].id) {
  214. this.list[i].is_show = 1;
  215. }
  216. }
  217. }
  218. })
  219. } else {
  220. this.$request({
  221. url: this.$api.app_admin.comments_show,
  222. method: 'POST',
  223. data: {
  224. is_show: 0,
  225. id: data.id,
  226. }
  227. }).then(response => {
  228. if (response.code === 0) {
  229. for (let i = 0; i < this.list.length; i++) {
  230. if (data.id === this.list[i].id) {
  231. this.list[i].is_show = 0;
  232. }
  233. }
  234. }
  235. })
  236. }
  237. }
  238. },
  239. }
  240. </script>
  241. <style scoped lang="scss">
  242. @import "./comment.scss";
  243. </style>