From e7976cf7de902c0ecb847db06fb6aaef98160b7f Mon Sep 17 00:00:00 2001
From: lwh <2679599887@qq.com>
Date: Wed, 19 Jul 2023 12:20:35 +0800
Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?=
=?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=AF=B9=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../components/images-videos/index.wxml | 4 +-
pages/goods/comments/index.js | 91 +++++++++++--------
pages/goods/comments/index.wxml | 8 +-
pages/goods/details/index.js | 14 +--
services/comments/fetchComments.js | 29 +++---
services/comments/fetchCommentsCount.js | 30 +++---
services/good/fetchGood.js | 19 ----
services/good/fetchGoodsDetailsComments.js | 62 +++++++------
8 files changed, 135 insertions(+), 122 deletions(-)
diff --git a/pages/goods/comments/components/comments-card/components/images-videos/index.wxml b/pages/goods/comments/components/comments-card/components/images-videos/index.wxml
index 2515909..a7aefd2 100644
--- a/pages/goods/comments/components/comments-card/components/images-videos/index.wxml
+++ b/pages/goods/comments/components/comments-card/components/images-videos/index.wxml
@@ -5,9 +5,9 @@
wx:for-item="resource"
wx:key="*this"
>
-
+
-
+
diff --git a/pages/goods/comments/index.js b/pages/goods/comments/index.js
index ef3b361..44f1c48 100644
--- a/pages/goods/comments/index.js
+++ b/pages/goods/comments/index.js
@@ -1,5 +1,9 @@
-import { fetchComments } from '../../../services/comments/fetchComments';
-import { fetchCommentsCount } from '../../../services/comments/fetchCommentsCount';
+import {
+ fetchComments
+} from '~/services/comments/fetchComments';
+import {
+ fetchCommentsCount
+} from '~/services/comments/fetchCommentsCount';
import dayjs from 'dayjs';
const layoutMap = {
0: 'vertical',
@@ -17,11 +21,11 @@ Page({
layoutText: layoutMap[0],
loadMoreStatus: 0,
myLoadStatus: 0,
- spuId: '1060004',
+ spuId: '',
commentLevel: '',
hasImage: '',
commentType: '',
- totalCount: 0,
+ totalNum: 0,
countObj: {
badCount: '0',
commentCount: '0',
@@ -37,14 +41,7 @@ Page({
},
async getCount(options) {
try {
- const result = await fetchCommentsCount(
- {
- spuId: options.spuId,
- },
- {
- method: 'POST',
- },
- );
+ const result = await fetchCommentsCount(options.spuId);
this.setData({
countObj: result,
});
@@ -64,25 +61,31 @@ Page({
} catch (error) {}
},
generalQueryData(reset) {
- const { hasImage, pageNum, pageSize, spuId, commentLevel } = this.data;
+ const {
+ hasImage,
+ pageNum,
+ pageSize,
+ spuId,
+ commentLevel
+ } = this.data;
const params = {
pageNum: 1,
- pageSize: 30,
- queryParameter: {
- spuId,
- },
+ pageSize: 10,
+ spuId: spuId,
+ commentLevel: 0,
+ hasImage: false
};
if (
Number(commentLevel) === 3 ||
Number(commentLevel) === 2 ||
Number(commentLevel) === 1
) {
- params.queryParameter.commentLevel = Number(commentLevel);
+ params.commentLevel = Number(commentLevel);
}
if (hasImage && hasImage === '1') {
- params.queryParameter.hasImage = true;
+ params.hasImage = true;
} else {
- delete params.queryParameter.hasImage;
+ delete params.hasImage;
}
// 重置请求
if (reset) return params;
@@ -94,7 +97,10 @@ Page({
};
},
async init(reset = true) {
- const { loadMoreStatus, commentList = [] } = this.data;
+ const {
+ loadMoreStatus,
+ commentList = []
+ } = this.data;
const params = this.generalQueryData(reset);
// 在加载中或者无更多数据,直接返回
@@ -106,34 +112,37 @@ Page({
try {
const data = await fetchComments(params, {
- method: 'POST',
+ method: 'GET',
});
const code = 'SUCCESS';
if (code.toUpperCase() === 'SUCCESS') {
- const { pageList, totalCount = 0 } = data;
- pageList.forEach((item) => {
+ const {
+ result,
+ totalNum = 0
+ } = data;
+ result.forEach((item) => {
// eslint-disable-next-line no-param-reassign
- item.commentTime = dayjs(Number(item.commentTime)).format(
- 'YYYY/MM/DD HH:mm',
- );
+ // item.commentTime = dayjs(Number(item.commentTime)).format(
+ // 'YYYY/MM/DD HH:mm',
+ // );
});
- if (Number(totalCount) === 0 && reset) {
+ if (Number(totalNum) === 0 && reset) {
this.setData({
commentList: [],
hasLoaded: true,
- total: totalCount,
+ total: totalNum,
loadMoreStatus: 2,
});
return;
}
- const _commentList = reset ? pageList : commentList.concat(pageList);
+ const _commentList = reset ? result : commentList.concat(result);
const _loadMoreStatus =
- _commentList.length === Number(totalCount) ? 2 : 0;
+ _commentList.length === Number(totalNum) ? 2 : 0;
this.setData({
commentList: _commentList,
pageNum: params.pageNum || 1,
- totalCount: Number(totalCount),
+ totalNum: Number(totalNum),
loadMoreStatus: _loadMoreStatus,
});
} else {
@@ -158,7 +167,9 @@ Page({
return array;
},
getComments(options) {
- const { commentLevel = -1, spuId, hasImage = '' } = options;
+ const {
+ commentLevel = -1, spuId, hasImage = ''
+ } = options;
if (commentLevel !== -1) {
this.setData({
commentLevel: commentLevel,
@@ -172,8 +183,12 @@ Page({
this.init(true);
},
changeTag(e) {
- var { commenttype } = e.currentTarget.dataset;
- var { commentType } = this.data;
+ var {
+ commenttype
+ } = e.currentTarget.dataset;
+ var {
+ commentType
+ } = this.data;
if (commentType === commenttype) return;
this.setData({
loadMoreStatus: 0,
@@ -214,7 +229,9 @@ Page({
}
},
onReachBottom() {
- const { total = 0, commentList } = this.data;
+ const {
+ total = 0, commentList
+ } = this.data;
if (commentList.length === total) {
this.setData({
loadMoreStatus: 2,
@@ -224,4 +241,4 @@ Page({
this.init(false);
},
-});
+});
\ No newline at end of file
diff --git a/pages/goods/comments/index.wxml b/pages/goods/comments/index.wxml
index 89d2b0f..0f9909d 100644
--- a/pages/goods/comments/index.wxml
+++ b/pages/goods/comments/index.wxml
@@ -2,24 +2,24 @@
全部({{countObj.commentCount}})
-
自己({{countObj.uidCount}})
-
+ -->
带图({{countObj.hasImageCount}})
-
+
好评({{countObj.goodCount}})
中评({{countObj.middleCount}})
-
+
差评({{countObj.badCount}})
diff --git a/pages/goods/details/index.js b/pages/goods/details/index.js
index 7862c05..a13a720 100644
--- a/pages/goods/details/index.js
+++ b/pages/goods/details/index.js
@@ -412,13 +412,13 @@ Page({
async getCommentsList() {
try {
const code = 'Success';
- const data = await getGoodsDetailsCommentList();
- const {
- homePageComments
- } = data;
+ const data = await getGoodsDetailsCommentList(this.data.spuId);
+ // const {
+ // homePageComments
+ // } = data;
if (code.toUpperCase() === 'SUCCESS') {
const nextState = {
- commentsList: homePageComments.map((item) => {
+ commentsList: data.map((item) => {
return {
goodsSpu: item.spuId,
userName: item.userName || '',
@@ -458,7 +458,7 @@ Page({
async getCommentsStatistics() {
try {
const code = 'Success';
- const data = await getGoodsDetailsCommentsCount();
+ const data = await getGoodsDetailsCommentsCount(this.data.spuId);
if (code.toUpperCase() === 'SUCCESS') {
const {
badCount,
@@ -497,7 +497,7 @@ Page({
const {
spuId
} = query;
- // const spuId = "1673671239077597184";
+ // const spuId = "1680467515018448896";
this.setData({
spuId: spuId,
diff --git a/services/comments/fetchComments.js b/services/comments/fetchComments.js
index 9bd1155..f23d5ac 100644
--- a/services/comments/fetchComments.js
+++ b/services/comments/fetchComments.js
@@ -1,18 +1,23 @@
import { config } from '../../config/index';
-
-/** 获取商品评论 */
-function mockFetchComments(parmas) {
- const { delay } = require('../_utils/delay');
- const { getGoodsAllComments } = require('../../model/comments');
- return delay().then(() => getGoodsAllComments(parmas));
-}
+import {
+ request
+} from '../_utils/request';
/** 获取商品评论 */
export function fetchComments(parmas) {
- if (config.useMock) {
- return mockFetchComments(parmas);
- }
- return new Promise((resolve) => {
- resolve('real api');
+ return new Promise((resolve, reject) => {
+ request({
+ url: `GoodsCommentApi/getGoodsCommentList`,
+ data: parmas,
+ method: 'GET',
+ success: function (res) {
+ let data = res.data;
+
+ resolve(data);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
});
}
diff --git a/services/comments/fetchCommentsCount.js b/services/comments/fetchCommentsCount.js
index cbb09d0..bf93c9b 100644
--- a/services/comments/fetchCommentsCount.js
+++ b/services/comments/fetchCommentsCount.js
@@ -1,18 +1,22 @@
-import { config } from '../../config/index';
-
-/** 获取商品评论数 */
-function mockFetchCommentsCount(ID = 0) {
- const { delay } = require('../_utils/delay');
- const { getGoodsCommentsCount } = require('../../model/comments');
- return delay().then(() => getGoodsCommentsCount(ID));
-}
+import {
+ request
+} from '../_utils/request';
/** 获取商品评论数 */
export function fetchCommentsCount(ID = 0) {
- if (config.useMock) {
- return mockFetchCommentsCount(ID);
- }
- return new Promise((resolve) => {
- resolve('real api');
+ return new Promise((resolve, reject) => {
+ request({
+ url: `GoodsCommentApi/GetGoodsDetailsCommentsCount`,
+ data: {SpuId: ID},
+ method: 'GET',
+ success: function (res) {
+ let data = res.data;
+
+ resolve(data);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
});
}
diff --git a/services/good/fetchGood.js b/services/good/fetchGood.js
index b531f21..8f39949 100644
--- a/services/good/fetchGood.js
+++ b/services/good/fetchGood.js
@@ -1,25 +1,6 @@
-import {
- config
-} from '../../config/index';
import {
request
} from '../_utils/request';
-/** 获取商品详情 */
-// function mockFetchGood(ID = 0) {
-// const { delay } = require('../_utils/delay');
-// const { genGood } = require('../../model/good');
-// return delay().then(() => genGood(ID));
-// }
-
-// /** 获取商品列表 */
-// export function fetchGood(ID = 0) {
-// if (config.useMock) {
-// return mockFetchGood(ID);
-// }
-// return new Promise((resolve) => {
-// resolve('real api');
-// });
-// }
/** 获取商品详情 */
export function fetchGood(ID) {
diff --git a/services/good/fetchGoodsDetailsComments.js b/services/good/fetchGoodsDetailsComments.js
index 95a11c4..7eab461 100644
--- a/services/good/fetchGoodsDetailsComments.js
+++ b/services/good/fetchGoodsDetailsComments.js
@@ -1,37 +1,43 @@
import { config } from '../../config/index';
+import {
+ request
+} from '../_utils/request';
+
/** 获取商品详情页评论数 */
-function mockFetchGoodDetailsCommentsCount(spuId = 0) {
- const { delay } = require('../_utils/delay');
- const {
- getGoodsDetailsCommentsCount,
- } = require('../../model/detailsComments');
- return delay().then(() => getGoodsDetailsCommentsCount(spuId));
-}
-
-/** 获取商品详情页评论数 */
-export function getGoodsDetailsCommentsCount(spuId = 0) {
- if (config.useMock) {
- return mockFetchGoodDetailsCommentsCount(spuId);
- }
- return new Promise((resolve) => {
- resolve('real api');
+export function getGoodsDetailsCommentsCount(spuId) {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `GoodsCommentApi/GetGoodsDetailsCommentsCount`,
+ data: {SpuId: spuId},
+ method: 'GET',
+ success: function (res) {
+ let data = res.data;
+
+ resolve(data);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
});
}
/** 获取商品详情页评论 */
-function mockFetchGoodDetailsCommentList(spuId = 0) {
- const { delay } = require('../_utils/delay');
- const { getGoodsDetailsComments } = require('../../model/detailsComments');
- return delay().then(() => getGoodsDetailsComments(spuId));
-}
-
-/** 获取商品详情页评论 */
-export function getGoodsDetailsCommentList(spuId = 0) {
- if (config.useMock) {
- return mockFetchGoodDetailsCommentList(spuId);
- }
- return new Promise((resolve) => {
- resolve('real api');
+export function getGoodsDetailsCommentList(spuId) {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `GoodsCommentApi/getGoodsDetailsComments`,
+ data: {SpuId: spuId},
+ method: 'GET',
+ success: function (res) {
+ let data = res.data;
+
+ resolve(data);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
});
}