comment.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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://shop.9026.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() { this.$commonLoad.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. uni.showLoading({
  136. title: '加载中...'
  137. });
  138. this.$request({
  139. url: this.$api.app_admin.comments,
  140. data: {
  141. score: this.score,
  142. is_reply: this.is_reply,
  143. page: this.page,
  144. }
  145. }).then(response => {
  146. uni.hideLoading();
  147. if (response.code === 0) {
  148. this.list = response.data.list;
  149. }
  150. })
  151. },
  152. setActiveReply(data) {
  153. this.page = 1;
  154. this.is_reply = data;
  155. this.over = false;
  156. uni.showLoading({
  157. title: '加载中...'
  158. });
  159. this.$request({
  160. url: this.$api.app_admin.comments,
  161. data: {
  162. score: this.score,
  163. is_reply: this.is_reply,
  164. page: this.page,
  165. }
  166. }).then(response => {
  167. uni.hideLoading();
  168. if (response.code === 0) {
  169. this.list = response.data.list;
  170. }
  171. });
  172. },
  173. request() {
  174. this.$request({
  175. url: this.$api.app_admin.comments,
  176. data: {
  177. score: this.score,
  178. is_reply: this.is_reply,
  179. page: this.page,
  180. }
  181. }).then(response => {
  182. if (response.code === 0) {
  183. if (response.data.list.length > 0) {
  184. this.list = [...this.list, ...response.data.list];
  185. } else {
  186. this.over = true;
  187. }
  188. }
  189. })
  190. },
  191. isTop(data, index) {
  192. const self = this;
  193. const is_top = data.is_top == 1 ? 0 : 1;
  194. self.$request({
  195. url: self.$api.app_admin.comments_top,
  196. method: 'POST',
  197. data: {
  198. status: is_top,
  199. id: data.id
  200. }
  201. }).then(info => {
  202. if (info.code === 0) {
  203. data.is_top = is_top;
  204. self.list.splice(index, 1, data);
  205. uni.showToast({title: info.msg, icon: 'none'});
  206. }
  207. })
  208. },
  209. isShow(data) {
  210. if (data.is_show === 0) {
  211. this.$request({
  212. url: this.$api.app_admin.comments_show,
  213. method: 'POST',
  214. data: {
  215. is_show: 1,
  216. id: data.id,
  217. }
  218. }).then(response => {
  219. if (response.code === 0) {
  220. for (let i = 0; i < this.list.length; i++) {
  221. if (data.id === this.list[i].id) {
  222. this.list[i].is_show = 1;
  223. }
  224. }
  225. }
  226. })
  227. } else {
  228. this.$request({
  229. url: this.$api.app_admin.comments_show,
  230. method: 'POST',
  231. data: {
  232. is_show: 0,
  233. id: data.id,
  234. }
  235. }).then(response => {
  236. if (response.code === 0) {
  237. for (let i = 0; i < this.list.length; i++) {
  238. if (data.id === this.list[i].id) {
  239. this.list[i].is_show = 0;
  240. }
  241. }
  242. }
  243. })
  244. }
  245. }
  246. },
  247. }
  248. </script>
  249. <style scoped lang="scss">
  250. @import "./comment.scss";
  251. </style>