From 1f1243365676326e1709f0df9fcb37e6d11b7e6c Mon Sep 17 00:00:00 2001 From: yvan.ni <765199919@qq.com> Date: Fri, 27 Dec 2019 17:54:00 +0800 Subject: [PATCH] 小程序自定义模板的 商品组合的组件 --- components/diy_goodsGroup/diy_goodsGroup.js | 107 +++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------- 1 file changed, 39 insertions(+), 68 deletions(-) diff --git a/components/diy_goodsGroup/diy_goodsGroup.js b/components/diy_goodsGroup/diy_goodsGroup.js index 71a584d..1514c65 100644 --- a/components/diy_goodsGroup/diy_goodsGroup.js +++ b/components/diy_goodsGroup/diy_goodsGroup.js @@ -107,12 +107,13 @@ Component({ this.data.is_new = 1 } this.data.requestData = new Array(); + //---将数组--- this.data.g_id = this.data.object.data; var arr = []; - - for (var i = 0; i < this.data.g_id.length; i += this.data.goodscount) { - arr.push(this.data.g_id.slice(i, i + this.data.goodscount)); + for (var i = 0; i < this.data.g_id .length; i += this.data.goodscount) { + arr.push(this.data.g_id .slice(i, i + this.data.goodscount)); } + this.data.firist_type_data = arr; this.init(this.data.classstyle_id, this.data.wgroup); }, @@ -124,7 +125,7 @@ Component({ var th = this; var g_id = this.data.g_id; if (classstyle_id == 1) { - //手动选择的时候 + //---手动选择的时候--- g_id = this.data.firist_type_data[th.data.firist_type_curr]; th.data.firist_type_curr++; } @@ -136,76 +137,46 @@ Component({ //--初始化卡类-- th.card_init(); - var os=getApp().globalData.setting; - classstyle_id = classstyle_id + ""; switch (classstyle_id) { - case "1": - g_id.forEach(function (val, ind) { - var item = {}; - var prom_id = null; - console.log(val.goodsid); - app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goodsid, {}).then(res => { - //商品地址 - var goods = res.data.data; - 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; - item.cardprice1 = goods.cardprice1; - item.cardprice2 = goods.cardprice2; - item.cardprice3 = goods.cardprice3; - - prom_id = res.data.data.prom_id; - - var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单 - - var url = ""; - if (prom_type == 6) { - url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id; - } else if (prom_type == 1) { - url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id; - } - if(url==""){ - th.data.requestData.push(item); - th.setData({ goods_array: th.data.requestData, }); - if (th.data.firist_type_curr == th.data.firist_type_data.length) { - th.setData({ goods_btn: [] }); - } - }else{ - return app.request.promiseGet(url, {}) - } - - }).then(res => { - index++; - var prom =null - if (res && res.data) res.data.data; - var now=ut.gettimestamp(); - if (prom != null && prom.is_end==0 && prom.end_time>now && prom.show_timenow) {item.prom_type=0; item.prom_price=0;} + new_arr.push(item); + } + rData = rData.concat(new_arr); + th.data.requestData = rData; + th.setData({ goods_array: rData }); + //---控制有没有加载更多的按钮--- + if (th.data.firist_type_curr == th.data.firist_type_data.length) {th.setData({ goods_btn: [] }); } + else th.setData({ goods_btn: res.data}); + } + } + + }) + break; case "2": - var item = {}; app.request.promiseGet("/api/weshop/goods/page", { data: { -- libgit2 0.21.4