From cff0e1914eccb0d510930d0824f902ab40b96d89 Mon Sep 17 00:00:00 2001 From: yvan.ni <765199919@qq.com> Date: Thu, 10 Oct 2019 16:02:53 +0800 Subject: [PATCH] 自定义模板商品分组, 减少接口的调用 --- components/diy_goodsGroup/diy_goodsGroup.js | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------- 1 file changed, 63 insertions(+), 75 deletions(-) diff --git a/components/diy_goodsGroup/diy_goodsGroup.js b/components/diy_goodsGroup/diy_goodsGroup.js index 3c0a401..d01be96 100644 --- a/components/diy_goodsGroup/diy_goodsGroup.js +++ b/components/diy_goodsGroup/diy_goodsGroup.js @@ -1,9 +1,3 @@ -// var e = function(e) { -// return e && e.__esModule ? e : { -// default: e -// }; -// }(require("../../utils/LoadMore3.js")), -// n = new e.default(), var t = getApp(), a = t.request, o = t.globalData.setting, @@ -82,7 +76,6 @@ Component({ }, methods: { // 这里是一个自定义方法 - init: function (classstyle_id, wgroup) { var th = this; var g_id = this.data.g_id; @@ -93,9 +86,11 @@ Component({ } var th = this, - app = getApp(), - index = 0, - gdata = []; + app = getApp(), + index = 0, + gdata = []; + + classstyle_id = classstyle_id + ""; switch (classstyle_id) { case "1": g_id.forEach(function (val, ind) { @@ -146,15 +141,15 @@ Component({ }) break; case "2": - console.log(2222222222222222222); + var item = {}; app.request.promiseGet("/api/weshop/goods/page", { data: { - store_id: 1, + store_id: os.stoid , is_recommend: th.data.is_recommend, is_hot: th.data.is_hot, is_new: th.data.is_new, - pageSize: th.data.goodscount , + pageSize: th.data.goodscount, page: th.data.currentPage, } }).then(res => { @@ -164,38 +159,34 @@ Component({ goods_btn: res.data.data.pageData, total: res.data.data.total }) - console.log(66666666677777777777); - console.log(res.data.data.total); - console.log(res.data); - console.log(this.data.total); th.data.currentPage++; goods.forEach(function (val, ind) { var item = {}; var prom_id = null; console.log(val.goodsid); - app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => { - //商品地址 - var goods = res.data.data; + //app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => { + //商品地址 + //var goods = res.data.data; - item.goods_name = goods.goods_name; - item.goods_img = th.data.imghost + goods.original_img; - item.market_price = goods.market_price; - item.shop_price = goods.shop_price; - item.sales_sum = goods.sales_sum; - item.goods_id = goods.goods_id; - prom_id = res.data.data.prom_id; + item.goods_name = val.goods_name; + item.goods_img = th.data.imghost + val.original_img; + item.market_price = val.market_price; + item.shop_price = val.shop_price; + item.sales_sum = val.sales_sum; + item.goods_id = val.goods_id; + prom_id = val.prom_id; - var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单 + var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单 - var url = ""; - if (prom_type == 1) { - url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id; - } else if (prom_type == 6) { - url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id; - } - return app.request.promiseGet(url, {}) - }).then(res => { + var url = ""; + if (prom_type == 1) { + url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id; + } else if (prom_type == 6) { + url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id; + } + + app.request.promiseGet(url, {}).then(res => { var prom = res.data.data; if (prom != null) { item.shop_price = res.data.data.price; @@ -203,19 +194,18 @@ Component({ th.data.requestData.push(item); th.setData({ goods_array: th.data.requestData, - page: th.data.currentPage-1, + page: th.data.currentPage - 1, }); }) }) }) - break; case "3": var item = {}; app.request.promiseGet("/api/weshop/goodsGroup/pageGoodsList", { data: { - store_id: 1, + store_id:os.stoid , gpid: wgroup, pageSize: th.data.goodscount, page: th.data.currentPage, @@ -223,45 +213,41 @@ Component({ }).then(res => { //商品地址 var goods = res.data.data.pageData; - console.log("333333333zwp" ); - console.log(res.data.data); th.setData({ - goods_btn: res.data.data.pageData, - total: res.data.data.total + goods_btn: res.data.data.pageData, total: res.data.data.total }) - console.log("goods_btn"); - console.log(th.data.goods_btn); + th.data.currentPage++; goods.forEach(function (val, ind) { var item = {}; var prom_id = null; console.log(val.goodsid); - app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => { - //商品地址 - var goods = res.data.data; - console.log("goods"); - console.log(goods); - // th.setData({ - // goods_btn: res.data.data - // }) - item.goods_name = goods.goods_name; - item.goods_img = th.data.imghost + goods.original_img; - item.market_price = goods.market_price; - item.shop_price = goods.shop_price; - item.sales_sum = goods.sales_sum; - item.goods_id = goods.goods_id; - prom_id = res.data.data.prom_id; + //app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => { + //商品地址 + var goods = res.data.data; + console.log("goods"); + console.log(goods); + // th.setData({ + // goods_btn: res.data.data + // }) + item.goods_name = val.goods_name; + item.goods_img = th.data.imghost + val.original_img; + item.market_price = val.market_price; + item.shop_price = val.shop_price; + item.sales_sum = val.sales_sum; + item.goods_id = val.goods_id; + prom_id = val.prom_id; - var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单 + var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单 - var url = ""; - if (prom_type == 1) { - url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id; - } else if (prom_type == 6) { - url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id; - } - return app.request.promiseGet(url, {}) - }).then(res => { + var url = ""; + if (prom_type == 1) { + url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id; + } else if (prom_type == 6) { + url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id; + } + + app.request.promiseGet(url, {}).then(res => { var prom = res.data.data; if (prom != null) { item.shop_price = res.data.data.price; @@ -269,14 +255,16 @@ Component({ th.data.requestData.push(item); th.setData({ goods_array: th.data.requestData, - page: th.data.currentPage-1, + page: th.data.currentPage - 1, }); }) }) + }) break; } }, + setLoading: function () { var that = this; that.init(that.data.classstyle_id, that.data.wgroup); @@ -284,10 +272,10 @@ Component({ //图片失败,默认图片 bind_bnerr3: function (e) { - var _errImg = e.target.dataset.errorimg; - var _errObj = {}; - _errObj[_errImg] = this.data.imghost+"/public/images/default_goods_image_240.gif"; - this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; - }, + var _errImg = e.target.dataset.errorimg; + var _errObj = {}; + _errObj[_errImg] = this.data.imghost + "/public/images/default_goods_image_240.gif"; + this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; + } } }) \ No newline at end of file -- libgit2 0.21.4