Commit 1f1243365676326e1709f0df9fcb37e6d11b7e6c

Authored by yvan.ni
1 parent d9df84d6

小程序自定义模板的 商品组合的组件

components/diy_goodsGroup/diy_goodsGroup.js
@@ -107,12 +107,13 @@ Component({ @@ -107,12 +107,13 @@ Component({
107 this.data.is_new = 1 107 this.data.is_new = 1
108 } 108 }
109 this.data.requestData = new Array(); 109 this.data.requestData = new Array();
  110 + //---将数组---
110 this.data.g_id = this.data.object.data; 111 this.data.g_id = this.data.object.data;
111 var arr = []; 112 var arr = [];
112 -  
113 - for (var i = 0; i < this.data.g_id.length; i += this.data.goodscount) {  
114 - arr.push(this.data.g_id.slice(i, i + this.data.goodscount)); 113 + for (var i = 0; i < this.data.g_id .length; i += this.data.goodscount) {
  114 + arr.push(this.data.g_id .slice(i, i + this.data.goodscount));
115 } 115 }
  116 +
116 this.data.firist_type_data = arr; 117 this.data.firist_type_data = arr;
117 this.init(this.data.classstyle_id, this.data.wgroup); 118 this.init(this.data.classstyle_id, this.data.wgroup);
118 }, 119 },
@@ -124,7 +125,7 @@ Component({ @@ -124,7 +125,7 @@ Component({
124 var th = this; 125 var th = this;
125 var g_id = this.data.g_id; 126 var g_id = this.data.g_id;
126 if (classstyle_id == 1) { 127 if (classstyle_id == 1) {
127 - //手动选择的时候 128 + //---手动选择的时候---
128 g_id = this.data.firist_type_data[th.data.firist_type_curr]; 129 g_id = this.data.firist_type_data[th.data.firist_type_curr];
129 th.data.firist_type_curr++; 130 th.data.firist_type_curr++;
130 } 131 }
@@ -136,76 +137,46 @@ Component({ @@ -136,76 +137,46 @@ Component({
136 137
137 //--初始化卡类-- 138 //--初始化卡类--
138 th.card_init(); 139 th.card_init();
139 -  
140 var os=getApp().globalData.setting; 140 var os=getApp().globalData.setting;
141 -  
142 classstyle_id = classstyle_id + ""; 141 classstyle_id = classstyle_id + "";
143 switch (classstyle_id) { 142 switch (classstyle_id) {
144 - case "1":  
145 - g_id.forEach(function (val, ind) {  
146 - var item = {};  
147 - var prom_id = null;  
148 - console.log(val.goodsid);  
149 - app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goodsid, {}).then(res => {  
150 - //商品地址  
151 - var goods = res.data.data;  
152 - th.setData({  
153 - goods_btn: res.data.data  
154 - })  
155 -  
156 - item.goods_name = goods.goods_name;  
157 - item.goods_img = th.data.imghost + goods.original_img;  
158 - item.market_price = goods.market_price;  
159 - item.shop_price = goods.shop_price;  
160 - item.sales_sum = goods.sales_sum;  
161 - item.goods_id = goods.goods_id;  
162 - item.cardprice1 = goods.cardprice1;  
163 - item.cardprice2 = goods.cardprice2;  
164 - item.cardprice3 = goods.cardprice3;  
165 -  
166 - prom_id = res.data.data.prom_id;  
167 -  
168 - var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单  
169 -  
170 - var url = "";  
171 - if (prom_type == 6) {  
172 - url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id;  
173 - } else if (prom_type == 1) {  
174 - url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id;  
175 - }  
176 - if(url==""){  
177 - th.data.requestData.push(item);  
178 - th.setData({ goods_array: th.data.requestData, });  
179 - if (th.data.firist_type_curr == th.data.firist_type_data.length) {  
180 - th.setData({ goods_btn: [] });  
181 - }  
182 - }else{  
183 - return app.request.promiseGet(url, {})  
184 - }  
185 -  
186 - }).then(res => {  
187 - index++;  
188 - var prom =null  
189 - if (res && res.data) res.data.data;  
190 - var now=ut.gettimestamp();  
191 - if (prom != null && prom.is_end==0 && prom.end_time>now && prom.show_time<now) {  
192 - item.prom_price = res.data.data.price;  
193 - }  
194 - th.data.requestData.push(item);  
195 - th.setData({  
196 - goods_array: th.data.requestData,  
197 - });  
198 143
199 - if (th.data.firist_type_curr == th.data.firist_type_data.length) {  
200 - th.setData({  
201 - goods_btn: []  
202 - });  
203 - }  
204 - })  
205 - }) 144 + //---手动选择商品---
  145 + case "1":
  146 + var str="";
  147 + for (var i = 0; i < g_id.length; i++) {
  148 + str += g_id[i].goodsid + ",";
  149 + }
  150 + str=str.substring(0, str.length - 1);
  151 + app.request.get("/api/weshop/goods/getgoodslistOrdby?store_id=" + os.stoid + "&goodsidlist=" + str, {
  152 + success: function(res) {
  153 + console.log("121212");
  154 + if(res.data.code==0 && res.data.data){
  155 + var rData = th.data.requestData;
  156 + if (rData == null) rData=[];
  157 + var now=ut.gettimestamp();
  158 +
  159 + var new_arr=[];
  160 + for (var ii in res.data.data){
  161 + var item=res.data.data[ii];
  162 + item.goods_img=th.data.imghost + item.original_img;
  163 + if(item.e_time<now) {item.prom_type=0; item.prom_price=0;}
  164 + if(item.warm_uptime>now) {item.prom_type=0; item.prom_price=0;}
  165 + new_arr.push(item);
  166 + }
  167 + rData = rData.concat(new_arr);
  168 + th.data.requestData = rData;
  169 + th.setData({ goods_array: rData });
  170 + //---控制有没有加载更多的按钮---
  171 + if (th.data.firist_type_curr == th.data.firist_type_data.length) {th.setData({ goods_btn: [] }); }
  172 + else th.setData({ goods_btn: res.data});
  173 + }
  174 + }
  175 +
  176 + })
  177 +
206 break; 178 break;
207 case "2": 179 case "2":
208 -  
209 var item = {}; 180 var item = {};
210 app.request.promiseGet("/api/weshop/goods/page", { 181 app.request.promiseGet("/api/weshop/goods/page", {
211 data: { 182 data: {