comment.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="comment">
  3. <view class="top-tab">
  4. <view class="tab-btn" :v-if="commentDetail">
  5. <view @click="select(0)" :class="{ cur: selectIndex == 0 }">全部</view>
  6. <view @click="select(1)" :class="{ cur: selectIndex == 1 }">好评{{ commentDetail.good }}</view>
  7. <view @click="select(2)" :class="{ cur: selectIndex == 2 }">中评{{ commentDetail.moderate }}</view>
  8. <view @click="select(3)" :class="{ cur: selectIndex == 3 }">差评{{ commentDetail.worse }}</view>
  9. <view @click="select(4)" :class="{ cur: selectIndex == 4 }">有图{{ commentDetail.haveImage }}</view>
  10. </view>
  11. </view>
  12. <!-- 评价 -->
  13. <div class="goodsBoxOver">
  14. <div class="scoll-page">
  15. <view class="eva-section">
  16. <div class="empty" v-if="commDetail.length < 1">
  17. <view>
  18. <u-empty mode="message" text="赞无评论"></u-empty>
  19. </view>
  20. </div>
  21. <view class="eva-box" v-for="(item, index) in commDetail" :key="index">
  22. <view class="section-info">
  23. <image class="portrait" :src="item.memberProfile || '/static/missing-face.png'" mode="aspectFill"></image>
  24. <view class="star-content">
  25. <text class="name">{{ item.memberName | noPassByName }}</text>
  26. <text class="time">{{ item.createTime }}</text>
  27. </view>
  28. <view class="stars">
  29. <text :class="{ star: item.deliveryScore > 0 }"></text>
  30. <text :class="{ star: item.deliveryScore > 1 }"></text>
  31. <text :class="{ star: item.deliveryScore > 2 }"></text>
  32. <text :class="{ star: item.deliveryScore > 3 }"></text>
  33. <text :class="{ star: item.deliveryScore > 4 }"></text>
  34. </view>
  35. </view>
  36. <view class="section-contant">
  37. <div class="content">{{ item.content }}</div>
  38. <view class="img">
  39. <!-- 循环出用户评价的图片 -->
  40. <u-image width="140rpx" height="140rpx" v-if="item.images" v-for="(img, i) in splitImg(item.images)" :src="img" :key="i" @click="preview(splitImg(item.images), i)">
  41. </u-image>
  42. </view>
  43. <view class="bot">
  44. <text class="attr">{{ item.goodsName }} - {{ gradeList[item.grade] }}</text>
  45. </view>
  46. </view>
  47. <view class="commentStyle" v-if="item.reply">
  48. 商家回复:
  49. <span class="addCommentSpan">{{ item.reply }}</span>
  50. <view class="img">
  51. <!-- 循环出商家回复评价的图片 -->
  52. <u-image width="140rpx" height="140rpx" v-if="item.replyImage" v-for="(replyImg, replyIndex) in splitImg(item.replyImage)" :src="replyImg" :key="replyIndex"
  53. @click="preview(splitImg( item.replyImage), index)">
  54. </u-image>
  55. </view>
  56. </view>
  57. </view>
  58. <u-loadmore bg-color="transparent" style="margin:40rpx 0" :status="status" @loadmore="loadmore()" icon-type="iconType" />
  59. </view>
  60. </div>
  61. </div>
  62. </view>
  63. </template>
  64. <script>
  65. // import { getGoodsDetail } from '@/api/goods.js';
  66. import * as membersApi from "@/api/members.js";
  67. export default {
  68. data() {
  69. return {
  70. status: "loadmore", //底部刷新状态
  71. commentDetail: "", //评价详情
  72. selectIndex: "0", //检索条件
  73. params: { // 评论分页提交数据
  74. pageNumber: 1,
  75. pageSize: 10,
  76. grade: "",
  77. },
  78. gradeList: {
  79. GOOD: "好评",
  80. MODERATE: "中评",
  81. WORSE: "差评",
  82. HAVEIMAGE: "有图",
  83. },
  84. // 评论详情
  85. commDetail: [],
  86. dataTotal: 0, //评论的总total数量
  87. opid: "", //上级传参id
  88. };
  89. },
  90. async onLoad(options) {
  91. this.getGoodsCommentsFun(options.id);
  92. this.getGoodsCommentsNum(options.id);
  93. this.opid = options.id;
  94. },
  95. /**
  96. * 触底加载
  97. */
  98. onReachBottom() {
  99. this.params.pageNumber++;
  100. this.getGoodsCommentsFun(this.opid);
  101. },
  102. methods: {
  103. /**
  104. * 切割图像
  105. */
  106. splitImg(val) {
  107. if (val && val.split(",")) {
  108. return val.split(",");
  109. } else if (val) {
  110. return val;
  111. } else {
  112. return false;
  113. }
  114. },
  115. /**
  116. * 获取商品评论
  117. */
  118. getGoodsCommentsFun(id) {
  119. this.status = "loading";
  120. // getGoodsComments
  121. membersApi.getGoodsComments(id, this.params).then((res) => {
  122. if (
  123. res.data.result.records == [] ||
  124. res.data.result.records == "" ||
  125. res.data.result.records == null
  126. ) {
  127. this.status = "noMore";
  128. return false;
  129. }
  130. this.commDetail = this.commDetail.concat(res.data.result.records);
  131. this.dataTotal = res.data.result.total;
  132. this.status = "loadmore";
  133. });
  134. },
  135. /**
  136. * 获取商品评论数
  137. */
  138. getGoodsCommentsNum(id) {
  139. membersApi.getGoodsCommentsCount(id).then((res) => {
  140. if (res.statusCode === 200) {
  141. this.commentDetail = res.data.result;
  142. }
  143. });
  144. },
  145. /**
  146. * 顶部筛选条件
  147. */
  148. select(index) {
  149. this.selectIndex = index;
  150. this.params.grade = ["", "GOOD", "MODERATE", "WORSE", ""][
  151. this.selectIndex
  152. ];
  153. this.selectIndex == 4 ? (this.params.haveImage = 1) : true;
  154. this.params.pageNumber = 1;
  155. this.params.pageSize = 10;
  156. this.commDetail = [];
  157. if (this.selectIndex == 0) {
  158. this.params = {
  159. pageNumber: 1,
  160. pageSize: 10,
  161. grade: "",
  162. };
  163. }
  164. // 重新加载评论
  165. this.getGoodsCommentsFun(this.opid);
  166. },
  167. /**
  168. * 点击图片放大或保存
  169. */
  170. preview(urls, index) {
  171. uni.previewImage({
  172. current: index,
  173. urls: urls,
  174. longPressActions: {
  175. itemList: ["保存图片"],
  176. success: function (data) {
  177. uni.showToast({
  178. title: "保存成功",
  179. duration: 2000,
  180. icon: "none",
  181. });
  182. },
  183. fail: function (err) {
  184. uni.showToast({
  185. title: "保存失败",
  186. duration: 2000,
  187. icon: "none",
  188. });
  189. },
  190. },
  191. });
  192. },
  193. },
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. .commentStyle {
  198. margin-top: 16rpx;
  199. padding: 14rpx 26rpx;
  200. background: #f5f5f5;
  201. border-radius: 6px;
  202. font-size: 22rpx;
  203. font-weight: 700;
  204. text-align: left;
  205. line-height: 40rpx;
  206. }
  207. .addCommentSpan {
  208. color: $u-tips-color !important;
  209. padding-left: 20rpx;
  210. }
  211. .img {
  212. display: flex;
  213. flex-wrap: wrap;
  214. /* height: 140rpx; */
  215. overflow: hidden;
  216. image {
  217. width: 166rpx;
  218. height: 166rpx;
  219. margin: 0 15rpx 15rpx 0;
  220. &:nth-of-type(3n + 0) {
  221. margin: 0 0 15rpx 0;
  222. }
  223. }
  224. }
  225. .goodsBoxOver {
  226. overflow-y: scroll;
  227. }
  228. page {
  229. background: #f7f7f7;
  230. }
  231. .comment {
  232. color: #333;
  233. background: #f7f7f7;
  234. overflow: hidden;
  235. .top-tab {
  236. background: #fff;
  237. margin-bottom: 10rpx;
  238. border-radius: 20rpx;
  239. display: flex;
  240. flex-direction: column;
  241. padding: 0 30rpx 0 30rpx;
  242. font-size: 24rpx;
  243. .tab-btn {
  244. margin-top: 20rpx;
  245. display: flex;
  246. flex-wrap: wrap;
  247. view {
  248. min-width: 118rpx;
  249. text-align: center;
  250. height: 50rpx;
  251. line-height: 50rpx;
  252. padding: 0 10rpx;
  253. background: #f8f8fe;
  254. border-radius: 25rpx;
  255. margin: 0 20rpx 30rpx 0;
  256. &.cur {
  257. background: $aider-light-color;
  258. color: #fff;
  259. }
  260. }
  261. }
  262. }
  263. .eva-section {
  264. padding: 20rpx 0;
  265. .eva-box {
  266. padding: 40rpx;
  267. margin-bottom: 10rpx;
  268. background: #fff;
  269. border-radius: 20rpx;
  270. /* star */
  271. .star-content {
  272. display: flex;
  273. flex-direction: column;
  274. view {
  275. flex: 1;
  276. display: flex;
  277. align-items: center;
  278. }
  279. .time {
  280. font-size: 24rpx;
  281. color: #999;
  282. }
  283. }
  284. .section-info {
  285. display: flex;
  286. .stars {
  287. flex: 1;
  288. display: flex;
  289. justify-content: flex-end;
  290. align-items: center;
  291. .star {
  292. width: 30rpx;
  293. height: 30rpx;
  294. background: url("/static/star.png");
  295. background-size: 100%;
  296. }
  297. }
  298. .portrait {
  299. flex-shrink: 0;
  300. width: 80rpx;
  301. height: 80rpx;
  302. border-radius: 100px;
  303. margin-right: 20rpx;
  304. }
  305. }
  306. .section-contant {
  307. display: flex;
  308. flex-direction: column;
  309. .content {
  310. font-size: 24rpx;
  311. line-height: 46rpx;
  312. font-weight: 400;
  313. color: $font-color-dark;
  314. color: #333;
  315. padding: 26rpx 0;
  316. }
  317. .img {
  318. display: flex;
  319. flex-wrap: wrap;
  320. /* height: 140rpx; */
  321. overflow: hidden;
  322. > * {
  323. margin-right: 16rpx;
  324. }
  325. }
  326. .bot {
  327. display: flex;
  328. justify-content: space-between;
  329. font-size: $font-sm;
  330. color: $font-color-light;
  331. margin-top: 20rpx;
  332. .good {
  333. color: #333;
  334. position: relative;
  335. &:before {
  336. content: "";
  337. width: 40rpx;
  338. height: 40rpx;
  339. background: url(/static/search/delete.png);
  340. background-size: 100%;
  341. position: absolute;
  342. left: -50rpx;
  343. top: -6rpx;
  344. }
  345. &.cur:before {
  346. background: url(/static/global/selected.png);
  347. background-size: 100%;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. .empty {
  356. padding-top: 300rpx;
  357. color: #999999;
  358. text-align: center;
  359. }
  360. </style>