index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view :style="colorStyle">
  3. <!-- 导航区 -->
  4. <view class="w-full fixed-lt bg--w111-fff z-10 rd-b-24rpx">
  5. <view class="pl-32 pr-32 pt-24 pb-32">
  6. <view class="flex-between-center">
  7. <view>
  8. <text class="text--w111-333 fs-30 fw-500">评价</text>
  9. <text class="fs-24 text--w111-666 pl-8">({{tabList[0].count}})</text>
  10. </view>
  11. <view class="flex-y-center">
  12. <text class="fs-28 text-primary-con Regular">{{replyData.reply_chance}}%</text>
  13. <text class="fs-24 text--w111-999 pl-4 pr-12">好评率</text>
  14. </view>
  15. </view>
  16. <view class="flex-y-center mt-34">
  17. <view
  18. class="tab_item inline-block h-56 rd-28rpx lh-56rpx text-center px-24 fs-24 bg--w111-f5f5f5 text--w111-333"
  19. v-for="(item, index) in tabList" :key="index"
  20. :class="index == type ? 'active' : ''"
  21. @click='changeType(index)'>{{ item.title }}({{ item.count }})</view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="h-186"></view>
  26. <!-- 评论卡片 -->
  27. <view v-if="reply.length">
  28. <view class="mt-20 rd-24rpx bg--w111-fff p-32"
  29. v-for="item in reply" :key="item.id" @click="goPage(item.id)">
  30. <view class="flex-between-center">
  31. <view class="flex-y-center">
  32. <image :src="item.avatar" class="w-56 h-56 rd-28rpx"></image>
  33. <text class="fs-28 text--w111-333 pl-12">{{item.nickname}}</text>
  34. </view>
  35. <view class="fs-26 text--w111-999 Regular">{{item.add_time}}</view>
  36. </view>
  37. <view class="flex-between-center mt-32">
  38. <view class="flex-y-center">
  39. <view class="flex pr-20">
  40. <text class="iconfont icon-ic_star1 fs-18 text-primary-con" v-for="star in Number(item.star)"
  41. :key="star"></text>
  42. </view>
  43. <text class="w-400 line1" v-show="item.suk">
  44. <text class="text--w111-ccc fs-18">|</text>
  45. <text class="pl-20 fs-22 text--w111-999">{{item.suk}}</text>
  46. </text>
  47. </view>
  48. <image src="../static/hp_icon.png" class="w-78 h-30" mode="aspectFit" v-show="item.reply_score == 3"></image>
  49. <image src="../static/zp_icon.png" class="w-78 h-30" mode="aspectFit" v-show="item.reply_score == 2"></image>
  50. <image src="../static/cp_icon.png" class="w-78 h-30" mode="aspectFit" v-show="item.reply_score == 1"></image>
  51. </view>
  52. <view class="mt-20 fs-28 text--w111-333 lh-44rpx">{{item.comment}}</view>
  53. <!-- 1张照片 -->
  54. <image :src="item.pics[0]" class="w-400 h-400 rd-16rpx mt-20" mode="aspectFill"
  55. v-if="item.pics.length == 1"></image>
  56. <!-- 2张照片 -->
  57. <view class="mt-20 grid-column-2 grid-gap-x-10rpx grid-gap-y-20rpx" v-if="item.pics.length == 2">
  58. <image class="w-full h-338 rd-16rpx" :src="itemp" mode="aspectFill" v-for="(itemp,ip) in item.pics"
  59. :key="ip"></image>
  60. </view>
  61. <!-- 多于2张照片 -->
  62. <view class="mt-20 grid-column-3 grid-gap-10rpx" v-if="item.pics.length > 2">
  63. <image class="w-full h-222 rd-16rpx" :src="itemp" mode="aspectFill" v-for="(itemp,ip) in item.pics"
  64. :key="ip"></image>
  65. </view>
  66. <!-- 浏览次数 点赞 -->
  67. <view class="flex-between-center mt-24">
  68. <text class="fs-22 text--w111-999">浏览{{item.views_num}}次</text>
  69. <view class="flex text--w111-333">
  70. <view class="flex-y-center" :class="item.is_praise ? 'text-primary-con':''">
  71. <text class="iconfont icon-ic_Like fs-32"
  72. @tap.stop="tapPraise(item)"></text>
  73. <text class="fs-22 pl-8">{{item.praise}}</text>
  74. </view>
  75. <view class="ml-32 flex-y-center">
  76. <text class="iconfont icon-ic_message fs-32"></text>
  77. <text class="fs-22 pl-8">{{item.replyComment ? item.replyComment.sum : 0}}</text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="px-20 mt-20" v-else>
  84. <emptyPage title="暂无评论,去看点别的吧~" src="/statics/images/noMessage.gif"></emptyPage>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import {
  90. getReplyList,
  91. getReplyConfig,
  92. getReplyPraise,
  93. getUnReplyPraise
  94. } from '@/api/store.js';
  95. import colors from '@/mixins/color.js';
  96. import {toLogin} from '@/libs/login.js';
  97. import {mapGetters} from "vuex";
  98. import {HTTP_REQUEST_URL} from '@/config/app';
  99. import emptyPage from '@/components/emptyPage.vue';
  100. export default {
  101. mixins: [colors],
  102. computed: mapGetters(['isLogin']),
  103. data() {
  104. return {
  105. tabList: [{
  106. title: '全部',
  107. count: ''
  108. },
  109. {
  110. title: '好评',
  111. count: ''
  112. },
  113. {
  114. title: '中评',
  115. count: ''
  116. },
  117. {
  118. title: '差评',
  119. count: ''
  120. },
  121. ],
  122. replyData: {},
  123. product_id: 0,
  124. reply: [],
  125. type: 0,
  126. loading: false,
  127. loadend: false,
  128. loadTitle: '加载更多',
  129. page: 1,
  130. limit: 20,
  131. imgHost: HTTP_REQUEST_URL,
  132. isShowAuth: false,
  133. };
  134. },
  135. components:{ emptyPage },
  136. /**
  137. * 生命周期函数--监听页面加载
  138. */
  139. onLoad: function(options) {
  140. let that = this;
  141. if (!options.product_id) return that.$util.Tips({
  142. title: '缺少参数'
  143. }, {
  144. tab: 3,
  145. url: 1
  146. });
  147. that.product_id = options.product_id;
  148. },
  149. onShow() {
  150. uni.removeStorageSync('form_type_cart');
  151. this.getProductReplyCount();
  152. this.loadend = false;
  153. this.page = 1;
  154. this.reply = [];
  155. this.getProductReplyList();
  156. },
  157. methods: {
  158. replyFun(e) {
  159. this.reply = e;
  160. },
  161. changeLogin() {
  162. toLogin()
  163. },
  164. onLoadFun() {
  165. this.isShowAuth = false
  166. },
  167. // 授权关闭
  168. authColse: function(e) {
  169. this.isShowAuth = e
  170. },
  171. /**
  172. * 获取评论统计数据
  173. *
  174. */
  175. getProductReplyCount: function() {
  176. let that = this;
  177. getReplyConfig(that.product_id).then(res => {
  178. that.$set(that, 'replyData', res.data);
  179. this.tabList[0].count = res.data.sum_count;
  180. this.tabList[1].count = res.data.good_count;
  181. this.tabList[2].count = res.data.in_count;
  182. this.tabList[3].count = res.data.poor_count;
  183. });
  184. },
  185. /**
  186. * 分页获取评论
  187. */
  188. getProductReplyList: function() {
  189. let that = this;
  190. if (that.loadend) return;
  191. if (that.loading) return;
  192. that.loading = true;
  193. that.loadTitle = '';
  194. getReplyList(that.product_id, {
  195. page: that.page,
  196. limit: that.limit,
  197. type: that.type,
  198. }).then(res => {
  199. let list = res.data,
  200. loadend = list.length < that.limit;
  201. that.reply = that.$util.SplitArray(list, that.reply);
  202. that.$set(that, 'reply', that.reply);
  203. that.loading = false;
  204. that.loadend = loadend;
  205. that.loadTitle = loadend ? "没有更多内容啦~" : "加载更多";
  206. that.page = that.page + 1;
  207. }).catch(err => {
  208. that.loading = false,
  209. that.loadTitle = '加载更多'
  210. });
  211. },
  212. /*
  213. * 点击事件切换
  214. * */
  215. changeType: function(e) {
  216. let type = parseInt(e);
  217. if (type == this.type) return;
  218. this.type = type;
  219. this.page = 1;
  220. this.loadend = false;
  221. this.$set(this, 'reply', []);
  222. this.getProductReplyList();
  223. },
  224. goPage(id) {
  225. uni.navigateTo({
  226. url: '/pages/goods/goods_comment_con/comment_con?id=' + id
  227. })
  228. },
  229. tapPraise(item) {
  230. if (item.is_praise) {
  231. getUnReplyPraise(item.id).then(res => {
  232. item.is_praise = !item.is_praise;
  233. item.praise = item.praise - 1;
  234. return this.$util.Tips({
  235. title: res.msg
  236. });
  237. });
  238. } else {
  239. getReplyPraise(item.id).then(res => {
  240. item.is_praise = !item.is_praise;
  241. item.praise = item.praise + 1;
  242. return this.$util.Tips({
  243. title: res.msg
  244. });
  245. });
  246. }
  247. },
  248. },
  249. /**
  250. * 页面上拉触底事件的处理函数
  251. */
  252. onReachBottom: function() {
  253. this.getProductReplyList();
  254. },
  255. }
  256. </script>
  257. <style lang="scss">
  258. .emptyBox {
  259. text-align: center;
  260. margin-top: 40rpx;
  261. .tips {
  262. color: #aaa;
  263. font-size: 26rpx;
  264. }
  265. image {
  266. width: 414rpx;
  267. height: 336rpx;
  268. }
  269. }
  270. .active {
  271. background: var(--view-minorColorT);
  272. border: 1rpx solid var(--view-theme);
  273. color: var(--view-theme);
  274. }
  275. .text-primary-con {
  276. color: var(--view-theme);
  277. }
  278. .tab_item~.tab_item {
  279. margin-left: 16rpx;
  280. }
  281. </style>