From 2583b21c3f0bad5646cc5bdda825c9b67f75016a Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Fri, 14 Jul 2023 15:35:04 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/goods-card/index.wxml | 7 +- components/goods-card/index.wxss | 2 +- model/search.js | 2 +- .../components/goods-specs-popup/index.js | 4 + .../components/goods-specs-popup/index.wxml | 8 +- .../components/goods-specs-popup/index.wxss | 5 + pages/goods/details/index.js | 156 +++++++++++++----- pages/goods/details/index.wxml | 34 +++- pages/goods/details/index.wxss | 20 +++ pages/goods/list/index.js | 34 ++-- services/good/fetchGood.js | 60 +++++-- services/good/fetchGoodsList.js | 97 +++++++---- 12 files changed, 308 insertions(+), 121 deletions(-) diff --git a/components/goods-card/index.wxml b/components/goods-card/index.wxml index 1292f65..a1bd5dd 100644 --- a/components/goods-card/index.wxml +++ b/components/goods-card/index.wxml @@ -6,13 +6,14 @@ > - + /> --> + @@ -34,6 +35,7 @@ - + + {{title}} + 库存 {{ limitMaxCount != 0 ? limitMaxCount : quantity }} 件 - 选择: + 选择: ({{limitBuyInfo}}) - + diff --git a/pages/goods/details/components/goods-specs-popup/index.wxss b/pages/goods/details/components/goods-specs-popup/index.wxss index de0c749..a7374ce 100644 --- a/pages/goods/details/components/goods-specs-popup/index.wxss +++ b/pages/goods/details/components/goods-specs-popup/index.wxss @@ -49,6 +49,7 @@ color: #333333; font-size: 26rpx; line-height: 36rpx; + flex-wrap: wrap; } .popup-sku-header @@ -298,3 +299,7 @@ color: #fff; background-color: #dddddd; } + +.goods-inventory{ + color: grey; +} \ No newline at end of file diff --git a/pages/goods/details/index.js b/pages/goods/details/index.js index b41f007..7862c05 100644 --- a/pages/goods/details/index.js +++ b/pages/goods/details/index.js @@ -1,12 +1,18 @@ import Toast from 'tdesign-miniprogram/toast/index'; -import { fetchGood } from '../../../services/good/fetchGood'; -import { fetchActivityList } from '../../../services/activity/fetchActivityList'; +import { + fetchGood +} from '~/services/good/fetchGood'; +import { + fetchActivityList +} from '~/services/activity/fetchActivityList'; import { getGoodsDetailsCommentList, getGoodsDetailsCommentsCount, -} from '../../../services/good/fetchGoodsDetailsComments'; +} from '~/services/good/fetchGoodsDetailsComments'; -import { cdnBase } from '../../../config/index'; +import { + cdnBase +} from '~/config/index'; const imgPrefix = `${cdnBase}/`; @@ -37,8 +43,7 @@ Page({ recLeftImg, recRightImg, details: {}, - goodsTabArray: [ - { + goodsTabArray: [{ name: '商品', value: '', // 空字符串代表置顶 }, @@ -49,8 +54,7 @@ Page({ ], storeLogo: `${imgPrefix}common/store-logo.png`, storeName: '云mall标准版旗舰店', - jumpArray: [ - { + jumpArray: [{ title: '首页', url: '/pages/home/home', iconName: 'home', @@ -76,13 +80,17 @@ Page({ buyType: 0, outOperateStatus: false, // 是否外层加入购物车 operateType: 0, + selectSkuQuantity: 0, selectSkuSellsPrice: 0, + selectSkuLinePrice: 0, maxLinePrice: 0, minSalePrice: 0, maxSalePrice: 0, list: [], spuId: '', - navigation: { type: 'fraction' }, + navigation: { + type: 'fraction' + }, current: 0, autoplay: true, duration: 500, @@ -113,29 +121,42 @@ Page({ }, toNav(e) { - const { url } = e.detail; + const { + url + } = e.detail; wx.switchTab({ url: url, }); }, showCurImg(e) { - const { index } = e.detail; - const { images } = this.data.details; + const { + index + } = e.detail; + const { + images + } = this.data.details; wx.previewImage({ current: images[index], urls: images, // 需要预览的图片http链接列表 }); }, - onPageScroll({ scrollTop }) { + onPageScroll({ + scrollTop + }) { const goodsTab = this.selectComponent('#goodsTab'); goodsTab && goodsTab.onScroll(scrollTop); }, chooseSpecItem(e) { - const { specList } = this.data.details; - const { selectedSku, isAllSelectedSku } = e.detail; + const { + specList + } = this.data.details; + const { + selectedSku, + isAllSelectedSku + } = e.detail; if (!isAllSelectedSku) { this.setData({ selectSkuSellsPrice: 0, @@ -148,7 +169,10 @@ Page({ }, getSkuItem(specList, selectedSku) { - const { skuArray, primaryImage } = this.data; + const { + skuArray, + primaryImage + } = this.data; const selectedSkuValues = this.getSelectedSkuValues(specList, selectedSku); let selectedAttrStr = ` 件 `; selectedSkuValues.forEach((item) => { @@ -171,16 +195,19 @@ Page({ if (skuItem) { this.setData({ selectItem: skuItem, - selectSkuSellsPrice: skuItem.price || 0, + selectSkuSellsPrice: skuItem[0]?.priceInfo[0].price || 0, + selectSkuLinePrice: skuItem[0]?.priceInfo[1].price || 0, + selectSkuQuantity: skuItem[0]?.quantity }); } else { this.setData({ selectItem: null, selectSkuSellsPrice: 0, + selectSkuLinePrice: 0, }); } this.setData({ - specImg: skuItem && skuItem.skuImage ? skuItem.skuImage : primaryImage, + specImg: skuItem && skuItem[0]?.skuImage ? skuItem[0]?.skuImage : primaryImage, }); }, @@ -221,36 +248,52 @@ Page({ }, addCart() { - const { isAllSelectedSku } = this.data; - Toast({ - context: this, - selector: '#t-toast', - message: isAllSelectedSku ? '点击加入购物车' : '请选择规格', - icon: '', - duration: 1000, - }); - }, - - gotoBuy(type) { - const { isAllSelectedSku, buyNum } = this.data; - if (!isAllSelectedSku) { + const { + isAllSelectedSku + } = this.data; + const { + specList + } = this.data.details; + if (specList.length != 0) { Toast({ context: this, selector: '#t-toast', - message: '请选择规格', + message: isAllSelectedSku ? '点击加入购物车' : '请选择规格', icon: '', duration: 1000, }); - return; } + }, + + gotoBuy(type) { + console.log(type); + const { + isAllSelectedSku, + buyNum + } = this.data; + const { + specList + } = this.data.details; + if (specList.length != 0) { + if (!isAllSelectedSku) { + Toast({ + context: this, + selector: '#t-toast', + message: '请选择规格', + icon: '', + duration: 1000, + }); + return; + } + } + this.handlePopupHide(); const query = { quantity: buyNum, storeId: '1', spuId: this.data.spuId, goodsName: this.data.details.title, - skuId: - type === 1 ? this.data.skuList[0].skuId : this.data.selectItem.skuId, + skuId: type === 1 ? null : this.data.selectItem.skuId, available: this.data.details.available, price: this.data.details.minSalePrice, specInfo: this.data.details.specList?.map((item) => ({ @@ -273,8 +316,17 @@ Page({ }, specsConfirm() { - const { buyType } = this.data; + const { + buyType + } = this.data; + const { + specList + } = this.data.details; if (buyType === 1) { + if (specList.length == 0) { + this.gotoBuy(1); + return; + } this.gotoBuy(); } else { this.addCart(); @@ -295,7 +347,9 @@ Page({ }, promotionChange(e) { - const { index } = e.detail; + const { + index + } = e.detail; wx.navigateTo({ url: `/pages/promotion-detail/index?promotion_id=${index}`, }); @@ -320,11 +374,16 @@ Page({ maxLinePrice, soldNum, } = details; + + // details.desc = details.desc.replace(/\ { skuArray.push({ skuId: item.skuId, - quantity: item.stockInfo ? item.stockInfo.stockQuantity : 0, + quantity: item.quantity ? item.quantity : 0, specInfo: item.specInfo, + priceInfo: item.priceInfo, + skuImage: item.skuImage, }); }); const promotionArray = []; @@ -354,7 +413,9 @@ Page({ try { const code = 'Success'; const data = await getGoodsDetailsCommentList(); - const { homePageComments } = data; + const { + homePageComments + } = data; if (code.toUpperCase() === 'SUCCESS') { const nextState = { commentsList: homePageComments.map((item) => { @@ -363,9 +424,8 @@ Page({ userName: item.userName || '', commentScore: item.commentScore, commentContent: item.commentContent || '用户未填写评价', - userHeadUrl: item.isAnonymity - ? this.anonymityAvatar - : item.userHeadUrl || this.anonymityAvatar, + userHeadUrl: item.isAnonymity ? + this.anonymityAvatar : item.userHeadUrl || this.anonymityAvatar, }; }), }; @@ -378,7 +438,9 @@ Page({ onShareAppMessage() { // 自定义的返回信息 - const { selectedAttrStr } = this.data; + const { + selectedAttrStr + } = this.data; let shareSubTitle = ''; if (selectedAttrStr.indexOf('件') > -1) { const count = selectedAttrStr.indexOf('件'); @@ -432,7 +494,11 @@ Page({ }, onLoad(query) { - const { spuId } = query; + const { + spuId + } = query; + // const spuId = "1673671239077597184"; + this.setData({ spuId: spuId, }); @@ -440,4 +506,4 @@ Page({ this.getCommentsList(spuId); this.getCommentsStatistics(spuId); }, -}); +}); \ No newline at end of file diff --git a/pages/goods/details/index.wxml b/pages/goods/details/index.wxml index 7442ff3..893d262 100644 --- a/pages/goods/details/index.wxml +++ b/pages/goods/details/index.wxml @@ -1,6 +1,7 @@ - --> + + + + + + + + + + + + + + @@ -17,10 +31,11 @@ wr-class="class-goods-price" symbol-class="class-goods-symbol" price="{{minSalePrice}}" + priceUnit="yuan" type="lighter" /> - + 已售{{soldNum}} @@ -92,8 +107,11 @@ 详情介绍 - + + + @@ -117,6 +135,8 @@ specList="{{details.specList || []}}" skuList="{{skuArray}}" limitBuyInfo="{{details.limitInfo[0].text || ''}}" + limitMaxCount="{{ selectSkuQuantity }}" + quantity="{{ details.spuStockQuantity }}" bind:closeSpecsPopup="handlePopupHide" bind:change="chooseSpecItem" bind:changeNum="changeNum" @@ -131,12 +151,14 @@ diff --git a/pages/goods/details/index.wxss b/pages/goods/details/index.wxss index d027cb1..04df6d3 100644 --- a/pages/goods/details/index.wxss +++ b/pages/goods/details/index.wxss @@ -220,6 +220,16 @@ page { height: auto; } +.desc-content_box{ + max-width: 100% !important; +} + +.desc-content_box img{ + width: 100% !important; + max-width: 100% !important; + height: auto; +} + .goods-bottom-operation { position: fixed; left: 0; @@ -340,3 +350,13 @@ page { font-size: 28rpx; font-weight: 400; } + +.swiper-container{ + width: 100%; + height: 750rpx; +} + +.swiper-item{ + width: 100%; + height: 750rpx; +} \ No newline at end of file diff --git a/pages/goods/list/index.js b/pages/goods/list/index.js index c16cd66..4788abd 100644 --- a/pages/goods/list/index.js +++ b/pages/goods/list/index.js @@ -23,7 +23,7 @@ Page({ }, pageNum: 1, - pageSize: 30, + pageSize: 6, total: 0, handleFilterChange(e) { @@ -43,10 +43,10 @@ Page({ const { pageNum, pageSize } = this; const { sorts, overall } = filter; const params = { - sort: 0, // 0 综合,1 价格 + // sort: 0, // 0 综合,1 价格 pageNum: 1, - pageSize: 30, - keyword: keywords, + pageSize: 6, + // keyword: keywords, }; if (sorts) { @@ -54,13 +54,13 @@ Page({ params.sortType = sorts === 'desc' ? 1 : 0; } - if (overall) { - params.sort = 0; - } else { - params.sort = 1; - } - params.minPrice = minVal ? minVal * 100 : 0; - params.maxPrice = maxVal ? maxVal * 100 : undefined; + // if (overall) { + // params.sort = 0; + // } else { + // params.sort = 1; + // } + // params.minPrice = minVal ? minVal * 100 : 0; + // params.maxPrice = maxVal ? maxVal * 100 : undefined; if (reset) return params; return { ...params, @@ -82,9 +82,9 @@ Page({ const code = 'Success'; const data = result; if (code.toUpperCase() === 'SUCCESS') { - const { spuList, totalCount = 0 } = data; - if (totalCount === 0 && reset) { - this.total = totalCount; + const { result, totalNum = 0 } = data; + if (totalNum === 0 && reset) { + this.total = totalNum; this.setData({ emptyInfo: { tip: '抱歉,未找到相关商品', @@ -97,10 +97,10 @@ Page({ return; } - const _goodsList = reset ? spuList : goodsList.concat(spuList); - const _loadMoreStatus = _goodsList.length === totalCount ? 2 : 0; + const _goodsList = reset ? result : goodsList.concat(result); + const _loadMoreStatus = _goodsList.length === totalNum ? 2 : 0; this.pageNum = params.pageNum || 1; - this.total = totalCount; + this.total = totalNum; this.setData({ goodsList: _goodsList, loadMoreStatus: _loadMoreStatus, diff --git a/services/good/fetchGood.js b/services/good/fetchGood.js index 7a196d4..b531f21 100644 --- a/services/good/fetchGood.js +++ b/services/good/fetchGood.js @@ -1,18 +1,48 @@ -import { config } from '../../config/index'; +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)); +// } -/** 获取商品列表 */ -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 = 0) { - if (config.useMock) { - return mockFetchGood(ID); - } - return new Promise((resolve) => { - resolve('real api'); +/** 获取商品详情 */ +export function fetchGood(ID) { + return new Promise((resolve, reject) => { + request({ + url: `GoodsApi/getGoodsDetails`, + data: {SpuId: ID}, + method: 'GET', + success: function (res) { + let data = res.data; + // 图片 + if (data.images) { + data.primaryImage = data.images.split(',')[0]; + data.images = data.images.split(','); + } + if(data.desc){ + data.desc = data.desc.replace(/]*)style=""([^>]*)>/gi, ''); + } + resolve(data); + }, + fail: function (error) { + reject(error); + } + }); }); -} +} \ No newline at end of file diff --git a/services/good/fetchGoodsList.js b/services/good/fetchGoodsList.js index 1650b9b..5867724 100644 --- a/services/good/fetchGoodsList.js +++ b/services/good/fetchGoodsList.js @@ -1,39 +1,74 @@ -/* eslint-disable no-param-reassign */ -import { config } from '../../config/index'; +import { + request +} from '../_utils/request'; -/** 获取商品列表 */ -function mockFetchGoodsList(params) { - const { delay } = require('../_utils/delay'); - const { getSearchResult } = require('../../model/search'); +/** 获取经营类目列表 */ +export function fetchGoodsList(params) { + return new Promise((resolve, reject) => { + + request({ + url: `GoodsApi/getGoodsList`, + data: params, + method: 'GET', + success: function (res) { + let list = res.data; + if (list.result.length) { + list.result.forEach((item) => { + // 图片 + if (item.images) { + item.thumb = item.images.split(',')[0]; + } + console.log(item.thumb); - const data = getSearchResult(params); - - if (data.spuList.length) { - data.spuList.forEach((item) => { - item.spuId = item.spuId; - item.thumb = item.primaryImage; - item.title = item.title; - item.price = item.minSalePrice; - item.originPrice = item.maxLinePrice; - item.desc = ''; - if (item.spuTagList) { - item.tags = item.spuTagList.map((tag) => tag.title); - } else { - item.tags = []; + // 标签 + // if (item.spuTagList) { + // item.tags = item.spuTagList.map((tag) => tag.title); + // } else { + // item.tags = []; + // } + }); + } + resolve(list); + }, + fail: function (error) { + reject(error); } }); - } - return delay().then(() => { - return data; }); } /** 获取商品列表 */ -export function fetchGoodsList(params) { - if (config.useMock) { - return mockFetchGoodsList(params); - } - return new Promise((resolve) => { - resolve('real api'); - }); -} +// function mockFetchGoodsList(params) { +// const { delay } = require('../_utils/delay'); +// // const { getSearchResult } = require('../../model/search'); +// // const data = getSearchResult(params); + +// if (data.spuList.length) { +// data.spuList.forEach((item) => { +// item.spuId = item.spuId; +// item.thumb = item.primaryImage; +// item.title = item.title; +// item.price = item.minSalePrice; +// item.originPrice = item.maxLinePrice; +// item.desc = ''; +// if (item.spuTagList) { +// item.tags = item.spuTagList.map((tag) => tag.title); +// } else { +// item.tags = []; +// } +// }); +// } +// return delay().then(() => { +// return data; +// }); +// } + +// /** 获取商品列表 */ +// export function fetchGoodsList(params) { +// if (config.useMock) { +// return mockFetchGoodsList(params); +// } +// return new Promise((resolve) => { +// resolve('real api'); +// }); +// } \ No newline at end of file