app-comments.vue 9.4 KB

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