yann 6 달 전
부모
커밋
af310d2079
5개의 변경된 파일35개의 추가작업 그리고 10개의 파일을 삭제
  1. 26 2
      components/product-list/product-list.js
  2. 1 1
      pages/Mall/hotCommodity/hotCommodity.wxml
  3. 2 2
      pages/index/index.js
  4. 4 3
      service/api.js
  5. 2 2
      utils/http.js

+ 26 - 2
components/product-list/product-list.js

@@ -1,4 +1,9 @@
 // components/product-list/product-list.js
+
+// 获取应用实例
+const {API} = require('../../service/api.js');
+
+
 Component({
     properties: {
         // header嵌入的位置,index:首页
@@ -52,9 +57,28 @@ Component({
         ],
     },
     methods: {
-        
+        // 获取今日热门商品列表
+        getHotCommodity(){
+            API.getLeftProds().then(res=>{
+                console.log(res);
+            })
+        },
+        // 获取上新商品列表
+        getNewCommodity(){
+            API.getMiddleProds().then(res=>{
+                console.log(res);
+            })
+        },
+        // 获取预售商品列表
+        getPresaleCommodity(){
+            API.getRightProds().then(res=>{
+                console.log(res);
+            })
+        }
     },
     ready: function(){
-        console.log(this.data.position);
+        if(this.data.position === 'hot') this.getHotCommodity();
+        if(this.data.position === 'new') this.getNewCommodity();
+        if(this.data.position === 'presale') this.getPresaleCommodity();
     }
 })

+ 1 - 1
pages/Mall/hotCommodity/hotCommodity.wxml

@@ -4,4 +4,4 @@
 <header position="hot"></header>
 
 <!-- 商品列表 -->
-<product-list></product-list>
+<product-list position="hot"></product-list>

+ 2 - 2
pages/index/index.js

@@ -1,5 +1,5 @@
 // index.js
-const { HomepageApi } = require('../../service/api.js');
+const { API } = require('../../service/api.js');
 
 const App = getApp();
 
@@ -73,7 +73,7 @@ Component({
       console.log("onLoad");
       console.log('App.globalData', App.globalData);
 
-      const res = await HomepageApi.getBanners({});
+      const res = await API.getBanners({});
       console.log('res', res);
     },
   },

+ 4 - 3
service/api.js

@@ -19,8 +19,8 @@ export const Qiniu = {
   },
 }
 
-// HomepageApiController
-export const HomepageApi = {
+// APIController
+export const API = {
   /** 
    * 返回示例:{
     "bannerList": [
@@ -119,7 +119,8 @@ export const HomepageApi = {
     ]
   }
   */
-  getLeftProds: function (payload) {
+  // 获取热门商品
+  getLeftProds: function (payload = {}) {
     return http.get("/api/store/homepage/leftProds", {
       ...payload,
     });

+ 2 - 2
utils/http.js

@@ -74,8 +74,8 @@ function getPromise(url, data, method) {
         method: method,
         data: data,
         success: function (res) {
-          if (res.data.code === 200) {
-            resolve(res.data.data);
+          if (res.statusCode === 200) {
+            resolve(res.data);
           } else {
             if (res.statusCode === 401) {
               reject(401);