feat 添加商品评论对接
This commit is contained in:
parent
8f5533ef66
commit
e7976cf7de
@ -5,9 +5,9 @@
|
|||||||
wx:for-item="resource"
|
wx:for-item="resource"
|
||||||
wx:key="*this"
|
wx:key="*this"
|
||||||
>
|
>
|
||||||
<t-image wx:if="{{resource.type === 'image'}}" t-class="resource-item-{{classType}}" src="{{resource.src}}" />
|
<image wx:if="{{resource.type === 'image'}}" class="resource-item-{{classType}}" src="{{resource.src}}" />
|
||||||
<my-video wx:else videoSrc="{{resource.src}} " my-video="resource-item-{{classType}}">
|
<my-video wx:else videoSrc="{{resource.src}} " my-video="resource-item-{{classType}}">
|
||||||
<t-image t-class="resource-item resource-item-{{classType}}" slot="cover-img" src="{{resource.coverSrc}}" />
|
<image class="resource-item resource-item-{{classType}}" slot="cover-img" src="{{resource.coverSrc}}" />
|
||||||
<image class="play-icon" slot="play-icon" src="./assets/play.png" />
|
<image class="play-icon" slot="play-icon" src="./assets/play.png" />
|
||||||
</my-video>
|
</my-video>
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import { fetchComments } from '../../../services/comments/fetchComments';
|
import {
|
||||||
import { fetchCommentsCount } from '../../../services/comments/fetchCommentsCount';
|
fetchComments
|
||||||
|
} from '~/services/comments/fetchComments';
|
||||||
|
import {
|
||||||
|
fetchCommentsCount
|
||||||
|
} from '~/services/comments/fetchCommentsCount';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
const layoutMap = {
|
const layoutMap = {
|
||||||
0: 'vertical',
|
0: 'vertical',
|
||||||
@ -17,11 +21,11 @@ Page({
|
|||||||
layoutText: layoutMap[0],
|
layoutText: layoutMap[0],
|
||||||
loadMoreStatus: 0,
|
loadMoreStatus: 0,
|
||||||
myLoadStatus: 0,
|
myLoadStatus: 0,
|
||||||
spuId: '1060004',
|
spuId: '',
|
||||||
commentLevel: '',
|
commentLevel: '',
|
||||||
hasImage: '',
|
hasImage: '',
|
||||||
commentType: '',
|
commentType: '',
|
||||||
totalCount: 0,
|
totalNum: 0,
|
||||||
countObj: {
|
countObj: {
|
||||||
badCount: '0',
|
badCount: '0',
|
||||||
commentCount: '0',
|
commentCount: '0',
|
||||||
@ -37,14 +41,7 @@ Page({
|
|||||||
},
|
},
|
||||||
async getCount(options) {
|
async getCount(options) {
|
||||||
try {
|
try {
|
||||||
const result = await fetchCommentsCount(
|
const result = await fetchCommentsCount(options.spuId);
|
||||||
{
|
|
||||||
spuId: options.spuId,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
this.setData({
|
this.setData({
|
||||||
countObj: result,
|
countObj: result,
|
||||||
});
|
});
|
||||||
@ -64,25 +61,31 @@ Page({
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
},
|
},
|
||||||
generalQueryData(reset) {
|
generalQueryData(reset) {
|
||||||
const { hasImage, pageNum, pageSize, spuId, commentLevel } = this.data;
|
const {
|
||||||
|
hasImage,
|
||||||
|
pageNum,
|
||||||
|
pageSize,
|
||||||
|
spuId,
|
||||||
|
commentLevel
|
||||||
|
} = this.data;
|
||||||
const params = {
|
const params = {
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 30,
|
pageSize: 10,
|
||||||
queryParameter: {
|
spuId: spuId,
|
||||||
spuId,
|
commentLevel: 0,
|
||||||
},
|
hasImage: false
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
Number(commentLevel) === 3 ||
|
Number(commentLevel) === 3 ||
|
||||||
Number(commentLevel) === 2 ||
|
Number(commentLevel) === 2 ||
|
||||||
Number(commentLevel) === 1
|
Number(commentLevel) === 1
|
||||||
) {
|
) {
|
||||||
params.queryParameter.commentLevel = Number(commentLevel);
|
params.commentLevel = Number(commentLevel);
|
||||||
}
|
}
|
||||||
if (hasImage && hasImage === '1') {
|
if (hasImage && hasImage === '1') {
|
||||||
params.queryParameter.hasImage = true;
|
params.hasImage = true;
|
||||||
} else {
|
} else {
|
||||||
delete params.queryParameter.hasImage;
|
delete params.hasImage;
|
||||||
}
|
}
|
||||||
// 重置请求
|
// 重置请求
|
||||||
if (reset) return params;
|
if (reset) return params;
|
||||||
@ -94,7 +97,10 @@ Page({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
async init(reset = true) {
|
async init(reset = true) {
|
||||||
const { loadMoreStatus, commentList = [] } = this.data;
|
const {
|
||||||
|
loadMoreStatus,
|
||||||
|
commentList = []
|
||||||
|
} = this.data;
|
||||||
const params = this.generalQueryData(reset);
|
const params = this.generalQueryData(reset);
|
||||||
|
|
||||||
// 在加载中或者无更多数据,直接返回
|
// 在加载中或者无更多数据,直接返回
|
||||||
@ -106,34 +112,37 @@ Page({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await fetchComments(params, {
|
const data = await fetchComments(params, {
|
||||||
method: 'POST',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
const code = 'SUCCESS';
|
const code = 'SUCCESS';
|
||||||
if (code.toUpperCase() === 'SUCCESS') {
|
if (code.toUpperCase() === 'SUCCESS') {
|
||||||
const { pageList, totalCount = 0 } = data;
|
const {
|
||||||
pageList.forEach((item) => {
|
result,
|
||||||
|
totalNum = 0
|
||||||
|
} = data;
|
||||||
|
result.forEach((item) => {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
item.commentTime = dayjs(Number(item.commentTime)).format(
|
// item.commentTime = dayjs(Number(item.commentTime)).format(
|
||||||
'YYYY/MM/DD HH:mm',
|
// 'YYYY/MM/DD HH:mm',
|
||||||
);
|
// );
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Number(totalCount) === 0 && reset) {
|
if (Number(totalNum) === 0 && reset) {
|
||||||
this.setData({
|
this.setData({
|
||||||
commentList: [],
|
commentList: [],
|
||||||
hasLoaded: true,
|
hasLoaded: true,
|
||||||
total: totalCount,
|
total: totalNum,
|
||||||
loadMoreStatus: 2,
|
loadMoreStatus: 2,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const _commentList = reset ? pageList : commentList.concat(pageList);
|
const _commentList = reset ? result : commentList.concat(result);
|
||||||
const _loadMoreStatus =
|
const _loadMoreStatus =
|
||||||
_commentList.length === Number(totalCount) ? 2 : 0;
|
_commentList.length === Number(totalNum) ? 2 : 0;
|
||||||
this.setData({
|
this.setData({
|
||||||
commentList: _commentList,
|
commentList: _commentList,
|
||||||
pageNum: params.pageNum || 1,
|
pageNum: params.pageNum || 1,
|
||||||
totalCount: Number(totalCount),
|
totalNum: Number(totalNum),
|
||||||
loadMoreStatus: _loadMoreStatus,
|
loadMoreStatus: _loadMoreStatus,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -158,7 +167,9 @@ Page({
|
|||||||
return array;
|
return array;
|
||||||
},
|
},
|
||||||
getComments(options) {
|
getComments(options) {
|
||||||
const { commentLevel = -1, spuId, hasImage = '' } = options;
|
const {
|
||||||
|
commentLevel = -1, spuId, hasImage = ''
|
||||||
|
} = options;
|
||||||
if (commentLevel !== -1) {
|
if (commentLevel !== -1) {
|
||||||
this.setData({
|
this.setData({
|
||||||
commentLevel: commentLevel,
|
commentLevel: commentLevel,
|
||||||
@ -172,8 +183,12 @@ Page({
|
|||||||
this.init(true);
|
this.init(true);
|
||||||
},
|
},
|
||||||
changeTag(e) {
|
changeTag(e) {
|
||||||
var { commenttype } = e.currentTarget.dataset;
|
var {
|
||||||
var { commentType } = this.data;
|
commenttype
|
||||||
|
} = e.currentTarget.dataset;
|
||||||
|
var {
|
||||||
|
commentType
|
||||||
|
} = this.data;
|
||||||
if (commentType === commenttype) return;
|
if (commentType === commenttype) return;
|
||||||
this.setData({
|
this.setData({
|
||||||
loadMoreStatus: 0,
|
loadMoreStatus: 0,
|
||||||
@ -214,7 +229,9 @@ Page({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onReachBottom() {
|
onReachBottom() {
|
||||||
const { total = 0, commentList } = this.data;
|
const {
|
||||||
|
total = 0, commentList
|
||||||
|
} = this.data;
|
||||||
if (commentList.length === total) {
|
if (commentList.length === total) {
|
||||||
this.setData({
|
this.setData({
|
||||||
loadMoreStatus: 2,
|
loadMoreStatus: 2,
|
||||||
@ -224,4 +241,4 @@ Page({
|
|||||||
|
|
||||||
this.init(false);
|
this.init(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
@ -2,24 +2,24 @@
|
|||||||
<t-tag t-class="comments-header-tag {{commentType === '' ? 'comments-header-active' : ''}}" data-commentType="" bindtap="changeTag">
|
<t-tag t-class="comments-header-tag {{commentType === '' ? 'comments-header-active' : ''}}" data-commentType="" bindtap="changeTag">
|
||||||
全部({{countObj.commentCount}})
|
全部({{countObj.commentCount}})
|
||||||
</t-tag>
|
</t-tag>
|
||||||
<t-tag
|
<!-- <t-tag
|
||||||
t-class="comments-header-tag {{commentType === '5' ? 'comments-header-active' : ''}}"
|
t-class="comments-header-tag {{commentType === '5' ? 'comments-header-active' : ''}}"
|
||||||
wx:if="{{countObj.uidCount !== '0'}}"
|
wx:if="{{countObj.uidCount !== '0'}}"
|
||||||
data-commentType="5"
|
data-commentType="5"
|
||||||
bindtap="changeTag"
|
bindtap="changeTag"
|
||||||
>
|
>
|
||||||
自己({{countObj.uidCount}})
|
自己({{countObj.uidCount}})
|
||||||
</t-tag>
|
</t-tag> -->
|
||||||
<t-tag t-class="comments-header-tag {{commentType === '4' ? 'comments-header-active' : ''}}" data-commentType="4" bindtap="changeTag">
|
<t-tag t-class="comments-header-tag {{commentType === '4' ? 'comments-header-active' : ''}}" data-commentType="4" bindtap="changeTag">
|
||||||
带图({{countObj.hasImageCount}})
|
带图({{countObj.hasImageCount}})
|
||||||
</t-tag>
|
</t-tag>
|
||||||
<t-tag t-class="comments-header-tag {{commentType === '3' ? 'comments-header-active' : ''}}" data-commentType="3" bindtap="changeTag">
|
<t-tag t-class="comments-header-tag {{commentType === '1' ? 'comments-header-active' : ''}}" data-commentType="1" bindtap="changeTag">
|
||||||
好评({{countObj.goodCount}})
|
好评({{countObj.goodCount}})
|
||||||
</t-tag>
|
</t-tag>
|
||||||
<t-tag t-class="comments-header-tag {{commentType === '2' ? 'comments-header-active' : ''}}" data-commentType="2" bindtap="changeTag">
|
<t-tag t-class="comments-header-tag {{commentType === '2' ? 'comments-header-active' : ''}}" data-commentType="2" bindtap="changeTag">
|
||||||
中评({{countObj.middleCount}})
|
中评({{countObj.middleCount}})
|
||||||
</t-tag>
|
</t-tag>
|
||||||
<t-tag t-class="comments-header-tag {{commentType === '1' ? 'comments-header-active' : ''}}" data-commentType="1" bindtap="changeTag">
|
<t-tag t-class="comments-header-tag {{commentType === '3' ? 'comments-header-active' : ''}}" data-commentType="3" bindtap="changeTag">
|
||||||
差评({{countObj.badCount}})
|
差评({{countObj.badCount}})
|
||||||
</t-tag>
|
</t-tag>
|
||||||
</view>
|
</view>
|
||||||
|
@ -412,13 +412,13 @@ Page({
|
|||||||
async getCommentsList() {
|
async getCommentsList() {
|
||||||
try {
|
try {
|
||||||
const code = 'Success';
|
const code = 'Success';
|
||||||
const data = await getGoodsDetailsCommentList();
|
const data = await getGoodsDetailsCommentList(this.data.spuId);
|
||||||
const {
|
// const {
|
||||||
homePageComments
|
// homePageComments
|
||||||
} = data;
|
// } = data;
|
||||||
if (code.toUpperCase() === 'SUCCESS') {
|
if (code.toUpperCase() === 'SUCCESS') {
|
||||||
const nextState = {
|
const nextState = {
|
||||||
commentsList: homePageComments.map((item) => {
|
commentsList: data.map((item) => {
|
||||||
return {
|
return {
|
||||||
goodsSpu: item.spuId,
|
goodsSpu: item.spuId,
|
||||||
userName: item.userName || '',
|
userName: item.userName || '',
|
||||||
@ -458,7 +458,7 @@ Page({
|
|||||||
async getCommentsStatistics() {
|
async getCommentsStatistics() {
|
||||||
try {
|
try {
|
||||||
const code = 'Success';
|
const code = 'Success';
|
||||||
const data = await getGoodsDetailsCommentsCount();
|
const data = await getGoodsDetailsCommentsCount(this.data.spuId);
|
||||||
if (code.toUpperCase() === 'SUCCESS') {
|
if (code.toUpperCase() === 'SUCCESS') {
|
||||||
const {
|
const {
|
||||||
badCount,
|
badCount,
|
||||||
@ -497,7 +497,7 @@ Page({
|
|||||||
const {
|
const {
|
||||||
spuId
|
spuId
|
||||||
} = query;
|
} = query;
|
||||||
// const spuId = "1673671239077597184";
|
// const spuId = "1680467515018448896";
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
spuId: spuId,
|
spuId: spuId,
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
import { config } from '../../config/index';
|
import { config } from '../../config/index';
|
||||||
|
import {
|
||||||
/** 获取商品评论 */
|
request
|
||||||
function mockFetchComments(parmas) {
|
} from '../_utils/request';
|
||||||
const { delay } = require('../_utils/delay');
|
|
||||||
const { getGoodsAllComments } = require('../../model/comments');
|
|
||||||
return delay().then(() => getGoodsAllComments(parmas));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取商品评论 */
|
/** 获取商品评论 */
|
||||||
export function fetchComments(parmas) {
|
export function fetchComments(parmas) {
|
||||||
if (config.useMock) {
|
return new Promise((resolve, reject) => {
|
||||||
return mockFetchComments(parmas);
|
request({
|
||||||
}
|
url: `GoodsCommentApi/getGoodsCommentList`,
|
||||||
return new Promise((resolve) => {
|
data: parmas,
|
||||||
resolve('real api');
|
method: 'GET',
|
||||||
|
success: function (res) {
|
||||||
|
let data = res.data;
|
||||||
|
|
||||||
|
resolve(data);
|
||||||
|
},
|
||||||
|
fail: function (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,22 @@
|
|||||||
import { config } from '../../config/index';
|
import {
|
||||||
|
request
|
||||||
/** 获取商品评论数 */
|
} from '../_utils/request';
|
||||||
function mockFetchCommentsCount(ID = 0) {
|
|
||||||
const { delay } = require('../_utils/delay');
|
|
||||||
const { getGoodsCommentsCount } = require('../../model/comments');
|
|
||||||
return delay().then(() => getGoodsCommentsCount(ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取商品评论数 */
|
/** 获取商品评论数 */
|
||||||
export function fetchCommentsCount(ID = 0) {
|
export function fetchCommentsCount(ID = 0) {
|
||||||
if (config.useMock) {
|
return new Promise((resolve, reject) => {
|
||||||
return mockFetchCommentsCount(ID);
|
request({
|
||||||
}
|
url: `GoodsCommentApi/GetGoodsDetailsCommentsCount`,
|
||||||
return new Promise((resolve) => {
|
data: {SpuId: ID},
|
||||||
resolve('real api');
|
method: 'GET',
|
||||||
|
success: function (res) {
|
||||||
|
let data = res.data;
|
||||||
|
|
||||||
|
resolve(data);
|
||||||
|
},
|
||||||
|
fail: function (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,6 @@
|
|||||||
import {
|
|
||||||
config
|
|
||||||
} from '../../config/index';
|
|
||||||
import {
|
import {
|
||||||
request
|
request
|
||||||
} from '../_utils/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) {
|
export function fetchGood(ID) {
|
||||||
|
@ -1,37 +1,43 @@
|
|||||||
import { config } from '../../config/index';
|
import { config } from '../../config/index';
|
||||||
|
import {
|
||||||
|
request
|
||||||
|
} from '../_utils/request';
|
||||||
|
|
||||||
|
|
||||||
/** 获取商品详情页评论数 */
|
/** 获取商品详情页评论数 */
|
||||||
function mockFetchGoodDetailsCommentsCount(spuId = 0) {
|
export function getGoodsDetailsCommentsCount(spuId) {
|
||||||
const { delay } = require('../_utils/delay');
|
return new Promise((resolve, reject) => {
|
||||||
const {
|
request({
|
||||||
getGoodsDetailsCommentsCount,
|
url: `GoodsCommentApi/GetGoodsDetailsCommentsCount`,
|
||||||
} = require('../../model/detailsComments');
|
data: {SpuId: spuId},
|
||||||
return delay().then(() => getGoodsDetailsCommentsCount(spuId));
|
method: 'GET',
|
||||||
}
|
success: function (res) {
|
||||||
|
let data = res.data;
|
||||||
/** 获取商品详情页评论数 */
|
|
||||||
export function getGoodsDetailsCommentsCount(spuId = 0) {
|
resolve(data);
|
||||||
if (config.useMock) {
|
},
|
||||||
return mockFetchGoodDetailsCommentsCount(spuId);
|
fail: function (error) {
|
||||||
}
|
reject(error);
|
||||||
return new Promise((resolve) => {
|
}
|
||||||
resolve('real api');
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取商品详情页评论 */
|
/** 获取商品详情页评论 */
|
||||||
function mockFetchGoodDetailsCommentList(spuId = 0) {
|
export function getGoodsDetailsCommentList(spuId) {
|
||||||
const { delay } = require('../_utils/delay');
|
return new Promise((resolve, reject) => {
|
||||||
const { getGoodsDetailsComments } = require('../../model/detailsComments');
|
request({
|
||||||
return delay().then(() => getGoodsDetailsComments(spuId));
|
url: `GoodsCommentApi/getGoodsDetailsComments`,
|
||||||
}
|
data: {SpuId: spuId},
|
||||||
|
method: 'GET',
|
||||||
/** 获取商品详情页评论 */
|
success: function (res) {
|
||||||
export function getGoodsDetailsCommentList(spuId = 0) {
|
let data = res.data;
|
||||||
if (config.useMock) {
|
|
||||||
return mockFetchGoodDetailsCommentList(spuId);
|
resolve(data);
|
||||||
}
|
},
|
||||||
return new Promise((resolve) => {
|
fail: function (error) {
|
||||||
resolve('real api');
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user