comment.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <!-- 评论 -->
  3. <view class="back">
  4. <view class="" v-if="commentlist.length >0">
  5. <view class="box" v-for="(item,idx) in commentlist" :key="idx">
  6. <!-- 顶部 -->
  7. <view class="" style="display: flex;justify-content: space-between;">
  8. <view class="u-flex">
  9. <image style="width: 68rpx;height: 68rpx;border: radius 34rpx;;" :src="item.member.avatar"
  10. mode="">
  11. </image>
  12. <view class="">
  13. <text
  14. class="name">{{item.member.nickname.slice(0,1)+'***'+item.member.nickname.slice(-1)}}</text>
  15. <uni-rate network allow-half :readonly="true" color="rgba(247, 181, 0, 1)" :size='8'
  16. :value="5" v-model="rate" />
  17. </view>
  18. </view>
  19. <text class="day">{{timeSince(item.created_at)}}</text>
  20. </view>
  21. <view class="day" style="margin-top: 24rpx;">{{item.sku_item.item}}</view>
  22. <view class="content" style="margin-top: 20rpx;">{{item.content}}</view>
  23. <!-- <view class="" v-for="(child,index) in item.image.split(',')" :key="index" style="margin-top: 22rpx;"> -->
  24. <view class="u-flex u-row-between" style="margin-top: 22rpx;flex-wrap: wrap;" v-if="item.image">
  25. <image v-for="(child,index) in item.image.split(',')" :key="index" :src="child"
  26. style="margin-bottom: 20rpx; width: 326rpx;height: 326rpx;border-radius: 12rpx;background: #D8D8D8;"
  27. mode=""></image>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="" style="height: 400rpx;text-align: center;line-height: 400rpx;">
  32. 暂无数据
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. merchant_goods_id: '',
  41. commentlist: [],
  42. rate: ''
  43. };
  44. },
  45. onLoad(options) {
  46. this.merchant_goods_id = options.id
  47. this.comment()
  48. },
  49. onshow() {
  50. },
  51. computed: {
  52. i18n() {
  53. return this.$t('index')
  54. }
  55. },
  56. methods: {
  57. //评论接口
  58. comment() {
  59. uni.$u.http.post('/api/goods/goods_comment', {
  60. merchant_goods_id: this.merchant_goods_id,
  61. page: 1,
  62. limit: 10
  63. }).then((res) => {
  64. console.log(res);
  65. this.commentlist = res.data
  66. }).catch(() => {
  67. })
  68. },
  69. timeSince(dateString) {
  70. // 为兼容iOS,转换日期格式
  71. // var dateArr = dateString.split("T")[0].split("-");
  72. // var timeArr = dateString.split("T")[1].split(":");
  73. // var date = new Date(dateArr[0], dateArr[1] - 1, dateArr[2], timeArr[0], timeArr[1], timeArr[2]);
  74. var date = dateString;
  75. const second = 1000;
  76. const minute = 60 * second;
  77. const hour = 60 * minute;
  78. const day = 24 * hour;
  79. const month = 30 * day;
  80. const year = 12 * month;
  81. const now = new Date().getTime();
  82. const inputDate = new Date(date).getTime();
  83. const diffValue = now - inputDate;
  84. if (diffValue < 0) {
  85. console.error('输入的时间不能在当前时间之后!');
  86. return dateString;
  87. }
  88. if (diffValue < minute) {
  89. return Math.round(diffValue / second) + '秒前';
  90. } else if (diffValue < hour) {
  91. return Math.round(diffValue / minute) + '分钟前';
  92. } else if (diffValue < day) {
  93. return Math.round(diffValue / hour) + '小时前';
  94. } else if (diffValue < month) {
  95. return Math.round(diffValue / day) + '天前';
  96. } else if (diffValue < year) {
  97. return Math.round(diffValue / month) + '个月前';
  98. } else {
  99. // 时间间隔超过一年,直接显示具体时间
  100. return dateArr.join('-');
  101. }
  102. },
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .back {
  108. // background-color:rgba(216, 216, 216, 1) ;
  109. padding: 20rpx;
  110. box-sizing: border-box;
  111. .box {
  112. background: #FFFFFF;
  113. border-radius: 16rpx;
  114. padding: 24rpx 20rpx;
  115. box-sizing: border-box;
  116. margin-bottom: 20rpx;
  117. }
  118. .day {
  119. font-family: SFPro, SFPro;
  120. font-weight: 400;
  121. font-size: 20rpx;
  122. color: #9E9E9E;
  123. line-height: 24rpx;
  124. text-align: justify;
  125. font-style: normal;
  126. }
  127. .content {
  128. font-family: PingFangSC, PingFang SC;
  129. font-weight: 400;
  130. font-size: 26rpx;
  131. color: #444444;
  132. line-height: 36rpx;
  133. text-align: justify;
  134. font-style: normal;
  135. }
  136. .name {
  137. font-family: PingFangSC, PingFang SC;
  138. font-weight: 500;
  139. font-size: 22rpx;
  140. color: #444444;
  141. line-height: 32rpx;
  142. text-align: left;
  143. font-style: normal;
  144. margin-bottom: 34rpx;
  145. }
  146. }
  147. </style>