Commit d4ceceee8c4f99fd419c5d33186483fbea58de4c

Authored by YunaiV
1 parent 92632c04

uniapp:【商品详情】对接后端接口

yudao-ui-app/api/product.js
@@ -5,4 +5,4 @@ const { http } = uni.$u @@ -5,4 +5,4 @@ const { http } = uni.$u
5 export const productSpuPage = params => http.get('product/spu/page', { params }) 5 export const productSpuPage = params => http.get('product/spu/page', { params })
6 6
7 // 查询商品 7 // 查询商品
8 -export const productSpu = id => http.get('product/spu/get-detail?id=' + id, { }) 8 +export const getSpuDetail = id => http.get('product/spu/get-detail?id=' + id, { })
yudao-ui-app/components/yd-cart-product/yd-cart-product.vue
@@ -49,7 +49,7 @@ export default { @@ -49,7 +49,7 @@ export default {
49 methods: { 49 methods: {
50 handleProductItemClick(productId) { 50 handleProductItemClick(productId) {
51 uni.$u.route('/pages/product/product', { 51 uni.$u.route('/pages/product/product', {
52 - productId: productId 52 + id: productId
53 }) 53 })
54 }, 54 },
55 handleItemCartClick(productId) { 55 handleItemCartClick(productId) {
yudao-ui-app/components/yd-order-product/yd-order-product.vue
@@ -39,7 +39,7 @@ export default { @@ -39,7 +39,7 @@ export default {
39 methods: { 39 methods: {
40 handleProductItemClick(productId) { 40 handleProductItemClick(productId) {
41 uni.$u.route('/pages/product/product', { 41 uni.$u.route('/pages/product/product', {
42 - productId: productId 42 + id: productId
43 }) 43 })
44 } 44 }
45 } 45 }
yudao-ui-app/components/yd-product-box/yd-product-box.vue
@@ -76,7 +76,7 @@ export default { @@ -76,7 +76,7 @@ export default {
76 methods: { 76 methods: {
77 handleProdItemClick(productId) { 77 handleProdItemClick(productId) {
78 uni.$u.route('/pages/product/product', { 78 uni.$u.route('/pages/product/product', {
79 - productId: productId 79 + id: productId
80 }) 80 })
81 } 81 }
82 } 82 }
yudao-ui-app/components/yd-product-more/yd-product-more.vue
@@ -62,7 +62,7 @@ export default { @@ -62,7 +62,7 @@ export default {
62 methods: { 62 methods: {
63 handleProdItemClick(productId) { 63 handleProdItemClick(productId) {
64 uni.$u.route('/pages/product/product', { 64 uni.$u.route('/pages/product/product', {
65 - productId: productId 65 + id: productId
66 }) 66 })
67 } 67 }
68 } 68 }
yudao-ui-app/pages.json
@@ -62,12 +62,12 @@ @@ -62,12 +62,12 @@
62 "navigationBarTitleText": "账户设置" 62 "navigationBarTitleText": "账户设置"
63 } 63 }
64 }, 64 },
65 - {  
66 - "path": "pages/product/product",  
67 - "style": {  
68 - "navigationBarTitleText": "商品详情"  
69 - }  
70 - }, 65 + {
  66 + "path": "pages/product/product",
  67 + "style": {
  68 + "navigationBarTitleText": "商品详情"
  69 + }
  70 + },
71 { 71 {
72 "path": "pages/checkout/checkout", 72 "path": "pages/checkout/checkout",
73 "style": { 73 "style": {
yudao-ui-app/pages/product/product.vue
1 <template> 1 <template>
2 <view class="container"> 2 <view class="container">
3 - <u-swiper :list="product.images" @change="e => (currentNum = e.current)" :autoplay="false" height="750rpx" radius="0" indicatorStyle="right: 20px"> 3 + <!-- 商品轮播图 -->
  4 + <u-swiper :list="spu.picUrls" @change="e => (currentNum = e.current)" :autoplay="false"
  5 + height="750rpx" radius="0" indicatorStyle="right: 20px">
4 <view slot="indicator" class="indicator-num"> 6 <view slot="indicator" class="indicator-num">
5 - <text class="indicator-num__text">{{ currentNum + 1 }}/{{ product.images.length }}</text> 7 + <text class="indicator-num__text">{{ currentNum + 1 }}/{{ spu.picUrls.length }}</text>
6 </view> 8 </view>
7 </u-swiper> 9 </u-swiper>
8 10
9 <view class="product-box"> 11 <view class="product-box">
  12 + <!-- TODO @Sfmind:样式讨论,要不要改成类似 likeshop 的样子?第一栏:价格 + 分享;第二栏:商品名;第三栏:库存、销量、浏览量 -->
10 <view class="prod-info"> 13 <view class="prod-info">
11 <view class="info-text"> 14 <view class="info-text">
12 - <u--text :lines="2" size="14px" color="#333333" :text="product.title"></u--text>  
13 - <u-gap height="5px"></u-gap>  
14 - <u--text :lines="3" size="12px" color="#939393" :text="product.desc"></u--text> 15 + <u--text :lines="2" size="14px" color="#333333" :text="spu.name"></u--text>
15 </view> 16 </view>
16 <view class="price-and-cart"> 17 <view class="price-and-cart">
17 - <custom-text-price color="red" size="16" intSize="26" :price="product.price"></custom-text-price> 18 + <!-- TODO @Sfmind:custom-text-price 会报错 -->
  19 + <custom-text-price color="red" size="16" intSize="26" :price="spu.minPrice"></custom-text-price>
18 </view> 20 </view>
19 </view> 21 </view>
20 <view class="prod-favor"> 22 <view class="prod-favor">
@@ -28,8 +30,8 @@ @@ -28,8 +30,8 @@
28 <view class="row-right" @click="skuPopup = true"> 30 <view class="row-right" @click="skuPopup = true">
29 <view class="row-content"> 31 <view class="row-content">
30 <view class="sku-box"> 32 <view class="sku-box">
31 - <view v-if="product.sku.length > 0" class="sku-item">  
32 - <view class="sku-desc">{{ product.sku[currentSkuIndex].desc }}</view> 33 + <view v-if="spu.skus.length > 0" class="sku-item">
  34 + <view class="sku-desc">{{ spu.skus[currentSkuIndex].desc }}</view>
33 </view> 35 </view>
34 </view> 36 </view>
35 </view> 37 </view>
@@ -39,19 +41,23 @@ @@ -39,19 +41,23 @@
39 </view> 41 </view>
40 </view> 42 </view>
41 43
42 - <!-- 商品SKU选择弹窗 --> 44 + <!-- 商品 SKU 选择弹窗 -->
43 <u-popup :show="skuPopup" :round="10" :closeable="true" :closeOnClickOverlay="false" @close="skuPopup = false"> 45 <u-popup :show="skuPopup" :round="10" :closeable="true" :closeOnClickOverlay="false" @close="skuPopup = false">
44 <view class="sku-popup-slot"> 46 <view class="sku-popup-slot">
45 <view class="current-sku-info"> 47 <view class="current-sku-info">
46 - <u--image class="current-sku-img" :showLoading="true" :src="product.sku[currentSkuIndex].picUrl" width="120rpx" height="120rpx"></u--image> 48 + <u--image class="current-sku-img" :showLoading="true" :src="spu.skus[currentSkuIndex].picUrl"
  49 + width="120rpx" height="120rpx"></u--image>
47 <view class="current-sku-desc"> 50 <view class="current-sku-desc">
48 - <view class="name">{{ product.sku[currentSkuIndex].desc }}</view>  
49 - <custom-text-price color="red" size="12" intSize="18" :price="product.sku[currentSkuIndex].price"></custom-text-price> 51 + <!-- TODO @Sfmind:name 这里的选择规格值的拼接 -->
  52 + <view class="name">{{ spu.skus[currentSkuIndex].desc }}</view>
  53 + <custom-text-price color="red" size="12" intSize="18" :price="spu.skus[currentSkuIndex].price"></custom-text-price>
50 <view class="current-sku-stock">库存: {{ 1 }}</view> 54 <view class="current-sku-stock">库存: {{ 1 }}</view>
51 </view> 55 </view>
52 </view> 56 </view>
53 <view class="sku-selection"> 57 <view class="sku-selection">
54 - <view class="sku-item" :class="{ active: currentSkuIndex === index }" v-for="(item, index) in product.sku" :key="item.id" @click="handleSkuItemClick(index)">{{ item.desc }}</view> 58 + <!-- TODO @Sfmind:name 这里是规格的具体选项 -->
  59 + <view class="sku-item" :class="{ active: currentSkuIndex === index }" v-for="(item, index) in spu.skus"
  60 + :key="item.id" @click="handleSkuItemClick(index)">{{ item.desc }}</view>
55 </view> 61 </view>
56 <view class="sku-num-box"> 62 <view class="sku-num-box">
57 <view class="text">选择数量</view> 63 <view class="text">选择数量</view>
@@ -70,22 +76,6 @@ @@ -70,22 +76,6 @@
70 76
71 <u-gap height="8" bgColor="#f3f3f3"></u-gap> 77 <u-gap height="8" bgColor="#f3f3f3"></u-gap>
72 <view class="row-box"> 78 <view class="row-box">
73 - <view class="row-left">配送</view>  
74 - <view class="row-right">  
75 - <view class="row-content">  
76 - <view class="delivery-box">  
77 - <view class="delivery-item" v-for="(item, index) in deliveryType" :key="item.id">  
78 - <u-icon name="checkmark-circle" color="#2979ff" size="16"></u-icon>  
79 - <text class="delivery-name">{{ item.name }}</text>  
80 - </view>  
81 - </view>  
82 - </view>  
83 - <view class="row-more"></view>  
84 - </view>  
85 - </view>  
86 -  
87 - <u-gap height="8" bgColor="#f3f3f3"></u-gap>  
88 - <view class="row-box">  
89 <view class="row-left">促销</view> 79 <view class="row-left">促销</view>
90 <view class="row-right" v-if="promotionList.length > 0" @click="promotionPopup = true"> 80 <view class="row-right" v-if="promotionList.length > 0" @click="promotionPopup = true">
91 <view class="row-content"> 81 <view class="row-content">
@@ -151,6 +141,8 @@ @@ -151,6 +141,8 @@
151 </view> 141 </view>
152 </view> 142 </view>
153 143
  144 + <!-- TODO @Sfmind:缺个商品详情 -->
  145 +
154 <view class="fixed-btn-box"> 146 <view class="fixed-btn-box">
155 <view class="btn-group"> 147 <view class="btn-group">
156 <navigator class="btn-item" url="/pages/index/index" open-type="switchTab" hover-class="none"> 148 <navigator class="btn-item" url="/pages/index/index" open-type="switchTab" hover-class="none">
@@ -161,9 +153,10 @@ @@ -161,9 +153,10 @@
161 <u-icon name="server-man" :size="24"></u-icon> 153 <u-icon name="server-man" :size="24"></u-icon>
162 <view class="btn-text">客服</view> 154 <view class="btn-text">客服</view>
163 </navigator> 155 </navigator>
  156 + <!-- TODO @Sfmind:改成收藏 -->
164 <navigator class="btn-item" url="/pages/cart/cart" open-type="switchTab" hover-class="none"> 157 <navigator class="btn-item" url="/pages/cart/cart" open-type="switchTab" hover-class="none">
165 - <u-icon name="bag" :size="24"></u-icon>  
166 - <view class="btn-text">购物车</view> 158 + <u-icon name="star" :size="24"></u-icon>
  159 + <view class="btn-text">收藏</view>
167 </navigator> 160 </navigator>
168 <view class="btn-item-main"> 161 <view class="btn-item-main">
169 <u-button type="warning" shape="circle" size="small" text="加入购物车"></u-button> 162 <u-button type="warning" shape="circle" size="small" text="加入购物车"></u-button>
@@ -178,7 +171,7 @@ @@ -178,7 +171,7 @@
178 </template> 171 </template>
179 172
180 <script> 173 <script>
181 - import { productSpu } from '../../api/product'; 174 +import { getSpuDetail } from '../../api/product';
182 175
183 export default { 176 export default {
184 data() { 177 data() {
@@ -187,12 +180,10 @@ export default { @@ -187,12 +180,10 @@ export default {
187 currentNum: 0, 180 currentNum: 0,
188 currentSkuIndex: 0, 181 currentSkuIndex: 0,
189 skuPopup: false, 182 skuPopup: false,
190 - product: { 183 + spu: {
191 id: '', 184 id: '',
192 - images: ['https://cdn.uviewui.com/uview/album/1.jpg', 'https://cdn.uviewui.com/uview/album/2.jpg', 'https://cdn.uviewui.com/uview/album/3.jpg'],  
193 - title: '山不在高,有仙则名。水不在深,有龙则灵。斯是陋室,惟吾德馨。',  
194 - desc: '山不在于高,有了神仙就会有名气。水不在于深,有了龙就会有灵气。这是简陋的房子,只是我品德好就感觉不到简陋了。',  
195 - price: '13.00', 185 + picUrls: [],
  186 + minPrice: '13.00',
196 sku: [ 187 sku: [
197 { 188 {
198 id: 0, 189 id: 0,
@@ -214,16 +205,6 @@ export default { @@ -214,16 +205,6 @@ export default {
214 } 205 }
215 ] 206 ]
216 }, 207 },
217 - deliveryType: [  
218 - {  
219 - id: 0,  
220 - name: '快递配送'  
221 - },  
222 - {  
223 - id: 1,  
224 - name: '到店自提'  
225 - }  
226 - ],  
227 promotionPopup: false, 208 promotionPopup: false,
228 promotionList: [ 209 promotionList: [
229 { 210 {
@@ -295,23 +276,21 @@ export default { @@ -295,23 +276,21 @@ export default {
295 } 276 }
296 }, 277 },
297 onLoad(e) { 278 onLoad(e) {
298 - if (!e.productId) { 279 + if (!e.id) {
299 uni.$u.toast('请求参数错误') 280 uni.$u.toast('请求参数错误')
300 - } else {  
301 - this.product.id = e.productId  
302 - this.loadProductData()  
303 - // TODO 请求接口获取商品详情数据 281 + return;
304 } 282 }
  283 +
  284 + // 加载商品详情
  285 + this.spu.id = e.id
  286 + this.loadProductData()
305 }, 287 },
306 methods: { 288 methods: {
307 loadProductData() { 289 loadProductData() {
308 - productSpu(this.product.id).then(res => {  
309 - this.product.images = res.data.picUrls;  
310 - this.product.sku = res.data.skus;  
311 - this.product.desc = res.data.description.replace(/<[^>]*>/g,'');  
312 - this.product.price = res.data.price;  
313 - this.product.title = res.data.name;  
314 - console.log(res) 290 + getSpuDetail(this.spu.id).then(res => {
  291 + // this.spu.desc = res.data.description.replace(/<[^>]*>/g,'');
  292 + // console.log(res)
  293 + this.spu = res.data;
315 }) 294 })
316 }, 295 },
317 handleSkuItemClick(index) { 296 handleSkuItemClick(index) {
@@ -382,18 +361,6 @@ export default { @@ -382,18 +361,6 @@ export default {
382 .row-content { 361 .row-content {
383 flex: 1; 362 flex: 1;
384 363
385 - .delivery-box {  
386 - @include flex-left;  
387 - .delivery-item {  
388 - margin-right: 20rpx;  
389 - @include flex-left;  
390 - font-size: 22rpx;  
391 - .delivery-name {  
392 - margin-left: 5rpx;  
393 - }  
394 - }  
395 - }  
396 -  
397 .prom-box { 364 .prom-box {
398 @include flex-left; 365 @include flex-left;
399 .prom-item { 366 .prom-item {