feature(uniapp分类): 分类列表以及商品加载
parent
f3c83488a3
commit
e2a6530acb
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.category;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryListRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.category.CategoryConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
|
||||
import cn.iocoder.yudao.module.product.service.category.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "用户 APP - 商品分类")
|
||||
@RestController
|
||||
@RequestMapping("/product/category")
|
||||
@Validated
|
||||
public class AppCategoryController {
|
||||
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得商品分类列表")
|
||||
public CommonResult<List<AppCategoryListRespVO>> listByQuery() {
|
||||
List<CategoryDO> list = categoryService.getCategoryList();
|
||||
list.sort(Comparator.comparing(CategoryDO::getSort));
|
||||
return success(CategoryConvert.INSTANCE.convertList03(list));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.category.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "App - 商品分类 列表 Request VO", description = "参数和 CategoryBaseVO 是一致的")
|
||||
public class AppCategoryListRespVO {
|
||||
|
||||
@ApiModelProperty(value = "分类编号", required = true, example = "2")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "父分类编号", required = true, example = "1")
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty(value = "分类名称", required = true, example = "办公文具")
|
||||
@NotBlank(message = "分类名称不能为空")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "分类图标")
|
||||
@NotBlank(message = "分类图标不能为空")
|
||||
private String icon;
|
||||
|
||||
@ApiModelProperty(value = "分类图片", required = true)
|
||||
@NotBlank(message = "分类图片不能为空")
|
||||
private String bannerUrl;
|
||||
|
||||
@ApiModelProperty(value = "分类排序", required = true, example = "1")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "分类描述", required = true, example = "描述")
|
||||
private String description;
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.spu;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
|
||||
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "用户 APP - 商品spu")
|
||||
@RestController
|
||||
@RequestMapping("/product/spu")
|
||||
@Validated
|
||||
public class AppProductSpuController {
|
||||
|
||||
@Resource
|
||||
private ProductSpuService spuService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得商品spu分页")
|
||||
public CommonResult<PageResult<AppSpuPageRespVO>> getSpuPage(@Valid AppSpuPageReqVO pageVO) {
|
||||
return success(spuService.getSpuPage(pageVO));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@ApiModel("App - 商品spu分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class AppSpuPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "分类id")
|
||||
private Long categoryId;
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("App - 商品spu分页 Request VO")
|
||||
@Data
|
||||
public class AppSpuPageRespVO {
|
||||
|
||||
@ApiModelProperty(value = "主键", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "商品名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "卖点", required = true)
|
||||
@NotNull(message = "卖点不能为空")
|
||||
private String sellPoint;
|
||||
|
||||
@ApiModelProperty(value = "描述", required = true)
|
||||
@NotNull(message = "描述不能为空")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(value = "分类id", required = true)
|
||||
@NotNull(message = "分类id不能为空")
|
||||
private Long categoryId;
|
||||
|
||||
@ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张", required = true)
|
||||
@NotNull(message = "商品主图地址,* 数组,以逗号分隔,最多上传15张不能为空")
|
||||
private List<String> picUrls;
|
||||
|
||||
@ApiModelProperty(value = "排序字段", required = true)
|
||||
@NotNull(message = "排序字段不能为空")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "点赞初始人数")
|
||||
private Integer likeCount;
|
||||
|
||||
@ApiModelProperty(value = "价格 单位使用:分")
|
||||
private Integer price;
|
||||
|
||||
@ApiModelProperty(value = "库存数量")
|
||||
private Integer quantity;
|
||||
|
||||
@ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
|
||||
private Boolean status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
|
||||
const { http } = uni.$u
|
||||
|
||||
// 查询分类列表
|
||||
export const categoryListData = params => http.get('product/category/list', { params })
|
||||
@ -0,0 +1,5 @@
|
||||
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
|
||||
const { http } = uni.$u
|
||||
|
||||
// 查询商品spu列表
|
||||
export const productSpuPage = params => http.get('/product/spu/page', { params })
|
||||
@ -0,0 +1,161 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<u-navbar :title="title" :autoBack="true" placeholder="true" titleStyle="font-size: 28rpx">
|
||||
</u-navbar>
|
||||
<view class="context">
|
||||
<view class="tabs-top">
|
||||
<u-tabs :list="categoryList" @click="changeTabs" :current="current" lineHeight="2" lineWidth="85rpx"
|
||||
itemStyle="padding-left: 15px; padding-right: 15px; height: 85rpx;"></u-tabs>
|
||||
</view>
|
||||
<scroll-view scroll-y="true" class="product-list" enable-flex="true">
|
||||
<view class="flex-box">
|
||||
<block v-for="(item, index) in productList[current]" :key="index">
|
||||
<view class="product-item">
|
||||
<view class="product-image">
|
||||
<image :src="item.picUrls[0]" mode='widthFix' />
|
||||
</view>
|
||||
<view class="product-button">
|
||||
<view class="product-text">【{{ item.sellPoint }}】{{ item.name }}</view>
|
||||
<view class="product-price-button">
|
||||
<text class="product-price">¥
|
||||
<text class="price-size">{{ towNumber(item.price) }}</text></text>
|
||||
<text class="product-like-ccount">销量 {{ item.likeCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
productSpuPage
|
||||
} from '../../api/product';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
title: "",
|
||||
current: 0,
|
||||
categoryList: [],
|
||||
productList: {}
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
const item = JSON.parse(decodeURIComponent(option.item))
|
||||
this.title = item.name
|
||||
this.categoryList = item.children
|
||||
this.handleProductSpu(option.index);
|
||||
},
|
||||
methods: {
|
||||
changeTabs(item) {
|
||||
if (item.index != this.current) {
|
||||
this.handleProductSpu(item.index)
|
||||
}
|
||||
},
|
||||
handleProductSpu(index) {
|
||||
let param = {}
|
||||
param.categoryId = this.categoryList[index].id
|
||||
console.log(this.categoryList)
|
||||
console.log(index)
|
||||
productSpuPage(param).then(res => {
|
||||
this.productList[index] = res.data.list
|
||||
this.current = index
|
||||
})
|
||||
},
|
||||
towNumber(val) {
|
||||
return (val / 100).toFixed(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.context {
|
||||
width: 100vw;
|
||||
position: fixed;
|
||||
top: 160rpx;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.tabs-top {
|
||||
position: relative;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 85rpx;
|
||||
}
|
||||
|
||||
.product-list {
|
||||
position: relative;
|
||||
background-color: #f2f2f2;
|
||||
height: calc(100vh - 88rpx - 100rpx - var(--status-bar-height));
|
||||
width: 100%;
|
||||
|
||||
.flex-box {
|
||||
width: 730rpx;
|
||||
margin: 0 auto;
|
||||
@include flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: left;
|
||||
|
||||
.product-item {
|
||||
width: 345rpx;
|
||||
height: 450rpx;
|
||||
background-color: #ffffff;
|
||||
margin: 20rpx 10rpx 0;
|
||||
border-radius: 20rpx;
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 300rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 20rpx;
|
||||
image {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.product-button {
|
||||
width: 330rpx;
|
||||
margin: 15rpx auto 0;
|
||||
|
||||
.product-text {
|
||||
font-size: 25rpx;
|
||||
height: 70rpx;
|
||||
overflow: hidden;
|
||||
-webkit-line-clamp: 2;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.product-price-button {
|
||||
font-size: 20rpx;
|
||||
margin-top: 20rpx;
|
||||
|
||||
.product-price {
|
||||
color: red;
|
||||
|
||||
.price-size {
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.product-like-ccount {
|
||||
font-size: 16rpx;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue