From 7eab148104c0e306f6d58bc8983b472fd3842cd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?=
<2291200076@qq.com>
Date: Sat, 18 Mar 2023 23:00:58 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=BE=AE=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=EF=BC=9Amicroservice-provider-shop-8003=EF=BC=9B=E5=B0=8F?=
=?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E7=AD=9B?=
=?UTF-8?q?=E9=80=89=E3=80=81=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=E5=AE=8C?=
=?UTF-8?q?=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/.idea/encodings.xml | 2 +
.../.idea/runConfigurations/MiniProgram.xml | 10 --
.../.idea/runConfigurations/ShopProvider.xml | 17 ++
.../runConfigurations/ShopProvider_Remote.xml | 20 +++
.../com/cxyxiaomo/epp/common/pojo/Good.java | 25 +++
.../epp/common/pojo/GoodCategory.java | 14 ++
.../epp/common/vo/GoodCategoryVO.java | 41 +++++
.../com/cxyxiaomo/epp/common/vo/GoodVO.java | 50 ++++++
.../src/main/resources/application.yml | 5 +
.../main/resources/mybatis/mybatis-config.xml | 3 +
.../microservice-provider-shop-8003/pom.xml | 159 ++++++++++++++++++
.../com/cxyxiaomo/epp/shop/ShopProvider.java | 17 ++
.../epp/shop/controller/GoodsController.java | 68 ++++++++
.../epp/shop/dao/GoodsCategoryDao.java | 16 ++
.../com/cxyxiaomo/epp/shop/dao/GoodsDao.java | 17 ++
.../epp/shop/service/GoodsService.java | 15 ++
.../epp/shop/service/GoodsServiceImpl.java | 43 +++++
.../src/main/resources/application-remote.yml | 9 +
.../src/main/resources/application.yml | 23 +++
.../mybatis/mapper/GoodsCategoryMapper.xml | 16 ++
.../resources/mybatis/mapper/GoodsMapper.xml | 28 +++
.../main/resources/mybatis/mybatis-config.xml | 13 ++
.../src/test/java/com/cxyxiaomo/AppTest.java | 20 +++
.../main/resources/mybatis/mybatis-config.xml | 3 +
backend/pom.xml | 1 +
database/epp.sql | 38 +++--
.../epp.postman_collection.json | 100 ++++++++++-
weixin-miniprogram/app.json | 3 +-
.../pages/shop/components/good-list-card.js | 28 +--
.../pages/shop/components/good-list-card.wxml | 2 +-
weixin-miniprogram/pages/shop/goodDetail.js | 85 ++++++++++
weixin-miniprogram/pages/shop/goodDetail.json | 4 +
weixin-miniprogram/pages/shop/goodDetail.wxml | 20 +++
weixin-miniprogram/pages/shop/goodDetail.wxss | 68 ++++++++
weixin-miniprogram/pages/shop/shop.js | 138 +++++++++++----
weixin-miniprogram/pages/shop/shop.json | 5 +-
weixin-miniprogram/pages/shop/shop.wxml | 10 +-
weixin-miniprogram/pages/shop/shop.wxss | 18 +-
.../project.private.config.json | 3 +-
weixin-miniprogram/services/good.js | 34 ++++
weixin-miniprogram/utils/sendRequest.js | 54 ++++++
41 files changed, 1161 insertions(+), 84 deletions(-)
delete mode 100644 backend/.idea/runConfigurations/MiniProgram.xml
create mode 100644 backend/.idea/runConfigurations/ShopProvider.xml
create mode 100644 backend/.idea/runConfigurations/ShopProvider_Remote.xml
create mode 100644 backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Good.java
create mode 100644 backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/GoodCategory.java
create mode 100644 backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java
create mode 100644 backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodVO.java
create mode 100644 backend/microservice-provider-shop-8003/pom.xml
create mode 100644 backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/ShopProvider.java
create mode 100644 backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodsController.java
create mode 100644 backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsCategoryDao.java
create mode 100644 backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsDao.java
create mode 100644 backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsService.java
create mode 100644 backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsServiceImpl.java
create mode 100644 backend/microservice-provider-shop-8003/src/main/resources/application-remote.yml
create mode 100644 backend/microservice-provider-shop-8003/src/main/resources/application.yml
create mode 100644 backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsCategoryMapper.xml
create mode 100644 backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsMapper.xml
create mode 100644 backend/microservice-provider-shop-8003/src/main/resources/mybatis/mybatis-config.xml
create mode 100644 backend/microservice-provider-shop-8003/src/test/java/com/cxyxiaomo/AppTest.java
create mode 100644 weixin-miniprogram/pages/shop/goodDetail.js
create mode 100644 weixin-miniprogram/pages/shop/goodDetail.json
create mode 100644 weixin-miniprogram/pages/shop/goodDetail.wxml
create mode 100644 weixin-miniprogram/pages/shop/goodDetail.wxss
create mode 100644 weixin-miniprogram/services/good.js
create mode 100644 weixin-miniprogram/utils/sendRequest.js
diff --git a/backend/.idea/encodings.xml b/backend/.idea/encodings.xml
index 2bdc926..e6d0856 100644
--- a/backend/.idea/encodings.xml
+++ b/backend/.idea/encodings.xml
@@ -9,6 +9,8 @@
+
+
diff --git a/backend/.idea/runConfigurations/MiniProgram.xml b/backend/.idea/runConfigurations/MiniProgram.xml
deleted file mode 100644
index 42e0a30..0000000
--- a/backend/.idea/runConfigurations/MiniProgram.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/backend/.idea/runConfigurations/ShopProvider.xml b/backend/.idea/runConfigurations/ShopProvider.xml
new file mode 100644
index 0000000..3535ef2
--- /dev/null
+++ b/backend/.idea/runConfigurations/ShopProvider.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/backend/.idea/runConfigurations/ShopProvider_Remote.xml b/backend/.idea/runConfigurations/ShopProvider_Remote.xml
new file mode 100644
index 0000000..2e235b8
--- /dev/null
+++ b/backend/.idea/runConfigurations/ShopProvider_Remote.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Good.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Good.java
new file mode 100644
index 0000000..3934988
--- /dev/null
+++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Good.java
@@ -0,0 +1,25 @@
+package com.cxyxiaomo.epp.common.pojo;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+@Data
+@NoArgsConstructor
+@Accessors(chain = true) // 链式写法
+public class Good {
+ Long id;
+ String goodsName;
+ Integer categoryId;
+ Integer brand;
+ String gallery;
+ String brief;
+ Boolean isOnSale;
+ String picUrl;
+ Integer type;
+ String unit;
+ Double counterPrice;
+ Double retailPrice;
+ String detail;
+ Boolean deleted;
+}
diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/GoodCategory.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/GoodCategory.java
new file mode 100644
index 0000000..a826fc9
--- /dev/null
+++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/GoodCategory.java
@@ -0,0 +1,14 @@
+package com.cxyxiaomo.epp.common.pojo;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+@Data
+@NoArgsConstructor
+@Accessors(chain = true) // 链式写法
+public class GoodCategory {
+ Long id;
+ String categoryName;
+ Integer order;
+}
diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java
new file mode 100644
index 0000000..4a617e7
--- /dev/null
+++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java
@@ -0,0 +1,41 @@
+package com.cxyxiaomo.epp.common.vo;
+
+import com.cxyxiaomo.epp.common.pojo.GoodCategory;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import org.springframework.beans.BeanUtils;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
+// 数据库关系映射
+
+@Data
+@NoArgsConstructor
+@Accessors(chain = true) // 链式写法
+// 微服务必须要实现Serializable
+public class GoodCategoryVO implements Serializable {
+
+ Long id;
+ String categoryName;
+ Integer order;
+
+ public static GoodCategoryVO convertFrom(GoodCategory goodCategory) {
+ if (goodCategory == null) {
+ return null;
+ }
+ GoodCategoryVO goodCategoryVO = new GoodCategoryVO();
+ BeanUtils.copyProperties(goodCategory, goodCategoryVO);
+ return goodCategoryVO;
+ }
+
+ public static List convertFrom(List goodCategoryList) {
+ if (goodCategoryList == null) {
+ return null;
+ }
+ List goodCategoryVOList = goodCategoryList.stream().map(GoodCategoryVO::convertFrom).collect(Collectors.toList());
+ return goodCategoryVOList;
+ }
+}
diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodVO.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodVO.java
new file mode 100644
index 0000000..cf45f34
--- /dev/null
+++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodVO.java
@@ -0,0 +1,50 @@
+package com.cxyxiaomo.epp.common.vo;
+
+import com.cxyxiaomo.epp.common.pojo.Good;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import org.springframework.beans.BeanUtils;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
+// 数据库关系映射
+
+@Data
+@NoArgsConstructor
+@Accessors(chain = true) // 链式写法
+// 微服务必须要实现Serializable
+public class GoodVO implements Serializable {
+ Long id;
+ String goodsName;
+ Integer categoryId;
+ Integer brand;
+ String gallery;
+ String brief;
+ Boolean isOnSale;
+ String picUrl;
+ Integer type;
+ String unit;
+ Double counterPrice;
+ Double retailPrice;
+ String detail;
+
+ public static GoodVO convertFrom(Good good) {
+ if (good == null) {
+ return null;
+ }
+ GoodVO goodVO = new GoodVO();
+ BeanUtils.copyProperties(good, goodVO);
+ return goodVO;
+ }
+
+ public static List convertFrom(List goodList) {
+ if (goodList == null) {
+ return null;
+ }
+ List goodVOList = goodList.stream().map(GoodVO::convertFrom).collect(Collectors.toList());
+ return goodVOList;
+ }
+}
diff --git a/backend/microservice-gateway/src/main/resources/application.yml b/backend/microservice-gateway/src/main/resources/application.yml
index 0d5b49f..2221824 100644
--- a/backend/microservice-gateway/src/main/resources/application.yml
+++ b/backend/microservice-gateway/src/main/resources/application.yml
@@ -25,6 +25,11 @@ spring:
predicates:
- Path=/access/**
- Method=GET,POST
+ - id: shop
+ uri: lb://microservice-provider-shop
+ predicates:
+ - Path=/shop/**
+ - Method=GET,POST
- id: test1
uri: lb://microservice-provider-test
diff --git a/backend/microservice-provider-access-8002/src/main/resources/mybatis/mybatis-config.xml b/backend/microservice-provider-access-8002/src/main/resources/mybatis/mybatis-config.xml
index e67a32d..a7de5d4 100644
--- a/backend/microservice-provider-access-8002/src/main/resources/mybatis/mybatis-config.xml
+++ b/backend/microservice-provider-access-8002/src/main/resources/mybatis/mybatis-config.xml
@@ -6,5 +6,8 @@
+
+
+
diff --git a/backend/microservice-provider-shop-8003/pom.xml b/backend/microservice-provider-shop-8003/pom.xml
new file mode 100644
index 0000000..8597719
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/pom.xml
@@ -0,0 +1,159 @@
+
+
+
+
+ epp
+ com.cxyxiaomo
+ 0.0.1-SNAPSHOT
+
+ 4.0.0
+
+ microservice-provider-shop
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+
+ com.cxyxiaomo
+ microservice-common
+ 0.0.1-SNAPSHOT
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+
+
+
+ mysql
+ mysql-connector-java
+ runtime
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+
+ com.alibaba
+ druid
+
+
+
+ ch.qos.logback
+ logback-core
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-simple
+
+
+
+
+ org.springframework.boot
+ spring-boot-test
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+
+ com.alibaba.fastjson2
+ fastjson2
+
+
+
+
+ com.squareup.okhttp3
+ okhttp
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+
+
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+
+ maven-resources-plugin
+ 3.0.2
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ maven-surefire-plugin
+ 2.22.1
+
+
+ maven-jar-plugin
+ 3.0.2
+
+
+ maven-install-plugin
+ 2.5.2
+
+
+ maven-deploy-plugin
+ 2.8.2
+
+
+
+ maven-site-plugin
+ 3.7.1
+
+
+ maven-project-info-reports-plugin
+ 3.0.0
+
+
+
+
+
diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/ShopProvider.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/ShopProvider.java
new file mode 100644
index 0000000..149da5d
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/ShopProvider.java
@@ -0,0 +1,17 @@
+package com.cxyxiaomo.epp.shop;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+// 启动类
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients
+public class ShopProvider {
+ public static void main(String[] args) {
+ SpringApplication.run(ShopProvider.class, args);
+ }
+}
diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodsController.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodsController.java
new file mode 100644
index 0000000..01e9315
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodsController.java
@@ -0,0 +1,68 @@
+package com.cxyxiaomo.epp.shop.controller;
+
+import com.cxyxiaomo.epp.common.response.Res;
+import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
+import com.cxyxiaomo.epp.common.vo.GoodVO;
+import com.cxyxiaomo.epp.shop.service.GoodsServiceImpl;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping("/shop/good")
+public class GoodsController {
+
+ @Resource
+ GoodsServiceImpl goodsService;
+
+ /**
+ * 小程序端商品列表
+ *
+ * @return
+ */
+ @GetMapping("/miniprogram/list")
+ public Res list(@RequestParam(value = "cateId", required = false) Integer cateId,
+ @RequestParam(value = "searchText", required = false) String searchText) {
+ if (cateId != null && cateId <= 0) {
+ cateId = null;
+ }
+ if (searchText != null) {
+ searchText = searchText.trim();
+ if (searchText.contains("%") || searchText.contains("_")) {
+ searchText = searchText
+ .replaceAll("[_%]", "");
+ }
+ if ("".equals(searchText)) {
+ searchText = null;
+ }
+ }
+ List list = goodsService.list(cateId, searchText);
+ return Res.success(list);
+ }
+
+ /**
+ * 小程序端商品详情
+ *
+ * @return
+ */
+ @GetMapping("/miniprogram/detail")
+ public Res detail(@RequestParam("id") Long id) {
+ GoodVO goodVO = goodsService.getById(id);
+ return Res.success(goodVO);
+ }
+
+ /**
+ * 小程序端商品分类列表
+ *
+ * @return
+ */
+ @GetMapping("/miniprogram/cateList")
+ public Res cateList() {
+ List list = goodsService.cateList();
+ return Res.success(list);
+ }
+}
diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsCategoryDao.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsCategoryDao.java
new file mode 100644
index 0000000..66831a4
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsCategoryDao.java
@@ -0,0 +1,16 @@
+package com.cxyxiaomo.epp.shop.dao;
+
+import com.cxyxiaomo.epp.common.pojo.GoodCategory;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface GoodsCategoryDao {
+
+ List list();
+
+ GoodCategory getById(Integer id);
+}
diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsDao.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsDao.java
new file mode 100644
index 0000000..ae0f8d6
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodsDao.java
@@ -0,0 +1,17 @@
+package com.cxyxiaomo.epp.shop.dao;
+
+import com.cxyxiaomo.epp.common.pojo.Good;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface GoodsDao {
+
+ List list(@Param("cateId") Integer cateId, @Param("searchText") String searchText);
+
+ Good getById(Long id);
+}
diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsService.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsService.java
new file mode 100644
index 0000000..34bba37
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsService.java
@@ -0,0 +1,15 @@
+package com.cxyxiaomo.epp.shop.service;
+
+import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
+import com.cxyxiaomo.epp.common.vo.GoodVO;
+
+import java.util.List;
+
+public interface GoodsService {
+
+ List list(Integer cateId, String searchText);
+
+ GoodVO getById(Long id);
+
+ List cateList();
+}
diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsServiceImpl.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsServiceImpl.java
new file mode 100644
index 0000000..deee43d
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodsServiceImpl.java
@@ -0,0 +1,43 @@
+package com.cxyxiaomo.epp.shop.service;
+
+import com.cxyxiaomo.epp.common.pojo.Good;
+import com.cxyxiaomo.epp.common.pojo.GoodCategory;
+import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
+import com.cxyxiaomo.epp.common.vo.GoodVO;
+import com.cxyxiaomo.epp.shop.dao.GoodsCategoryDao;
+import com.cxyxiaomo.epp.shop.dao.GoodsDao;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+public class GoodsServiceImpl implements GoodsService {
+
+ @Resource
+ GoodsDao goodsDao;
+
+ @Resource
+ GoodsCategoryDao goodsCategoryDao;
+
+ @Override
+ public List list(Integer cateId, String searchText) {
+ List list = goodsDao.list(cateId, searchText);
+ List goodVOS = GoodVO.convertFrom(list);
+ return goodVOS;
+ }
+
+ @Override
+ public GoodVO getById(Long id) {
+ Good good = goodsDao.getById(id);
+ GoodVO goodVO = GoodVO.convertFrom(good);
+ return goodVO;
+ }
+
+ @Override
+ public List cateList() {
+ List list = goodsCategoryDao.list();
+ List goodCategoryVOList = GoodCategoryVO.convertFrom(list);
+ return goodCategoryVOList;
+ }
+}
diff --git a/backend/microservice-provider-shop-8003/src/main/resources/application-remote.yml b/backend/microservice-provider-shop-8003/src/main/resources/application-remote.yml
new file mode 100644
index 0000000..16bbb63
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/resources/application-remote.yml
@@ -0,0 +1,9 @@
+spring:
+ datasource:
+ url: jdbc:mysql://127.0.0.1:3306/epp?useUnicode=true&characterEncoding=utf8&useSSL=false
+ username: root
+ password: 123456
+ cloud:
+ nacos:
+ discovery:
+ server-addr: 106.75.217.14:8488
diff --git a/backend/microservice-provider-shop-8003/src/main/resources/application.yml b/backend/microservice-provider-shop-8003/src/main/resources/application.yml
new file mode 100644
index 0000000..b966e76
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/resources/application.yml
@@ -0,0 +1,23 @@
+server:
+ port: 8003
+
+# Mybatis 配置
+mybatis:
+ type-aliases-package: com.cxyxiaomo.epp.pojo
+ config-location: classpath:mybatis/mybatis-config.xml
+ mapper-locations: classpath:mybatis/mapper/*.xml
+
+# Spring 配置
+spring:
+ application:
+ name: microservice-provider-shop
+ cloud:
+ nacos:
+ discovery:
+ server-addr: 127.0.0.1:8848
+ datasource:
+ type: com.alibaba.druid.pool.DruidDataSource
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ url: jdbc:mysql://127.0.0.1:3306/epp?useUnicode=true&characterEncoding=utf8&useSSL=false
+ username: root
+ password: root
diff --git a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsCategoryMapper.xml b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsCategoryMapper.xml
new file mode 100644
index 0000000..423dd06
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsCategoryMapper.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsMapper.xml b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsMapper.xml
new file mode 100644
index 0000000..7ea0473
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodsMapper.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mybatis-config.xml b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mybatis-config.xml
new file mode 100644
index 0000000..a7de5d4
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mybatis-config.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/backend/microservice-provider-shop-8003/src/test/java/com/cxyxiaomo/AppTest.java b/backend/microservice-provider-shop-8003/src/test/java/com/cxyxiaomo/AppTest.java
new file mode 100644
index 0000000..ef44881
--- /dev/null
+++ b/backend/microservice-provider-shop-8003/src/test/java/com/cxyxiaomo/AppTest.java
@@ -0,0 +1,20 @@
+package com.cxyxiaomo;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+{
+ /**
+ * Rigorous Test :-)
+ */
+ @Test
+ public void shouldAnswerWithTrue()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/backend/microservice-provider-user-8001/src/main/resources/mybatis/mybatis-config.xml b/backend/microservice-provider-user-8001/src/main/resources/mybatis/mybatis-config.xml
index e67a32d..a7de5d4 100644
--- a/backend/microservice-provider-user-8001/src/main/resources/mybatis/mybatis-config.xml
+++ b/backend/microservice-provider-user-8001/src/main/resources/mybatis/mybatis-config.xml
@@ -6,5 +6,8 @@
+
+
+
diff --git a/backend/pom.xml b/backend/pom.xml
index 4aa923a..ddd5dcd 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -17,6 +17,7 @@
microservice-common
microservice-provider-user-8001
microservice-provider-access-8002
+ microservice-provider-shop-8003
microservice-provider-test-8011
diff --git a/database/epp.sql b/database/epp.sql
index d08f81f..6fbe103 100644
--- a/database/epp.sql
+++ b/database/epp.sql
@@ -1,17 +1,17 @@
/*
Navicat Premium Data Transfer
- Source Server : 192.168.2.29 测试库(装Nacos的Ubuntu)
+ Source Server : localhost MySQL 8.0 123456
Source Server Type : MySQL
- Source Server Version : 80032
- Source Host : 192.168.2.29:3306
+ Source Server Version : 80012
+ Source Host : localhost:3306
Source Schema : epp
Target Server Type : MySQL
- Target Server Version : 80032
+ Target Server Version : 80012
File Encoding : 65001
- Date: 17/03/2023 02:12:17
+ Date: 18/03/2023 21:36:40
*/
SET NAMES utf8mb4;
@@ -93,45 +93,51 @@ INSERT INTO `feedback1` VALUES (5, '123', '123456', '2022-03-28 19:34:04', 2, NU
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
- `goods_name` varchar(127) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品名称',
+ `goods_name` varchar(127) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品名称',
`category_id` int NULL DEFAULT 0 COMMENT '商品所属类目ID',
`brand` int NULL DEFAULT 0 COMMENT '商品品牌',
`gallery` varchar(1023) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品宣传图片列表,采用JSON数组格式',
`brief` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品简介',
- `is_on_sale` tinyint(1) NULL DEFAULT 1 COMMENT '是否上架',
+ `is_on_sale` tinyint(1) NULL DEFAULT 1 COMMENT '是否上架 0为下架 1为上架',
`sort_order` smallint NULL DEFAULT 100 COMMENT '排序',
`pic_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品页面商品图片',
`type` tinyint(1) NULL DEFAULT 0 COMMENT '商品类型',
- `unit` varchar(31) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '’件‘' COMMENT '商品单位,例如件、盒',
- `counter_price` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '专柜价格',
- `retail_price` decimal(10, 2) NULL DEFAULT 100000.00 COMMENT '零售价格',
+ `unit` varchar(31) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '件' COMMENT '商品单位,例如件、盒',
+ `counter_price` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '专柜价格(原价 / 划线价)',
+ `retail_price` decimal(10, 2) NULL DEFAULT 100000.00 COMMENT '零售价格(售价 / 未划线价)',
`detail` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '商品详细介绍,是富文本格式',
`deleted` tinyint(1) NULL DEFAULT 0 COMMENT '逻辑删除 0为正常 1为删除',
PRIMARY KEY (`id`) USING BTREE,
INDEX `category_id`(`category_id`) USING BTREE,
INDEX `brand_id`(`brand`) USING BTREE,
INDEX `sort_order`(`sort_order`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商品基本信息表' ROW_FORMAT = DYNAMIC;
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商品基本信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of goods
-- ----------------------------
-INSERT INTO `goods` VALUES (1, '口罩', 0, 0, NULL, NULL, 1, 100, NULL, 0, '’件‘', 0.00, 100000.00, NULL, 0);
+INSERT INTO `goods` VALUES (1, '口罩', 3, 0, NULL, '', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/gh-2b.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '件', 20.00, 48.00, NULL, 0);
+INSERT INTO `goods` VALUES (2, '水银温度计', 3, 0, NULL, '医用玻璃水银体温计腋下温度计家用成人儿童婴儿口腔发烧探热针', 1, 200, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '件', 59.90, 66.90, NULL, 0);
-- ----------------------------
-- Table structure for goods_category
-- ----------------------------
DROP TABLE IF EXISTS `goods_category`;
CREATE TABLE `goods_category` (
- `id` int NOT NULL,
+ `id` bigint NOT NULL AUTO_INCREMENT,
`category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品分类名',
- `order` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '排序',
+ `order` int NULL DEFAULT NULL COMMENT '排序',
PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of goods_category
-- ----------------------------
+INSERT INTO `goods_category` VALUES (1, '水果蔬菜', 1);
+INSERT INTO `goods_category` VALUES (2, '日用品', 2);
+INSERT INTO `goods_category` VALUES (3, '药品', 4);
+INSERT INTO `goods_category` VALUES (4, '防疫物资', 3);
+INSERT INTO `goods_category` VALUES (5, '零食', 5);
-- ----------------------------
-- Table structure for notice1
@@ -213,7 +219,7 @@ CREATE TABLE `user` (
-- ----------------------------
-- Records of user
-- ----------------------------
-INSERT INTO `user` VALUES (1, 'root', '99adc231b045331e514a516b4b7680f588e3823213abe901738bc3ad67b2f6fcb3c64efb93d18002588d3ccc1a49efbae1ce20cb43df36b38651f11fa75678e8', '管理员 密码root', '420111111111111111', NULL, 1, NULL, NULL, 0, NULL);
+INSERT INTO `user` VALUES (1, 'root', '99adc231b045331e514a516b4b7680f588e3823213abe901738bc3ad67b2f6fcb3c64efb93d18002588d3ccc1a49efbae1ce20cb43df36b38651f11fa75678e8', '管理员 密码root', '420111111111111111', NULL, 2, NULL, NULL, 0, NULL);
INSERT INTO `user` VALUES (2, 'lhz', 'lhz', '廖鸿志', NULL, NULL, 2, NULL, NULL, 0, NULL);
INSERT INTO `user` VALUES (3, '21180000', '21180000', '李', NULL, NULL, 2, NULL, NULL, 0, NULL);
INSERT INTO `user` VALUES (4, '211', '211', '11', NULL, NULL, 2, NULL, NULL, 0, NULL);
diff --git a/postman-collection/epp.postman_collection.json b/postman-collection/epp.postman_collection.json
index 7896b7b..13f2ce8 100644
--- a/postman-collection/epp.postman_collection.json
+++ b/postman-collection/epp.postman_collection.json
@@ -1,8 +1,9 @@
{
"info": {
- "_postman_id": "0d464ada-cc15-4b2f-a0b7-5ee5fc690c39",
+ "_postman_id": "2cec316d-df1e-4815-b5b7-b49cf2e9c197",
"name": "epp",
- "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
+ "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
+ "_exporter_id": "24657033"
},
"item": [
{
@@ -218,6 +219,101 @@
"response": []
}
]
+ },
+ {
+ "name": "ShopProvider",
+ "item": [
+ {
+ "name": "[线上] 获取商品列表",
+ "request": {
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "https://epp.only4.work/shop/good/miniprogram/list?cateId=4&searchText=罩",
+ "protocol": "https",
+ "host": [
+ "epp",
+ "only4",
+ "work"
+ ],
+ "path": [
+ "shop",
+ "good",
+ "miniprogram",
+ "list"
+ ],
+ "query": [
+ {
+ "key": "cateId",
+ "value": "4"
+ },
+ {
+ "key": "searchText",
+ "value": "%25%25",
+ "disabled": true
+ },
+ {
+ "key": "searchText",
+ "value": "罩"
+ }
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "[线上] 获取商品详情",
+ "request": {
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "https://epp.only4.work/shop/good/miniprogram/detail?id=1",
+ "protocol": "https",
+ "host": [
+ "epp",
+ "only4",
+ "work"
+ ],
+ "path": [
+ "shop",
+ "good",
+ "miniprogram",
+ "detail"
+ ],
+ "query": [
+ {
+ "key": "id",
+ "value": "1"
+ }
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "[线上] 获取商品分类列表",
+ "request": {
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "https://epp.only4.work/shop/good/miniprogram/cateList",
+ "protocol": "https",
+ "host": [
+ "epp",
+ "only4",
+ "work"
+ ],
+ "path": [
+ "shop",
+ "good",
+ "miniprogram",
+ "cateList"
+ ]
+ }
+ },
+ "response": []
+ }
+ ]
}
]
}
\ No newline at end of file
diff --git a/weixin-miniprogram/app.json b/weixin-miniprogram/app.json
index 6c6b59e..24b28ce 100644
--- a/weixin-miniprogram/app.json
+++ b/weixin-miniprogram/app.json
@@ -6,6 +6,7 @@
"pages/residents/report",
"pages/residents/reportHistory",
"pages/shop/shop",
+ "pages/shop/goodDetail",
"pages/scan/entrance",
"pages/person/person"
],
@@ -64,4 +65,4 @@
"lazyCodeLoading": "requiredComponents",
"style": "v2",
"sitemapLocation": "sitemap.json"
-}
\ No newline at end of file
+}
diff --git a/weixin-miniprogram/pages/shop/components/good-list-card.js b/weixin-miniprogram/pages/shop/components/good-list-card.js
index fbf26c6..fa68310 100644
--- a/weixin-miniprogram/pages/shop/components/good-list-card.js
+++ b/weixin-miniprogram/pages/shop/components/good-list-card.js
@@ -15,23 +15,29 @@ Component({
* 组件的初始数据
*/
data: {
- displayGoodsInfo: "",
- displayInfo: "",
+ // displayGoodsInfo: "",
},
- observers: {
- 'goodinfo': function (goodinfo) {
- console.log("observers -> goodinfo", goodinfo)
- this.setData({
- displayGoodsInfo: JSON.stringify(this.properties.goodinfo)
- })
- }
- },
+ // observers: {
+ // 'goodinfo': function (goodinfo) {
+ // console.log("observers -> goodinfo", goodinfo)
+ // this.setData({
+ // displayGoodsInfo: JSON.stringify(this.properties.goodinfo)
+ // })
+ // }
+ // },
/**
* 组件的方法列表
*/
methods: {
-
+ cardOntap(event) {
+ let dataset = event.currentTarget.dataset
+ console.log("cardOntap dataset", dataset)
+ let goodInfo = dataset.goodinfo
+ wx.navigateTo({
+ url: '/pages/shop/goodDetail?id=' + goodInfo.id,
+ })
+ }
}
})
diff --git a/weixin-miniprogram/pages/shop/components/good-list-card.wxml b/weixin-miniprogram/pages/shop/components/good-list-card.wxml
index d4f008d..e97d4fa 100644
--- a/weixin-miniprogram/pages/shop/components/good-list-card.wxml
+++ b/weixin-miniprogram/pages/shop/components/good-list-card.wxml
@@ -1,5 +1,5 @@
-
+
diff --git a/weixin-miniprogram/pages/shop/goodDetail.js b/weixin-miniprogram/pages/shop/goodDetail.js
new file mode 100644
index 0000000..5599458
--- /dev/null
+++ b/weixin-miniprogram/pages/shop/goodDetail.js
@@ -0,0 +1,85 @@
+// pages/shop/goodDetail.js
+
+const goodService = require("../../services/good")
+
+Page({
+
+ /**
+ * 页面的初始数据
+ */
+ data: {
+ goodId: -1,
+ goodinfo: {}
+ },
+
+ /**
+ * 生命周期函数--监听页面加载
+ */
+ onLoad(options) {
+ console.log("goodDetail ->options", options)
+ let goodId = options.id
+ this.setData({
+ goodId: goodId
+ })
+ this.loadPageData()
+ },
+
+ /**
+ * 生命周期函数--监听页面初次渲染完成
+ */
+ onReady() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面显示
+ */
+ onShow() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面隐藏
+ */
+ onHide() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面卸载
+ */
+ onUnload() {
+
+ },
+
+ /**
+ * 页面相关事件处理函数--监听用户下拉动作
+ */
+ onPullDownRefresh() {
+
+ },
+
+ /**
+ * 页面上拉触底事件的处理函数
+ */
+ onReachBottom() {
+
+ },
+
+ /**
+ * 用户点击右上角分享
+ */
+ onShareAppMessage() {
+
+ },
+
+ loadPageData() {
+ (async () => {
+ let goodDetail = await goodService.getGoodDetail(this.data.goodId)
+ console.log("goodDetail", goodDetail)
+ this.setData({
+ goodinfo: goodDetail
+ })
+ })();
+ }
+})
\ No newline at end of file
diff --git a/weixin-miniprogram/pages/shop/goodDetail.json b/weixin-miniprogram/pages/shop/goodDetail.json
new file mode 100644
index 0000000..ae4a221
--- /dev/null
+++ b/weixin-miniprogram/pages/shop/goodDetail.json
@@ -0,0 +1,4 @@
+{
+ "usingComponents": {},
+ "navigationBarTitleText": "商品详情"
+}
\ No newline at end of file
diff --git a/weixin-miniprogram/pages/shop/goodDetail.wxml b/weixin-miniprogram/pages/shop/goodDetail.wxml
new file mode 100644
index 0000000..216a329
--- /dev/null
+++ b/weixin-miniprogram/pages/shop/goodDetail.wxml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+ ¥
+ {{ goodinfo.counterPrice }}
+
+
+
+
+ ¥
+ {{ goodinfo.retailPrice }}
+
+
+ {{ goodinfo.goodsName }}
+
+
+
\ No newline at end of file
diff --git a/weixin-miniprogram/pages/shop/goodDetail.wxss b/weixin-miniprogram/pages/shop/goodDetail.wxss
new file mode 100644
index 0000000..8488725
--- /dev/null
+++ b/weixin-miniprogram/pages/shop/goodDetail.wxss
@@ -0,0 +1,68 @@
+/* pages/shop/goodDetail.wxss */
+.good-image {
+ width: 100%;
+ height: 100vw;
+}
+
+.good-detail {
+ padding: 5px 18px;
+}
+
+/* 商品价格 */
+.good-price {
+ white-space: nowrap;
+ font-weight: 700;
+ margin: 0;
+ display: inline;
+ position: relative;
+}
+
+.good-price-counter {
+ color: #fa4126;
+ font-size: 72rpx;
+}
+
+.good-price-retail {
+ color: #bbbbbb;
+ font-size: 32rpx;
+ margin: 0 0 0 18rpx;
+ font-weight: 500;
+}
+
+.good-price-counter .good-price-symbol {
+ font-size: 36rpx;
+ display: inline;
+ margin-right: 6rpx;
+}
+
+.good-price-retail .good-price-symbol {
+ font-size: 24rpx;
+ display: inline;
+}
+
+.good-price .good-price-number {
+ display: inline;
+}
+
+.good-price .good-price-line {
+ position: absolute;
+ top: 50%;
+ left: 0;
+ right: 0;
+ transform: translateY(-50%);
+ margin: 0;
+ background-color: currentColor;
+}
+
+/* 商品标题 */
+.good-title {
+ width: 600rpx;
+ font-weight: 500;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ overflow: hidden;
+ font-size: 32rpx;
+ word-break: break-all;
+ color: #333333;
+}
diff --git a/weixin-miniprogram/pages/shop/shop.js b/weixin-miniprogram/pages/shop/shop.js
index a7c0371..a520296 100644
--- a/weixin-miniprogram/pages/shop/shop.js
+++ b/weixin-miniprogram/pages/shop/shop.js
@@ -1,4 +1,7 @@
// pages/shop/shop.js
+
+const goodService = require("../../services/good")
+
Page({
/**
@@ -6,48 +9,49 @@ Page({
*/
data: {
sidebarActiveId: -1,
+ searchText: '',
sidebarList: [
{
id: -1,
- title: "全部分类",
- },
- {
- id: 1,
- title: "1",
- },
- {
- id: 2,
- title: "防疫物资",
- },
- {
- id: 3,
- title: "111",
- },
- {
- id: 4,
- title: "111",
- },
- {
- id: 5,
- title: "111",
+ categoryName: "全部分类",
},
+ // {
+ // id: 1,
+ // title: "1",
+ // },
+ // {
+ // id: 2,
+ // title: "防疫物资",
+ // },
+ // {
+ // id: 3,
+ // title: "111",
+ // },
+ // {
+ // id: 4,
+ // title: "111",
+ // },
+ // {
+ // id: 5,
+ // title: "111",
+ // },
],
tabbarList: [
- {
- id: 1,
- goodsName: "温度计",
- counterPrice: "10.00",
- retailPrice: "12.00",
- picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/gh-2b.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
- },
- {
- id: 2,
- goodsName: "医用口罩",
- counterPrice: "100.00",
- retailPrice: "12.50",
- picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
- }
+ // {
+ // id: 1,
+ // goodsName: "温度计",
+ // counterPrice: "10.00",
+ // retailPrice: "12.00",
+ // picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/gh-2b.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
+ // },
+ // {
+ // id: 2,
+ // goodsName: "医用口罩",
+ // counterPrice: "100.00",
+ // retailPrice: "12.50",
+ // picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
+ // }
]
},
@@ -55,7 +59,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
-
+ this.loadPageData();
},
/**
@@ -90,7 +94,8 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
-
+ console.log('sidebarActiveId', this.data.sidebarActiveId)
+ this.updatePageData()
},
/**
@@ -108,6 +113,20 @@ Page({
},
+ bindSearchInput(e) {
+ this.setData({
+ searchText: e.detail.value,
+ })
+ this.updatePageData()
+ },
+ clearSearchInput() {
+ this.setData({
+ searchText: '',
+ sidebarActiveId: -1,
+ })
+ this.updatePageData()
+ },
+
sidebarItemTap(event) {
// 清除原来的选中项,并设置新的选中项
// console.log("event.target", event.target)
@@ -117,6 +136,51 @@ Page({
this.setData({
sidebarActiveId: dataset.item.id,
})
+ this.loadPageData()
return
+ },
+
+ loadPageData() {
+ (async () => {
+ let goodCategoryListPromise = goodService.getGoodCategoryList()
+ let goodListPromise = goodService.getGoodList(this.data.sidebarActiveId, this.data.searchText)
+ Promise.all([
+ goodCategoryListPromise,
+ goodListPromise,
+ ]).then(data => {
+ let goodCategoryList = data[0]
+ let goodList = data[1]
+ console.log("goodCategoryList", goodCategoryList)
+ console.log("goodList", goodList)
+ goodCategoryList.unshift({
+ id: -1,
+ categoryName: "全部分类",
+ order: 0
+ })
+ console.log("goodCategoryList", goodCategoryList)
+ this.setData({
+ sidebarList: goodCategoryList,
+ tabbarList: goodList,
+ })
+ })
+ })();
+ },
+
+ updatePageData() {
+ (async () => {
+ this.setData({
+ tabbarList: [],
+ })
+ let goodListPromise = goodService.getGoodList(this.data.sidebarActiveId, this.data.searchText)
+ Promise.all([
+ goodListPromise,
+ ]).then(data => {
+ let goodList = data[0]
+ console.log("goodList", goodList)
+ this.setData({
+ tabbarList: goodList,
+ })
+ })
+ })();
}
})
\ No newline at end of file
diff --git a/weixin-miniprogram/pages/shop/shop.json b/weixin-miniprogram/pages/shop/shop.json
index f17f36b..5d7ce72 100644
--- a/weixin-miniprogram/pages/shop/shop.json
+++ b/weixin-miniprogram/pages/shop/shop.json
@@ -1,6 +1,7 @@
{
"usingComponents": {
- "listcard":"./components/good-list-card"
+ "listcard": "./components/good-list-card"
},
- "navigationBarTitleText": "生活物资"
+ "navigationBarTitleText": "生活物资",
+ "enablePullDownRefresh": true
}
\ No newline at end of file
diff --git a/weixin-miniprogram/pages/shop/shop.wxml b/weixin-miniprogram/pages/shop/shop.wxml
index 463f095..0627cc4 100644
--- a/weixin-miniprogram/pages/shop/shop.wxml
+++ b/weixin-miniprogram/pages/shop/shop.wxml
@@ -1,14 +1,20 @@
+
+
+