app-comments.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <view class="app-comments" v-if="mall.setting.is_comment == 1">
  3. <view class="empty" v-if="showType !== 'detail'">
  4. <view class="app-top dir-left-nowrap cross-center">
  5. <view class="box box-grow-1 main-center cross-center" @click="clickStatus(item.index)"
  6. v-for="(item, index) in commentCount"
  7. :key="index"
  8. :class="status === item.index ? getTheme + '-m-back u-text ' + getTheme : 'background'">
  9. {{item.name}}({{item.count}})
  10. </view>
  11. </view>
  12. </view>
  13. <view class="list" v-if="list.length > 0">
  14. <view class="dir-left-nowrap block cross-center" v-if="showType === 'detail'">
  15. <view class="box-grow-1">评价</view>
  16. <view class="box-grow-0 more" @click="goto">查看更多</view>
  17. <image class="box-grow-0" src="../../../static/image/icon/arrow-right.png"></image>
  18. </view>
  19. <view class="comments" v-for="(item, index) in list" :key="index" :class="showType === 'detail' ? 'bt' : 'bb'">
  20. <view class="title dir-left-nowrap cross-center">
  21. <image class="box-grow-0" :src="item.avatar"></image>
  22. <view class="box-grow-1">{{item.nickname}}</view>
  23. <view class="more box-grow-0">{{item.time}}</view>
  24. </view>
  25. <view class="c-attr-name">{{ item.attr_name }}</view>
  26. <view :class="showType === 'detail' ? 'content' : ''">{{item.content}}</view>
  27. <view class="dir-left-wrap pic-list">
  28. <image :src="pic_url" v-for="(pic_url,pic_url_index) in item.pic_url" :key="pic_url_index"
  29. @click="imgPreview(index, pic_url_index)"></image>
  30. </view>
  31. <view class="replay" v-if="showType !== 'detail' && item.reply_content">
  32. <view>
  33. <text :class="getTheme + '-m-text ' + getTheme">商家:</text>
  34. {{item.reply_content}}
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="block cross-center" v-else>暂无评价</view>
  40. </view>
  41. </template>
  42. <script>
  43. import {mapGetters, mapState} from 'vuex';
  44. let page = 1;
  45. let is_loading = false;
  46. let is_no_more = false;
  47. export default {
  48. name: 'app-comments',
  49. props: {
  50. goodsId: Number,
  51. url: {
  52. type: String,
  53. default() {
  54. return '';
  55. }
  56. },
  57. showType: {
  58. type: String,
  59. default() {
  60. return 'detail'
  61. }
  62. },
  63. reachBottom: Number,
  64. },
  65. watch: {
  66. goodsId: {
  67. handler() {
  68. this.loadData();
  69. }
  70. },
  71. reachBottom: {
  72. handler(){
  73. if (is_no_more) return;
  74. this.loadData();
  75. }
  76. }
  77. },
  78. computed: {
  79. ...mapState({
  80. mall: state => state.mallConfig.mall
  81. }),
  82. ...mapGetters('mallConfig', {
  83. getTheme: 'getTheme',
  84. }),
  85. },
  86. methods: {
  87. loadData() {
  88. if (this.mall.setting.is_comment == 0) return;
  89. if (is_loading) return;
  90. is_loading = true;
  91. if (this.showType !== 'detail') {
  92. uni.showLoading({
  93. title: '加载中'
  94. });
  95. }
  96. this.$request({
  97. url: this.url ? this.url : this.$api.goods.comments_list,
  98. data: {
  99. goods_id: this.goodsId,
  100. page: page,
  101. status: this.status,
  102. }
  103. }).then(response => {
  104. is_loading = false;
  105. uni.hideLoading();
  106. if (response.code === 0) {
  107. this.commentCount = response.data.comment_count;
  108. if (page === 1) {
  109. this.list = [];
  110. }
  111. let list = response.data.comments;
  112. if (list.length > 0) {
  113. if (this.showType === 'detail') {
  114. list = list.splice(0, 2)
  115. }
  116. this.list = [...this.list, ...list];
  117. page++;
  118. } else {
  119. is_no_more = true;
  120. }
  121. }
  122. }).catch(() => {
  123. is_loading = false;
  124. uni.hideLoading();
  125. });
  126. },
  127. goto() {
  128. uni.navigateTo({
  129. url: `/pages/comments/comments?goods_id=${this.goodsId}`
  130. })
  131. },
  132. clickStatus(status) {
  133. this.status = status;
  134. page = 1;
  135. is_no_more = false;
  136. this.loadData();
  137. },
  138. imgPreview(index, pic_index) {
  139. if (this.list && this.list[index] && this.list[index].pic_url && this.list[index].pic_url.length > 0) {
  140. uni.previewImage({
  141. current: pic_index,
  142. urls: this.list[index].pic_url
  143. });
  144. }
  145. },
  146. },
  147. data() {
  148. return {
  149. commentCount: [],
  150. list: [],
  151. status: 0,
  152. };
  153. },
  154. created() {
  155. page = 1;
  156. is_loading = false;
  157. is_no_more = false;
  158. },
  159. mounted() {
  160. if (this.goodsId) this.loadData();
  161. },
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .app-comments {
  166. .c-attr-name {
  167. color: #999999;
  168. font-size: #{24rpx};
  169. }
  170. .more {
  171. font-size: $uni-font-size-weak-one;
  172. color: $uni-general-color-two;
  173. }
  174. .block {
  175. width: 100%;
  176. height: #{80rpx};
  177. font-size: $uni-font-size-general-two;
  178. background-color: #FFFFFF;
  179. padding: 0 #{24rpx};
  180. image {
  181. width: #{12rpx};
  182. height: #{22rpx};
  183. display: block;
  184. margin-left: #{12rpx};
  185. }
  186. }
  187. .empty {
  188. width: 100%;
  189. height: #{100rpx};
  190. margin-bottom: #{20rpx};
  191. }
  192. .app-top {
  193. padding: #{24rpx};
  194. background-color: #FFFFFF;
  195. width: 100%;
  196. height: #{100rpx};
  197. position: fixed;
  198. left: 0;
  199. top: 0;
  200. .box {
  201. padding: 0 #{20rpx};
  202. margin-right: #{16rpx};
  203. border-radius: #{26rpx};
  204. font-size: $uni-font-size-general-two;
  205. height: 100%;
  206. &.background {
  207. background-color: #f1f1f1;
  208. color: $uni-general-color-one;
  209. }
  210. }
  211. }
  212. .list {
  213. background-color: #ffffff;
  214. padding: 0 #{24rpx};
  215. .block {
  216. padding: 0;
  217. }
  218. .comments {
  219. padding: #{28rpx} 0;
  220. width: 100%;
  221. word-break: break-all;
  222. .title {
  223. font-size: $uni-font-size-general-one;
  224. color: $uni-general-color-two;
  225. margin-bottom: #{26rpx};
  226. image {
  227. width: #{56rpx};
  228. height: #{56rpx};
  229. display: block;
  230. margin-right: #{26rpx};
  231. border-radius: #{28upx};
  232. }
  233. }
  234. &.bt {
  235. border-top: #{1rpx} solid #e2e2e2;
  236. }
  237. &.bb {
  238. border-bottom: #{1rpx} solid #e2e2e2;
  239. }
  240. &.bb:last-child {
  241. border: none;
  242. }
  243. .content {
  244. word-break: break-all;
  245. text-overflow: ellipsis;
  246. display: -webkit-box;
  247. -webkit-box-orient: vertical;
  248. -webkit-line-clamp: 2;
  249. overflow: hidden;
  250. }
  251. .pic-list {
  252. image {
  253. width: #{214rpx};
  254. height: #{214rpx};
  255. display: inline-block;
  256. margin: #{20rpx} #{20rpx} 0 0;
  257. }
  258. }
  259. .replay {
  260. width: 100%;
  261. background-color: $uni-weak-color-two;
  262. padding: #{28rpx};
  263. border-radius: #{16rpx};
  264. font-size: $uni-font-size-general-one;
  265. color: $uni-general-color-one;
  266. }
  267. }
  268. }
  269. }
  270. .u-text {
  271. color: #ffffff;
  272. }
  273. </style>